00001 #ifndef Impala_Core_Array_Trait_TalkNgbExtraP2Loop_h
00002 #define Impala_Core_Array_Trait_TalkNgbExtraP2Loop_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, class ExtraArrayT>
00021 class TalkNgbExtraP2Loop
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 typedef typename ExtraArrayT::StorType ExtraStorType;
00036 typedef typename ExtraArrayT::ArithType ExtraArithType;
00037
00039 TalkNgbExtraP2Loop(bool verbose, int ngbWidth, int ngbHeight)
00040 {
00041 mNgbWidth = ngbWidth;
00042 mNgbHeight = ngbHeight;
00043 mFactor = Element::E1Cast(ngbWidth * ngbHeight, DstArithType());
00044 mVerbose = verbose;
00045 }
00046
00048 int
00049 Width()
00050 {
00051 return mNgbWidth;
00052 }
00053
00055 int
00056 Height()
00057 {
00058 return mNgbHeight;
00059 }
00060
00062 void
00063 Init(int x, int y, const SrcArithType& v1, const ExtraArithType& v2)
00064 {
00065 if (mVerbose)
00066 std::cout << " TalkNgbExtraP2Loop::init(" << x << "," << y << ","
00067 << v1 << "," << v2 << ") " << std::endl;
00068 mResult = Element::E1Cast(0, DstArithType());
00069 }
00070
00072 void
00073 Init2(int x, int y, const SrcArithType& v1, const ExtraArithType& v2)
00074 {
00075 if (mVerbose)
00076 std::cout << " TalkNgbExtraP2Loop::init2(" << x << "," << y << ","
00077 << v1 << "," << v2 << ") " << std::endl;
00078 }
00079
00081 void
00082 NextEl(int x, int y, const SrcArithType& v1, const ExtraArithType& v2)
00083 {
00084 if (mVerbose)
00085 std::cout << " TalkNgbExtraP2Loop::next(" << x << "," << y
00086 << "," << v1 << "," << v2 << ") " << std::endl;
00087 DstArithType tmp(v1, v2, 0);
00088 mResult += tmp;
00089 }
00090
00092 void
00093 NextEl2(int x, int y, const SrcArithType& v1, const ExtraArithType& v2)
00094 {
00095 if (mVerbose)
00096 std::cout << " TalkNgbExtraP2Loop::next2(" << x << "," << y
00097 << "," << v1 << "," << v2 << ") " << std::endl;
00098 DstArithType tmp(v1, v2, 0);
00099 mResult += tmp;
00100 }
00101
00103 DstArithType
00104 Result() const
00105 {
00106 return mResult / mFactor;
00107 }
00108
00109 private:
00110 int mNgbWidth;
00111 int mNgbHeight;
00112 DstArithType mResult;
00113 DstArithType mFactor;
00114 bool mVerbose;
00115 };
00116
00117 }
00118 }
00119 }
00120 }
00121
00122 #endif