ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkShapeOpeningLabelMapFilter.h
Go to the documentation of this file.
00001 /*=========================================================================
00002  *
00003  *  Copyright Insight Software Consortium
00004  *
00005  *  Licensed under the Apache License, Version 2.0 (the "License");
00006  *  you may not use this file except in compliance with the License.
00007  *  You may obtain a copy of the License at
00008  *
00009  *         http://www.apache.org/licenses/LICENSE-2.0.txt
00010  *
00011  *  Unless required by applicable law or agreed to in writing, software
00012  *  distributed under the License is distributed on an "AS IS" BASIS,
00013  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  *  See the License for the specific language governing permissions and
00015  *  limitations under the License.
00016  *
00017  *=========================================================================*/
00018 #ifndef __itkShapeOpeningLabelMapFilter_h
00019 #define __itkShapeOpeningLabelMapFilter_h
00020 
00021 #include "itkInPlaceLabelMapFilter.h"
00022 #include "itkShapeLabelObjectAccessors.h"
00023 #include "itkProgressReporter.h"
00024 
00025 namespace itk
00026 {
00048 template< class TImage >
00049 class ITK_EXPORT ShapeOpeningLabelMapFilter:
00050   public InPlaceLabelMapFilter< TImage >
00051 {
00052 public:
00054   typedef ShapeOpeningLabelMapFilter      Self;
00055   typedef InPlaceLabelMapFilter< TImage > Superclass;
00056   typedef SmartPointer< Self >            Pointer;
00057   typedef SmartPointer< const Self >      ConstPointer;
00058 
00060   typedef TImage                              ImageType;
00061   typedef typename ImageType::Pointer         ImagePointer;
00062   typedef typename ImageType::ConstPointer    ImageConstPointer;
00063   typedef typename ImageType::PixelType       PixelType;
00064   typedef typename ImageType::IndexType       IndexType;
00065   typedef typename ImageType::LabelObjectType LabelObjectType;
00066 
00067   typedef typename LabelObjectType::AttributeType AttributeType;
00068 
00070   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00071 
00073   itkNewMacro(Self);
00074 
00076   itkTypeMacro(ShapeOpeningLabelMapFilter, InPlaceLabelMapFilter);
00077 
00078 #ifdef ITK_USE_CONCEPT_CHECKING
00079 
00080 /*  itkConceptMacro(InputEqualityComparableCheck,
00081     (Concept::EqualityComparable<InputImagePixelType>));
00082   itkConceptMacro(IntConvertibleToInputCheck,
00083     (Concept::Convertible<int, InputImagePixelType>));
00084   itkConceptMacro(InputOStreamWritableCheck,
00085     (Concept::OStreamWritable<InputImagePixelType>));*/
00086 
00088 #endif
00089 
00093   itkGetConstMacro(Lambda, double);
00094   itkSetMacro(Lambda, double);
00096 
00103   itkGetConstMacro(ReverseOrdering, bool);
00104   itkSetMacro(ReverseOrdering, bool);
00105   itkBooleanMacro(ReverseOrdering);
00107 
00112   itkGetConstMacro(Attribute, AttributeType);
00113   itkSetMacro(Attribute, AttributeType);
00114   void SetAttribute(const std::string & s)
00115   {
00116     this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
00117   }
00119 
00120 protected:
00121   ShapeOpeningLabelMapFilter();
00122   ~ShapeOpeningLabelMapFilter() {}
00123 
00124   void GenerateData();
00125 
00126   template< class TAttributeAccessor >
00127   void TemplatedGenerateData(const TAttributeAccessor & accessor)
00128   {
00129     // Allocate the output
00130     this->AllocateOutputs();
00131 
00132     ImageType *output = this->GetOutput();
00133     ImageType *output2 = this->GetOutput(1);
00134     itkAssertInDebugAndIgnoreInReleaseMacro(this->GetNumberOfIndexedOutputs() == 2);
00135     itkAssertInDebugAndIgnoreInReleaseMacro(output2 != NULL);
00136 
00137     // set the background value for the second output - this is not done in the
00138     // superclasses
00139     output2->SetBackgroundValue( output->GetBackgroundValue() );
00140 
00141     ProgressReporter progress( this, 0, output->GetNumberOfLabelObjects() );
00142 
00143     typename ImageType::Iterator it( output );
00144     while ( ! it.IsAtEnd() )
00145       {
00146       typename LabelObjectType::LabelType label = it.GetLabel();
00147       LabelObjectType *labelObject = it.GetLabelObject();
00148 
00149       if ( ( !m_ReverseOrdering && accessor(labelObject) < m_Lambda )
00150            || ( m_ReverseOrdering && accessor(labelObject) > m_Lambda ) )
00151         {
00152         // must increment the iterator before removing the object to avoid
00153         // invalidating the iterator
00154         ++it;
00155         output2->AddLabelObject(labelObject);
00156         output->RemoveLabel(label);
00157         }
00158       else
00159         {
00160         ++it;
00161         }
00162 
00163       progress.CompletedPixel();
00164       }
00165   }
00166 
00167   void PrintSelf(std::ostream & os, Indent indent) const;
00168 
00169   double m_Lambda;
00170 
00171   bool m_ReverseOrdering;
00172 
00173   AttributeType m_Attribute;
00174 private:
00175   ShapeOpeningLabelMapFilter(const Self &); //purposely not implemented
00176   void operator=(const Self &);             //purposely not implemented
00177 };                                          // end of class
00178 } // end namespace itk
00179 
00180 #ifndef ITK_MANUAL_INSTANTIATION
00181 #include "itkShapeOpeningLabelMapFilter.hxx"
00182 #endif
00183 
00184 #endif
00185