00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef HxImgFtorQueueBased_h
00010 #define HxImgFtorQueueBased_h
00011
00012 #include "HxImgFtorI3Cast.h"
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 class PointT {
00023 public:
00024 int x, y;
00025 PointT(int x_, int y_) : x(x_), y(y_) {}
00026 PointT() {}
00027 bool operator == (const PointT & rhs) { return x==rhs.x && y==rhs.y; }
00028 PointT operator + (const PointT & rhs) const { return PointT(x+rhs.x, y+rhs.y); }
00029 };
00030
00031
00032 template <class T> class FcvArray {
00033 private:
00034 T *ptr;
00035 int nr;
00036 int index;
00037 FcvArray(const FcvArray &);
00038 FcvArray& operator = (const FcvArray &);
00039 public:
00040 FcvArray(int n=1000) : index(0), nr(n) { ptr=new T[nr]; }
00041 ~FcvArray() { delete []ptr; }
00042 void clear() { index=0; }
00043 void push_back(const T &val) { ptr[index++]=val; }
00044 int size() const { return index; }
00045 T & operator [] (int i) { return ptr[i]; }
00046 const T & operator [] (int i) const { return ptr[i]; }
00047 bool empty() const { return index==0; }
00048
00049 bool isThere(const T &val)
00050 {for(int i=0;i<index;i++) if(ptr[i]==val) return true; return false;}
00051 void setSize(int s) { nr=s; ptr=new T[nr]; }
00052
00053 };
00054
00055
00058 template <class ImgSigT, class ExtraSigT, class AnotherSigT, class FunctorT>
00059 class HxImgFtorQueueBased : public HxImgFtorI3Cast<ImgSigT, ExtraSigT, AnotherSigT> {
00060 public:
00061
00062 typedef typename FunctorT::QT QueueT;
00063 typedef FcvArray<PointT> VecPointT;
00064 typedef typename FunctorT::VecNeighbors VecNeighborT;
00065 QueueT queuet;
00066 HxImgFtorQueueBased();
00067 ~HxImgFtorQueueBased();
00068 virtual void doIt(
00069 Img1DataPtrType imgPtr,
00070 Img2DataPtrType extraPtr,
00071 Img3DataPtrType anotherPtr,
00072 HxSizes imgSize,
00073 HxSizes extraSize,
00074 HxSizes anotherSize,
00075 HxTagList &tags,
00076 HxImgFtorDescription * =0);
00077 static HxString className() { return "QueueBased"; }
00078 static inline void fillNeighborValues(
00079 PointT centralPoint,
00080 const VecPointT &neighborCoordinates,
00081 VecNeighborT &vecneighbors,
00082 HxSizes imgSize,
00083 Img1DataPtrType imgPtr,
00084 Img2DataPtrType extraPtr,
00085 Img3DataPtrType anotherPtr);
00086 void fillNeighborValues(
00087 const PointT ¢ralPoint,
00088 int connectivity,
00089 VecNeighborT &vecneighbors,
00090 const HxSizes &imgSize,
00091 const Img1DataPtrType &imgPtr,
00092 const Img2DataPtrType &extraPtr,
00093 const Img3DataPtrType &anotherPtr);
00094 static void createNeighborCoordinates(
00095 VecPointT &neighborCoordinates,
00096 HxTagList &tags);
00097 };
00098
00099
00100 template <class ImgSigT, class ExtraSigT, class AnotherSigT, class FunctorT>
00101
00102 void
00103 HxImgFtorQueueBased<ImgSigT, ExtraSigT, AnotherSigT, FunctorT>::fillNeighborValues(
00104 const PointT ¢ralPoint,
00105 int connectivity,
00106 VecNeighborT &vecneighbors,
00107 const HxSizes &imgSize,
00108 const Img1DataPtrType &imgPtr,
00109 const Img2DataPtrType &extraPtr,
00110 const Img3DataPtrType &anotherPtr) {
00111
00112 vecneighbors.clear();
00113 int imgsizex=imgSize.x(), imgsizey=imgSize.y();
00114 if (connectivity==8) {
00115 for (int y=-1; y<=1; y++) {
00116 for (int x=-1; x<=1; x++) {
00117 int tempx=centralPoint.x+x, tempy=centralPoint.y+y;
00118 if (tempx>=0 && tempx<imgsizex &&
00119 tempy>=0 && tempy<imgsizey &&
00120 !(x==0 && y==0)) {
00121 Img1DataPtrType d=imgPtr;
00122 Img2DataPtrType s1=extraPtr;
00123 Img3DataPtrType s2=anotherPtr;
00124 d.incXYZ(tempx, tempy);
00125 s1.incXYZ(tempx, tempy);
00126 s2.incXYZ(tempx, tempy);
00127 typename FunctorT::Neighbors neighbors;
00128 neighbors.point=PointT(tempx, tempy);
00129 neighbors.arith=d.read();
00130 neighbors.img=s1.read();
00131 neighbors.mask=s2.read();
00132 vecneighbors.push_back(neighbors);
00133 }
00134 }
00135 }
00136 } else if (connectivity==4) {
00137 for (int y=-1; y<=1; y++) {
00138 for (int x=-1; x<=1; x++) {
00139 int tempx=centralPoint.x+x, tempy=centralPoint.y+y;
00140 if (tempx>=0 && tempx<imgsizex &&
00141 tempy>=0 && tempy<imgsizey &&
00142 !(x==0 && y==0) &&
00143 (x==0 || y==0)) {
00144 Img1DataPtrType d=imgPtr;
00145 Img2DataPtrType s1=extraPtr;
00146 Img3DataPtrType s2=anotherPtr;
00147 d.incXYZ(tempx, tempy);
00148 s1.incXYZ(tempx, tempy);
00149 s2.incXYZ(tempx, tempy);
00150 typename FunctorT::Neighbors neighbors;
00151 neighbors.point=PointT(tempx, tempy);
00152 neighbors.arith=d.read();
00153 neighbors.img=s1.read();
00154 neighbors.mask=s2.read();
00155 vecneighbors.push_back(neighbors);
00156 }
00157 }
00158 }
00159 }
00160 }
00161
00162
00163 #ifdef INC_TEMPLATE_SRC
00164 #include "HxImgFtorQueueBased.c"
00165 #endif
00166
00167 #endif // #ifndef HxImgFtorQueue_h
00168