Medical Imaging Interaction Toolkit  2016.11.0
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,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 #ifndef __itkAdaptiveThresholdIterator_h
18 #define __itkAdaptiveThresholdIterator_h
19 
20 #include "itkConditionalConstIterator.h"
21 #include "itkImage.h"
22 #include "itkIndex.h"
23 #include "itkSize.h"
24 
25 #include <map>
26 #include <queue>
27 #include <utility>
28 #include <vector>
29 
30 namespace itk
31 {
40  template <class TImage, class TFunction>
41  class ITK_EXPORT AdaptiveThresholdIterator : public ConditionalConstIterator<TImage>
42  {
43  public:
46 
47  typedef ConditionalConstIterator<TImage> Superclass;
48 
49  typedef TImage ImageType;
50 
51  // A temporary image used for storing info about all indices
52  typedef TImage TTempImage;
53 
55  //[!] isn't really used?!
56 
58  typedef TFunction FunctionType;
59 
61  typedef typename TFunction::InputType FunctionInputType;
62 
64  typedef typename TImage::SizeType SizeType;
65 
67  typedef typename TImage::RegionType RegionType;
68 
69  typedef typename TImage::IndexType IndexType;
70 
72  typedef typename TImage::InternalPixelType InternalPixelType;
73 
75  typedef typename TImage::PixelType PixelType;
76 
78  typedef std::queue<IndexType> IndexQueueType;
79 
81  typedef std::map<unsigned int, IndexQueueType> QueueMapType;
82 
87  itkStaticConstMacro(NDimensions, unsigned int, TImage::ImageDimension);
88 
92  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, IndexType startIndex);
93 
97  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr, std::vector<IndexType> &startIndex);
98 
102  AdaptiveThresholdIterator(ImageType *imagePtr, FunctionType *fnPtr);
103 
106 
108  void InitializeIterator();
109 
110  // makes the iterator go one step further
111  void DoExtendedFloodStep();
112 
113  // set-method for member-variable
114  void SetExpansionDirection(bool upwards);
115 
116  // Init-method
117  void InitRegionGrowingState();
118 
119  void SetMinTH(int min);
120 
121  void SetMaxTH(int max);
122 
123  int GetSeedPointValue(void);
124 
126  void SetFineDetectionMode(bool fine = false)
127  {
128  m_FineDetectionMode = fine;
129  m_DetectionStop = false;
130  }
131 
136  const IndexType GetIndex()
137  {
138  return (*m_QueueMap.find(m_RegionGrowingState)).second.front();
139  } // [!] is never called?!
140 
141  const PixelType Get(void) const
142  {
143  return const_cast<ImageType *>(this->m_Image.GetPointer())
144  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front());
145  }
146  //[!] is never called?!
147 
148  void Set(const PixelType &value)
149  {
150  const_cast<ImageType *>(this->m_Image.GetPointer())
151  ->GetPixel((*m_QueueMap.find(m_RegionGrowingState)).second.front()) = value;
152  }
153 
154  void GoToBegin();
155 
157  bool IsAtEnd() { return this->m_IsAtEnd; };
159  void operator++() { this->DoExtendedFloodStep(); }
160  virtual SmartPointer<FunctionType> GetFunction() const { return m_Function; }
163  Self &operator=(const Self &it)
164  {
165  this->m_Image = it.m_Image; // copy the smart pointer
166  this->m_Region = it.m_Region;
167  return *this;
168  }
169 
171  bool IsPixelIncluded(const IndexType &index) const;
172 
173  // Calculate the value the outputImage is initialized to
174  static int CalculateInitializeValue(int lower, int upper) { return ((upper - lower) + 1) * (-1); };
175  int GetLeakagePoint(void) { return m_DetectedLeakagePoint; }
176  protected:
177  /*
178  * @brief Pointer on the output image to which the result shall be written
179  */
181 
183 
185  std::vector<IndexType> m_StartIndices;
186 
189 
191  typename ImageType::SpacingType m_ImageSpacing;
192 
194  RegionType m_ImageRegion;
195 
197 
199 
200  void ExpandThresholdUpwards();
201 
202  void ExpandThresholdDownwards();
203 
204  void IncrementRegionGrowingState();
205 
206  // calculates how many steps the voxel is from the current step
207  int EstimateDistance(IndexType);
208 
209  // calculates how many expansion steps will be taken
210  unsigned int CalculateMaxRGS();
211 
212  private:
213  void InsertIndexTypeIntoQueueMap(unsigned int key, IndexType index);
214 
215  int m_RegionGrowingState;
216 
217  QueueMapType m_QueueMap;
218 
219  int m_MinTH;
220 
221  int m_MaxTH;
222 
223  int m_SeedPointValue;
224 
225  unsigned int m_VoxelCounter;
226  unsigned int m_LastVoxelNumber;
227 
228  int m_DetectedLeakagePoint;
229  float m_CurrentLeakageRatio;
230 
231  void CheckSeedPointValue();
232 
233  /* flag for switching between raw leakage detection (bigger bronchial vessels)
234  * and fine leakage detection (smaller bronchial vessels [starting from leaves])
235  */
236  bool m_FineDetectionMode;
237  bool m_DetectionStop;
238  };
239 } // end namespace itk
240 
241 #ifndef ITK_MANUAL_INSTANTIATION
243 #endif
244 
245 #endif
mitk::Point3D PointType
SmartPointer< FunctionType > m_Function
itk::SmartPointer< Self > Pointer
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
static T max(T x, T y)
Definition: svm.cpp:70
std::map< unsigned int, IndexQueueType > QueueMapType
static T min(T x, T y)
Definition: svm.cpp:67
virtual SmartPointer< FunctionType > GetFunction() const
unsigned short PixelType