Home || Architecture || Video Search || Visual Search || Scripts || Applications || Important Messages || OGL || Src

QbLabel.h

Go to the documentation of this file.
00001 #ifndef Impala_Core_Array_Trait_QbLabel_h
00002 #define Impala_Core_Array_Trait_QbLabel_h
00003 
00004 #include "Core/Geometry/PointZ.h"
00005 #include "Core/Array/Trait/FcvArray.h"
00006 #include "Core/Array/Pattern/QCollection.h"
00007 
00008 namespace Impala
00009 {
00010 namespace Core
00011 {
00012 namespace Array
00013 {
00014 namespace Trait
00015 {
00016 
00017 
00018 template<class DstArrayT, class SrcArrayT>
00019 class QbLabel {
00020 
00021     typedef typename DstArrayT::ArithType DstArithT;
00022     typedef typename SrcArrayT::ArithType SrcArithT;
00023 
00024 private:
00025 
00026     typedef struct {
00027         Geometry::PointZ point; 
00028         DstArithT arith; 
00029         SrcArithT img;
00030     } Temp;
00031 
00032 public:
00033 
00034     // just put everything in it, sorting might be functor dependent
00035     typedef struct structPointValue {
00036         Geometry::PointZ point; // mandatory !!!!!!!!!
00037     } PointValueT;
00038 
00039     //typedef std::set<PointValueT> QT; 
00040     typedef Pattern::Qstack<PointValueT> QT; 
00041 
00042     // combine parameters of next() :
00043     typedef struct { 
00044         Geometry::PointZ point;
00045         DstArithT arith;
00046         SrcArithT img;
00047     } NeighborsT; 
00048 
00049     // combine sequence of calls to next() :
00050     typedef FcvArray<NeighborsT> VecNeighborsT;
00051 
00052     QbLabel()
00053     {
00054         labelcode=0;
00055     }
00056 
00057     ~QbLabel()
00058     {
00059     }
00060 
00061     // pattern writes ALWAYS vp.arith but queues ONLY if pixelinit() returns true
00062     bool
00063     GlobalPixelInit(PointValueT&, DstArithT& arith, SrcArithT)
00064     { 
00065         arith = Element::E0LargeVal<DstArithT>(DstArithT()); // = unlabeled
00066         return false; // dont Q
00067     }
00068 
00069     // algo can continue from last point
00070     bool
00071     WantFreshStartLocalPixelInit()
00072     {
00073         return false; // default true
00074     }
00075 
00076     // need only 1 unlabeled pixel as seed, take first and quit in init()
00077     bool
00078     LocalPixelInit(PointValueT &vp, DstArithT &arith, SrcArithT img,
00079                    bool &continueloop)
00080     { 
00081         if (arith==Element::E0LargeVal<DstArithT>(DstArithT())) { 
00082             labelcode=labelcode+1;
00083             arith=labelcode;
00084             continueloop=false; // this is last
00085             OhYesIReallyWouldLikeToHaveAnotherLoop=true;
00086             return true; // do Q
00087         } else {
00088             continueloop=true; // try next
00089             OhYesIReallyWouldLikeToHaveAnotherLoop=false;
00090             return false; // dont Q
00091         }
00092     }
00093 
00094     // first from queue, NOTE: arith at (val.point) may have been altered
00095     void
00096     First(const PointValueT& val, DstArithT arith, SrcArithT img)
00097     { 
00098         // clear 
00099         index=0; // for result()
00100         neighborsout.clear();
00101         actionsout.clear();
00102         // store center pixel top() pop() from queue
00103         centrum.point=val.point; 
00104         centrum.img=img;
00105         centrum.arith=arith; // pattern doesnt put it in VP anymore
00106     }
00107 
00108     void
00109     Calculate(VecNeighborsT& vecneighbors)
00110     {
00111         for (int i=0; i<vecneighbors.size(); i++) {
00112             NeighborsT n=vecneighbors[i];
00113             if (n.arith==Element::E0LargeVal<DstArithT>(DstArithT()) &&
00114                 n.img == centrum.img) {
00115                 //roughlyEqual(n.img, centrum.img, tolerance)) {
00116                 Temp val;
00117                 val.arith=centrum.arith;
00118                 val.point=n.point;
00119                 val.img=n.img;
00120                 neighborsout.push_back(val);
00121                 actionsout.push_back(Pattern::WRITE);
00122                 neighborsout.push_back(val);
00123                 actionsout.push_back(Pattern::QUEUE);
00124             }
00125         }
00126     }
00127 
00128     Pattern::QAction
00129     Result()
00130     {
00131         if (index>=neighborsout.size())
00132             return Pattern::STOP; // quit asking 
00133         output=neighborsout[index];
00134         Pattern::QAction action=actionsout[index];
00135         index++;
00136         return action;
00137     }
00138 
00139     void
00140     GetItemToQueue(PointValueT& vp)
00141     {
00142         vp.point=output.point;
00143     }
00144 
00145     // this algo doesnt remove anything from the queue
00146     void
00147     GetItemToRemove(PointValueT&, PointValueT&)
00148     {
00149     }
00150 
00151     // this algo doesnt remove anything from the queue
00152     bool
00153     KillThisOne(PointValueT&)
00154     {
00155         return false; 
00156     }
00157 
00158     void
00159     GetItemToWrite(Geometry::PointZ& point, DstArithT& arith)
00160     {
00161         point=output.point;
00162         arith=output.arith;
00163     }
00164 
00165     bool
00166     WantAnotherLoop()
00167     {
00168         return OhYesIReallyWouldLikeToHaveAnotherLoop;
00169     }
00170 
00171 private:
00172 
00173     FcvArray<Temp> neighborsout; 
00174     Temp centrum, output;
00175     FcvArray<Pattern::QAction> actionsout;
00176     int index;
00177     DstArithT labelcode;
00178     bool OhYesIReallyWouldLikeToHaveAnotherLoop;
00179 };
00180 
00181 } // namespace Trait
00182 } // namespace Array
00183 } // namespace Core
00184 } // namespace Impala
00185 
00186 #endif

Generated on Fri Mar 19 09:30:59 2010 for ImpalaSrc by  doxygen 1.5.1