ITK  4.1.0
Insight Segmentation and Registration Toolkit
itkRegionBasedLevelSetFunctionSharedData.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 __itkRegionBasedLevelSetFunctionSharedData_h
00019 #define __itkRegionBasedLevelSetFunctionSharedData_h
00020 
00021 #include "itkLightObject.h"
00022 
00023 #include "itkVector.h"
00024 #include "itkListSample.h"
00025 #include "itkKdTreeGenerator.h"
00026 
00027 #include "itkImageRegionIterator.h"
00028 #include "itkImageRegionIteratorWithIndex.h"
00029 
00030 namespace itk
00031 {
00067 template< class TInputImage, class TFeatureImage, class TSingleData >
00068 class RegionBasedLevelSetFunctionSharedData:public LightObject
00069 {
00070 public:
00071 
00072   typedef RegionBasedLevelSetFunctionSharedData Self;
00073   typedef LightObject                           Superclass;
00074   typedef SmartPointer< Self >                  Pointer;
00075   typedef SmartPointer< const Self >            ConstPointer;
00076 
00077   itkStaticConstMacro(ImageDimension, unsigned int, TFeatureImage::ImageDimension);
00078 
00079   itkTypeMacro(RegionBasedLevelSetFunctionSharedData, LightObject);
00080 
00081   typedef TInputImage                             InputImageType;
00082   typedef typename InputImageType::Pointer        InputImagePointer;
00083   typedef typename InputImageType::ConstPointer   InputImageConstPointer;
00084   typedef typename InputImageType::PixelType      InputPixelType;
00085   typedef typename InputImageType::RegionType     InputRegionType;
00086   typedef typename InputImageType::SizeType       InputSizeType;
00087   typedef typename InputSizeType::SizeValueType   InputSizeValueType;
00088   typedef typename InputImageType::SpacingType    InputSpacingType;
00089   typedef typename InputImageType::IndexType      InputIndexType;
00090   typedef typename InputIndexType::IndexValueType InputIndexValueType;
00091   typedef typename InputImageType::PointType      InputPointType;
00092 
00093   typedef TFeatureImage                           FeatureImageType;
00094   typedef typename FeatureImageType::Pointer      FeatureImagePointer;
00095   typedef typename FeatureImageType::ConstPointer FeatureImageConstPointer;
00096   typedef typename FeatureImageType::PixelType    FeaturePixelType;
00097   typedef typename FeatureImageType::RegionType   FeatureRegionType;
00098   typedef typename FeatureImageType::SizeType     FeatureSizeType;
00099   typedef typename FeatureSizeType::SizeValueType FeatureSizeValueType;
00100   typedef typename FeatureImageType::SpacingType  FeatureSpacingType;
00101   typedef typename FeatureImageType::IndexType    FeatureIndexType;
00102   typedef typename FeatureImageType::PointType    FeaturePointType;
00103 
00104   typedef std::list< unsigned int > ListPixelType;
00105   typedef Image< ListPixelType, itkGetStaticConstMacro(ImageDimension) >
00106   ListImageType;
00107   typedef typename ListImageType::Pointer               ListImagePointer;
00108   typedef typename ListImageType::ConstPointer          ListImageConstPointer;
00109   typedef typename ListImageType::RegionType            ListRegionType;
00110   typedef typename ListImageType::SizeType              ListSizeType;
00111   typedef typename ListSizeType::SizeValueType          ListSizeValueType;
00112   typedef typename ListImageType::SpacingType           ListSpacingType;
00113   typedef typename ListImageType::IndexType             ListIndexType;
00114   typedef typename ListIndexType::IndexValueType        ListIndexValueType;
00115   typedef typename ListImageType::PointType             ListPointType;
00116   typedef ImageRegionIteratorWithIndex< ListImageType > ListIteratorType;
00117 
00118   typedef Vector< float, itkGetStaticConstMacro(ImageDimension) >
00119   CentroidVectorType;
00120   typedef itk::Statistics::ListSample< CentroidVectorType > SampleType;
00121   typedef itk::Statistics::KdTreeGenerator< SampleType >    TreeGeneratorType;
00122   typedef typename TreeGeneratorType::Pointer               TreePointer;
00123   typedef typename TreeGeneratorType::KdTreeType            TreeType;
00124   typedef typename TreeType::Pointer                        KdTreePointer;
00125 
00126   typedef TSingleData                                  LevelSetDataType;
00127   typedef typename LevelSetDataType::Pointer           LevelSetDataPointer;
00128   typedef std::vector< LevelSetDataPointer >           LevelSetDataPointerVector;
00129   typedef typename LevelSetDataPointerVector::iterator LevelSetDataPointerVectorIterator;
00130 
00131   void SetFunctionCount(const unsigned int & n)
00132   {
00133     this->m_FunctionCount = n;
00134     this->m_LevelSetDataPointerVector.resize(n, 0);
00135 
00136     LevelSetDataPointerVectorIterator it = m_LevelSetDataPointerVector.begin();
00137     LevelSetDataPointerVectorIterator end = m_LevelSetDataPointerVector.end();
00138     while ( it != end )
00139       {
00140       ( *it ) = LevelSetDataType::New();
00141       it++;
00142       }
00143   }
00144 
00145   void SetNumberOfNeighbors(const unsigned int & n)
00146   {
00147     this->m_NumberOfNeighbors = n;
00148   }
00149 
00150   void CreateHeavisideFunctionOfLevelSetImage(const unsigned int & j, const InputImageType *image)
00151   {
00152     m_LevelSetDataPointerVector[j]->CreateHeavisideFunctionOfLevelSetImage(image);
00153   }
00154 
00155   void SetKdTree(KdTreePointer kdtree)
00156   {
00157     this->m_KdTree = kdtree;
00158   }
00159 
00160   void AllocateListImage(const FeatureImageType *featureImage)
00161   {
00162     this->m_NearestNeighborListImage = ListImageType::New();
00163     this->m_NearestNeighborListImage->CopyInformation(featureImage);
00164     this->m_NearestNeighborListImage->SetRegions( featureImage->GetLargestPossibleRegion() );
00165     this->m_NearestNeighborListImage->Allocate();
00166   }
00167 
00168   virtual void PopulateListImage() = 0;
00169 
00170   LevelSetDataPointerVector m_LevelSetDataPointerVector;
00171 
00172   unsigned int     m_FunctionCount;
00173   unsigned int     m_NumberOfNeighbors;
00174   ListImagePointer m_NearestNeighborListImage;
00175   KdTreePointer    m_KdTree;
00176 protected:
00177   RegionBasedLevelSetFunctionSharedData():m_NumberOfNeighbors(6), m_KdTree(0){}
00178   ~RegionBasedLevelSetFunctionSharedData(){}
00179 private:
00180   RegionBasedLevelSetFunctionSharedData(const Self &); //purposely not
00181                                                        // implemented
00182   void operator=(const Self &);                        //purposely not
00183                                                        // implemented
00184 };
00185 } //end namespace itk
00186 
00187 #endif
00188