00001 #ifndef Impala_Core_Array_Trait_InOutCircle_h 00002 #define Impala_Core_Array_Trait_InOutCircle_h 00003 00004 #include "Core/Array/Pattern/Categories.h" 00005 #include "Core/Array/Element/E1Cast.h" 00006 00007 namespace Impala 00008 { 00009 namespace Core 00010 { 00011 namespace Array 00012 { 00013 namespace Trait 00014 { 00015 00016 00017 template<class ArrayT> 00018 class InOutCircle 00019 { 00020 public: 00021 typedef Pattern::TagPixOpIn DirectionCategory; 00022 typedef Pattern::TagTransVar TransVarianceCategory; 00023 typedef Pattern::Tag1Phase PhaseCategory; 00024 00025 typedef typename ArrayT::ArithType ArithT; 00026 00027 InOutCircle(int centerX, int centerY, Real64 radius, ArithT circleValue, 00028 ArithT outsideValue) 00029 { 00030 mCenterX = centerX; 00031 mCenterY = centerY; 00032 mRadiusSquared = radius * radius; 00033 mCircleValue = circleValue; 00034 mOutsideValue = outsideValue; 00035 } 00036 00037 const ArithT& 00038 DoIt(int x, int y) 00039 { 00040 int d = (mCenterX - x) * (mCenterX - x) + (mCenterY - y) * (mCenterY - y); 00041 if(d <= mRadiusSquared) { 00042 mRes = mCircleValue; 00043 } else { 00044 mRes = mOutsideValue; 00045 } 00046 return mRes; // without mRes compiler warns ??? 00047 } 00048 00049 private: 00050 00051 int mCenterX; 00052 int mCenterY; 00053 Real64 mRadiusSquared; 00054 ArithT mCircleValue; 00055 ArithT mOutsideValue; 00056 ArithT mRes; 00057 }; 00058 00059 } // namespace Trait 00060 } // namespace Array 00061 } // namespace Core 00062 } // namespace Impala 00063 00064 #endif