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
00035 typedef struct structPointValue {
00036 Geometry::PointZ point;
00037 } PointValueT;
00038
00039
00040 typedef Pattern::Qstack<PointValueT> QT;
00041
00042
00043 typedef struct {
00044 Geometry::PointZ point;
00045 DstArithT arith;
00046 SrcArithT img;
00047 } NeighborsT;
00048
00049
00050 typedef FcvArray<NeighborsT> VecNeighborsT;
00051
00052 QbLabel()
00053 {
00054 labelcode=0;
00055 }
00056
00057 ~QbLabel()
00058 {
00059 }
00060
00061
00062 bool
00063 GlobalPixelInit(PointValueT&, DstArithT& arith, SrcArithT)
00064 {
00065 arith = Element::E0LargeVal<DstArithT>(DstArithT());
00066 return false;
00067 }
00068
00069
00070 bool
00071 WantFreshStartLocalPixelInit()
00072 {
00073 return false;
00074 }
00075
00076
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;
00085 OhYesIReallyWouldLikeToHaveAnotherLoop=true;
00086 return true;
00087 } else {
00088 continueloop=true;
00089 OhYesIReallyWouldLikeToHaveAnotherLoop=false;
00090 return false;
00091 }
00092 }
00093
00094
00095 void
00096 First(const PointValueT& val, DstArithT arith, SrcArithT img)
00097 {
00098
00099 index=0;
00100 neighborsout.clear();
00101 actionsout.clear();
00102
00103 centrum.point=val.point;
00104 centrum.img=img;
00105 centrum.arith=arith;
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
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;
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
00146 void
00147 GetItemToRemove(PointValueT&, PointValueT&)
00148 {
00149 }
00150
00151
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 }
00182 }
00183 }
00184 }
00185
00186 #endif