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{
63template <typename TLabel, unsigned int VImageDimension>
64class ITK_TEMPLATE_EXPORT LabelObject : public LightObject
65{
66public:
67 ITK_DISALLOW_COPY_AND_MOVE(LabelObject);
68
76
78 itkNewMacro(Self);
79
81 itkOverrideGetNameOfClassMacro(LabelObject);
82
83 static constexpr unsigned int ImageDimension = VImageDimension;
84
87 using LabelType = TLabel;
90 using AttributeType = unsigned int;
92
93 static constexpr AttributeType LABEL = 0;
94
95 static AttributeType
96 GetAttributeFromName(const std::string & s);
97
98 static std::string
104 const LabelType &
105 GetLabel() const;
106
107 void
108 SetLabel(const LabelType & label);
109
114 bool
115 HasIndex(const IndexType & idx) const;
116
121 void
122 AddIndex(const IndexType & idx);
123
129 bool
130 RemoveIndex(const IndexType & idx);
131
135 void
136 AddLine(const IndexType & idx, const LengthType & length);
137
141 void
142 AddLine(const LineType & line);
143
146
147 const LineType &
149
150 LineType &
152
161 Size() const;
162
167 bool
168 Empty() const;
169
170 void
172
178 GetIndex(SizeValueType offset) const;
179
181 template <typename TSourceLabelObject>
182 void
183 CopyLinesFrom(const TSourceLabelObject * src);
184
186 template <typename TSourceLabelObject>
187 void
188 CopyAttributesFrom(const TSourceLabelObject * src);
189
191 template <typename TSourceLabelObject>
192 void
193 CopyAllFrom(const TSourceLabelObject * src);
194
198 void
200
202 void
204
211 {
212 public:
213 ConstLineIterator() = default;
214
216 : m_Begin(lo->m_LineContainer.begin())
217 , m_End(lo->m_LineContainer.end())
218 {
220 }
221
223 : m_Iterator(iter.m_Iterator)
224 , m_Begin(iter.m_Begin)
225 , m_End(iter.m_End)
226 {}
227
229 operator=(const ConstLineIterator & iter) = default;
230
231 [[nodiscard]] const LineType &
232 GetLine() const
233 {
234 return *m_Iterator;
235 }
236
239 {
240 const ConstLineIterator tmp = *this;
241 ++(*this);
242 return tmp;
243 }
244
247 {
248 ++m_Iterator;
249 return *this;
250 }
251
252 bool
253 operator==(const ConstLineIterator & iter) const
254 {
255 return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
256 }
257
259
260 void
262 {
264 }
265
266 [[nodiscard]] bool
267 IsAtEnd() const
268 {
269 return m_Iterator == m_End;
270 }
271
272 private:
273 using LineContainerType = typename std::deque<LineType>;
274 using InternalIteratorType = typename LineContainerType::const_iterator;
278 };
279
286 {
287 public:
289 : m_Iterator()
290 , m_Begin()
291 , m_End()
292 {
293 m_Index.Fill(0);
294 }
295
297 : m_Begin(lo->m_LineContainer.begin())
298 , m_End(lo->m_LineContainer.end())
299 {
300 GoToBegin();
301 }
302
304 : m_Iterator(iter.m_Iterator)
305 , m_Begin(iter.m_Begin)
306 , m_End(iter.m_End)
307 , m_Index(iter.m_Index)
308 {}
309
311 operator=(const ConstIndexIterator & iter) = default;
312
313 [[nodiscard]] const IndexType &
314 GetIndex() const
315 {
316 return m_Index;
317 }
318
321 {
322 m_Index[0]++;
323 if (m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength())
324 {
325 // we've reached the end of the line - go to the next one
326 ++m_Iterator;
328 }
329 return *this;
330 }
331
334 {
335 ConstIndexIterator tmp = *this;
336 ++(*this);
337 return tmp;
338 }
339
340 bool
341 operator==(const ConstIndexIterator & iter) const
342 {
343 return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
344 }
345
347
348 void
350 {
352 m_Index.Fill(0);
354 }
355
356 [[nodiscard]] bool
357 IsAtEnd() const
358 {
359 return m_Iterator == m_End;
360 }
361
362 private:
363 using LineContainerType = typename std::deque<LineType>;
364 using InternalIteratorType = typename LineContainerType::const_iterator;
365 void
367 {
368 // search for the next valid position
369 while (m_Iterator != m_End && m_Iterator->GetLength() == 0)
370 {
371 ++m_Iterator;
372 }
373 if (m_Iterator != m_End)
374 {
375 m_Index = m_Iterator->GetIndex();
376 }
377 }
378
383 };
384
385protected:
387 void
388 PrintSelf(std::ostream & os, Indent indent) const override;
389
390private:
391 using LineContainerType = typename std::deque<LineType>;
392
395};
396} // end namespace itk
397
398#ifndef ITK_MANUAL_INSTANTIATION
399# include "itkLabelObject.hxx"
400#endif
401
402#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
SmartPointer< Self > Pointer
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
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
LightObject Superclass
void AddLine(const IndexType &idx, const LengthType &length)
LineType & GetLine(SizeValueType i)
Implements transparent reference counting.
SmartPointer< const Self > ConstPointer
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