MultiElementImage.h
Go to the documentation of this file.
00001 
00009 #ifndef MultiElementImageTemplate_H
00010 #define MultiElementImageTemplate_H
00011 
00012 #include "BaseImageTemplate.h"
00013 
00014 namespace puma2
00015 {
00016 
00017 //Class acts exactly like an array, only that it supports the assignment operator.
00018 template <class T, int N> class MultiElementPixel
00019 {
00020   public:
00021 
00022     T data[N];
00023 
00024     inline operator T*() { return data; }
00025     inline operator const T*() const { return data; }
00026 
00027     inline MultiElementPixel< T, N >& operator=( MultiElementPixel< T, N > other ) {
00028       for ( unsigned i=0; i < N; i++ )
00029       {
00030         data[i] = other.data[i];
00031       }
00032       return *this;
00033     }
00034 };
00035 
00036 template <class T, int N> class MultiElementImageIter;
00037 template <class T, int N> class MultiElementImageIterChannel;
00038 
00050 template <class T, int N> class MultiElementImage : public TBaseImg < MultiElementPixel< T, N > >
00051 {
00052     friend class MultiElementImageIter<T, N>;
00053     friend class MultiElementImageIterChannel<T, N>;
00054   public:
00055     typedef T ElementType;     
00056     typedef MultiElementPixel< T, N > PixelType;    
00057   public:
00058     static int numberOfChannels() { return N; }
00059     MultiElementImage ( int width = 0, int height = 0 ) : TBaseImg < MultiElementPixel< T, N > > ( width, height ) {}
00061     MultiElementImage ( int width, int height, MultiElementImage* master, int xOffset, int yOffset )
00062         : TBaseImg < MultiElementPixel< T, N > > ( width, height, master, xOffset, yOffset ) {}
00063     const ElementType sample ( int x, int y, int n ) const {
00064       assert ( n < N );
00065       return TBaseImg < MultiElementPixel< T, N > >::c0[y][x][n];
00066     }
00067     ElementType& sample ( int x, int y, int n ) {
00068       assert ( n < N );
00069       return TBaseImg < MultiElementPixel< T, N > >::c0[y][x][n];
00070     }
00071 
00073     MultiElementImageIter<T, N> begin() {
00074       MultiElementImageIter<T, N> iter;
00075       iter.start = & this->c0[0][0];
00076       iter.end = iter.start + this->getHeight() * this->getWidth();
00077       iter.curr = iter.start;
00078       // cerr << "Begin Curr: " << reinterpret_cast<unsigned long>(iter.curr) << endl;
00079       return iter;
00080     }
00082     MultiElementImageIterChannel<T, N> begin ( int n ) {
00083       MultiElementImageIterChannel<T, N> iter;
00084       iter.start = & this->c0[0][0];
00085       iter.end = iter.start + this->getHeight() * this->getWidth();
00086       iter.curr = iter.start;
00087       // cerr << "Begin Curr: " << reinterpret_cast<unsigned long>(iter.curr) << endl;
00088       iter.c = n;
00089       return iter;
00090     }
00092     MultiElementImageIter<T, N> end() {
00093       MultiElementImageIter<T, N> iter;
00094       iter.start = & this->c0[0][0];
00095       iter.end = iter.start + this->getHeight() * this->getWidth();
00096       iter.curr = iter.end;
00097       // cerr << "End Curr: " << reinterpret_cast<unsigned long>(iter.curr) << endl;
00098       return iter;
00099     }
00101     MultiElementImageIterChannel<T, N> end ( int n ) {
00102       MultiElementImageIterChannel<T, N> iter;
00103       iter.start = & this->c0[0][0];
00104       iter.end = iter.start + this->getHeight() * this->getWidth();
00105       iter.curr = iter.end;
00106       // cerr << "End Curr: " << reinterpret_cast<unsigned long>(iter.curr) << endl;
00107       iter.c = n;
00108       return iter;
00109     }
00110     typedef MultiElementImageIter<T, N> PixelIterator;           //< Simplify notation
00111     typedef MultiElementImageIterChannel<T, N> ChannelIterator;  //< Simplify notation
00112 };
00113 
00115 template <class T, int N> class MultiElementImageIter
00116 {
00117     friend class MultiElementImage<T, N>;
00118     typedef T P[N];   
00119     P * start;
00120     P * curr;
00121     P * end;
00122   public:
00123     bool operator== ( const MultiElementImageIter& i ) const {
00124       // cerr << "Compare: " << reinterpret_cast<unsigned long>(i.curr) << " to "
00125       //                    << reinterpret_cast<unsigned long>(curr) << endl;
00126       return i.curr == curr;
00127     }
00128     bool operator!= ( const MultiElementImageIter& i ) const
00129     { return ! operator== ( i ); }
00131     MultiElementImageIter& operator++ ()
00132     { curr++; return *this; }
00133     MultiElementImageIter  operator++ ( int )
00134     { MultiElementImageIter old = *this; ++curr; return old; }
00135     MultiElementImageIter& operator-- ()
00136     { curr--; return *this; }
00137     MultiElementImageIter  operator-- ( int )
00138     { MultiElementImageIter old = *this; --curr; return old; }
00139     P& operator * ()
00140     { return * curr; }
00141     P * operator-> ()
00142     { return curr; }
00143     operator P* ()
00144     { return curr; }
00145 };
00146 
00148 template <class T, int N> class MultiElementImageIterChannel
00149 {
00150     friend class MultiElementImage<T, N>;
00151     typedef T P[N];
00152     P * start;
00153     P * curr;
00154     P * end;
00155     int c;
00156   public:
00157     bool operator== ( const MultiElementImageIterChannel& i ) const
00158     { return i.curr == curr; }
00159     bool operator!= ( const MultiElementImageIterChannel& i ) const
00160     { return ! operator== ( i ); }
00161     MultiElementImageIterChannel& operator++ ()
00162     { curr++; return *this; }
00163     MultiElementImageIterChannel  operator++ ( int )
00164     { MultiElementImageIterChannel old = *this; ++curr; return old; }
00165     MultiElementImageIterChannel& operator-- ()
00166     { curr--; return *this; }
00167     MultiElementImageIterChannel  operator-- ( int )
00168     { MultiElementImageIterChannel old = *this; --curr; return old; }
00169     T& operator * ()
00170     { return * curr[c]; }
00171     T ** operator-> ()
00172     { return curr[c]; }
00173     operator P** ()
00174     { return curr[c]; }
00175 };
00176 
00177 }
00178 
00179 #endif


obj_rec_gui
Author(s): AGAS/agas@uni-koblenz.de
autogenerated on Mon Oct 6 2014 02:53:43