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 {
00115 template < typename TInputImage,
00116 typename TRealType = float,
00117 typename TOutputImage = Image< TRealType,
00118 ::itk::GetImageDimension<TInputImage>::ImageDimension >
00119 >
00120 class ITK_EXPORT DeformationFieldJacobianDeterminantFilter :
00121 public ImageToImageFilter< TInputImage, TOutputImage >
00122 {
00123 public:
00125 typedef DeformationFieldJacobianDeterminantFilter Self;
00126 typedef ImageToImageFilter< TInputImage, TOutputImage > Superclass;
00127 typedef SmartPointer<Self> Pointer;
00128 typedef SmartPointer<const Self> ConstPointer;
00129
00131 itkNewMacro(Self);
00132
00134 itkTypeMacro(DeformationFieldJacobianDeterminantFilter, ImageToImageFilter);
00135
00138 typedef typename TOutputImage::PixelType OutputPixelType;
00139 typedef typename TInputImage::PixelType InputPixelType;
00140
00142 typedef TInputImage InputImageType;
00143 typedef TOutputImage OutputImageType;
00144 typedef typename InputImageType::Pointer InputImagePointer;
00145 typedef typename OutputImageType::Pointer OutputImagePointer;
00146
00148 itkStaticConstMacro(ImageDimension, unsigned int,
00149 TOutputImage::ImageDimension);
00150
00152 itkStaticConstMacro(VectorDimension, unsigned int,
00153 InputPixelType::Dimension);
00154
00156 typedef TRealType RealType;
00157 typedef Vector<TRealType, ::itk::GetVectorDimension<InputPixelType>::VectorDimension> RealVectorType;
00158 typedef Image<RealVectorType, ::itk::GetImageDimension<TInputImage>::ImageDimension> RealVectorImageType;
00159
00160
00163 typedef ConstNeighborhoodIterator<RealVectorImageType> ConstNeighborhoodIteratorType;
00164 typedef typename ConstNeighborhoodIteratorType::RadiusType RadiusType;
00165
00167 typedef typename Superclass::OutputImageRegionType OutputImageRegionType;
00168
00177 virtual void GenerateInputRequestedRegion() throw(InvalidRequestedRegionError);
00178
00182 void SetUseImageSpacingOn()
00183 { this->SetUseImageSpacing(true); }
00184
00188 void SetUseImageSpacingOff()
00189 { this->SetUseImageSpacing(false); }
00190
00193 void SetUseImageSpacing(bool);
00194 itkGetMacro(UseImageSpacing, bool);
00195
00198 void SetDerivativeWeights(TRealType data[]);
00199 itkGetVectorMacro(DerivativeWeights, const TRealType, itk::GetImageDimension<TInputImage>::ImageDimension);
00200
00201 protected:
00202 DeformationFieldJacobianDeterminantFilter();
00203 virtual ~DeformationFieldJacobianDeterminantFilter() {}
00204
00208 void BeforeThreadedGenerateData ();
00209
00222 void ThreadedGenerateData(const OutputImageRegionType& outputRegionForThread,
00223 int threadId );
00224
00225 void PrintSelf(std::ostream& os, Indent indent) const;
00226
00227 typedef typename InputImageType::Superclass ImageBaseType;
00228
00230 itkGetConstObjectMacro( RealValuedInputImage, ImageBaseType );
00231
00233 itkGetConstReferenceMacro( NeighborhoodRadius, RadiusType );
00234 itkSetMacro( NeighborhoodRadius, RadiusType );
00235
00236
00237 TRealType EvaluateAtNeighborhood
00238 (const ConstNeighborhoodIteratorType &it) const
00239 {
00240 unsigned i, j;
00241 vnl_matrix_fixed<TRealType,ImageDimension,VectorDimension> J;
00242
00243 for (i = 0; i < ImageDimension; ++i)
00244 {
00245 for (j = 0; j < VectorDimension; ++j)
00246 {
00247 J[i][j] = m_DerivativeWeights[i]
00248 * 0.5 * (it.GetNext(i)[j] - it.GetPrevious(i)[j]);
00249 }
00250 }
00251
00252 return vnl_det(J);
00253 }
00254
00256 TRealType m_DerivativeWeights[itk::GetImageDimension<TInputImage>::ImageDimension];
00257
00258 private:
00259 bool m_UseImageSpacing;
00260 int m_RequestedNumberOfThreads;
00261
00262 typename ImageBaseType::ConstPointer m_RealValuedInputImage;
00263
00264 DeformationFieldJacobianDeterminantFilter(const Self&);
00265 void operator=(const Self&);
00266
00267 RadiusType m_NeighborhoodRadius;
00268 };
00269
00270 }
00271
00272 #ifndef ITK_MANUAL_INSTANTIATION
00273 #include "itkDeformationFieldJacobianDeterminantFilter.txx"
00274 #endif
00275
00276 #endif