ITK  5.3.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  * http://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:
61  static constexpr unsigned int Dimension = TDimension;
62 
67  using IndexType = std::pair<unsigned, unsigned>;
70  using ScalarType = TScalar;
71 
73  struct face_pixel_t
74  {
75 
90  short flow;
91 
94  };
95 
98  {
99 
103  std::list<IdentifierType> offset_list;
104 
108 
112 
115  };
116 
120 
122  using flat_hash_t = std::unordered_map<IdentifierType, flat_region_t>;
123  using FlatHashValueType = typename flat_hash_t::value_type;
124 
127  using Self = Boundary;
131  itkNewMacro(Self);
132  itkTypeMacro(WatershedBoundary, DataObject);
134 
136  using FacePointer = typename face_t::Pointer;
137 
140  GetFace(const IndexType & idx)
141  {
142  return this->GetFace(idx.first, idx.second);
143  }
144 
148  FacePointer
149  GetFace(unsigned dimension, unsigned highlow)
150  {
151  if (highlow == 0)
152  {
153  return m_Faces[dimension].first;
154  }
155  else
156  {
157  return m_Faces[dimension].second;
158  }
159  }
161 
162  void
163  SetFace(FacePointer f, const IndexType & idx)
164  {
165  this->SetFace(f, idx.first, idx.second);
166  }
167 
168  void
169  SetFace(FacePointer f, unsigned dimension, unsigned highlow)
170  {
171  if (highlow == 0)
172  {
173  m_Faces[dimension].first = f;
174  }
175  else
176  {
177  m_Faces[dimension].second = f;
178  }
179  this->Modified();
180  }
181 
183  flat_hash_t *
184  GetFlatHash(const IndexType & idx)
185  {
186  return this->GetFlatHash(idx.first, idx.second);
187  }
188  flat_hash_t *
189  GetFlatHash(unsigned dimension, unsigned highlow)
190  {
191  if (highlow == 0)
192  {
193  return &(m_FlatHashes[dimension].first);
194  }
195  else
196  {
197  return &(m_FlatHashes[dimension].second);
198  }
199  }
201 
202  void
204  {
205  this->SetFlatHash(l, idx.first, idx.second);
206  }
207  void
208  SetFlatHash(flat_hash_t & l, unsigned dimension, unsigned highlow)
209  {
210  if (highlow == 0)
211  {
212  m_FlatHashes[dimension].first = l;
213  }
214  else
215  {
216  m_FlatHashes[dimension].second = l;
217  }
218  this->Modified();
219  }
220 
225  void
226  SetValid(bool & l, const IndexType & idx)
227  {
228  this->SetValid(l, idx.first, idx.second);
229  }
230  void
231  SetValid(bool b, unsigned dimension, unsigned highlow)
232  {
233  if (highlow == 0)
234  {
235  m_Valid[dimension].first = b;
236  }
237  else
238  {
239  m_Valid[dimension].second = b;
240  }
241  this->Modified();
242  }
244 
245  bool
246  GetValid(const IndexType & idx) const
247  {
248  return this->GetValid(idx.first, idx.second);
249  }
250  bool
251  GetValid(unsigned dimension, unsigned highlow) const
252  {
253  if (highlow == 0)
254  {
255  return m_Valid[dimension].first;
256  }
257  else
258  {
259  return m_Valid[dimension].second;
260  }
261  }
262 
263 protected:
264  Boundary();
265  ~Boundary() override = default;
266  Boundary(const Self &) {}
267  void
268  operator=(const Self &)
269  {}
270  void
271  PrintSelf(std::ostream & os, Indent indent) const override;
272 
274  std::vector<std::pair<FacePointer, FacePointer>> m_Faces;
275 
278  std::vector<std::pair<flat_hash_t, flat_hash_t>> m_FlatHashes;
279 
282  std::vector<std::pair<bool, bool>> m_Valid;
283 };
284 } // end namespace watershed
285 } // end namespace itk
286 
287 #ifndef ITK_MANUAL_INSTANTIATION
288 # include "itkWatershedBoundary.hxx"
289 #endif
290 
291 #endif
itk::watershed::Boundary::SetValid
void SetValid(bool b, unsigned dimension, unsigned highlow)
Definition: itkWatershedBoundary.h:231
itk::watershed::Boundary::ImageIndexType
typename ImageType::IndexType ImageIndexType
Definition: itkWatershedBoundary.h:69
itk::watershed::Boundary::GetValid
bool GetValid(unsigned dimension, unsigned highlow) const
Definition: itkWatershedBoundary.h:251
itk::watershed::Boundary::GetFace
FacePointer GetFace(unsigned dimension, unsigned highlow)
Definition: itkWatershedBoundary.h:149
itk::watershed::Boundary::SetFlatHash
void SetFlatHash(flat_hash_t &l, const IndexType &idx)
Definition: itkWatershedBoundary.h:203
itk::watershed::Boundary::face_pixel_t
Definition: itkWatershedBoundary.h:73
itk::watershed::Boundary::face_pixel_t::label
IdentifierType label
Definition: itkWatershedBoundary.h:93
itkImage.h
itk::SmartPointer< Self >
itk::Indent
Control indentation during Print() invocation.
Definition: itkIndent.h:49
itk::watershed::Boundary::IndexType
std::pair< unsigned, unsigned > IndexType
Definition: itkWatershedBoundary.h:67
itk::watershed::Boundary::flat_region_t
Definition: itkWatershedBoundary.h:97
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:163
itk::watershed::Boundary::SetFace
void SetFace(FacePointer f, unsigned dimension, unsigned highlow)
Definition: itkWatershedBoundary.h:169
itk::watershed::Boundary
Definition: itkWatershedBoundary.h:54
itk::watershed::Boundary::GetFlatHash
flat_hash_t * GetFlatHash(unsigned dimension, unsigned highlow)
Definition: itkWatershedBoundary.h:189
itk::watershed::Boundary::flat_region_t::min_label
IdentifierType min_label
Definition: itkWatershedBoundary.h:111
itkProcessObject.h
itk::watershed::Boundary::face_pixel_t::flow
short flow
Definition: itkWatershedBoundary.h:90
itk::watershed::Boundary::SetFlatHash
void SetFlatHash(flat_hash_t &l, unsigned dimension, unsigned highlow)
Definition: itkWatershedBoundary.h:208
itk::watershed::Boundary::FlatHashValueType
typename flat_hash_t::value_type FlatHashValueType
Definition: itkWatershedBoundary.h:123
itk::watershed::Boundary::m_FlatHashes
std::vector< std::pair< flat_hash_t, flat_hash_t > > m_FlatHashes
Definition: itkWatershedBoundary.h:278
itk::DataObject
class ITK_FORWARD_EXPORT DataObject
Definition: itkDataObject.h:42
itk::watershed::Boundary::GetFace
FacePointer GetFace(const IndexType &idx)
Definition: itkWatershedBoundary.h:140
itk::watershed::Boundary::GetFlatHash
flat_hash_t * GetFlatHash(const IndexType &idx)
Definition: itkWatershedBoundary.h:184
itk::watershed::Boundary::flat_hash_t
std::unordered_map< IdentifierType, flat_region_t > flat_hash_t
Definition: itkWatershedBoundary.h:122
itk::watershed::Boundary::GetValid
bool GetValid(const IndexType &idx) const
Definition: itkWatershedBoundary.h:246
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::watershed::Boundary::ScalarType
TScalar ScalarType
Definition: itkWatershedBoundary.h:70
itk::watershed::Boundary::Boundary
Boundary(const Self &)
Definition: itkWatershedBoundary.h:266
itk::watershed::Boundary::m_Valid
std::vector< std::pair< bool, bool > > m_Valid
Definition: itkWatershedBoundary.h:282
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::watershed::Boundary::operator=
void operator=(const Self &)
Definition: itkWatershedBoundary.h:268
itk::watershed::Boundary::m_Faces
std::vector< std::pair< FacePointer, FacePointer > > m_Faces
Definition: itkWatershedBoundary.h:274
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::watershed::Boundary::FacePointer
typename face_t::Pointer FacePointer
Definition: itkWatershedBoundary.h:136
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:114
itk::watershed::Boundary::flat_region_t::bounds_min
ScalarType bounds_min
Definition: itkWatershedBoundary.h:107
itk::watershed::Boundary::SetValid
void SetValid(bool &l, const IndexType &idx)
Definition: itkWatershedBoundary.h:226
itk::IdentifierType
SizeValueType IdentifierType
Definition: itkIntTypes.h:87
itk::watershed::Boundary::flat_region_t::offset_list
std::list< IdentifierType > offset_list
Definition: itkWatershedBoundary.h:103
itk::DataObject
Base class for all data objects in ITK.
Definition: itkDataObject.h:293