Orfeo Toolbox  4.0
itkLabelMap.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 __itkLabelMap_h
19 #define __itkLabelMap_h
20 
21 #include "itkImageBase.h"
22 #include "itkWeakPointer.h"
23 #include <map>
24 
25 namespace itk
26 {
69 template< typename TLabelObject >
70 class LabelMap:public ImageBase< TLabelObject::ImageDimension >
71 {
72 public:
74  typedef LabelMap Self;
79 
81  itkNewMacro(Self);
82 
84  itkTypeMacro(LabelMap, ImageBase);
85 
86  typedef TLabelObject LabelObjectType;
87 
88  typedef typename LabelObjectType::Pointer LabelObjectPointerType;
89 
92 
97  itkStaticConstMacro(ImageDimension, unsigned int, LabelObjectType::ImageDimension);
98 
100  typedef typename LabelObjectType::LabelType LabelType;
102 
104  typedef std::vector< LabelType > LabelVectorType;
105  typedef std::vector< LabelObjectPointerType > LabelObjectVectorType;
106 
109 
112 
114  typedef typename Superclass::SizeType SizeType;
115 
118 
122 
126 
130 
133 
136  virtual void Initialize();
137 
139  virtual void Allocate();
140 
141  virtual void Graft(const DataObject *data);
142 
148  LabelObjectType * GetLabelObject(const LabelType & label);
149  const LabelObjectType * GetLabelObject(const LabelType & label) const;
150 
156  bool HasLabel(const LabelType label) const;
157 
165  const LabelObjectType * GetNthLabelObject(const SizeValueType & pos) const;
166 
174  const LabelType & GetPixel(const IndexType & idx) const;
175 
185  void SetPixel(const IndexType & idx, const LabelType & label);
186 
194  void AddPixel(const IndexType & idx, const LabelType & label);
195 
200  void RemovePixel(const IndexType & idx, const LabelType & label);
201 
209  void SetLine(const IndexType & idx, const LengthType & length, const LabelType & label);
210 
216  LabelObjectType * GetLabelObject(const IndexType & idx) const;
217 
222  void AddLabelObject(LabelObjectType *labelObject);
223 
228  void PushLabelObject(LabelObjectType *labelObject);
229 
233  void RemoveLabelObject(LabelObjectType *labelObject);
234 
238  void RemoveLabel(const LabelType & label);
239 
243  void ClearLabels();
244 
249 
253  LabelVectorType GetLabels() const;
254 
259 
263  itkGetConstMacro(BackgroundValue, LabelType);
264  itkSetMacro(BackgroundValue, LabelType);
265 
270  void PrintLabelObjects(std::ostream & os) const;
271 
272  void PrintLabelObjects() const
273  {
274  this->PrintLabelObjects(std::cerr);
275  }
276 
280  void Optimize();
281 
287  {
288  public:
289 
291 
292  ConstIterator(const Self *lm)
293  {
294  m_Begin = lm->m_LabelObjectContainer.begin();
295  m_End = lm->m_LabelObjectContainer.end();
297  }
298 
300  {
301  m_Iterator = iter.m_Iterator;
302  m_Begin = iter.m_Begin;
303  m_End = iter.m_End;
304  }
305 
307  {
308  m_Iterator = iter.m_Iterator;
309  m_Begin = iter.m_Begin;
310  m_End = iter.m_End;
311  return *this;
312  }
313 
315  {
316  return m_Iterator->second;
317  }
318 
319  const LabelType & GetLabel() const
320  {
321  return m_Iterator->first;
322  }
323 
325  {
326  ConstIterator tmp = *this;
327  ++(*this);
328  return tmp;
329  }
330 
332  {
333  ++m_Iterator;
334  return *this;
335  }
336 
337  bool operator==(const ConstIterator & iter) const
338  {
339  return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
340  }
341 
342  bool operator!=(const ConstIterator & iter) const
343  {
344  return !( *this == iter );
345  }
346 
347  void GoToBegin()
348  {
350  }
351 
352  bool IsAtEnd() const
353  {
354  return m_Iterator == m_End;
355  }
356 
357  private:
358  typedef typename std::map< LabelType, LabelObjectPointerType >::const_iterator InternalIteratorType;
362  };
363 
368  class Iterator
369  {
370  public:
371 
372  Iterator() {}
373 
375  {
376  m_Begin = lm->m_LabelObjectContainer.begin();
377  m_End = lm->m_LabelObjectContainer.end();
379  }
380 
381  Iterator(const Iterator & iter)
382  {
383  m_Iterator = iter.m_Iterator;
384  m_Begin = iter.m_Begin;
385  m_End = iter.m_End;
386  }
387 
388  Iterator & operator=(const Iterator & iter)
389  {
390  m_Iterator = iter.m_Iterator;
391  m_Begin = iter.m_Begin;
392  m_End = iter.m_End;
393  return *this;
394  }
395 
397  {
398  return m_Iterator->second;
399  }
400 
401  const LabelType & GetLabel() const
402  {
403  return m_Iterator->first;
404  }
405 
407  {
408  Iterator tmp = *this;
409  ++(*this);
410  return tmp;
411  }
412 
414  {
415  ++m_Iterator;
416  return *this;
417  }
418 
419  bool operator==(const Iterator & iter) const
420  {
421  return m_Iterator == iter.m_Iterator && m_Begin == iter.m_Begin && m_End == iter.m_End;
422  }
423 
424  bool operator!=(const Iterator & iter) const
425  {
426  return !( *this == iter );
427  }
428 
429  void GoToBegin()
430  {
432  }
433 
434  bool IsAtEnd() const
435  {
436  return m_Iterator == m_End;
437  }
438 
439  private:
440  typedef typename std::map< LabelType, LabelObjectPointerType >::iterator InternalIteratorType;
444 
445  friend class LabelMap;
446  };
447 
448 protected:
449  LabelMap();
450  virtual ~LabelMap() {}
451  void PrintSelf(std::ostream & os, Indent indent) const;
452 
453 private:
454  LabelMap(const Self &); //purposely not implemented
455  void operator=(const Self &); //purposely not implemented
456 
458  typedef std::map< LabelType, LabelObjectPointerType > LabelObjectContainerType;
459  typedef typename LabelObjectContainerType::iterator LabelObjectContainerIterator;
460  typedef typename LabelObjectContainerType::const_iterator
462 
465 
466  void AddPixel( const LabelObjectContainerIterator& it,
467  const IndexType& idx,
468  const LabelType& iLabel );
469 
471  const IndexType& idx,
472  bool iEmitModifiedEvent );
473 };
474 } // end namespace itk
475 
476 #ifndef ITK_MANUAL_INSTANTIATION
477 #include "itkLabelMap.hxx"
478 #endif
479 
480 #endif

Generated at Sat Mar 8 2014 15:02:31 for Orfeo Toolbox with doxygen 1.8.3.1