16 #ifndef __itkStochasticTractographyFilter_h__
17 #define __itkStochasticTractographyFilter_h__
19 #include "itkImageToImageFilter.h"
20 #include "vnl/vnl_random.h"
21 #include "vnl/vnl_vector_fixed.h"
22 #include "vnl/vnl_matrix.h"
24 #include "itkVectorContainer.h"
25 #include "vnl/algo/vnl_qr.h"
26 #include "itkVariableLengthVector.h"
28 #include "itkSimpleFastMutexLock.h"
29 #include "itkRealTimeClock.h"
30 #include "itkDiffusionTensor3D.h"
41 template<
class TInputDWIImage,
class TInputWhiteMatterProbabilityImage,
42 class TOutputConnectivityImage >
44 public ImageToImageFilter< TInputDWIImage,
45 TOutputConnectivityImage >{
48 typedef ImageToImageFilter< TInputDWIImage,
53 itkFactorylessNewMacro(Self)
71 typedef VectorContainer<
unsigned int, typename TractType::Pointer >
78 typedef VectorContainer<
unsigned int, vnl_vector_fixed<
double, 3 > >
89 typedef VectorContainer<
unsigned int, vnl_vector_fixed<
double, 3 > >
93 itkSetMacro( TotalTracts,
unsigned int)
94 itkGetMacro( TotalTracts,
unsigned int)
97 itkSetMacro( MaxTractLength,
unsigned int )
98 itkGetMacro( MaxTractLength,
unsigned int )
101 itkSetConstObjectMacro( bValues, bValueContainerType )
102 itkGetConstObjectMacro( bValues, bValueContainerType )
113 itkSetInputMacro(WhiteMatterProbabilityImage, InputWhiteMatterProbabilityImageType)
114 itkGetInputMacro(WhiteMatterProbabilityImage, InputWhiteMatterProbabilityImageType)
119 void SetPrimaryInput(DataObject *input)
124 dwiimagePtr =
dynamic_cast<InputDWIImageType*
>( input );
126 catch(itk::ExceptionObject &e)
128 MITK_INFO <<
"wrong image type: " << e.what();
131 Superclass::SetPrimaryInput( input );
134 this->m_LikelihoodCachePtr->CopyInformation( this->GetInput() );
135 this->m_LikelihoodCachePtr->SetBufferedRegion( this->GetInput()->GetBufferedRegion() );
136 this->m_LikelihoodCachePtr->SetRequestedRegion( this->GetInput()->GetRequestedRegion() );
137 this->m_LikelihoodCachePtr->Allocate();
138 this->m_CurrentLikelihoodCacheElements = 0;
141 this->m_LikelihoodCacheMutexImagePtr->CopyInformation( this->GetInput() );
142 this->m_LikelihoodCacheMutexImagePtr->SetBufferedRegion( this->GetInput()->GetBufferedRegion() );
143 this->m_LikelihoodCacheMutexImagePtr->SetRequestedRegion( this->GetInput()->GetRequestedRegion() );
144 this->m_LikelihoodCacheMutexImagePtr->Allocate();
148 itkSetMacro( SeedIndex,
typename InputDWIImageType::IndexType )
149 itkGetMacro( SeedIndex, typename InputDWIImageType::IndexType )
152 itkSetConstObjectMacro( SampleDirections, TractOrientationContainerType )
153 itkGetConstObjectMacro( SampleDirections, TractOrientationContainerType )
156 itkSetMacro( MeasurementFrame, MeasurementFrameType )
157 itkGetMacro( MeasurementFrame, MeasurementFrameType )
160 itkSetMacro( MaxLikelihoodCacheSize,
unsigned int )
161 itkGetMacro( MaxLikelihoodCacheSize,
unsigned int )
167 itkGetObjectMacro( OutputTensorImage, OutputTensorImageType )
170 void GenerateTractContainerOutput(
void );
171 void GenerateTensorImageOutput(
void );
186 typedef
Image< Array<
double >, 3 > ProbabilityDistributionImageType;
195 void LoadDefaultSampleDirections(
void );
198 void ProbabilisticallyInterpolate( vnl_random& randomgenerator,
199 const
TractType::ContinuousIndexType& cindex,
203 void UpdateGradientDirections(
void);
204 void UpdateTensorModelFittingMatrices(
void );
205 void CalculateTensorModelParameters( const DWIVectorImageType::
PixelType& dwivalues,
206 vnl_diag_matrix<
double>& W,
207 TensorModelParamType& tensormodelparams);
209 void CalculateConstrainedModelParameters( const TensorModelParamType& tensormodelparams,
210 ConstrainedModelParamType& constrainedmodelparams);
212 void CalculateNoiseFreeDWIFromConstrainedModel( const ConstrainedModelParamType& constrainedmodelparams,
213 DWIVectorImageType::
PixelType& noisefreedwi);
215 void CalculateResidualVariance( const DWIVectorImageType::
PixelType& noisydwi,
216 const DWIVectorImageType::
PixelType& noisefreedwi,
217 const vnl_diag_matrix<
double >& W,
218 const
unsigned int numberofparameters,
219 double& residualvariance);
221 void CalculateLikelihood( const DWIVectorImageType::
PixelType &dwipixel,
223 ProbabilityDistributionImageType::
PixelType& likelihood);
227 ProbabilityDistributionImageType::
PixelType& prior );
229 void CalculatePosterior( const ProbabilityDistributionImageType::
PixelType& likelihood,
230 const ProbabilityDistributionImageType::
PixelType& prior,
231 ProbabilityDistributionImageType::
PixelType& posterior);
233 void SampleTractOrientation( vnl_random& randomgenerator,
234 const ProbabilityDistributionImageType::
PixelType& posterior,
238 void StochasticTractGeneration( typename
InputDWIImageType::ConstPointer dwiimagePtr,
241 unsigned long randomseed,
247 static ITK_THREAD_RETURN_TYPE StochasticTractGenerationCallback(
void *arg );
255 AccessLikelihoodCache(
typename InputDWIImageType::IndexType index );
257 bool DelegateTract(
unsigned long& randomseed);
263 bool FiberExistenceTest( vnl_random& randomgenerator,
265 typename InputWhiteMatterProbabilityImageType::IndexType index );
287 vnl_matrix< double >*
m_A;
311 #ifndef ITK_MANUAL_INSTANTIATION
vnl_vector_fixed< double, 6 > ConstrainedModelParamType
Represent a path of line segments through ND Space.
itk::SmartPointer< Self > Pointer
TractContainerType::Pointer m_OutputTractContainer
TInputWhiteMatterProbabilityImage InputWhiteMatterProbabilityImageType
vnl_matrix< double > * m_A
TInputDWIImage InputDWIImageType
bValueContainerType::ConstPointer m_bValues
unsigned int m_TotalTracts
Image< Array< double >, 3 > ProbabilityDistributionImageType
Performs probabilistic streamline tracking on the input dwi.
VectorContainer< unsigned int, vnl_vector_fixed< double, 3 > > GradientDirectionContainerType
SmartPointer< const Self > ConstPointer
SimpleFastMutexLock m_LikelihoodCacheMutex
SmartPointer< Self > Pointer
itk::SmartPointer< const Self > ConstPointer
vnl_matrix_fixed< double, 3, 3 > MeasurementFrameType
GradientDirectionContainerType::ConstPointer m_Gradients
InputDWIImageType::IndexType m_SeedIndex
VectorContainer< unsigned int, vnl_vector_fixed< double, 3 > > TractOrientationContainerType
Image< VariableLengthVector< double >, 3 > DWIVectorImageType
GradientDirectionContainerType::Pointer m_TransformedGradients
MeasurementFrameType m_MeasurementFrame
ImageToImageFilter< TInputDWIImage, TOutputConnectivityImage > Superclass
Image< SimpleFastMutexLock, 3 > LikelihoodCacheMutexImageType
LikelihoodCacheMutexImageType::Pointer m_LikelihoodCacheMutexImagePtr
unsigned long m_MaxLikelihoodCacheElements
TractOrientationContainerType::ConstPointer m_SampleDirections
RealTimeClock::Pointer m_ClockPtr
unsigned int m_TotalDelegatedTracts
vnl_random m_RandomGenerator
SimpleFastMutexLock m_TotalDelegatedTractsMutex
VectorContainer< unsigned int, bValueType > bValueContainerType
TOutputConnectivityImage OutputConnectivityImageType
ProbabilityDistributionImageType::Pointer m_LikelihoodCachePtr
vnl_vector_fixed< double, 7 > TensorModelParamType
unsigned long m_MaxLikelihoodCacheSize
VectorContainer< unsigned int, typename TractType::Pointer > TractContainerType
Image< DiffusionTensor3D< double >, 3 > OutputTensorImageType
SimpleFastMutexLock m_OutputTractContainerMutex
StochasticTractographyFilter Self
unsigned long m_CurrentLikelihoodCacheElements
OutputTensorImageType::Pointer m_OutputTensorImage
unsigned int m_MaxTractLength
SimpleFastMutexLock m_OutputImageMutex
static itkEventMacro(BoundingShapeInteractionEvent, itk::AnyEvent) class MITKBOUNDINGSHAPE_EXPORT BoundingShapeInteractor Pointer New()
Basic interaction methods for mitk::GeometryData.