ITK  6.0.0
Insight Toolkit
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
66{
67public:
68 ITK_DISALLOW_COPY_AND_MOVE(LabelObject);
78
80 itkNewMacro(Self);
81
83 itkOverrideGetNameOfClassMacro(LabelObject);
84
85 static constexpr unsigned int ImageDimension = VImageDimension;
86
89 using LabelType = TLabel;
92 using AttributeType = unsigned int;
94
95 static constexpr AttributeType LABEL = 0;
96
97 static AttributeType
98 GetAttributeFromName(const std::string & s);
99
100 static std::string
102
106 const LabelType &
107 GetLabel() const;
108
109 void
110 SetLabel(const LabelType & label);
111
116 bool
117 HasIndex(const IndexType & idx) const;
118
123 void
124 AddIndex(const IndexType & idx);
125
131 bool
132 RemoveIndex(const IndexType & idx);
133
137 void
138 AddLine(const IndexType & idx, const LengthType & length);
139
143 void
144 AddLine(const LineType & line);
145
148
149 const LineType &
151
152 LineType &
154
163 Size() const;
164
169 bool
170 Empty() const;
171
172 void
174
180 GetIndex(SizeValueType offset) const;
181
183 template <typename TSourceLabelObject>
184 void
185 CopyLinesFrom(const TSourceLabelObject * src);
186
188 template <typename TSourceLabelObject>
189 void
190 CopyAttributesFrom(const TSourceLabelObject * src);
191
193 template <typename TSourceLabelObject>
194 void
195 CopyAllFrom(const TSourceLabelObject * src);
196
200 void
202
204 void
206
213 {
214 public:
215 ConstLineIterator() = default;
216
218 {
219 m_Begin = lo->m_LineContainer.begin();
220 m_End = lo->m_LineContainer.end();
221 m_Iterator = m_Begin;
222 }
223
225 {
226 m_Iterator = iter.m_Iterator;
227 m_Begin = iter.m_Begin;
228 m_End = iter.m_End;
229 }
230
233 {
234 m_Iterator = iter.m_Iterator;
235 m_Begin = iter.m_Begin;
236 m_End = iter.m_End;
237 return *this;
238 }
239
240 const LineType &
241 GetLine() const
242 {
243 return *m_Iterator;
244 }
245
248 {
249 ConstLineIterator tmp = *this;
250 ++(*this);
251 return tmp;
252 }
253
256 {
257 ++m_Iterator;
258 return *this;
259 }
260
261 bool
262 operator==(const ConstLineIterator & iter) const
263 {
264 return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
265 }
266
268
269 void
271 {
272 m_Iterator = m_Begin;
273 }
274
275 bool
276 IsAtEnd() const
277 {
278 return m_Iterator == m_End;
279 }
280
281 private:
282 using LineContainerType = typename std::deque<LineType>;
283 using InternalIteratorType = typename LineContainerType::const_iterator;
287 };
288
295 {
296 public:
298 : m_Iterator()
299 , m_Begin()
300 , m_End()
301 {
302 m_Index.Fill(0);
303 }
304
306 {
307 m_Begin = lo->m_LineContainer.begin();
308 m_End = lo->m_LineContainer.end();
309 GoToBegin();
310 }
311
313 {
314 m_Iterator = iter.m_Iterator;
315 m_Index = iter.m_Index;
316 m_Begin = iter.m_Begin;
317 m_End = iter.m_End;
318 }
319
322 {
323 m_Iterator = iter.m_Iterator;
324 m_Index = iter.m_Index;
325 m_Begin = iter.m_Begin;
326 m_End = iter.m_End;
327 return *this;
328 }
329
330 const IndexType &
331 GetIndex() const
332 {
333 return m_Index;
334 }
335
338 {
339 m_Index[0]++;
340 if (m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength())
341 {
342 // we've reached the end of the line - go to the next one
343 ++m_Iterator;
344 NextValidLine();
345 }
346 return *this;
347 }
348
351 {
352 ConstIndexIterator tmp = *this;
353 ++(*this);
354 return tmp;
355 }
356
357 bool
358 operator==(const ConstIndexIterator & iter) const
359 {
360 return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
361 }
362
364
365 void
367 {
368 m_Iterator = m_Begin;
369 m_Index.Fill(0);
370 NextValidLine();
371 }
372
373 bool
374 IsAtEnd() const
375 {
376 return m_Iterator == m_End;
377 }
378
379 private:
380 using LineContainerType = typename std::deque<LineType>;
381 using InternalIteratorType = typename LineContainerType::const_iterator;
382 void
384 {
385 // search for the next valid position
386 while (m_Iterator != m_End && m_Iterator->GetLength() == 0)
387 {
388 ++m_Iterator;
389 }
390 if (m_Iterator != m_End)
391 {
392 m_Index = m_Iterator->GetIndex();
393 }
394 }
395
400 };
401
402protected:
404 void
405 PrintSelf(std::ostream & os, Indent indent) const override;
406
407private:
408 using LineContainerType = typename std::deque<LineType>;
409
410 LineContainerType m_LineContainer{};
411 LabelType m_Label{};
412};
413} // end namespace itk
414
415#ifndef ITK_MANUAL_INSTANTIATION
416# include "itkLabelObject.hxx"
417#endif
418
419#endif
Control indentation during Print() invocation.
Definition: itkIndent.h:50
ConstIndexIterator operator++(int)
typename LineContainerType::const_iterator InternalIteratorType
typename std::deque< LineType > LineContainerType
const IndexType & GetIndex() const
ConstIndexIterator(const ConstIndexIterator &iter)
bool operator==(const ConstIndexIterator &iter) const
ConstIndexIterator & operator=(const ConstIndexIterator &iter)
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)
bool operator==(const ConstLineIterator &iter) const
typename std::deque< LineType > LineContainerType
ConstLineIterator operator++(int)
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
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
void AddLine(const LineType &line)
unsigned int AttributeType
SizeValueType Size() const
static std::string GetNameFromAttribute(const AttributeType &a)
void CopyLinesFrom(const TSourceLabelObject *src)
void CopyAttributesFrom(const TSourceLabelObject *src)
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 a weak reference to an object.
AddImageFilter Self
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 offset between two n-dimensional indexes of n-dimensional image.
Definition: itkOffset.h:67