Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef __itkAttributeMorphologyBaseImageFilter_h
00019 #define __itkAttributeMorphologyBaseImageFilter_h
00020
00021 #include "itkImageToImageFilter.h"
00022 #include "itkImage.h"
00023 #include <vector>
00024
00025 #define PAMI
00026
00027 namespace itk
00028 {
00029
00056 template <class TInputImage, class TOutputImage, class TAttribute, class TFunction>
00057 class ITK_EXPORT AttributeMorphologyBaseImageFilter :
00058 public ImageToImageFilter< TInputImage, TOutputImage >
00059 {
00060 public:
00064 typedef AttributeMorphologyBaseImageFilter Self;
00065 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00066
00070 typedef typename Superclass::InputImagePointer InputImagePointer;
00071
00076 typedef typename TOutputImage::PixelType OutputPixelType;
00077 typedef typename TOutputImage::InternalPixelType OutputInternalPixelType;
00078 typedef typename TInputImage::PixelType InputPixelType;
00079 typedef typename TInputImage::InternalPixelType InputInternalPixelType;
00080 typedef typename TInputImage::IndexType IndexType;
00081 typedef typename TInputImage::OffsetType OffsetType;
00082 typedef typename TInputImage::SizeType SizeType;
00083
00084 itkStaticConstMacro(ImageDimension, unsigned int,
00085 TOutputImage::ImageDimension);
00086
00090 typedef TInputImage InputImageType;
00091 typedef TOutputImage OutputImageType;
00092
00093
00094 typedef typename TOutputImage::RegionType RegionType;
00095 typedef std::list<IndexType> ListType;
00096 typedef TAttribute AttributeType;
00097
00101 typedef SmartPointer<Self> Pointer;
00102 typedef SmartPointer<const Self> ConstPointer;
00103
00107 itkTypeMacro(AttributeMorphologyBaseImageFilter, ImageToImageFilter);
00108
00112 itkNewMacro(Self);
00113
00120 itkSetMacro(FullyConnected, bool);
00121 itkGetConstReferenceMacro(FullyConnected, bool);
00122 itkBooleanMacro(FullyConnected);
00124
00130 itkSetMacro(Lambda, AttributeType);
00131 itkGetConstMacro(Lambda, AttributeType);
00133
00134 protected:
00135 AttributeMorphologyBaseImageFilter()
00136 {
00137 m_FullyConnected = false;
00138 m_AttributeValuePerPixel = 1;
00139 m_Lambda = 0;
00140 }
00141 virtual ~AttributeMorphologyBaseImageFilter() {}
00142 AttributeMorphologyBaseImageFilter(const Self&) {}
00143 void PrintSelf(std::ostream& os, Indent indent) const;
00144
00148 void GenerateData();
00149
00153 void GenerateInputRequestedRegion();
00154
00159 void EnlargeOutputRequestedRegion(DataObject *itkNotUsed(output));
00160
00161 AttributeType m_AttributeValuePerPixel;
00162
00163 private:
00164
00165 bool m_FullyConnected;
00166 AttributeType m_Lambda;
00167
00168
00169 itkStaticConstMacro(INACTIVE, long, -1);
00170 itkStaticConstMacro(ACTIVE, long, -2);
00171 itkStaticConstMacro(ROOT, long, -3);
00172
00173
00174 AttributeType * m_AuxData;
00175
00176 typedef std::vector<OffsetType> OffsetVecType;
00177
00178 typedef std::vector<long> OffsetDirectVecType;
00179
00180 void SetupOffsetVec(OffsetDirectVecType &PosOffsets, OffsetVecType &Offsets);
00181
00182 class GreyAndPos
00183 {
00184 public:
00185 InputPixelType Val;
00186 long Pos;
00187 };
00188
00189 GreyAndPos * m_SortPixels;
00190 long * m_Parent;
00191 #ifndef PAMI
00192 bool * m_Processed;
00193 #endif
00194
00195 InputPixelType * m_Raw;
00196
00197 class ComparePixStruct
00198 {
00199 public:
00200 TFunction m_TFunction;
00201 bool operator()(GreyAndPos const &l, GreyAndPos const &r) const
00202 {
00203 if (m_TFunction(l.Val, r.Val))
00204 {
00205 return true;
00206 }
00207 if (l.Val == r.Val)
00208 {
00209 return (l.Pos < r.Pos);
00210 }
00211 return false;
00212 }
00213 };
00214
00215 #ifdef PAMI
00216
00217
00218 void MakeSet(long x)
00219 {
00220 m_Parent[x] = ACTIVE;
00221 m_AuxData[x] = m_AttributeValuePerPixel;
00222 }
00223
00224 long FindRoot(long x)
00225 {
00226 if (m_Parent[x] >= 0)
00227 {
00228 m_Parent[x] = FindRoot(m_Parent[x]);
00229 return(m_Parent[x]);
00230 }
00231 else
00232 {
00233 return(x);
00234 }
00235 }
00236
00237 bool Criterion(long x, long y)
00238 {
00239 return((m_Raw[x] == m_Raw[y]) || (m_AuxData[x] < m_Lambda));
00240 }
00241
00242 void Union(long n, long p)
00243 {
00244 long r = FindRoot(n);
00245 if (r != p)
00246 {
00247 if (Criterion(r, p))
00248 {
00249 m_AuxData[p] += m_AuxData[r];
00250 m_Parent[r] = p;
00251 }
00252 else
00253 {
00254 m_AuxData[p] = m_Lambda;
00255 }
00256 }
00257 }
00258
00259 #else
00260
00261 void MakeSet(long x)
00262 {
00263 m_Parent[x] = ACTIVE;
00264 m_AuxData[x] = m_AttributeValuePerPixel;
00265 }
00266
00267 void Link(long x, long y)
00268 {
00269 if ((m_Parent[y] == ACTIVE) && (m_Parent[x] == ACTIVE))
00270 {
00271
00272 m_AuxData[y] = m_AuxData[x] + m_AuxData[y];
00273 m_AuxData[x] = -m_AttributeValuePerPixel;
00274 }
00275 else if (m_Parent[x] == ACTIVE)
00276 {
00277 m_AuxData[x] = -m_AttributeValuePerPixel;
00278 }
00279 else
00280 {
00281 m_AuxData[y] = -m_AttributeValuePerPixel;
00282 m_Parent[y] = INACTIVE;
00283 }
00284 m_Parent[x] = y;
00285 }
00286
00287 long FindRoot(long x)
00288 {
00289 if (m_Parent[x] >= 0)
00290 {
00291 m_Parent[x] = FindRoot(m_Parent[x]);
00292 return(m_Parent[x]);
00293 }
00294 else
00295 {
00296 return(x);
00297 }
00298 }
00299
00300 bool Equiv(long x, long y)
00301 {
00302 return((m_Raw[x] == m_Raw[y]) || (m_Parent[x] == ACTIVE));
00303 }
00304
00305 void Union(long n, long p)
00306 {
00307 long r = FindRoot(n);
00308 if (r != p)
00309 {
00310 if (Equiv(r, p))
00311 {
00312 Link(r, p);
00313 }
00314 else if (m_Parent[p] == ACTIVE)
00315 {
00316 m_Parent[p] = INACTIVE;
00317 m_AuxData[p] = -m_AttributeValuePerPixel;
00318 }
00319 }
00320 }
00321 #endif
00322 };
00323
00324 }
00325
00326 #ifndef ITK_MANUAL_INSTANTIATION
00327 #include "itkAttributeMorphologyBaseImageFilter.txx"
00328 #endif
00329
00330 #endif
00331