ITK  4.8.0
Insight Segmentation and Registration Toolkit
itkLabelObject.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright Insight Software Consortium
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 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 
27 namespace itk
28 {
62 template< typename TLabel, unsigned int VImageDimension >
64 {
65 public:
67  typedef LabelObject Self;
73 
75  itkNewMacro(Self);
76 
78  itkTypeMacro(LabelObject, LightObject);
79 
80  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
81 
84  typedef TLabel LabelType;
86  typedef typename LineType::LengthType LengthType;
87  typedef unsigned int AttributeType;
89 
90  itkStaticConstMacro(LABEL, AttributeType, 0);
91 
92  static AttributeType GetAttributeFromName(const std::string & s);
93 
94  static std::string GetNameFromAttribute(const AttributeType & a);
95 
99  const LabelType & GetLabel() const;
100 
101  void SetLabel(const LabelType & label);
102 
107  bool HasIndex(const IndexType & idx) const;
108 
113  void AddIndex(const IndexType & idx);
114 
120  bool RemoveIndex(const IndexType & idx );
121 
125  void AddLine(const IndexType & idx, const LengthType & length);
126 
130  void AddLine(const LineType & line);
131 
133 
134  const LineType & GetLine(SizeValueType i) const;
135 
137 
145  SizeValueType Size() const;
146 
151  bool Empty() const;
152 
153  void Clear();
154 
160 
162  virtual void CopyAttributesFrom(const Self *src);
163 
165  void CopyAllFrom(const Self *src);
166 
170  void Optimize();
171 
173  void Shift( OffsetType offset );
174 
180  {
181  public:
182 
184 
186  {
187  m_Begin = lo->m_LineContainer.begin();
188  m_End = lo->m_LineContainer.end();
190  }
191 
193  {
194  m_Iterator = iter.m_Iterator;
195  m_Begin = iter.m_Begin;
196  m_End = iter.m_End;
197  }
198 
200  {
201  m_Iterator = iter.m_Iterator;
202  m_Begin = iter.m_Begin;
203  m_End = iter.m_End;
204  return *this;
205  }
206 
207  const LineType & GetLine() const
208  {
209  return *m_Iterator;
210  }
211 
213  {
214  ConstLineIterator tmp = *this;
215  ++(*this);
216  return tmp;
217  }
218 
220  {
221  ++m_Iterator;
222  return *this;
223  }
224 
225  bool operator==(const ConstLineIterator & iter) const
226  {
227  return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
228  }
229 
230  bool operator!=(const ConstLineIterator & iter) const
231  {
232  return !( *this == iter );
233  }
234 
235  void GoToBegin()
236  {
238  }
239 
240  bool IsAtEnd() const
241  {
242  return m_Iterator == m_End;
243  }
244 
245  private:
246  typedef typename std::deque< LineType > LineContainerType;
247  typedef typename LineContainerType::const_iterator InternalIteratorType;
251  };
252 
258  {
259  public:
260 
262  m_Iterator(),
263  m_Begin(),
264  m_End()
265  {
266  m_Index.Fill(0);
267  }
268 
270  {
271  m_Begin = lo->m_LineContainer.begin();
272  m_End = lo->m_LineContainer.end();
273  GoToBegin();
274  }
275 
277  {
278  m_Iterator = iter.m_Iterator;
279  m_Index = iter.m_Index;
280  m_Begin = iter.m_Begin;
281  m_End = iter.m_End;
282  }
283 
285  {
286  m_Iterator = iter.m_Iterator;
287  m_Index = iter.m_Index;
288  m_Begin = iter.m_Begin;
289  m_End = iter.m_End;
290  return *this;
291  }
292 
293  const IndexType & GetIndex() const
294  {
295  return m_Index;
296  }
297 
299  {
300  m_Index[0]++;
301  if( m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength() )
302  {
303  // we've reached the end of the line - go to the next one
304  ++m_Iterator;
305  NextValidLine();
306  }
307  return *this;
308  }
309 
311  {
312  ConstIndexIterator tmp = *this;
313  ++(*this);
314  return tmp;
315  }
316 
317  bool operator==(const ConstIndexIterator & iter) const
318  {
319  return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
320  }
321 
322  bool operator!=(const ConstIndexIterator & iter) const
323  {
324  return !( *this == iter );
325  }
326 
327  void GoToBegin()
328  {
330  m_Index.Fill(0);
331  NextValidLine();
332  }
333 
334  bool IsAtEnd() const
335  {
336  return m_Iterator == m_End;
337  }
338 
339  private:
340 
341  typedef typename std::deque< LineType > LineContainerType;
342  typedef typename LineContainerType::const_iterator InternalIteratorType;
344  {
345  // search for the next valid position
346  while( m_Iterator != m_End && m_Iterator->GetLength() == 0 )
347  {
348  ++m_Iterator;
349  }
350  if( m_Iterator != m_End )
351  {
352  m_Index = m_Iterator->GetIndex();
353  }
354  }
355 
360  };
361 
362 protected:
363  LabelObject();
364  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
365 
366 private:
367  LabelObject(const Self &); //purposely not implemented
368  void operator=(const Self &); //purposely not implemented
369 
370  typedef typename std::deque< LineType > LineContainerType;
371 
374 };
375 } // end namespace itk
376 
377 #ifndef ITK_MANUAL_INSTANTIATION
378 #include "itkLabelObject.hxx"
379 #endif
380 
381 #endif
LightObject Superclass
void operator=(const Self &)
void AddLine(const IndexType &idx, const LengthType &length)
bool RemoveIndex(const IndexType &idx)
Light weight base class for most itk classes.
bool operator==(const ConstLineIterator &iter) const
Represent the offset between two n-dimensional indexes in a n-dimensional image.
Definition: itkOffset.h:55
IndexType GetIndex(SizeValueType i) const
void CopyAllFrom(const Self *src)
bool Empty() const
virtual void CopyAttributesFrom(const Self *src)
signed long OffsetValueType
Definition: itkIntTypes.h:154
bool operator==(const ConstIndexIterator &iter) const
bool operator!=(const ConstIndexIterator &iter) const
std::deque< LineType > LineContainerType
static AttributeType GetAttributeFromName(const std::string &s)
std::deque< LineType > LineContainerType
void SetLabel(const LabelType &label)
Implements a weak reference to an object.
static const unsigned int ImageDimension
std::deque< LineType > LineContainerType
unsigned long SizeValueType
Definition: itkIntTypes.h:143
LabelObjectLine< VImageDimension > LineType
const IndexType & GetIndex() const
SmartPointer< const Self > ConstPointer
LabelObject Self
LineContainerType m_LineContainer
unsigned int AttributeType
Index< VImageDimension > IndexType
static std::string GetNameFromAttribute(const AttributeType &a)
const LineType & GetLine() const
void AddIndex(const IndexType &idx)
LineType::LengthType LengthType
Offset< VImageDimension > OffsetType
void Shift(OffsetType offset)
const LineType & GetLine(SizeValueType i) const
LineContainerType::const_iterator InternalIteratorType
virtual void PrintSelf(std::ostream &os, Indent indent) const override
void Fill(IndexValueType value)
Definition: itkIndex.h:292
ConstIndexIterator & operator=(const ConstIndexIterator &iter)
bool HasIndex(const IndexType &idx) const
SizeValueType Size() const
itk::SizeValueType SizeValueType
ConstLineIterator operator++(int)
ConstIndexIterator(const ConstIndexIterator &iter)
ConstIndexIterator operator++(int)
bool operator!=(const ConstLineIterator &iter) const
The base class for the representation of an labeled binary object in an image.
WeakPointer< const Self > ConstWeakPointer
SmartPointer< Self > Pointer
ConstLineIterator(const ConstLineIterator &iter)
LineContainerType::const_iterator InternalIteratorType
Control indentation during Print() invocation.
Definition: itkIndent.h:49
static const AttributeType LABEL
const LabelType & GetLabel() const
SizeValueType GetNumberOfLines() const
A forward iterator over the lines of a LabelObject.
ConstLineIterator & operator=(const ConstLineIterator &iter)