ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkLabelShapeKeepNObjectsImageFilter.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 __itkLabelShapeKeepNObjectsImageFilter_h
00019 #define __itkLabelShapeKeepNObjectsImageFilter_h
00020 
00021 #include "itkShapeLabelObject.h"
00022 #include "itkLabelImageToLabelMapFilter.h"
00023 #include "itkShapeLabelMapFilter.h"
00024 #include "itkShapeKeepNObjectsLabelMapFilter.h"
00025 #include "itkLabelMapToLabelImageFilter.h"
00026 
00027 namespace itk
00028 {
00050 template< class TInputImage >
00051 class ITK_EXPORT LabelShapeKeepNObjectsImageFilter:
00052   public ImageToImageFilter< TInputImage, TInputImage >
00053 {
00054 public:
00056   typedef LabelShapeKeepNObjectsImageFilter              Self;
00057   typedef ImageToImageFilter< TInputImage, TInputImage > Superclass;
00058   typedef SmartPointer< Self >                           Pointer;
00059   typedef SmartPointer< const Self >                     ConstPointer;
00060 
00062   typedef TInputImage                            InputImageType;
00063   typedef TInputImage                            OutputImageType;
00064   typedef typename InputImageType::Pointer       InputImagePointer;
00065   typedef typename InputImageType::ConstPointer  InputImageConstPointer;
00066   typedef typename InputImageType::RegionType    InputImageRegionType;
00067   typedef typename InputImageType::PixelType     InputImagePixelType;
00068   typedef typename OutputImageType::Pointer      OutputImagePointer;
00069   typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
00070   typedef typename OutputImageType::RegionType   OutputImageRegionType;
00071   typedef typename OutputImageType::PixelType    OutputImagePixelType;
00072 
00074   itkStaticConstMacro(InputImageDimension, unsigned int,
00075                       TInputImage::ImageDimension);
00076   itkStaticConstMacro(OutputImageDimension, unsigned int,
00077                       TInputImage::ImageDimension);
00078   itkStaticConstMacro(ImageDimension, unsigned int,
00079                       TInputImage::ImageDimension);
00081 
00082   typedef ShapeLabelObject< InputImagePixelType, itkGetStaticConstMacro(ImageDimension) > LabelObjectType;
00083   typedef LabelMap< LabelObjectType >                                                     LabelMapType;
00084   typedef LabelImageToLabelMapFilter< InputImageType, LabelMapType >                      LabelizerType;
00085   typedef Image< typename OutputImageType::PixelType,
00086                  itkGetStaticConstMacro(OutputImageDimension) > ShapeLabelFilterOutput;
00087   typedef ShapeLabelMapFilter< LabelMapType,
00088                                ShapeLabelFilterOutput >                                LabelObjectValuatorType;
00089   typedef typename LabelObjectType::AttributeType                     AttributeType;
00090   typedef ShapeKeepNObjectsLabelMapFilter< LabelMapType >             KeepNObjectsType;
00091   typedef LabelMapToLabelImageFilter< LabelMapType, OutputImageType > BinarizerType;
00092 
00094   itkNewMacro(Self);
00095 
00097   itkTypeMacro(LabelShapeKeepNObjectsImageFilter,
00098                ImageToImageFilter);
00099 
00100 #ifdef ITK_USE_CONCEPT_CHECKING
00101 
00102   itkConceptMacro( InputEqualityComparableCheck,
00103                    ( Concept::EqualityComparable< InputImagePixelType > ) );
00104   itkConceptMacro( IntConvertibleToInputCheck,
00105                    ( Concept::Convertible< int, InputImagePixelType > ) );
00106   itkConceptMacro( InputOStreamWritableCheck,
00107                    ( Concept::OStreamWritable< InputImagePixelType > ) );
00108 
00110 #endif
00111 
00116   itkSetMacro(BackgroundValue, OutputImagePixelType);
00117   itkGetConstMacro(BackgroundValue, OutputImagePixelType);
00119 
00123   itkGetConstMacro(NumberOfObjects, SizeValueType);
00124   itkSetMacro(NumberOfObjects, SizeValueType);
00126 
00132   itkGetConstMacro(ReverseOrdering, bool);
00133   itkSetMacro(ReverseOrdering, bool);
00134   itkBooleanMacro(ReverseOrdering);
00136 
00141   itkGetConstMacro(Attribute, AttributeType);
00142   itkSetMacro(Attribute, AttributeType);
00143   void SetAttribute(const std::string & s)
00144   {
00145     this->SetAttribute( LabelObjectType::GetAttributeFromName(s) );
00146   }
00148 
00149 protected:
00150   LabelShapeKeepNObjectsImageFilter();
00151   ~LabelShapeKeepNObjectsImageFilter() {}
00152   void PrintSelf(std::ostream & os, Indent indent) const;
00153 
00157   void GenerateInputRequestedRegion();
00158 
00160   void EnlargeOutputRequestedRegion( DataObject *itkNotUsed(output) );
00161 
00164   void GenerateData();
00165 
00166 private:
00167   LabelShapeKeepNObjectsImageFilter(const Self &); //purposely not implemented
00168   void operator=(const Self &);                    //purposely not implemented
00169 
00170   OutputImagePixelType m_BackgroundValue;
00171   SizeValueType        m_NumberOfObjects;
00172   bool                 m_ReverseOrdering;
00173   AttributeType        m_Attribute;
00174 }; // end of class
00175 } // end namespace itk
00176 
00177 #ifndef ITK_MANUAL_INSTANTIATION
00178 #include "itkLabelShapeKeepNObjectsImageFilter.hxx"
00179 #endif
00180 
00181 #endif
00182