00001 #ifndef Impala_Core_Array_Trait_TalkNgbP2Loop_h
00002 #define Impala_Core_Array_Trait_TalkNgbP2Loop_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 TalkNgbP2Loop
00022 {
00023 public:
00024
00026 typedef Pattern::TagLoop IteratorCategory;
00027
00029 typedef Pattern::Tag2Phase 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 TalkNgbP2Loop(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 << " TalkNgbP2Loop::init(" << x << "," << y << ","
00065 << value << ") " << std::endl;
00066 mResult = Element::E1Cast(0, DstArithType());
00067 }
00068
00070 void
00071 Init2(int x, int y, const SrcArithType& value)
00072 {
00073 if (mVerbose)
00074 std::cout << " TalkNgbP2Loop::init2(" << x << "," << y << ","
00075 << value << ") " << std::endl;
00076 }
00077
00079 void
00080 NextEl(int x, int y, const SrcArithType& value)
00081 {
00082 if (mVerbose)
00083 std::cout << " TalkNgbP2Loop::next(" << x << "," << y << ","
00084 << value << ") " << std::endl;
00085 mResult += value;
00086 }
00087
00089 void
00090 NextEl2(int x, int y, const SrcArithType& value)
00091 {
00092 if (mVerbose)
00093 std::cout << " TalkNgbP2Loop::next2(" << x << "," << y << ","
00094 << value << ") " << std::endl;
00095 mResult += value;
00096 }
00097
00099 DstArithType
00100 Result() const
00101 {
00102 return Element::E1Cast(mResult, DstArithType()) /
00103 Element::E1Cast(mFactor, DstArithType());
00104 }
00105
00106 private:
00107 int mNgbWidth;
00108 int mNgbHeight;
00109 SrcArithType mResult;
00110 SrcArithType mFactor;
00111 bool mVerbose;
00112 };
00113
00114 }
00115 }
00116 }
00117 }
00118
00119 #endif