ITK  6.0.0
Insight Toolkit
itkWatershedBoundary.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * https://www.apache.org/licenses/LICENSE-2.0.txt
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  *=========================================================================*/
18 #ifndef itkWatershedBoundary_h
19 #define itkWatershedBoundary_h
20 
21 
22 #include <list>
23 #include <vector>
24 #include "itkImage.h"
25 #include "itkProcessObject.h"
26 #include <unordered_map>
27 
28 namespace itk
29 {
30 namespace watershed
31 {
53 template <typename TScalar, unsigned int TDimension>
54 class ITK_TEMPLATE_EXPORT Boundary : public DataObject
55 {
56 public:
57  ITK_DISALLOW_COPY_AND_MOVE(Boundary);
58 
63  static constexpr unsigned int Dimension = TDimension;
64 
69  using IndexType = std::pair<unsigned int, unsigned int>;
72  using ScalarType = TScalar;
73 
75  struct face_pixel_t
76  {
77 
92  short flow;
93 
96  };
97 
100  {
101 
105  std::list<IdentifierType> offset_list;
106 
110 
114 
117  };
118 
122 
124  using flat_hash_t = std::unordered_map<IdentifierType, flat_region_t>;
125  using FlatHashValueType = typename flat_hash_t::value_type;
126 
129  using Self = Boundary;
133  itkNewMacro(Self);
134  itkOverrideGetNameOfClassMacro(Boundary);
138  using FacePointer = typename face_t::Pointer;
139 
142  GetFace(const IndexType & idx)
143  {
144  return this->GetFace(idx.first, idx.second);
145  }
146 
150  FacePointer
151  GetFace(unsigned int dimension, unsigned int highlow)
152  {
153  if (highlow == 0)
154  {
155  return m_Faces[dimension].first;
156  }
157  else
158  {
159  return m_Faces[dimension].second;
160  }
161  }
164  void
165  SetFace(FacePointer f, const IndexType & idx)
166  {
167  this->SetFace(f, idx.first, idx.second);
168  }
169 
170  void
171  SetFace(FacePointer f, unsigned int dimension, unsigned int highlow)
172  {
173  if (highlow == 0)
174  {
175  m_Faces[dimension].first = f;
176  }
177  else
178  {
179  m_Faces[dimension].second = f;
180  }
181  this->Modified();
182  }
183 
185  flat_hash_t *
186  GetFlatHash(const IndexType & idx)
187  {
188  return this->GetFlatHash(idx.first, idx.second);
189  }
190  flat_hash_t *
191  GetFlatHash(unsigned int dimension, unsigned int highlow)
192  {
193  if (highlow == 0)
194  {
195  return &(m_FlatHashes[dimension].first);
196  }
197  else
198  {
199  return &(m_FlatHashes[dimension].second);
200  }
201  }
204  void
206  {
207  this->SetFlatHash(l, idx.first, idx.second);
208  }
209  void
210  SetFlatHash(flat_hash_t & l, unsigned int dimension, unsigned int highlow)
211  {
212  if (highlow == 0)
213  {
214  m_FlatHashes[dimension].first = l;
215  }
216  else
217  {
218  m_FlatHashes[dimension].second = l;
219  }
220  this->Modified();
221  }
222 
227  void
228  SetValid(bool & l, const IndexType & idx)
229  {
230  this->SetValid(l, idx.first, idx.second);
231  }
232  void
233  SetValid(bool b, unsigned int dimension, unsigned int highlow)
234  {
235  if (highlow == 0)
236  {
237  m_Valid[dimension].first = b;
238  }
239  else
240  {
241  m_Valid[dimension].second = b;
242  }
243  this->Modified();
244  }
247  bool
248  GetValid(const IndexType & idx) const
249  {
250  return this->GetValid(idx.first, idx.second);
251  }
252  bool
253  GetValid(unsigned int dimension, unsigned int highlow) const
254  {
255  if (highlow == 0)
256  {
257  return m_Valid[dimension].first;
258  }
259  else
260  {
261  return m_Valid[dimension].second;
262  }
263  }
264 
265 protected:
266  Boundary();
267  ~Boundary() override = default;
268 
269  void
270  PrintSelf(std::ostream & os, Indent indent) const override;
271 
273  std::vector<std::pair<FacePointer, FacePointer>> m_Faces{};
274 
277  std::vector<std::pair<flat_hash_t, flat_hash_t>> m_FlatHashes{};
278 
281  std::vector<std::pair<bool, bool>> m_Valid{};
282 };
283 } // end namespace watershed
284 } // end namespace itk
285 
286 #ifndef ITK_MANUAL_INSTANTIATION
287 # include "itkWatershedBoundary.hxx"
288 #endif
289 
290 #endif
Pointer
SmartPointer< Self > Pointer
Definition: itkAddImageFilter.h:93
itk::watershed::Boundary::ImageIndexType
typename ImageType::IndexType ImageIndexType
Definition: itkWatershedBoundary.h:71
itk::watershed::Boundary::SetFlatHash
void SetFlatHash(flat_hash_t &l, const IndexType &idx)
Definition: itkWatershedBoundary.h:205
itk::watershed::Boundary::face_pixel_t
Definition: itkWatershedBoundary.h:75
itk::watershed::Boundary::SetFlatHash
void SetFlatHash(flat_hash_t &l, unsigned int dimension, unsigned int highlow)
Definition: itkWatershedBoundary.h:210
itk::watershed::Boundary::face_pixel_t::label
IdentifierType label
Definition: itkWatershedBoundary.h:95
itkImage.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::watershed::Boundary::GetValid
bool GetValid(unsigned int dimension, unsigned int highlow) const
Definition: itkWatershedBoundary.h:253
itk::watershed::Boundary::SetValid
void SetValid(bool b, unsigned int dimension, unsigned int highlow)
Definition: itkWatershedBoundary.h:233
itk::watershed::Boundary::flat_region_t
Definition: itkWatershedBoundary.h:99
itk::GTest::TypedefsAndConstructors::Dimension2::IndexType
ImageBaseType::IndexType IndexType
Definition: itkGTestTypedefsAndConstructors.h:50
itk::watershed::Boundary::SetFace
void SetFace(FacePointer f, const IndexType &idx)
Definition: itkWatershedBoundary.h:165
itk::watershed::Boundary::GetFace
FacePointer GetFace(unsigned int dimension, unsigned int highlow)
Definition: itkWatershedBoundary.h:151
itk::watershed::Boundary
Definition: itkWatershedBoundary.h:54
itk::watershed::Boundary::flat_region_t::min_label
IdentifierType min_label
Definition: itkWatershedBoundary.h:113
itkProcessObject.h
itk::watershed::Boundary::face_pixel_t::flow
short flow
Definition: itkWatershedBoundary.h:92
itk::watershed::Boundary::FlatHashValueType
typename flat_hash_t::value_type FlatHashValueType
Definition: itkWatershedBoundary.h:125
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::watershed::Boundary::GetFace
FacePointer GetFace(const IndexType &idx)
Definition: itkWatershedBoundary.h:142
itk::watershed::Boundary::GetFlatHash
flat_hash_t * GetFlatHash(const IndexType &idx)
Definition: itkWatershedBoundary.h:186
itk::watershed::Boundary::flat_hash_t
std::unordered_map< IdentifierType, flat_region_t > flat_hash_t
Definition: itkWatershedBoundary.h:124
itk::watershed::Boundary::GetValid
bool GetValid(const IndexType &idx) const
Definition: itkWatershedBoundary.h:248
itk::watershed::Boundary::GetFlatHash
flat_hash_t * GetFlatHash(unsigned int dimension, unsigned int highlow)
Definition: itkWatershedBoundary.h:191
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnatomicalOrientation.h:29
itk::watershed::Boundary::ScalarType
TScalar ScalarType
Definition: itkWatershedBoundary.h:72
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:61
itk::watershed::Boundary::IndexType
std::pair< unsigned int, unsigned int > IndexType
Definition: itkWatershedBoundary.h:69
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::watershed::Boundary::FacePointer
typename face_t::Pointer FacePointer
Definition: itkWatershedBoundary.h:138
itk::watershed::Boundary::SetFace
void SetFace(FacePointer f, unsigned int dimension, unsigned int highlow)
Definition: itkWatershedBoundary.h:171
itk::GTest::TypedefsAndConstructors::Dimension2::Dimension
constexpr unsigned int Dimension
Definition: itkGTestTypedefsAndConstructors.h:44
itk::watershed::Boundary::flat_region_t::value
ScalarType value
Definition: itkWatershedBoundary.h:116
itk::watershed::Boundary::flat_region_t::bounds_min
ScalarType bounds_min
Definition: itkWatershedBoundary.h:109
itk::watershed::Boundary::SetValid
void SetValid(bool &l, const IndexType &idx)
Definition: itkWatershedBoundary.h:228
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:90
itk::watershed::Boundary::flat_region_t::offset_list
std::list< IdentifierType > offset_list
Definition: itkWatershedBoundary.h:105
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293