00001 #ifndef Impala_Core_Array_Trait_TalkNgbP1Loop_h
00002 #define Impala_Core_Array_Trait_TalkNgbP1Loop_h
00003
00004 #include "Core/Array/Pattern/Categories.h"
00005 #include "Core/Array/Pattern/Cnum.h"
00006 #include "Core/Array/Element/E1Cast.h"
00007
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 namespace Trait
00015 {
00016
00017
00020 template<class DstArrayT, class SrcArrayT>
00021 class TalkNgbP1Loop
00022 {
00023 public:
00024
00026 typedef Pattern::TagLoop IteratorCategory;
00027
00029 typedef Pattern::Tag1Phase PhaseCategory;
00030
00031 typedef typename DstArrayT::StorType DstStorType;
00032 typedef typename DstArrayT::ArithType DstArithType;
00033 typedef typename SrcArrayT::StorType SrcStorType;
00034 typedef typename SrcArrayT::ArithType SrcArithType;
00035
00037 TalkNgbP1Loop(bool verbose, int ngbWidth, int ngbHeight)
00038 {
00039 mNgbWidth = ngbWidth;
00040 mNgbHeight = ngbHeight;
00041 mFactor = ngbWidth * ngbHeight;
00042 mVerbose = verbose;
00043 }
00044
00046 int
00047 Width()
00048 {
00049 return mNgbWidth;
00050 }
00051
00053 int
00054 Height()
00055 {
00056 return mNgbHeight;
00057 }
00058
00060 void
00061 Init(int x, int y, const SrcArithType& value)
00062 {
00063 if (mVerbose)
00064 std::cout << " TalkNgbP1Loop::init(" << x << "," << y << ","
00065 << value << ") " << std::endl;
00066 mResult = Element::E1Cast(0, DstArithType());
00067 }
00068
00070 void
00071 NextEl(int x, int y, const SrcArithType& value)
00072 {
00073 if (mVerbose)
00074 std::cout << " TalkNgbP1Loop::next(" << x << "," << y << ","
00075 << value << ") " << std::endl;
00076 mResult += value;
00077 }
00078
00080 DstArithType
00081 Result() const
00082 {
00083 return Element::E1Cast(mResult, DstArithType()) /
00084 Element::E1Cast(mFactor, DstArithType());
00085 }
00086
00087 private:
00088 int mNgbWidth;
00089 int mNgbHeight;
00090 SrcArithType mResult;
00091 SrcArithType mFactor;
00092 bool mVerbose;
00093 };
00094
00095 }
00096 }
00097 }
00098 }
00099
00100 #endif