ITK  4.0.0
Insight Segmentation and Registration Toolkit
itkAttributeKeepNObjectsLabelMapFilter.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 __itkAttributeKeepNObjectsLabelMapFilter_h
00019 #define __itkAttributeKeepNObjectsLabelMapFilter_h
00020 
00021 #include "itkInPlaceLabelMapFilter.h"
00022 #include "itkAttributeLabelObject.h"
00023 
00024 namespace itk {
00041 template<class TImage, class TAttributeAccessor=
00042     typename Functor::AttributeLabelObjectAccessor< typename TImage::LabelObjectType > >
00043 class ITK_EXPORT AttributeKeepNObjectsLabelMapFilter :
00044     public InPlaceLabelMapFilter<TImage>
00045 {
00046 public:
00048   typedef AttributeKeepNObjectsLabelMapFilter 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 TAttributeAccessor AttributeAccessorType;
00062   typedef typename AttributeAccessorType::AttributeValueType AttributeValueType;
00063 
00065   itkStaticConstMacro(ImageDimension, unsigned int,
00066                       TImage::ImageDimension);
00067 
00069   itkNewMacro(Self);
00070 
00072   itkTypeMacro(AttributeKeepNObjectsLabelMapFilter,
00073                InPlaceLabelMapFilter);
00074 
00075 #ifdef ITK_USE_CONCEPT_CHECKING
00076 
00077 /*  itkConceptMacro(InputEqualityComparableCheck,
00078     (Concept::EqualityComparable<InputImagePixelType>));
00079   itkConceptMacro(IntConvertibleToInputCheck,
00080     (Concept::Convertible<int, InputImagePixelType>));
00081   itkConceptMacro(InputOStreamWritableCheck,
00082     (Concept::OStreamWritable<InputImagePixelType>));*/
00083 
00085 #endif
00086 
00092   itkSetMacro( ReverseOrdering, bool );
00093   itkGetConstReferenceMacro( ReverseOrdering, bool );
00094   itkBooleanMacro( ReverseOrdering );
00096 
00100   itkSetMacro( NumberOfObjects, SizeValueType );
00101   itkGetConstReferenceMacro( NumberOfObjects, SizeValueType );
00103 
00104 protected:
00105   AttributeKeepNObjectsLabelMapFilter();
00106   ~AttributeKeepNObjectsLabelMapFilter() {};
00107 
00108   void GenerateData();
00109 
00110   void PrintSelf(std::ostream& os, Indent indent) const;
00111 
00112   class ReverseComparator
00113     {
00114     public:
00115     bool operator()( const typename LabelObjectType::Pointer & a, const typename LabelObjectType::Pointer & b )
00116       {
00117       return m_Accessor( a ) < m_Accessor( b );
00118       }
00119     ReverseComparator() : m_Accessor() {}
00120     private:
00121      AttributeAccessorType m_Accessor;
00122     };
00123 
00124   class Comparator
00125     {
00126   public:
00127     bool operator()( const typename LabelObjectType::Pointer & a, const typename LabelObjectType::Pointer & b )
00128       {
00129       return m_Accessor( a ) > m_Accessor( b );
00130       }
00131     Comparator(): m_Accessor () {}
00132   private:
00133     AttributeAccessorType m_Accessor;
00134     };
00135 
00136 private:
00137   AttributeKeepNObjectsLabelMapFilter(const Self&); //purposely not implemented
00138   void operator=(const Self&); //purposely not implemented
00139 
00140   bool           m_ReverseOrdering;
00141   SizeValueType  m_NumberOfObjects;
00142 
00143 }; // end of class
00144 
00145 } // end namespace itk
00146 
00147 #ifndef ITK_MANUAL_INSTANTIATION
00148 #include "itkAttributeKeepNObjectsLabelMapFilter.hxx"
00149 #endif
00150 
00151 #endif
00152