Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkMinMaxLabelmageFilterWithIndex.h
Go to the documentation of this file.
1 #ifndef MITK_MINMAXLABELIMAGEFILTERWITHINDEX_H
2 #define MITK_MINMAXLABELIMAGEFILTERWITHINDEX_H
3 
5 
6 #include <itkImage.h>
7 #include <itkImageToImageFilter.h>
8 #include <itkImageRegionConstIteratorWithIndex.h>
9 #include "itksys/hash_map.hxx"
10 
11 
12 namespace itk
13 {
14 template <typename TInputImage, typename TLabelImage>
15 class MinMaxLabelImageFilterWithIndex: public itk::ImageToImageFilter<TInputImage, TInputImage>
16 {
17 public:
20  typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
23 
25  itkNewMacro(Self);
26 
28  itkTypeMacro(MinMaxLabelImageFilterWithIndex, ImageToImageFilter);
29 
30  typedef typename TInputImage::RegionType RegionType;
31  typedef typename TInputImage::SizeType SizeType;
32  typedef typename TInputImage::IndexType IndexType;
34  typedef typename NumericTraits< PixelType >::RealType RealType;
35 
36  typedef typename TLabelImage::RegionType LabelRegionType;
37  typedef typename TLabelImage::SizeType LabelSizeType;
38  typedef typename TLabelImage::IndexType LabelIndexType;
40 
45  {
46  public:
47  PixelType m_Min, m_Max;
48  IndexType m_MinIndex, m_MaxIndex;
49 
51  m_Min(std::numeric_limits<PixelType>::max()),
52  m_Max(std::numeric_limits<PixelType>::min())
53  {}
54  };
55 
56  typedef typename itksys::hash_map<LabelPixelType, LabelExtrema> ExtremaMapType;
57  typedef typename ExtremaMapType::iterator ExtremaMapTypeIterator;
58  typedef typename ExtremaMapType::const_iterator ExtremaMapTypeConstIterator;
59  typedef typename ExtremaMapType::value_type MapValueType;
60 
61  PixelType GetMin(LabelPixelType label) const
62  {
63  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
64  if (it == m_LabelExtrema.end())
65  {
66  MITK_ERROR << "invalid label";
67  }
68 
69  return (*it).second.m_Min;
70  }
71 
72  PixelType GetMax(LabelPixelType label) const
73  {
74  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
75  if (it == m_LabelExtrema.end())
76  {
77  MITK_ERROR << "invalid label";
78  }
79 
80  return (*it).second.m_Max;
81  }
82 
86  std::vector<LabelPixelType> GetRelevantLabels() const
87  {
88  std::vector<LabelPixelType> labels;
89  for (auto&& it:m_LabelExtrema)
90  {
91  labels.push_back(it.first);
92  }
93  return labels;
94  }
95 
96  IndexType GetMinIndex(LabelPixelType label) const
97  {
98  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
99  if (it == m_LabelExtrema.end())
100  {
101  MITK_ERROR << "invalid label";
102  }
103 
104  return (*it).second.m_MinIndex;
105 
106  }
107 
108  IndexType GetMaxIndex(LabelPixelType label) const
109  {
110  ExtremaMapTypeConstIterator it = m_LabelExtrema.find(label);
111  if (it == m_LabelExtrema.end())
112  {
113  MITK_ERROR << "invalid label";
114  }
115 
116  return (*it).second.m_MaxIndex;
117 
118  }
119 
120  PixelType GetGlobalMin() const
121  {
122  return m_GlobalMin;
123  }
124 
125  PixelType GetGlobalMax() const
126  {
127  return m_GlobalMax;
128  }
129 
130  IndexType GetGlobalMinIndex() const
131  {
132  return m_GlobalMinIndex;
133  }
134 
135  IndexType GetGlobalMaxIndex() const
136  {
137  return m_GlobalMaxIndex;
138  }
139 
141  void SetLabelInput(const TLabelImage *input)
142  {
143  // Process object is not const-correct so the const casting is required.
144  this->SetNthInput( 1, const_cast< TLabelImage * >( input ) );
145  }
146 
148  const TLabelImage * GetLabelInput() const
149  {
150  return itkDynamicCastInDebugMode< TLabelImage * >( const_cast< DataObject * >( this->ProcessObject::GetInput(1) ) );
151  }
152 
153 protected:
154  void AllocateOutputs();
155 
156  void ThreadedGenerateData(const RegionType &
157  outputRegionForThread,
158  ThreadIdType threadId);
159 
161 
163 
164 private:
165  std::vector<ExtremaMapType> m_ThreadExtrema;
166 
167  ExtremaMapType m_LabelExtrema;
168  PixelType m_GlobalMin;
169  PixelType m_GlobalMax;
170  IndexType m_GlobalMinIndex, m_GlobalMaxIndex;
171 };
172 }
173 
174 #include "mitkMinMaxLabelmageFilterWithIndex.hxx"
175 
176 
177 #endif
itksys::hash_map< LabelPixelType, LabelExtrema > ExtremaMapType
#define MITK_ERROR
Definition: mitkLogMacros.h:24
NumericTraits< PixelType >::RealType RealType
PixelType GetMax(LabelPixelType label) const
STL namespace.
IndexType GetMaxIndex(LabelPixelType label) const
IndexType GetMinIndex(LabelPixelType label) const
PixelType GetMin(LabelPixelType label) const
static T max(T x, T y)
Definition: svm.cpp:70
static T min(T x, T y)
Definition: svm.cpp:67
The LabelExtrema class is just a container for global min/max values and their indices as well as all...
unsigned short PixelType
void ThreadedGenerateData(const RegionType &outputRegionForThread, ThreadIdType threadId)
ImageToImageFilter< TInputImage, TInputImage > Superclass
std::vector< LabelPixelType > GetRelevantLabels() const
Returns a std::vector containing all labels for which min and max values (and indices) have been comp...
ExtremaMapType::const_iterator ExtremaMapTypeConstIterator