00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017 #ifndef __itkDeformationFieldJacobianDeterminantFilter_h
00018 #define __itkDeformationFieldJacobianDeterminantFilter_h
00019
00020 #include "itkConstNeighborhoodIterator.h"
00021 #include "itkNeighborhoodIterator.h"
00022 #include "itkImageToImageFilter.h"
00023 #include "itkImage.h"
00024 #include "itkVector.h"
00025 #include "vnl/vnl_matrix.h"
00026 #include "vnl/vnl_det.h"
00027
00028 namespace itk
00029 {
00105 template < typename TInputImage,
00106 typename TRealType = float,
00107 typename TOutputImage = Image< TRealType,
00108 ::itk::GetImageDimension<TInputImage>::ImageDimension >
00109 >
00110 class ITK_EXPORT DeformationFieldJacobianDeterminantFilter :
00111 public ImageToImageFilter< TInputImage, TOutputImage >
00112 {
00113 public:
00115 typedef DeformationFieldJacobianDeterminantFilter Self;
00116 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00117 typedef SmartPointer<Self> Pointer;
00118 typedef SmartPointer<const Self> ConstPointer;
00119
00121 itkNewMacro(Self);
00122
00124 itkTypeMacro(DeformationFieldJacobianDeterminantFilter, ImageToImageFilter);
00125
00128 typedef typename TOutputImage::PixelType OutputPixelType;
00129 typedef typename TInputImage::PixelType InputPixelType;
00130
00132 typedef TInputImage InputImageType;
00133 typedef TOutputImage OutputImageType;
00134 typedef typename InputImageType::Pointer InputImagePointer;
00135 typedef typename OutputImageType::Pointer OutputImagePointer;
00136
00138 itkStaticConstMacro(ImageDimension, unsigned int,
00139 TOutputImage::ImageDimension);
00140
00142 itkStaticConstMacro(VectorDimension, unsigned int,
00143 InputPixelType::Dimension);
00144
00146 typedef TRealType RealType;
00147 typedef Vector<TRealType, ::itk::GetVectorDimension<InputPixelType>::VectorDimension> RealVectorType;
00148 typedef Image<RealVectorType, ::itk::GetImageDimension<TInputImage>::ImageDimension> RealVectorImageType;
00149
00150
00153 typedef ConstNeighborhoodIterator<RealVectorImageType> ConstNeighborhoodIteratorType;
00154 typedef typename ConstNeighborhoodIteratorType::RadiusType RadiusType;
00155
00157 typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
00158
00167 virtual void GenerateInputRequestedRegion() throw(InvalidRequestedRegionError);
00168
00172 void SetUseImageSpacingOn()
00173 { this->SetUseImageSpacing(true); }
00174
00178 void SetUseImageSpacingOff()
00179 { this->SetUseImageSpacing(false); }
00180
00183 void SetUseImageSpacing(bool);
00184 itkGetMacro(UseImageSpacing, bool);
00185
00188 void SetDerivativeWeights(TRealType data[]);
00189 itkGetVectorMacro(DerivativeWeights, const TRealType, itk::GetImageDimension<TInputImage>::ImageDimension);
00190
00191 protected:
00192 DeformationFieldJacobianDeterminantFilter();
00193 virtual ~DeformationFieldJacobianDeterminantFilter() {}
00194
00198 void BeforeThreadedGenerateData ();
00199
00212 void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
00213 int threadId );
00214
00215 void PrintSelf(std::ostream& os, Indent indent) const;
00216
00217 typedef typename InputImageType::Superclass ImageBaseType;
00218
00220 itkGetConstObjectMacro( RealValuedInputImage, ImageBaseType );
00221
00223 itkGetConstReferenceMacro( NeighborhoodRadius, RadiusType );
00224 itkSetMacro( NeighborhoodRadius, RadiusType );
00225
00226
00227 TRealType EvaluateAtNeighborhood
00228 (const ConstNeighborhoodIteratorType &it) const
00229 {
00230 unsigned i, j;
00231 vnl_matrix_fixed<TRealType,ImageDimension,VectorDimension> J;
00232
00233 for (i = 0; i < ImageDimension; ++i)
00234 {
00235 for (j = 0; j < VectorDimension; ++j)
00236 {
00237 J[i][j] = m_DerivativeWeights[i]
00238 * 0.5 * (it.GetNext(i)[j] - it.GetPrevious(i)[j]);
00239 }
00240 }
00241
00242 return vnl_det(J);
00243 }
00244
00246 TRealType m_DerivativeWeights[itk::GetImageDimension<TInputImage>::ImageDimension];
00247
00248 private:
00249 bool m_UseImageSpacing;
00250 int m_RequestedNumberOfThreads;
00251
00252 typename ImageBaseType::ConstPointer m_RealValuedInputImage;
00253
00254 DeformationFieldJacobianDeterminantFilter(const Self&);
00255 void operator=(const Self&);
00256
00257 RadiusType m_NeighborhoodRadius;
00258 };
00259
00260 }
00261
00262 #ifndef ITK_MANUAL_INSTANTIATION
00263 #include "itkDeformationFieldJacobianDeterminantFilter.txx"
00264 #endif
00265
00266 #endif