Go to the documentation of this file.00001
00009 #ifndef MIRROR_H
00010 #define MIRROR_H
00011
00012 #include "ImageToImageOperator.h"
00013
00014
00015
00016
00017 namespace puma2 {
00018
00026 template <class T> class Mirror : public ImageToImageOperator<T,T>
00027 {
00028 private:
00029 bool mVertical;
00030 bool mHorizontal;
00031
00032 public:
00033
00039 virtual void apply(const T & iImg, T & oImg);
00040
00044 Mirror(const bool iVertical = true, const bool iHorizontal=true);
00045
00049 virtual ~Mirror();
00050
00054 void setVertical(const bool iEnable=true){
00055 mVertical=iEnable;
00056 };
00057
00061 void setHorizontal(const bool iEnable=true){
00062 mHorizontal=iEnable;
00063 };
00064
00069 bool getHorizontalEnabled() const {
00070 return mHorizontal;
00071 };
00072
00077 bool getVerticalEnabled() const {
00078 return mVertical;
00079 };
00080 };
00081
00082 template <class T> Mirror<T>::Mirror(const bool iVertical,
00083 const bool iHorizontal){
00084 mVertical = iVertical;
00085 mHorizontal = iHorizontal;
00086 }
00087
00088 template <class T> Mirror<T>::~Mirror(){
00089 }
00090
00091 template <class T> void Mirror<T>::apply(const T & iImg, T & oImg){
00092
00093
00094 if (iImg == oImg)
00095 throw "No inplace operator";
00096
00097
00098 int numOfChannels = T::numberOfChannels() - 1;
00099
00100
00101 if ( mVertical == true && mHorizontal == true ) {
00102 for (int y = iImg.getHeight() - 1 ; y >= 0; --y){
00103 for (int x = iImg.getWidth() - 1 ; x >= 0; --x){
00104 for (int n = numOfChannels ; n >= 0; --n) {
00105 oImg.sample(iImg.getWidth() - x - 1, iImg.getHeight() - y - 1, n) =
00106 iImg.sample(x, y, n);
00107 }
00108 }
00109 }
00110 } else {
00111 if ( mVertical == true ) {
00112 for (int y = iImg.getHeight() - 1 ; y >= 0; --y){
00113 for (int x = iImg.getWidth() - 1 ; x >= 0; --x){
00114 for (int n = numOfChannels ; n >= 0; --n) {
00115 oImg.sample(x, iImg.getHeight() - y - 1, n) = iImg.sample(x, y, n);
00116 }
00117 }
00118 }
00119 }
00120
00121 if ( mHorizontal == true ) {
00122 for (int y = iImg.getHeight() - 1 ; y >= 0; --y){
00123 for (int x = iImg.getWidth() - 1 ; x >= 0; --x){
00124 for (int n = numOfChannels ; n >= 0; --n) {
00125 oImg.sample(iImg.getWidth() - x - 1, y, n) = iImg.sample(x, y, n);
00126 }
00127 }
00128 }
00129 }
00130
00131 if ( mVertical == false && mHorizontal == false ) {
00132
00133
00134
00135 for (int y = iImg.getHeight() - 1 ; y >= 0; --y){
00136 for (int x = iImg.getWidth() - 1 ; x >= 0; --x){
00137 for (int n = numOfChannels ; n >= 0; --n) {
00138 oImg.sample(x,y,n) = iImg.sample(x,y,n);
00139 }
00140 }
00141 }
00142 }
00143 }
00144 }
00145
00146 }
00147
00148 #endif