00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkBSplineScatteredDataPointSetToImageFilter_h
00018 #define __itkBSplineScatteredDataPointSetToImageFilter_h
00019
00020 #include "itkPointSetToImageFilter.h"
00021 #include "itkCoxDeBoorBSplineKernelFunction.h"
00022 #include "itkFixedArray.h"
00023 #include "itkVariableSizeMatrix.h"
00024 #include "itkVector.h"
00025 #include "itkVectorContainer.h"
00026
00027 #include "vnl/vnl_matrix.h"
00028
00029 namespace itk
00030 {
00031
00073 template <class TInputPointSet, class TOutputImage>
00074 class BSplineScatteredDataPointSetToImageFilter
00075 : public PointSetToImageFilter<TInputPointSet, TOutputImage>
00076 {
00077 public:
00078 typedef BSplineScatteredDataPointSetToImageFilter Self;
00079 typedef PointSetToImageFilter<TInputPointSet, TOutputImage> Superclass;
00080 typedef SmartPointer<Self> Pointer;
00081 typedef SmartPointer<const Self> ConstPointer;
00082
00084 itkNewMacro(Self);
00085
00087 itkStaticConstMacro( ImageDimension, unsigned int,
00088 TOutputImage::ImageDimension );
00089
00090 typedef TOutputImage ImageType;
00091 typedef TInputPointSet PointSetType;
00092
00094 typedef typename ImageType::PixelType PixelType;
00095 typedef typename ImageType::RegionType RegionType;
00096 typedef typename ImageType::SizeType SizeType;
00097 typedef typename ImageType::IndexType IndexType;
00098 typedef typename ImageType::PointType ContinuousIndexType;
00099
00101 typedef typename PointSetType::PointType PointType;
00102 typedef typename PointSetType::PixelType PointDataType;
00103 typedef typename PointSetType::PointDataContainer PointDataContainerType;
00104
00106 typedef float RealType;
00107 typedef VectorContainer<unsigned, RealType> WeightsContainerType;
00108 typedef Image<PointDataType,
00109 itkGetStaticConstMacro( ImageDimension )> PointDataImageType;
00110 typedef Image<RealType,
00111 itkGetStaticConstMacro( ImageDimension )> RealImageType;
00112 typedef FixedArray<unsigned,
00113 itkGetStaticConstMacro( ImageDimension )> ArrayType;
00114 typedef VariableSizeMatrix<RealType> GradientType;
00115 typedef RealImageType HessianType;
00117
00119 typedef CoxDeBoorBSplineKernelFunction<3> KernelType;
00120
00123 void SetNumberOfLevels( unsigned int );
00124 void SetNumberOfLevels( ArrayType );
00125 itkGetConstReferenceMacro( NumberOfLevels, ArrayType );
00126
00127 void SetSplineOrder( unsigned int );
00128 void SetSplineOrder( ArrayType );
00129 itkGetConstReferenceMacro( SplineOrder, ArrayType );
00130
00131 itkSetMacro( NumberOfControlPoints, ArrayType );
00132 itkGetConstReferenceMacro( NumberOfControlPoints, ArrayType );
00133 itkGetConstReferenceMacro( CurrentNumberOfControlPoints, ArrayType );
00134
00135 itkSetMacro( CloseDimension, ArrayType );
00136 itkGetConstReferenceMacro( CloseDimension, ArrayType );
00137
00138 itkSetMacro( GenerateOutputImage, bool );
00139 itkGetConstReferenceMacro( GenerateOutputImage, bool );
00140 itkBooleanMacro( GenerateOutputImage );
00141
00142 void SetPointWeights( const WeightsContainerType * weights );
00143
00147 itkSetMacro( PhiLattice, typename PointDataImageType::Pointer );
00148 itkGetConstMacro( PhiLattice, typename PointDataImageType::Pointer );
00150
00155 void EvaluateAtPoint( PointType, PointDataType & );
00156 void EvaluateAtIndex( IndexType, PointDataType & );
00157 void EvaluateAtContinuousIndex( ContinuousIndexType, PointDataType & );
00159
00165 void Evaluate( PointType, PointDataType & );
00166
00171 void EvaluateGradientAtPoint( PointType, GradientType & );
00172 void EvaluateGradientAtIndex( IndexType, GradientType & );
00173 void EvaluateGradientAtContinuousIndex( ContinuousIndexType, GradientType & );
00175
00182 void EvaluateGradient( PointType, GradientType & );
00183
00184 protected:
00185 BSplineScatteredDataPointSetToImageFilter();
00186 virtual ~BSplineScatteredDataPointSetToImageFilter();
00187 void PrintSelf( std::ostream& os, Indent indent ) const;
00188
00189 void GenerateData();
00190
00191 private:
00192 BSplineScatteredDataPointSetToImageFilter(const Self&);
00193 void operator=(const Self&);
00194
00195 void GenerateControlLattice();
00196 void RefineControlLattice();
00197 void UpdatePointSet();
00198 void GenerateOutputImage();
00199 void GenerateOutputImageFast();
00200 void CollapsePhiLattice( PointDataImageType *,
00201 PointDataImageType *,
00202 RealType, unsigned int );
00203
00204
00205 bool m_DoMultilevel;
00206 bool m_GenerateOutputImage;
00207 bool m_UsePointWeights;
00208 unsigned int m_MaximumNumberOfLevels;
00209 unsigned int m_CurrentLevel;
00210 ArrayType m_NumberOfControlPoints;
00211 ArrayType m_CurrentNumberOfControlPoints;
00212 ArrayType m_CloseDimension;
00213 ArrayType m_SplineOrder;
00214 ArrayType m_NumberOfLevels;
00215 typename WeightsContainerType::Pointer m_PointWeights;
00216 typename KernelType::Pointer m_Kernel[ImageDimension];
00217 vnl_matrix<RealType> m_RefinedLatticeCoefficients[ImageDimension];
00218 typename PointDataImageType::Pointer m_PhiLattice;
00219 typename PointDataImageType::Pointer m_PsiLattice;
00220 typename PointDataContainerType::Pointer m_InputPointData;
00221 typename PointDataContainerType::Pointer m_OutputPointData;
00222
00223 inline typename RealImageType::IndexType
00224 NumberToIndex( unsigned int number, typename RealImageType::SizeType size )
00225 {
00226 typename RealImageType::IndexType k;
00227 k[0] = 1;
00228
00229 for ( unsigned int i = 1; i < ImageDimension; i++ )
00230 {
00231 k[i] = size[ImageDimension-i-1]*k[i-1];
00232 }
00233 typename RealImageType::IndexType index;
00234 for ( unsigned int i = 0; i < ImageDimension; i++ )
00235 {
00236 index[ImageDimension-i-1] = static_cast<unsigned int>( number/k[ImageDimension-i-1] );
00237 number %= k[ImageDimension-i-1];
00238 }
00239 return index;
00240 }
00241 };
00242
00243 }
00244
00245 #ifndef ITK_MANUAL_INSTANTIATION
00246 #include "itkBSplineScatteredDataPointSetToImageFilter.txx"
00247 #endif
00248
00249 #endif
00250