Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
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
00074
00075
00076
00077
00078
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
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
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
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
00151
00152
00153 output->ClearLabels();
00154 unsigned int label = 0;
00155 typename VectorType::const_iterator it2 = labelObjects.begin();
00156 while( it2 != labelObjects.end() )
00157 {
00158
00159 if( label == output->GetBackgroundValue() )
00160 {
00161 label++;
00162 }
00163 ( *it2 )->SetLabel( label );
00164 output->AddLabelObject( *it2 );
00165
00166
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&);
00181 void operator=(const Self&);
00182
00183 };
00184
00185 }
00186
00187 #ifndef ITK_MANUAL_INSTANTIATION
00188 #include "itkShapeRelabelLabelMapFilter.txx"
00189 #endif
00190
00191 #endif
00192