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

QbLabelOld.h

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

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