Medical Imaging Interaction Toolkit  2021.10.00
Medical Imaging Interaction Toolkit
itkAdaptiveThresholdIterator.h
Go to the documentation of this file.
1 /*============================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 
13 #ifndef __itkAdaptiveThresholdIterator_h
14 #define __itkAdaptiveThresholdIterator_h
15 
16 #include "itkConditionalConstIterator.h"
17 #include "itkImage.h"
18 #include "itkIndex.h"
19 #include "itkSize.h"
20 
21 #include <map>
22 #include <queue>
23 #include <utility>
24 #include <vector>
25 
26 namespace itk
27 {
36  template <class TImage, class TFunction>
37  class ITK_EXPORT AdaptiveThresholdIterator : public ConditionalConstIterator<TImage>
38  {
39  public:
42 
43  typedef ConditionalConstIterator<TImage> Superclass;
44 
45  typedef TImage ImageType;
46 
47  // A temporary image used for storing info about all indices
48  typedef TImage TTempImage;
49 
50  typename TTempImage::Pointer tempPtr;
51  //[!] isn't really used?!
52 
54  typedef TFunction FunctionType;
55 
57  typedef typename TFunction::InputType FunctionInputType;
58 
60  typedef typename TImage::SizeType SizeType;
61 
63  typedef typename TImage::RegionType RegionType;
64 
65  typedef typename TImage::IndexType IndexType;
66 
68  typedef typename TImage::InternalPixelType InternalPixelType;
69 
71  typedef typename TImage::PixelType PixelType;
72 
74  typedef std::queue<IndexType> IndexQueueType;
75 
77  typedef std::map<unsigned int, IndexQueueType> QueueMapType;
78 
83  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
84 
88  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex);
89 
93  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, std::vector<IndexType> &startIndex);
94 
98  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr);
99 
102 
104  void InitializeIterator();
105 
106  // makes the iterator go one step further
107  void DoExtendedFloodStep();
108 
109  // set-method for member-variable
110  void SetExpansionDirection(bool upwards);
111 
112  // Init-method
113  void InitRegionGrowingState();
114 
115  void SetMinTH(int min);
116 
117  void SetMaxTH(int max);
118 
119  int GetSeedPointValue(void);
120 
122  void SetFineDetectionMode(bool fine = false)
123  {
124  m_FineDetectionMode = fine;
125  m_DetectionStop = false;
126  }
127 
132  const IndexType GetIndex() override
133  {
134  return (*m_QueueMap.find(m_RegionGrowingState)).second.front();
135  } // [!] is never called?!
136 
137  const PixelType Get(void) const override
138  {
139  return const_cast<ImageType *>(this->m_Image.GetPointer())
140  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front());
141  }
142  //[!] is never called?!
143 
144  void Set(const PixelType &value)
145  {
146  const_cast<ImageType *>(this->m_Image.GetPointer())
147  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front()) = value;
148  }
149 
150  void GoToBegin();
151 
153  bool IsAtEnd() override { return this->m_IsAtEnd; };
155  void operator++() override { this->DoExtendedFloodStep(); }
156  virtual SmartPointer<FunctionType> GetFunction() const { return m_Function; }
159  Self &operator=(const Self &it)
160  {
161  this->m_Image = it.m_Image; // copy the smart pointer
162  this->m_Region = it.m_Region;
163  this->m_InitializeValue = it.m_InitializeValue;
164  this->m_RegionGrowingState = it.m_RegionGrowingState;
165  this->m_MinTH = it.m_MinTH;
166  this->m_MaxTH = it.m_MaxTH;
167  this->m_SeedPointValue = it.m_SeedPointValue;
168  this->m_VoxelCounter = it.m_VoxelCounter;
169  this->m_LastVoxelNumber = it.m_LastVoxelNumber;
170  this->m_DetectedLeakagePoint = it.m_DetectedLeakagePoint;
171  this->m_CurrentLeakageRatio = it.m_CurrentLeakageRatio;
172  return *this;
173  }
174 
176  bool IsPixelIncluded(const IndexType &index) const override;
177 
178  // Calculate the value the outputImage is initialized to
179  static int CalculateInitializeValue(int lower, int upper) { return ((upper - lower) + 1) * (-1); };
180  int GetLeakagePoint(void) { return m_DetectedLeakagePoint; }
181  protected:
182  /*
183  * @brief Pointer on the output image to which the result shall be written
184  */
186 
188 
190  std::vector<IndexType> m_StartIndices;
191 
193  typename ImageType::PointType m_ImageOrigin;
194 
196  typename ImageType::SpacingType m_ImageSpacing;
197 
199  RegionType m_ImageRegion;
200 
202 
204 
205  void ExpandThresholdUpwards();
206 
207  void ExpandThresholdDownwards();
208 
209  void IncrementRegionGrowingState();
210 
211  // calculates how many steps the voxel is from the current step
212  int EstimateDistance(IndexType);
213 
214  // calculates how many expansion steps will be taken
215  unsigned int CalculateMaxRGS();
216 
217  private:
218  void InsertIndexTypeIntoQueueMap(unsigned int key, IndexType index);
219 
220  int m_RegionGrowingState;
221 
222  QueueMapType m_QueueMap;
223 
224  int m_MinTH;
225 
226  int m_MaxTH;
227 
228  int m_SeedPointValue;
229 
230  unsigned int m_VoxelCounter;
231  unsigned int m_LastVoxelNumber;
232 
233  int m_DetectedLeakagePoint;
234  float m_CurrentLeakageRatio;
235 
236  void CheckSeedPointValue();
237 
238  /* flag for switching between raw leakage detection (bigger bronchial vessels)
239  * and fine leakage detection (smaller bronchial vessels [starting from leaves])
240  */
241  bool m_FineDetectionMode;
242  bool m_DetectionStop;
243  };
244 } // end namespace itk
245 
246 #ifndef ITK_MANUAL_INSTANTIATION
247 #include "itkAdaptiveThresholdIterator.txx"
248 #endif
249 
250 #endif
SmartPointer< FunctionType > m_Function
virtual SmartPointer< FunctionType > GetFunction() const
ConditionalConstIterator< TImage > Superclass
static int CalculateInitializeValue(int lower, int upper)
Iterates over an image using a variable image function, which threshold can be varied during the iter...
TImage::InternalPixelType InternalPixelType
std::map< unsigned int, IndexQueueType > QueueMapType
const PixelType Get(void) const override