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

HxImgFtorQueueBased Class Template Reference

Instantiation of generic algorithm for queue based operations on 2d images. More...

#include <HxImgFtorQueueBased.h>

Inheritance diagram for HxImgFtorQueueBased::

HxImgFtorI3Cast< ImgSigT, ExtraSigT, AnotherSigT > HxImgFtorI3 HxImgFunctor List of all members.

Public Types

typedef FunctorT::QT QueueT
typedef FcvArray< PointT > VecPointT
typedef FunctorT::VecNeighbors VecNeighborT

Public Methods

 HxImgFtorQueueBased ()
 ~HxImgFtorQueueBased ()
virtual void doIt (Img1DataPtrType imgPtr, Img2DataPtrType extraPtr, Img3DataPtrType anotherPtr, HxSizes imgSize, HxSizes extraSize, HxSizes anotherSize, HxTagList &tags, HxImgFtorDescription *=0)
 doIt is implemented by derived image functors:. More...

void fillNeighborValues (const PointT &centralPoint, int connectivity, VecNeighborT &vecneighbors, const HxSizes &imgSize, const Img1DataPtrType &imgPtr, const Img2DataPtrType &extraPtr, const Img3DataPtrType &anotherPtr)

Static Public Methods

HxString className ()
void fillNeighborValues (PointT centralPoint, const VecPointT &neighborCoordinates, VecNeighborT &vecneighbors, HxSizes imgSize, Img1DataPtrType imgPtr, Img2DataPtrType extraPtr, Img3DataPtrType anotherPtr)
void createNeighborCoordinates (VecPointT &neighborCoordinates, HxTagList &tags)

Public Attributes

QueueT queuet

Detailed Description

template<class ImgSigT, class ExtraSigT, class AnotherSigT, class FunctorT>
class HxImgFtorQueueBased< ImgSigT, ExtraSigT, AnotherSigT, FunctorT >

Instantiation of generic algorithm for queue based operations on 2d images.


Member Function Documentation

template<class ImgSigT, class ExtraSigT, class AnotherSigT, class FunctorT>
void HxImgFtorQueueBased< ImgSigT, ExtraSigT, AnotherSigT, FunctorT >::doIt Img1DataPtrType    imgPtr,
Img2DataPtrType    extraPtr,
Img3DataPtrType    anotherPtr,
HxSizes    imgSize,
HxSizes    extraSize,
HxSizes    anotherSize,
HxTagList   tags,
HxImgFtorDescription   f = 0
[virtual]
 

doIt is implemented by derived image functors:.

Reimplemented from HxImgFtorI3Cast.

00141                                   {
00142 
00143     SHOW(imgSize); SHOW(extraSize); SHOW(anotherSize); SHOW(tags); 
00144     if (!(imgSize==extraSize && imgSize==anotherSize)) { 
00145         HxString err("ERROR: unequal sizes in ");
00146 //      err+=typeid(*this).name();
00147         throw err;
00148     }
00149     HxAddTag(tags, "imgSize", imgSize); // need it for debugging
00150 
00151 
00152     int imgsizex = imgSize.x();
00153     int imgsizey = imgSize.y();
00154     int imgsizez = imgSize.z(); if (imgsizez!=1) throw HxString("QueueBeased pattern not (yet) certified for imgsizez!=1");
00155     FunctorT functor(tags, imgsizex, imgsizey);
00156     SHOW(typeid(*this).name());
00157 
00158     int connectivity=HxGetTag(tags, "connectivity", 8);
00159 //  std::cout << "connectivity=" <<connectivity<<std::endl;
00160 
00161     // GLOBAL INIT
00162     { // local scope
00163         if (!queuet.empty()) { // debug only
00164             SHOW(queuet.size()); // uhhhhhhhhhhhhhhhhhhh
00165             queuet.clear(); 
00166         }
00167         Img1DataPtrType d=imgPtr;
00168         Img2DataPtrType s1=extraPtr;
00169         Img3DataPtrType s2=anotherPtr;
00170         for (int y=0; y<imgsizey; y++) {
00171             for (int x=0 ; x<imgsizex; x++) {
00172                 typename FunctorT::PointValueT vp;
00173                 PointT p(x, y);
00174                 vp.point=p;
00175                 typename ImgSigT::ArithType dest=d.read();
00176                 typename ExtraSigT::ArithType src1=s1.read();
00177                 typename AnotherSigT::ArithType src2=s2.read();
00178                 bool q=functor.globalPixelInit(vp, dest, src1, src2);
00179                 if (q) queuet.push(vp); // NOTE: bool ok=queue.insert(vp).second is NEVER false
00180                 d.write(dest);
00181                 d.incX(); s1.incX(); s2.incX();
00182             }
00183             d.decX(imgsizex); s1.decX(imgsizex); s2.decX(imgsizex);
00184             d.incY(); s1.incY(); s2.incY();
00185         }
00186     } // end local scope
00187 
00188     // NEW: array of points to simplify loop 4/8/... connectivity, now skip (0,0,0)
00189     FcvArray<PointT> neighborCoordinates;
00190     createNeighborCoordinates(neighborCoordinates, tags);
00191 
00192     // clear speedup startpoint for localPixelInit() in large do while loop
00193     //__asm int 3
00194     PointT startpoint(0,0);
00195 
00196     typename FunctorT::VecNeighbors vecneighbors;
00197 
00198 
00199     // LOOP until done with INIT local + PROPAGATE
00200     do {
00201 
00202         // INIT: FILL QUEUE
00203         { // local scope
00204             bool freshstart=functor.wantFreshStartLocalPixelInit();
00205             if (freshstart) {
00206                 startpoint.x=0;
00207                 startpoint.y=0;
00208             }
00209             Img1DataPtrType d=imgPtr;
00210             Img2DataPtrType s1=extraPtr;
00211             Img3DataPtrType s2=anotherPtr;
00212             bool continueloop=true;
00213             int x=startpoint.x;
00214             int y=startpoint.y;
00215             d.incXYZ(x, y);
00216             s1.incXYZ(x, y);
00217             s2.incXYZ(x, y);
00218             bool wenttonewpoint=false;
00219             if (wenttonewpoint) y=0;
00220             for (; y<imgsizey; y++) {
00221                 if (wenttonewpoint) x=0;
00222                 for (; x<imgsizex; x++) {
00223                     if (!wenttonewpoint) {
00224                         wenttonewpoint=true;
00225                     }
00226                     typename FunctorT::PointValueT vp;
00227                     vp.point.x=x;
00228                     vp.point.y=y;
00229                     typename ImgSigT::ArithType dest=d.read();
00230                     typename ExtraSigT::ArithType src1=s1.read();
00231                     typename AnotherSigT::ArithType src2=s2.read();
00232                     bool q=functor.localPixelInit(vp, dest, src1, src2, continueloop);
00233                     if (q) queuet.push(vp); // NOTE: bool ok=queue.insert(vp).second is NEVER false
00234                     d.write(dest);
00235                     if (!continueloop) break;
00236                     d.incX(); s1.incX(); s2.incX();
00237                 }
00238                 if (!continueloop) break;
00239                 d.decX(imgsizex); s1.decX(imgsizex); s2.decX(imgsizex);
00240                 d.incY(); s1.incY(); s2.incY();
00241             }
00242             // rememmber startpoint for next time
00243             startpoint.x=x;
00244             startpoint.y=y;
00245 
00246         } // end local scope
00247 
00248         // PROPAGATION
00249         { // local scope
00250             while (!queuet.empty()) { // line 4
00251                 typename FunctorT::PointValueT vp(queuet.top()); queuet.pop(); // line 5
00252 
00253                 // give functor first=this=center data
00254                 { // local scope
00255                     int tempx=vp.point.x, tempy=vp.point.y;
00256                     Img1DataPtrType d=imgPtr;
00257                     Img2DataPtrType s1=extraPtr;
00258                     Img3DataPtrType s2=anotherPtr;
00259                     d.incXYZ(tempx, tempy);
00260                     s1.incXYZ(tempx, tempy);
00261                     s2.incXYZ(tempx, tempy);
00262                     functor.first(vp, d.read(), s1.read(), s2.read());
00263                 } // local scope
00264 
00265                 // give functor the neighbour pixels
00266                 // NOT yet optimized for iterator++ or LUT for coords
00267                 // NEW: use vector to pass neighbors, here be compatible with sequential code
00268                 { //local scope
00269                     fillNeighborValues(
00270                         vp.point, 
00271                         neighborCoordinates, 
00272                         //connectivity, 
00273                         vecneighbors, 
00274                         imgSize,
00275                         imgPtr,
00276                         extraPtr,
00277                         anotherPtr);
00278                     // CALCULATE put functor to work, might be removed by first call to getdata()
00279                     functor.calculate(vecneighbors);
00280                 } //local scope
00281 
00282 
00283 
00284                 // read out phase, might have many values of different types
00285                 { // local scope
00286                     typename FunctorT::ActionT action;
00287                     while ((action=functor.result3())!=FunctorT::stopAction) { 
00288                         switch (action) {
00289                         case FunctorT::queueAction: 
00290                             { // local scope
00291                                 typename FunctorT::PointValueT vp;
00292                                 functor.getItemToQueue(vp);
00293                                 queuet.push(vp); 
00294                             } // local scope
00295                             break;
00296                         case FunctorT::removeAction: 
00297                             { // local scope
00298                                 typename FunctorT::PointValueT low, high;
00299                                 functor.getItemToRemove(low, high);
00300                                 typename QueueT::iterator lowiter=queuet.lower_bound(low);
00301                                 typename QueueT::iterator highiter=queuet.after_upper_bound(high);
00302                                 for (typename QueueT::iterator iter=lowiter; iter!=highiter; iter++) {
00303                                     bool k=functor.killThisOne(*iter);
00304                                     if (k) {
00305                                         queuet.erase(iter);
00306                                         break;
00307                                     } 
00308                                 }
00309                             } // local scope
00310                             break;
00311                         case FunctorT::writeAction:
00312                             { // local scope
00313                                 Img1DataPtrType p=imgPtr;
00314                                 PointT point; 
00315                                 typename ImgSigT::ArithType arith;
00316                                 functor.getItemToWrite(point, arith);
00317                                 p.incXYZ(point.x, point.y);
00318                                 p.write(arith);
00319                             } // local scope
00320                             break;
00321                         default: throw HxString("ERROR switch (action) default:");
00322                         }; // switch (action)
00323                     } // while ((action=functor.result3())!=FunctorT::stopAction) 
00324                 } // local scope
00325             } // while (!queuet.empty()) 
00326         } // end local scope PROPAGATION
00327     } while (functor.wantAnotherLoop());
00328 
00329     
00330 }


The documentation for this class was generated from the following files:
Generated on Tue Feb 3 14:19:00 2004 for C++Reference by doxygen1.2.12 written by Dimitri van Heesch, © 1997-2001