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