00001 #ifndef Impala_Core_Array_Trait_TalkNgbExtra2P1Loop_h
00002 #define Impala_Core_Array_Trait_TalkNgbExtra2P1Loop_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, class Extra2ArrayT>
00021 class TalkNgbExtra2P1Loop
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 typedef typename ExtraArrayT::StorType ExtraStorType;
00036 typedef typename ExtraArrayT::ArithType ExtraArithType;
00037 typedef typename Extra2ArrayT::StorType Extra2StorType;
00038 typedef typename Extra2ArrayT::ArithType Extra2ArithType;
00039
00041 TalkNgbExtra2P1Loop(bool verbose, int ngbWidth, int ngbHeight)
00042 {
00043 mNgbWidth = ngbWidth;
00044 mNgbHeight = ngbHeight;
00045 mFactor = Element::E1Cast(ngbWidth * ngbHeight, DstArithType());
00046 mVerbose = verbose;
00047 }
00048
00050 int
00051 Width()
00052 {
00053 return mNgbWidth;
00054 }
00055
00057 int
00058 Height()
00059 {
00060 return mNgbHeight;
00061 }
00062
00064 void
00065 Init(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00066 const Extra2ArithType& v3)
00067 {
00068 if (mVerbose)
00069 std::cout << " TalkNgbExtra2P1Loop::init(" << x << "," << y << ","
00070 << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00071 mResult = Element::E1Cast(0, DstArithType());
00072 }
00073
00075 void
00076 NextEl(int x, int y, const SrcArithType& v1, const ExtraArithType& v2,
00077 const Extra2ArithType& v3)
00078 {
00079 if (mVerbose)
00080 std::cout << " TalkNgbExtra2P1Loop::next(" << x << "," << y
00081 << "," << v1 << "," << v2 << "," << v3 << ") " << std::endl;
00082 DstArithType tmp(v1, v2, v3);
00083 mResult += tmp;
00084 }
00085
00087 DstArithType
00088 Result() const
00089 {
00090 return mResult / mFactor;
00091 }
00092
00093 private:
00094 int mNgbWidth;
00095 int mNgbHeight;
00096 DstArithType mResult;
00097 DstArithType mFactor;
00098 bool mVerbose;
00099 };
00100
00101 }
00102 }
00103 }
00104 }
00105
00106 #endif