ITK 6.0.0
Insight Toolkit
 
Loading...
Searching...
No Matches
itkLabelObject.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 itkLabelObject_h
19#define itkLabelObject_h
20
21#include <deque>
22#include "itkLightObject.h"
23#include "itkLabelObjectLine.h"
24#include "itkWeakPointer.h"
25#include "itkObjectFactory.h"
26
27namespace itk
28{
64template <typename TLabel, unsigned int VImageDimension>
65class ITK_TEMPLATE_EXPORT LabelObject : public LightObject
67public:
68 ITK_DISALLOW_COPY_AND_MOVE(LabelObject);
69
77
79 itkNewMacro(Self);
82 itkOverrideGetNameOfClassMacro(LabelObject);
83
84 static constexpr unsigned int ImageDimension = VImageDimension;
85
88 using LabelType = TLabel;
91 using AttributeType = unsigned int;
93
94 static constexpr AttributeType LABEL = 0;
95
97 GetAttributeFromName(const std::string & s);
98
99 static std::string
101
105 const LabelType &
106 GetLabel() const;
107
108 void
109 SetLabel(const LabelType & label);
110
115 bool
116 HasIndex(const IndexType & idx) const;
117
122 void
123 AddIndex(const IndexType & idx);
124
130 bool
131 RemoveIndex(const IndexType & idx);
132
136 void
137 AddLine(const IndexType & idx, const LengthType & length);
138
142 void
143 AddLine(const LineType & line);
144
147
148 const LineType &
150
151 LineType &
153
162 Size() const;
163
168 bool
169 Empty() const;
170
171 void
173
179 GetIndex(SizeValueType offset) const;
180
182 template <typename TSourceLabelObject>
183 void
184 CopyLinesFrom(const TSourceLabelObject * src);
185
187 template <typename TSourceLabelObject>
188 void
189 CopyAttributesFrom(const TSourceLabelObject * src);
190
192 template <typename TSourceLabelObject>
193 void
194 CopyAllFrom(const TSourceLabelObject * src);
195
199 void
201
203 void
205
212 {
213 public:
214 ConstLineIterator() = default;
215
217 : m_Begin(lo->m_LineContainer.begin())
218 , m_End(lo->m_LineContainer.end())
219 {
221 }
222
224 : m_Iterator(iter.m_Iterator)
225 , m_Begin(iter.m_Begin)
226 , m_End(iter.m_End)
227 {}
228
230 operator=(const ConstLineIterator & iter) = default;
231
232 [[nodiscard]] const LineType &
233 GetLine() const
234 {
235 return *m_Iterator;
236 }
237
240 {
241 const ConstLineIterator tmp = *this;
242 ++(*this);
243 return tmp;
244 }
245
248 {
249 ++m_Iterator;
250 return *this;
251 }
252
253 bool
254 operator==(const ConstLineIterator & iter) const
255 {
256 return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
257 }
258
260
261 void
263 {
265 }
266
267 [[nodiscard]] bool
268 IsAtEnd() const
269 {
270 return m_Iterator == m_End;
271 }
272
273 private:
274 using LineContainerType = typename std::deque<LineType>;
275 using InternalIteratorType = typename LineContainerType::const_iterator;
279 };
280
287 {
288 public:
290 : m_Iterator()
291 , m_Begin()
292 , m_End()
293 {
294 m_Index.Fill(0);
295 }
296
298 : m_Begin(lo->m_LineContainer.begin())
299 , m_End(lo->m_LineContainer.end())
300 {
301 GoToBegin();
302 }
303
305 : m_Iterator(iter.m_Iterator)
306 , m_Begin(iter.m_Begin)
307 , m_End(iter.m_End)
308 , m_Index(iter.m_Index)
309 {}
310
312 operator=(const ConstIndexIterator & iter) = default;
313
314 [[nodiscard]] const IndexType &
315 GetIndex() const
316 {
317 return m_Index;
318 }
319
322 {
323 m_Index[0]++;
324 if (m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength())
325 {
326 // we've reached the end of the line - go to the next one
327 ++m_Iterator;
329 }
330 return *this;
331 }
332
335 {
336 ConstIndexIterator tmp = *this;
337 ++(*this);
338 return tmp;
339 }
340
341 bool
342 operator==(const ConstIndexIterator & iter) const
343 {
344 return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
345 }
346
348
349 void
351 {
353 m_Index.Fill(0);
355 }
356
357 [[nodiscard]] bool
358 IsAtEnd() const
359 {
360 return m_Iterator == m_End;
361 }
362
363 private:
364 using LineContainerType = typename std::deque<LineType>;
365 using InternalIteratorType = typename LineContainerType::const_iterator;
366 void
368 {
369 // search for the next valid position
370 while (m_Iterator != m_End && m_Iterator->GetLength() == 0)
371 {
372 ++m_Iterator;
373 }
374 if (m_Iterator != m_End)
375 {
376 m_Index = m_Iterator->GetIndex();
377 }
378 }
379
384 };
385
386protected:
388 void
389 PrintSelf(std::ostream & os, Indent indent) const override;
390
391private:
392 using LineContainerType = typename std::deque<LineType>;
393
396};
397} // end namespace itk
398
399#ifndef ITK_MANUAL_INSTANTIATION
400# include "itkLabelObject.hxx"
401#endif
402
403#endif
Control indentation during Print() invocation.
Definition itkIndent.h:50
typename LineContainerType::const_iterator InternalIteratorType
typename std::deque< LineType > LineContainerType
const IndexType & GetIndex() const
ConstIndexIterator & operator=(const ConstIndexIterator &iter)=default
ConstIndexIterator(const ConstIndexIterator &iter)
bool operator==(const ConstIndexIterator &iter) const
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstIndexIterator)
A forward iterator over the lines of a LabelObject.
typename LineContainerType::const_iterator InternalIteratorType
ITK_UNEQUAL_OPERATOR_MEMBER_FUNCTION(ConstLineIterator)
ConstLineIterator(const ConstLineIterator &iter)
const LineType & GetLine() const
ConstLineIterator & operator=(const ConstLineIterator &iter)=default
bool operator==(const ConstLineIterator &iter) const
typename std::deque< LineType > LineContainerType
The base class for the representation of a labeled binary object in an image.
bool HasIndex(const IndexType &idx) const
static AttributeType GetAttributeFromName(const std::string &s)
itk::SizeValueType SizeValueType
static constexpr AttributeType LABEL
LabelObjectLine< VImageDimension > LineType
WeakPointer< const Self > ConstWeakPointer
typename std::deque< LineType > LineContainerType
void Shift(OffsetType offset)
void CopyAllFrom(const TSourceLabelObject *src)
void SetLabel(const LabelType &label)
void AddIndex(const IndexType &idx)
bool RemoveIndex(const IndexType &idx)
const LineType & GetLine(SizeValueType i) const
IndexType GetIndex(SizeValueType offset) const
void PrintSelf(std::ostream &os, Indent indent) const override
const LabelType & GetLabel() const
LineContainerType m_LineContainer
void AddLine(const LineType &line)
Index< VImageDimension > IndexType
SmartPointer< const Self > ConstPointer
unsigned int AttributeType
SizeValueType Size() const
static constexpr unsigned int ImageDimension
static std::string GetNameFromAttribute(const AttributeType &a)
void CopyLinesFrom(const TSourceLabelObject *src)
void CopyAttributesFrom(const TSourceLabelObject *src)
Offset< VImageDimension > OffsetType
bool Empty() const
typename LineType::LengthType LengthType
SizeValueType GetNumberOfLines() const
void AddLine(const IndexType &idx, const LengthType &length)
LineType & GetLine(SizeValueType i)
Light weight base class for most itk classes.
Implements transparent reference counting.
ShapeLabelObject< TLabel, VImageDimension > Superclass
Implements a weak reference to an object.
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
unsigned long SizeValueType
Definition itkIntTypes.h:86
long OffsetValueType
Definition itkIntTypes.h:97
Represent a n-dimensional index in a n-dimensional image.
Definition itkIndex.h:69
Represent a n-dimensional offset between two n-dimensional indexes of n-dimensional image.
Definition itkOffset.h:67