ITK  4.9.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 {
63 template< typename TLabel, unsigned int VImageDimension >
65 {
66 public:
68  typedef LabelObject Self;
74 
76  itkNewMacro(Self);
77 
79  itkTypeMacro(LabelObject, LightObject);
80 
81  itkStaticConstMacro(ImageDimension, unsigned int, VImageDimension);
82 
85  typedef TLabel LabelType;
87  typedef typename LineType::LengthType LengthType;
88  typedef unsigned int AttributeType;
90 
91  itkStaticConstMacro(LABEL, AttributeType, 0);
92 
93  static AttributeType GetAttributeFromName(const std::string & s);
94 
95  static std::string GetNameFromAttribute(const AttributeType & a);
96 
100  const LabelType & GetLabel() const;
101 
102  void SetLabel(const LabelType & label);
103 
108  bool HasIndex(const IndexType & idx) const;
109 
114  void AddIndex(const IndexType & idx);
115 
121  bool RemoveIndex(const IndexType & idx );
122 
126  void AddLine(const IndexType & idx, const LengthType & length);
127 
131  void AddLine(const LineType & line);
132 
134 
135  const LineType & GetLine(SizeValueType i) const;
136 
138 
146  SizeValueType Size() const;
147 
152  bool Empty() const;
153 
154  void Clear();
155 
161 
163  template< typename TSourceLabelObject >
164  void CopyLinesFrom(const TSourceLabelObject *src);
165 
167  template< typename TSourceLabelObject >
168  void CopyAttributesFrom(const TSourceLabelObject *src);
169 
171  template< typename TSourceLabelObject >
172  void CopyAllFrom(const TSourceLabelObject *src);
173 
177  void Optimize();
178 
180  void Shift( OffsetType offset );
181 
187  {
188  public:
189 
191 
193  {
194  m_Begin = lo->m_LineContainer.begin();
195  m_End = lo->m_LineContainer.end();
197  }
198 
200  {
201  m_Iterator = iter.m_Iterator;
202  m_Begin = iter.m_Begin;
203  m_End = iter.m_End;
204  }
205 
207  {
208  m_Iterator = iter.m_Iterator;
209  m_Begin = iter.m_Begin;
210  m_End = iter.m_End;
211  return *this;
212  }
213 
214  const LineType & GetLine() const
215  {
216  return *m_Iterator;
217  }
218 
220  {
221  ConstLineIterator tmp = *this;
222  ++(*this);
223  return tmp;
224  }
225 
227  {
228  ++m_Iterator;
229  return *this;
230  }
231 
232  bool operator==(const ConstLineIterator & iter) const
233  {
234  return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
235  }
236 
237  bool operator!=(const ConstLineIterator & iter) const
238  {
239  return !( *this == iter );
240  }
241 
242  void GoToBegin()
243  {
245  }
246 
247  bool IsAtEnd() const
248  {
249  return m_Iterator == m_End;
250  }
251 
252  private:
253  typedef typename std::deque< LineType > LineContainerType;
254  typedef typename LineContainerType::const_iterator InternalIteratorType;
258  };
259 
265  {
266  public:
267 
269  m_Iterator(),
270  m_Begin(),
271  m_End()
272  {
273  m_Index.Fill(0);
274  }
275 
277  {
278  m_Begin = lo->m_LineContainer.begin();
279  m_End = lo->m_LineContainer.end();
280  GoToBegin();
281  }
282 
284  {
285  m_Iterator = iter.m_Iterator;
286  m_Index = iter.m_Index;
287  m_Begin = iter.m_Begin;
288  m_End = iter.m_End;
289  }
290 
292  {
293  m_Iterator = iter.m_Iterator;
294  m_Index = iter.m_Index;
295  m_Begin = iter.m_Begin;
296  m_End = iter.m_End;
297  return *this;
298  }
299 
300  const IndexType & GetIndex() const
301  {
302  return m_Index;
303  }
304 
306  {
307  m_Index[0]++;
308  if( m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength() )
309  {
310  // we've reached the end of the line - go to the next one
311  ++m_Iterator;
312  NextValidLine();
313  }
314  return *this;
315  }
316 
318  {
319  ConstIndexIterator tmp = *this;
320  ++(*this);
321  return tmp;
322  }
323 
324  bool operator==(const ConstIndexIterator & iter) const
325  {
326  return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
327  }
328 
329  bool operator!=(const ConstIndexIterator & iter) const
330  {
331  return !( *this == iter );
332  }
333 
334  void GoToBegin()
335  {
337  m_Index.Fill(0);
338  NextValidLine();
339  }
340 
341  bool IsAtEnd() const
342  {
343  return m_Iterator == m_End;
344  }
345 
346  private:
347 
348  typedef typename std::deque< LineType > LineContainerType;
349  typedef typename LineContainerType::const_iterator InternalIteratorType;
351  {
352  // search for the next valid position
353  while( m_Iterator != m_End && m_Iterator->GetLength() == 0 )
354  {
355  ++m_Iterator;
356  }
357  if( m_Iterator != m_End )
358  {
359  m_Index = m_Iterator->GetIndex();
360  }
361  }
362 
367  };
368 
369 protected:
370  LabelObject();
371  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
372 
373 private:
374  LabelObject(const Self &) ITK_DELETE_FUNCTION;
375  void operator=(const Self &) ITK_DELETE_FUNCTION;
376 
377  typedef typename std::deque< LineType > LineContainerType;
378 
379  LineContainerType m_LineContainer;
381 };
382 } // end namespace itk
383 
384 #ifndef ITK_MANUAL_INSTANTIATION
385 #include "itkLabelObject.hxx"
386 #endif
387 
388 #endif
LightObject Superclass
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
bool Empty() const
signed long OffsetValueType
Definition: itkIntTypes.h:154
bool operator==(const ConstIndexIterator &iter) const
bool operator!=(const ConstIndexIterator &iter) const
std::deque< LineType > LineContainerType
void CopyLinesFrom(const TSourceLabelObject *src)
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 CopyAllFrom(const TSourceLabelObject *src)
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
void CopyAttributesFrom(const TSourceLabelObject *src)
SizeValueType GetNumberOfLines() const
A forward iterator over the lines of a LabelObject.
ConstLineIterator & operator=(const ConstLineIterator &iter)