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

itkShapeOpeningLabelMapFilter.h

Go to the documentation of this file.
00001 /*=========================================================================
00002 
00003   Program:   Insight Segmentation & Registration Toolkit
00004   Module:    $RCSfile: itkShapeOpeningLabelMapFilter.h,v $
00005   Language:  C++
00006   Date:      $Date: 2009-08-05 15:52:35 $
00007   Version:   $Revision: 1.3 $
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 __itkShapeOpeningLabelMapFilter_h
00018 #define __itkShapeOpeningLabelMapFilter_h
00019 
00020 #include "itkInPlaceLabelMapFilter.h"
00021 #include "itkLabelObjectAccessors.h"
00022 #include "itkShapeLabelObjectAccessors.h"
00023 #include "itkProgressReporter.h"
00024 
00025 namespace itk {
00042 template<class TImage>
00043 class ITK_EXPORT ShapeOpeningLabelMapFilter : 
00044     public InPlaceLabelMapFilter<TImage>
00045 {
00046 public:
00048   typedef ShapeOpeningLabelMapFilter    Self;
00049   typedef InPlaceLabelMapFilter<TImage> Superclass;
00050   typedef SmartPointer<Self>            Pointer;
00051   typedef SmartPointer<const Self>      ConstPointer;
00052 
00054   typedef TImage                              ImageType;
00055   typedef typename ImageType::Pointer         ImagePointer;
00056   typedef typename ImageType::ConstPointer    ImageConstPointer;
00057   typedef typename ImageType::PixelType       PixelType;
00058   typedef typename ImageType::IndexType       IndexType;
00059   typedef typename ImageType::LabelObjectType LabelObjectType;
00060 
00061   typedef typename LabelObjectType::AttributeType AttributeType;
00062 
00064   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00065 
00067   itkNewMacro(Self);
00068 
00070   itkTypeMacro(ShapeOpeningLabelMapFilter, InPlaceLabelMapFilter);
00071 
00072 #ifdef ITK_USE_CONCEPT_CHECKING
00073 
00074 /*  itkConceptMacro(InputEqualityComparableCheck,
00075     (Concept::EqualityComparable<InputImagePixelType>));
00076   itkConceptMacro(IntConvertibleToInputCheck,
00077     (Concept::Convertible<int, InputImagePixelType>));
00078   itkConceptMacro(InputOStreamWritableCheck,
00079     (Concept::OStreamWritable<InputImagePixelType>));*/
00080 
00082 #endif
00083 
00087   itkGetConstMacro(Lambda, double);
00088   itkSetMacro(Lambda, double);
00090 
00097   itkGetConstMacro( ReverseOrdering, bool );
00098   itkSetMacro( ReverseOrdering, bool );
00099   itkBooleanMacro( ReverseOrdering );
00101 
00106   itkGetConstMacro( Attribute, AttributeType );
00107   itkSetMacro( Attribute, AttributeType );
00108   void SetAttribute( const std::string & s )
00109     {
00110     this->SetAttribute( LabelObjectType::GetAttributeFromName( s ) );
00111     }
00113 
00114 
00115 protected:
00116   ShapeOpeningLabelMapFilter();
00117   ~ShapeOpeningLabelMapFilter() {};
00118 
00119   void GenerateData();
00120 
00121   template <class TAttributeAccessor> 
00122   void TemplatedGenerateData( const TAttributeAccessor & accessor )
00123     {
00124     // Allocate the output
00125     this->AllocateOutputs();
00126 
00127     ImageType * output = this->GetOutput();
00128     ImageType * output2 = this->GetOutput( 1 );
00129     assert( this->GetNumberOfOutputs() == 2 );
00130     assert( output2 != NULL );
00131 
00132     // set the background value for the second output - this is not done in the superclasses
00133     output2->SetBackgroundValue( output->GetBackgroundValue() );
00134 
00135     const typename ImageType::LabelObjectContainerType & labelObjectContainer = output->GetLabelObjectContainer();
00136 
00137     ProgressReporter progress( this, 0, labelObjectContainer.size() );
00138 
00139     typename ImageType::LabelObjectContainerType::const_iterator it = labelObjectContainer.begin();
00140     while( it != labelObjectContainer.end() )
00141       {
00142       typename LabelObjectType::LabelType label = it->first;
00143       LabelObjectType * labelObject = it->second;
00144 
00145       if( ( !m_ReverseOrdering && accessor( labelObject ) < m_Lambda )
00146         || ( m_ReverseOrdering && accessor( labelObject ) > m_Lambda ) )
00147         {
00148         // must increment the iterator before removing the object to avoid invalidating the iterator
00149         it++;
00150         output2->AddLabelObject( labelObject );
00151         output->RemoveLabel( label );
00152         }
00153       else
00154         {
00155         it++;
00156         }
00157 
00158       progress.CompletedPixel();
00159       }
00160     }
00161 
00162   void PrintSelf(std::ostream& os, Indent indent) const;
00163 
00164   double        m_Lambda;
00165   bool          m_ReverseOrdering;
00166   AttributeType m_Attribute;
00167 
00168 private:
00169   ShapeOpeningLabelMapFilter(const Self&); //purposely not implemented
00170   void operator=(const Self&); //purposely not implemented
00171 
00172 }; // end of class
00173 
00174 } // end namespace itk
00175   
00176 #ifndef ITK_MANUAL_INSTANTIATION
00177 #include "itkShapeOpeningLabelMapFilter.txx"
00178 #endif
00179 
00180 #endif
00181 

Generated at Fri Apr 16 19:39:46 2010 for ITK by doxygen 1.6.1 written by Dimitri van Heesch, © 1997-2000