00001 #ifndef Impala_Core_Array_Pattern_PatNgbOp2d_h
00002 #define Impala_Core_Array_Pattern_PatNgbOp2d_h
00003
00004 #include "Core/Array/CheckBorderSize.h"
00005 #include "Core/Array/Pattern/PatSetBorder.h"
00006 #include "Core/Array/Pattern/FuncNgbOp2d.h"
00007
00008 #ifdef PX_HORUS_USED
00009 #include "Core/Array/Pattern/PxArrayFunc.h"
00010 #include "Core/Array/Pattern/PxStateTrans.h"
00011 #endif
00012
00013 namespace Impala
00014 {
00015 namespace Core
00016 {
00017 namespace Array
00018 {
00019 namespace Pattern
00020 {
00021
00022
00023 template <class DstArrayT, class SrcArrayT, class NgbT>
00024 inline void
00025 PatNgbOp2d(DstArrayT*& dst, SrcArrayT* src, NgbT& ngb, bool borderAlreadySet=false)
00026 {
00027 ILOG_VAR(Impala.Core.Array.Pattern.PatNgbOp2d);
00028 int numX = ngb.Width() / 2;
00029 int numY = ngb.Height() / 2;
00030 SrcArrayT* checkedSrc = CheckBorderSize(src, numX, numY);
00031 if(borderAlreadySet && (checkedSrc != src))
00032 {
00033 ILOG_WARNING("borderAlreadySet==true, but border too smal... " <<
00034 "ignoring border");
00035 borderAlreadySet = false;
00036 }
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046 if (dst == 0)
00047 dst = ArrayClone<DstArrayT>(checkedSrc);
00048 if(dst == (DstArrayT*) checkedSrc)
00049 {
00050 static bool didWarning = false;
00051 if(!didWarning)
00052 ILOG_WARNING("You're doing a neighbourhood operation in place. " <<
00053 "Is this really what you want?");
00054 didWarning = true;
00055 }
00056
00057 #ifdef PX_HORUS_USED
00058 if (!PxRunParallel()) {
00059 #endif
00060 if(!borderAlreadySet)
00061 PatSetBorder(checkedSrc, numX, numY);
00062 FuncNgbOp2dDispatch(dst, checkedSrc, ngb);
00063
00064 #ifdef PX_HORUS_USED
00065 } else {
00066 PxArrayPreStateTrans(checkedSrc, PAR_PART, STRONG);
00067 PxArrayPreStateTrans(dst, PAR_PART, WEAK);
00068 PatSetBorder(PxArrayPD(checkedSrc), numX, numY);
00069 FuncNgbOp2dDispatch(PxArrayPD(dst),
00070 PxArrayPD(checkedSrc), ngb);
00071 if (PxArrayPD(checkedSrc) != PxArrayPD(src))
00072 PxArrayDeletePD(checkedSrc);
00073 PxArrayPostStateTrans(dst);
00074
00075 if (!PxRunLazyParallel()) {
00076 PxArrayForceNonDistributed(src);
00077 PxArrayForceNonDistributed(dst);
00078 }
00079 }
00080 #endif
00081
00082 if (checkedSrc != src)
00083 delete checkedSrc;
00084 }
00085
00086 }
00087 }
00088 }
00089 }
00090
00091 #endif