Horus Doc || C++ Reference || Class Overview   Pixels   Images   Detector   Geometry   Registry || Doxygen's quick Index  

HxImgFtorQueueBased.h

00001 /*
00002  *  Copyright (c) 2000, University of Amsterdam, The Netherlands.
00003  *  All rights reserved.
00004  *
00005  *  Author(s):
00006  *  Frans Verster (verster@science.uva.nl)
00007  */
00008 
00009 #ifndef HxImgFtorQueueBased_h
00010 #define HxImgFtorQueueBased_h
00011 
00012 #include "HxImgFtorI3Cast.h"
00013 
00014 
00015 
00016 /* 
00017 resp. INOUT, IN, IN
00018 for Q based watershed resp. 
00019 */
00020 
00021 //typedef HxVec2Int PointT; // 2D
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     //leon added this
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     //typedef std::set<FunctorT::PointValueT> QueueT; // because of localOrderCounter a normal set might work as well ???
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( // couldnt store imgPtr as members (no default ctor), so pass everything -> static
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( // couldnt store imgPtr as members (no default ctor), so pass everything -> static
00087         const PointT &centralPoint, 
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); // no member vars used
00097 };
00098 
00099 
00100 template <class ImgSigT, class ExtraSigT, class AnotherSigT, class FunctorT>
00101 //__forceinline void 
00102 void
00103 HxImgFtorQueueBased<ImgSigT, ExtraSigT, AnotherSigT, FunctorT>::fillNeighborValues( // couldnt store imgPtr as members (no default ctor), so pass everything -> static
00104         const PointT &centralPoint, 
00105         int connectivity, 
00106         VecNeighborT &vecneighbors,
00107         const HxSizes &imgSize,
00108         const Img1DataPtrType &imgPtr,
00109         const Img2DataPtrType &extraPtr,
00110         const Img3DataPtrType &anotherPtr) {
00111 //#pragma message("compiling fillNeighborValues with ...int connectivity...")
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 && // border
00119                     tempy>=0 && tempy<imgsizey && // border
00120                     !(x==0 && y==0)) { // not center
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 && // border
00141                     tempy>=0 && tempy<imgsizey && // border
00142                     !(x==0 && y==0) && // not center
00143                     (x==0 || y==0)) { // 4 conn
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     } //else throw HxString ("unsupported connectivity");
00160 } 
00161 
00162 
00163 #ifdef INC_TEMPLATE_SRC
00164 #include "HxImgFtorQueueBased.c"
00165 #endif
00166 
00167 #endif // #ifndef HxImgFtorQueue_h
00168 

Generated on Mon Jan 27 15:48:45 2003 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001