Main Page   Groups   Namespace List   Class Hierarchy   Alphabetical List   Compound List   File List   Namespace Members   Compound Members   File Members   Concepts

itkShapeRelabelLabelMapFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkShapeRelabelLabelMapFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-08-09 17:53:01 $
00007   Version:   $Revision: 1.7 $
00008 
00009   Copyright (c) Insight Software Consortium. All rights reserved.
00010   See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
00011 
00012      This software is distributed WITHOUT ANY WARRANTY; without even 
00013      the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
00014      PURPOSE.  See the above copyright notices for more information.
00015 
00016 =========================================================================*/
00017 #ifndef __itkShapeRelabelLabelMapFilter_h
00018 #define __itkShapeRelabelLabelMapFilter_h
00019 
00020 #include "itkInPlaceLabelMapFilter.h"
00021 #include "itkLabelObject.h"
00022 #include "itkLabelObjectAccessors.h"
00023 #include "itkShapeLabelObjectAccessors.h"
00024 
00025 namespace itk {
00041 template<class TImage >
00042 class ITK_EXPORT ShapeRelabelLabelMapFilter : 
00043     public InPlaceLabelMapFilter<TImage>
00044 {
00045 public:
00047   typedef ShapeRelabelLabelMapFilter    Self;
00048   typedef InPlaceLabelMapFilter<TImage> Superclass;
00049   typedef SmartPointer<Self>            Pointer;
00050   typedef SmartPointer<const Self>      ConstPointer;
00051 
00053   typedef TImage                                   ImageType;
00054   typedef typename ImageType::Pointer              ImagePointer;
00055   typedef typename ImageType::ConstPointer         ImageConstPointer;
00056   typedef typename ImageType::PixelType            PixelType;
00057   typedef typename ImageType::IndexType            IndexType;
00058   typedef typename ImageType::LabelObjectType      LabelObjectType;
00059 
00060   typedef typename LabelObjectType::AttributeType AttributeType;
00061   
00063   itkStaticConstMacro( ImageDimension, unsigned int, TImage::ImageDimension );
00064 
00066   itkNewMacro( Self );
00067 
00069   itkTypeMacro( ShapeRelabelLabelMapFilter, InPlaceLabelMapFilter );
00070 
00071 #ifdef ITK_USE_CONCEPT_CHECKING
00072 
00073 /*  itkConceptMacro(InputEqualityComparableCheck,
00074     (Concept::EqualityComparable<InputImagePixelType>));
00075   itkConceptMacro(IntConvertibleToInputCheck,
00076     (Concept::Convertible<int, InputImagePixelType>));
00077   itkConceptMacro(InputOStreamWritableCheck,
00078     (Concept::OStreamWritable<InputImagePixelType>));*/
00079 
00081 #endif
00082 
00088   itkSetMacro( ReverseOrdering, bool );
00089   itkGetConstReferenceMacro( ReverseOrdering, bool );
00090   itkBooleanMacro( ReverseOrdering );
00092 
00097   itkGetConstMacro( Attribute, AttributeType );
00098   itkSetMacro( Attribute, AttributeType );
00099   void SetAttribute( const std::string & s )
00100     {
00101     this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) );
00102     }
00104 
00105 
00106 protected:
00107   ShapeRelabelLabelMapFilter();
00108   ~ShapeRelabelLabelMapFilter() {};
00109 
00110   void GenerateData();
00111 
00112   typedef typename Superclass::LabelObjectContainerType LabelObjectContainerType;
00113 
00114   template <class TAttributeAccessor> 
00115   void TemplatedGenerateData( const TAttributeAccessor & )
00116     {
00117     // Allocate the output
00118     this->AllocateOutputs();
00119 
00120     ImageType * output = this->GetOutput();
00121 
00122     const LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer();
00123     typedef typename LabelObjectType::Pointer     LabelObjectPointer;
00124     typedef std::vector< LabelObjectPointer >     VectorType;
00125 
00126     ProgressReporter progress( this, 0, 2 * labelObjectContainer.size() );
00127 
00128     // Get the label objects in a vector, so they can be sorted
00129     VectorType labelObjects;
00130     labelObjects.reserve( labelObjectContainer.size() );
00131     for( typename LabelObjectContainerType::const_iterator it = labelObjectContainer.begin();
00132       it != labelObjectContainer.end();
00133       it++ )
00134       {
00135       labelObjects.push_back( it->second );
00136       progress.CompletedPixel();
00137       }
00138 
00139     // Instantiate the comparator and sort the vector
00140     if( m_ReverseOrdering )
00141       {
00142       std::sort( labelObjects.begin(), labelObjects.end(),
00143         Functor::LabelObjectReverseComparator< LabelObjectType, TAttributeAccessor >() );
00144       }
00145     else
00146       {
00147       std::sort( labelObjects.begin(), labelObjects.end(),
00148         Functor::LabelObjectComparator< LabelObjectType, TAttributeAccessor >() );
00149       }
00150     //   progress.CompletedPixel();
00151     
00152     // and put back the objects in the map
00153     output->ClearLabels();
00154     unsigned int label = 0;
00155     typename VectorType::const_iterator it2 = labelObjects.begin();
00156     while( it2 != labelObjects.end() )
00157       {
00158       // Avoid the background label if it is used
00159       if( label == output->GetBackgroundValue() )
00160         {
00161         label++;
00162         }
00163       ( *it2 )->SetLabel( label );
00164       output->AddLabelObject( *it2 );
00165       
00166       // Go to the next label
00167       label++;
00168       progress.CompletedPixel();
00169 
00170       it2++;
00171       }
00172     }
00173 
00174   void PrintSelf(std::ostream& os, Indent indent) const;
00175 
00176   bool          m_ReverseOrdering;
00177   AttributeType m_Attribute;
00178 
00179 private:
00180   ShapeRelabelLabelMapFilter(const Self&); //purposely not implemented
00181   void operator=(const Self&); //purposely not implemented
00182 
00183 }; // end of class
00184 
00185 } // end namespace itk
00186   
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkShapeRelabelLabelMapFilter.txx"
00189 #endif
00190 
00191 #endif
00192 

Generated at Mon Jul 12 2010 19:52:26 for ITK by doxygen 1.7.1 written by Dimitri van Heesch, © 1997-2000