ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkShapeLabelMapFilter.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 __itkShapeLabelMapFilter_h
00019 #define __itkShapeLabelMapFilter_h
00020 
00021 #include "itkInPlaceLabelMapFilter.h"
00022 
00023 namespace itk
00024 {
00051 template< class TImage, class TLabelImage =
00052             Image< typename TImage::PixelType, ::itk::GetImageDimension< TImage >::ImageDimension > >
00053 class ITK_EXPORT ShapeLabelMapFilter:
00054   public
00055   InPlaceLabelMapFilter< TImage >
00056 {
00057 public:
00059   typedef ShapeLabelMapFilter             Self;
00060   typedef InPlaceLabelMapFilter< TImage > Superclass;
00061   typedef SmartPointer< Self >            Pointer;
00062   typedef SmartPointer< const Self >      ConstPointer;
00063 
00065   typedef TImage                               ImageType;
00066   typedef typename ImageType::Pointer          ImagePointer;
00067   typedef typename ImageType::ConstPointer     ImageConstPointer;
00068   typedef typename ImageType::PixelType        PixelType;
00069   typedef typename ImageType::IndexType        IndexType;
00070   typedef typename ImageType::SizeType         SizeType;
00071   typedef typename ImageType::RegionType       RegionType;
00072   typedef typename ImageType::OffsetType       OffsetType;
00073   typedef typename ImageType::LabelObjectType  LabelObjectType;
00074   typedef typename LabelObjectType::MatrixType MatrixType;
00075   typedef typename LabelObjectType::VectorType VectorType;
00076 
00077   typedef TLabelImage                           LabelImageType;
00078   typedef typename LabelImageType::Pointer      LabelImagePointer;
00079   typedef typename LabelImageType::ConstPointer LabelImageConstPointer;
00080   typedef typename LabelImageType::PixelType    LabelPixelType;
00081 
00083   itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
00084 
00086   itkNewMacro(Self);
00087 
00089   itkTypeMacro(ShapeLabelMapFilter, InPlaceLabelMapFilter);
00090 
00091 #ifdef ITK_USE_CONCEPT_CHECKING
00092 
00093 /*  itkConceptMacro(InputEqualityComparableCheck,
00094     (Concept::EqualityComparable<InputImagePixelType>));
00095   itkConceptMacro(IntConvertibleToInputCheck,
00096     (Concept::Convertible<int, InputImagePixelType>));
00097   itkConceptMacro(InputOStreamWritableCheck,
00098     (Concept::OStreamWritable<InputImagePixelType>));*/
00099 
00101 #endif
00102 
00107   itkSetMacro(ComputeFeretDiameter, bool);
00108   itkGetConstReferenceMacro(ComputeFeretDiameter, bool);
00109   itkBooleanMacro(ComputeFeretDiameter);
00111 
00116   itkSetMacro(ComputePerimeter, bool);
00117   itkGetConstReferenceMacro(ComputePerimeter, bool);
00118   itkBooleanMacro(ComputePerimeter);
00120 
00122   void SetLabelImage(const TLabelImage *input)
00123   {
00124     m_LabelImage = input;
00125   }
00126 
00127 protected:
00128   ShapeLabelMapFilter();
00129   ~ShapeLabelMapFilter() {}
00130 
00131   virtual void ThreadedProcessLabelObject(LabelObjectType *labelObject);
00132 
00133   virtual void BeforeThreadedGenerateData();
00134 
00135   virtual void AfterThreadedGenerateData();
00136 
00137   void PrintSelf(std::ostream & os, Indent indent) const;
00138 
00139 private:
00140   ShapeLabelMapFilter(const Self &); //purposely not implemented
00141   void operator=(const Self &);      //purposely not implemented
00142 
00143   bool                   m_ComputeFeretDiameter;
00144   bool                   m_ComputePerimeter;
00145   LabelImageConstPointer m_LabelImage;
00146 
00147   void ComputeFeretDiameter(LabelObjectType *labelObject);
00148   void ComputePerimeter(LabelObjectType *labelObject);
00149 
00150   typedef itk::Offset<2>                                                          Offset2Type;
00151   typedef itk::Offset<3>                                                          Offset3Type;
00152   typedef itk::Vector<double, 2>                                                  Spacing2Type;
00153   typedef itk::Vector<double, 3>                                                  Spacing3Type;
00154   typedef std::map<Offset2Type, SizeValueType, Offset2Type::LexicographicCompare> MapIntercept2Type;
00155   typedef std::map<Offset3Type, SizeValueType, Offset3Type::LexicographicCompare> MapIntercept3Type;
00156 
00157   // it seems impossible to specialize a method without specializing the whole class, but we
00158   // can use simple overloading
00159   template<class TMapIntercept, class TSpacing> double PerimeterFromInterceptCount( TMapIntercept & intercepts, const TSpacing & spacing );
00160 #if ! defined(ITK_DO_NOT_USE_PERIMETER_SPECIALIZATION)
00161   double PerimeterFromInterceptCount( MapIntercept2Type & intercepts, const Spacing2Type spacing );
00162   double PerimeterFromInterceptCount( MapIntercept3Type & intercepts, const Spacing3Type spacing );
00163 #endif
00164 };
00165 
00166 
00167 } // end namespace itk
00168 
00169 #ifndef ITK_MANUAL_INSTANTIATION
00170 #include "itkShapeLabelMapFilter.hxx"
00171 #endif
00172 
00173 #endif
00174