ITK  4.6.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  virtual void CopyAttributesFrom(const Self *src);
164 
166  void CopyAllFrom(const Self *src);
167 
171  void Optimize();
172 
174  void Shift( OffsetType offset );
175 
181  {
182  public:
183 
185 
187  {
188  m_Begin = lo->m_LineContainer.begin();
189  m_End = lo->m_LineContainer.end();
191  }
192 
194  {
195  m_Iterator = iter.m_Iterator;
196  m_Begin = iter.m_Begin;
197  m_End = iter.m_End;
198  }
199 
201  {
202  m_Iterator = iter.m_Iterator;
203  m_Begin = iter.m_Begin;
204  m_End = iter.m_End;
205  return *this;
206  }
207 
208  const LineType & GetLine() const
209  {
210  return *m_Iterator;
211  }
212 
214  {
215  ConstLineIterator tmp = *this;
216  ++(*this);
217  return tmp;
218  }
219 
221  {
222  ++m_Iterator;
223  return *this;
224  }
225 
226  bool operator==(const ConstLineIterator & iter) const
227  {
228  return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
229  }
230 
231  bool operator!=(const ConstLineIterator & iter) const
232  {
233  return !( *this == iter );
234  }
235 
236  void GoToBegin()
237  {
239  }
240 
241  bool IsAtEnd() const
242  {
243  return m_Iterator == m_End;
244  }
245 
246  private:
247  typedef typename std::deque< LineType > LineContainerType;
248  typedef typename LineContainerType::const_iterator InternalIteratorType;
252  };
253 
259  {
260  public:
261 
263  m_Iterator(),
264  m_Begin(),
265  m_End()
266  {
267  m_Index.Fill(0);
268  }
269 
271  {
272  m_Begin = lo->m_LineContainer.begin();
273  m_End = lo->m_LineContainer.end();
274  GoToBegin();
275  }
276 
278  {
279  m_Iterator = iter.m_Iterator;
280  m_Index = iter.m_Index;
281  m_Begin = iter.m_Begin;
282  m_End = iter.m_End;
283  }
284 
286  {
287  m_Iterator = iter.m_Iterator;
288  m_Index = iter.m_Index;
289  m_Begin = iter.m_Begin;
290  m_End = iter.m_End;
291  return *this;
292  }
293 
294  const IndexType & GetIndex() const
295  {
296  return m_Index;
297  }
298 
300  {
301  m_Index[0]++;
302  if( m_Index[0] >= m_Iterator->GetIndex()[0] + (OffsetValueType)m_Iterator->GetLength() )
303  {
304  // we've reached the end of the line - go to the next one
305  ++m_Iterator;
306  NextValidLine();
307  }
308  return *this;
309  }
310 
312  {
313  ConstIndexIterator tmp = *this;
314  ++(*this);
315  return tmp;
316  }
317 
318  bool operator==(const ConstIndexIterator & iter) const
319  {
320  return m_Index == iter.m_Index && m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
321  }
322 
323  bool operator!=(const ConstIndexIterator & iter) const
324  {
325  return !( *this == iter );
326  }
327 
328  void GoToBegin()
329  {
331  m_Index.Fill(0);
332  NextValidLine();
333  }
334 
335  bool IsAtEnd() const
336  {
337  return m_Iterator == m_End;
338  }
339 
340  private:
341 
342  typedef typename std::deque< LineType > LineContainerType;
343  typedef typename LineContainerType::const_iterator InternalIteratorType;
345  {
346  // search for the next valid position
347  while( m_Iterator != m_End && m_Iterator->GetLength() == 0 )
348  {
349  ++m_Iterator;
350  }
351  if( m_Iterator != m_End )
352  {
353  m_Index = m_Iterator->GetIndex();
354  }
355  }
356 
361  };
362 
363 protected:
364  LabelObject();
365  virtual void PrintSelf(std::ostream & os, Indent indent) const ITK_OVERRIDE;
366 
367 private:
368  LabelObject(const Self &); //purposely not implemented
369  void operator=(const Self &); //purposely not implemented
370 
371  typedef typename std::deque< LineType > LineContainerType;
372 
375 };
376 } // end namespace itk
377 
378 #ifndef ITK_MANUAL_INSTANTIATION
379 #include "itkLabelObject.hxx"
380 #endif
381 
382 #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
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
virtual void PrintSelf(std::ostream &os, Indent indent) const ITK_OVERRIDE
A forward iterator over the lines of a LabelObject.
ConstLineIterator & operator=(const ConstLineIterator &iter)