00001 #ifndef Impala_Core_Array_Trait_CoordinateEnumerators_h
00002 #define Impala_Core_Array_Trait_CoordinateEnumerators_h
00003 
00004 namespace Impala
00005 {
00006 namespace Core
00007 {
00008 namespace Array
00009 {
00010 namespace Trait
00011 {
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 template<class DstArrayT, class SrcArrayT>
00063 class CoordinateEnumeratorAll2
00064 {
00065 public:
00066     CoordinateEnumeratorAll2(DstArrayT* dst, SrcArrayT* src)
00067     {
00068         mWidth = dst->CW();
00069         mHeight = dst->CH();
00070         mX = 0;
00071         mY = 0;
00072         mDone = false;
00073         mSrcPointer = dst->CPB(mX, mY);
00074         mDstPointer = src->CPB(mX, mY);
00075     }
00076 
00077     typename DstArrayT::StorType*
00078     DstPointer(DstArrayT* dst)
00079     {
00080         return mDstPointer;
00081     }
00082 
00083     typename SrcArrayT::ArithType*
00084     SrcPointer(SrcArrayT* src)
00085     {
00086         return mSrcPointer;
00087     }
00088 
00089     void
00090     NextCoordinate(DstArrayT* dst, SrcArrayT* src)
00091     {
00092         mX++;
00093         mDstPointer += DstArrayT::ElemSize();
00094         mSrcPointer += SrcArrayT::ElemSize();
00095         if (mX >= mWidth)
00096         {
00097             mX = 0;
00098             mY++;
00099             mDstPointer = dst->CPB(mX, mY);
00100             mSrcPointer = src->CPB(mX, mY);
00101             if (mY >= mHeight)
00102             {  
00103                 mDone = true;
00104                 mY = 0;
00105             }
00106         }
00107     }
00108 
00109     bool
00110     Done() const
00111     {
00112         return mDone;
00113     }
00114 
00115     int
00116     X() const
00117     {
00118         return mX;
00119     }
00120 
00121     int
00122     Y() const
00123     {
00124         return mY;
00125     }
00126 
00127 private:
00128     int mHeight, mWidth;
00129     int mX, mY;
00130     bool mDone;
00131     typename DstArrayT::StorType* mDstPointer;
00132     typename SrcArrayT::ArithType* mSrcPointer;
00133 };
00134 
00135 
00136 
00137 
00138 
00139 #include "Core/Geometry/Rectangle.h"
00140 
00141 template<class DstArrayT, class SrcArrayT>
00142 class CoordinateEnumeratorRect
00143 {
00144 public:
00145     CoordinateEnumeratorRect(DstArrayT* dst, SrcArrayT* src,
00146                              const Geometry::Rectangle& rect)
00147         :mRect(rect)
00148     {
00149         mX = rect.mLeft;
00150         mY = rect.mTop;
00151         mDone = false;
00152         mDstPointer = dst->CPB(mX, mY);
00153         mSrcPointer = src->CPB(mX, mY);
00154     }
00155 
00156     typename DstArrayT::StorType*
00157     DstPointer(DstArrayT* dst)
00158     {
00159         return mDstPointer;
00160     }
00161 
00162     typename SrcArrayT::StorType*
00163     SrcPointer(SrcArrayT* src)
00164     {
00165         return mSrcPointer;
00166     }
00167 
00168     void
00169     NextCoordinate(DstArrayT* dst, SrcArrayT* src)
00170     {
00171         mX++;
00172         mDstPointer += DstArrayT::ElemSize();
00173         mSrcPointer += SrcArrayT::ElemSize();
00174         if (mX >= mRect.Right())
00175         {
00176             mX = mRect.Left();
00177             mY++;
00178             mDstPointer = dst->CPB(mX, mY);
00179             mSrcPointer = src->CPB(mX, mY);
00180             if (mY >= mRect.Bottom())
00181             {  
00182                 mDone = true;
00183                 mY = mRect.Top();
00184             }
00185         }
00186     }
00187 
00188     bool
00189     Done() const
00190     {
00191         return mDone;
00192     }
00193 
00194     int
00195     X() const
00196     {
00197         return mX;
00198     }
00199 
00200     int
00201     Y() const
00202     {
00203         return mY;
00204     }
00205 
00206 private:
00207     const Geometry::Rectangle& mRect;
00208     int mX, mY;
00209     bool mDone;
00210     typename DstArrayT::StorType* mDstPointer;
00211     typename SrcArrayT::StorType* mSrcPointer;
00212 };
00213 
00214 } 
00215 } 
00216 } 
00217 } 
00218 
00219 #endif