ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
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
29{
51template <typename TScalar, unsigned int TDimension>
52class ITK_TEMPLATE_EXPORT Boundary : public DataObject
53{
54public:
55 ITK_DISALLOW_COPY_AND_MOVE(Boundary);
56
61 static constexpr unsigned int Dimension = TDimension;
62
67 using IndexType = std::pair<unsigned int, unsigned int>;
70 using ScalarType = TScalar;
71
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
128 using Self = Boundary;
132 itkNewMacro(Self);
133 itkOverrideGetNameOfClassMacro(Boundary);
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 int dimension, unsigned int highlow)
150 {
151 if (highlow == 0)
152 {
153 return m_Faces[dimension].first;
154 }
155
156 return m_Faces[dimension].second;
157 }
158
159 void
161 {
162 this->SetFace(f, idx.first, idx.second);
163 }
164
165 void
166 SetFace(FacePointer f, unsigned int dimension, unsigned int highlow)
167 {
168 if (highlow == 0)
169 {
170 m_Faces[dimension].first = f;
171 }
172 else
173 {
174 m_Faces[dimension].second = f;
175 }
176 this->Modified();
177 }
178
181 flat_hash_t *
183 {
184 return this->GetFlatHash(idx.first, idx.second);
185 }
186 flat_hash_t *
187 GetFlatHash(unsigned int dimension, unsigned int highlow)
188 {
189 if (highlow == 0)
190 {
191 return &(m_FlatHashes[dimension].first);
192 }
193
194 return &(m_FlatHashes[dimension].second);
195 }
196
197 void
199 {
200 this->SetFlatHash(l, idx.first, idx.second);
201 }
202 void
203 SetFlatHash(flat_hash_t & l, unsigned int dimension, unsigned int highlow)
204 {
205 if (highlow == 0)
206 {
207 m_FlatHashes[dimension].first = l;
208 }
209 else
210 {
211 m_FlatHashes[dimension].second = l;
212 }
213 this->Modified();
214 }
215
216
222 void
223 SetValid(bool & l, const IndexType & idx)
224 {
225 this->SetValid(l, idx.first, idx.second);
226 }
227 void
228 SetValid(bool b, unsigned int dimension, unsigned int highlow)
229 {
230 if (highlow == 0)
231 {
232 m_Valid[dimension].first = b;
233 }
234 else
235 {
236 m_Valid[dimension].second = b;
237 }
238 this->Modified();
239 }
240
241 bool
242 GetValid(const IndexType & idx) const
243 {
244 return this->GetValid(idx.first, idx.second);
245 }
246 bool
247 GetValid(unsigned int dimension, unsigned int highlow) const
248 {
249 if (highlow == 0)
250 {
251 return m_Valid[dimension].first;
252 }
253
254 return m_Valid[dimension].second;
255 }
256
257
258protected:
260 ~Boundary() override = default;
261
262 void
263 PrintSelf(std::ostream & os, Indent indent) const override;
264
266 std::vector<std::pair<FacePointer, FacePointer>> m_Faces{};
267
270 std::vector<std::pair<flat_hash_t, flat_hash_t>> m_FlatHashes{};
271
274 std::vector<std::pair<bool, bool>> m_Valid{};
275};
276} // namespace itk::watershed
277
278#ifndef ITK_MANUAL_INSTANTIATION
279# include "itkWatershedBoundary.hxx"
280#endif
281
282#endif
Templated n-dimensional image class.
Definition itkImage.h:89
Index< VImageDimension > IndexType
Control indentation during Print() invocation.
Definition itkIndent.h:50
virtual void Modified() const
Implements transparent reference counting.
flat_hash_t * GetFlatHash(const IndexType &idx)
flat_hash_t * GetFlatHash(unsigned int dimension, unsigned int highlow)
bool GetValid(unsigned int dimension, unsigned int highlow) const
void SetValid(bool b, unsigned int dimension, unsigned int highlow)
Image< IdentifierType, TDimension > ImageType
void SetFace(FacePointer f, unsigned int dimension, unsigned int highlow)
std::vector< std::pair< FacePointer, FacePointer > > m_Faces
SmartPointer< const Self > ConstPointer
void SetValid(bool &l, const IndexType &idx)
~Boundary() override=default
void SetFace(FacePointer f, const IndexType &idx)
typename face_t::Pointer FacePointer
bool GetValid(const IndexType &idx) const
std::pair< unsigned int, unsigned int > IndexType
std::unordered_map< IdentifierType, flat_region_t > flat_hash_t
void PrintSelf(std::ostream &os, Indent indent) const override
typename flat_hash_t::value_type FlatHashValueType
void SetFlatHash(flat_hash_t &l, const IndexType &idx)
Image< face_pixel_t, TDimension > face_t
std::vector< std::pair< flat_hash_t, flat_hash_t > > m_FlatHashes
typename ImageType::IndexType ImageIndexType
std::vector< std::pair< bool, bool > > m_Valid
FacePointer GetFace(const IndexType &idx)
FacePointer GetFace(unsigned int dimension, unsigned int highlow)
void SetFlatHash(flat_hash_t &l, unsigned int dimension, unsigned int highlow)
SizeValueType IdentifierType
Definition itkIntTypes.h:90