Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
itkMLBSTrackingFilter.h
Go to the documentation of this file.
1 /*===================================================================
2 
3 The Medical Imaging Interaction Toolkit (MITK)
4 
5 Copyright (c) German Cancer Research Center,
6 Division of Medical and Biological Informatics.
7 All rights reserved.
8 
9 This software is distributed WITHOUT ANY WARRANTY; without
10 even the implied warranty of MERCHANTABILITY or FITNESS FOR
11 A PARTICULAR PURPOSE.
12 
13 See LICENSE.txt or http://www.mitk.org for details.
14 
15 ===================================================================*/
16 
17 /*===================================================================
18 
19 This file is based heavily on a corresponding ITK filter.
20 
21 ===================================================================*/
22 #ifndef __itkMLBSTrackingFilter_h_
23 #define __itkMLBSTrackingFilter_h_
24 
25 #include <itkImageToImageFilter.h>
26 #include <itkVectorContainer.h>
27 #include <itkVectorImage.h>
28 #include <vtkSmartPointer.h>
29 #include <vtkPolyData.h>
30 #include <vtkCellArray.h>
31 #include <vtkPoints.h>
32 #include <vtkPolyLine.h>
33 #include <vtkCleanPolyData.h>
35 #include <itkMersenneTwisterRandomVariateGenerator.h>
37 #include <itkSimpleFastMutexLock.h>
39 #include <mitkPointSet.h>
40 #include <chrono>
42 
43 // classification includes
44 #include <vigra/random_forest.hxx>
45 #include <vigra/multi_array.hxx>
46 #include <vigra/random_forest_hdf5_impex.hxx>
47 
48 namespace itk{
49 
53 template< int ShOrder=6, int NumImageFeatures=100 >
54 class MLBSTrackingFilter : public ImageToImageFilter< VectorImage< short, 3 >, Image< double, 3 > >
55 {
56 
57 public:
58 
62  typedef ImageToImageFilter< VectorImage< short, 3 >, Image< double, 3 > > Superclass;
63 
65  typedef typename Superclass::InputImageRegionType InputImageRegionType;
66  typedef Image< Vector< float, NumImageFeatures > , 3 > FeatureImageType;
67 
69  itkFactorylessNewMacro(Self)
70  itkCloneMacro(Self)
71 
73  itkTypeMacro(MLBSTrackingFilter, ImageToImageFilter)
74 
75  typedef itk::Image<unsigned char, 3> ItkUcharImgType;
76  typedef itk::Image<double, 3> ItkDoubleImgType;
77  typedef itk::Image<float, 3> ItkFloatImgType;
78  typedef vtkSmartPointer< vtkPolyData > PolyDataType;
79 
80  typedef std::deque< itk::Point<double> > FiberType;
81  typedef std::vector< FiberType > BundleType;
82 
83  volatile bool m_PauseTracking;
87  volatile bool m_Stop;
88  mitk::PointSet::Pointer m_SamplingPointset;
89  mitk::PointSet::Pointer m_AlternativePointset;
90 
91  itkGetMacro( FiberPolyData, PolyDataType )
92  itkSetMacro( SeedImage, ItkUcharImgType::Pointer)
93  itkSetMacro( MaskImage, ItkUcharImgType::Pointer)
94  itkSetMacro( SeedsPerVoxel, int)
95  itkSetMacro( StepSize, double)
96  itkSetMacro( MinTractLength, double )
97  itkSetMacro( MaxTractLength, double )
98  itkSetMacro( AngularThreshold, double )
99  itkSetMacro( SamplingDistance, double )
100  itkSetMacro( NumberOfSamples, int )
101  itkSetMacro( StoppingRegions, ItkUcharImgType::Pointer)
102  itkSetMacro( DemoMode, bool )
103  itkSetMacro( RemoveWmEndFibers, bool )
104  itkSetMacro( AposterioriCurvCheck, bool )
105  itkSetMacro( AvoidStop, bool )
106  itkSetMacro( RandomSampling, bool )
107 
108  void SetForestHandler( mitk::TrackingForestHandler<ShOrder> fh )
109  {
110  m_ForestHandler = fh;
111  }
112 
113  protected:
116 
117  void CalculateNewPosition(itk::Point<double, 3>& pos, vnl_vector_fixed<double,3>& dir);
118  double FollowStreamline(itk::Point<double, 3> pos, vnl_vector_fixed<double,3> dir, FiberType* fib, double tractLength, bool front);
119  bool IsValidPosition(itk::Point<double, 3>& pos);
120  vnl_vector_fixed<double,3> GetNewDirection(itk::Point<double, 3>& pos, vnl_vector_fixed<double,3>& olddir);
121 
122  double GetRandDouble(double min=-1, double max=1);
123  double RoundToNearest(double num);
124 
125  void BeforeThreadedGenerateData() override;
126  void ThreadedGenerateData( const InputImageRegionType &outputRegionForThread, ThreadIdType threadId) override;
127  void AfterThreadedGenerateData() override;
128 
130  vtkSmartPointer<vtkPoints> m_Points;
131  vtkSmartPointer<vtkCellArray> m_Cells;
133 
135  double m_StepSize;
143 
144  SimpleFastMutexLock m_Mutex;
148 
154  void BuildFibers(bool check);
155  int CheckCurvature(FiberType* fib, bool front);
156 
157  // decision forest
160 
161 
162  std::vector< PolyDataType > m_PolyDataContainer;
163 
164  std::chrono::time_point<std::chrono::system_clock> m_StartTime;
165  std::chrono::time_point<std::chrono::system_clock> m_EndTime;
166 
167 private:
168 
169 };
170 
171 }
172 
173 #ifndef ITK_MANUAL_INSTANTIATION
174 #include "itkMLBSTrackingFilter.cpp"
175 #endif
176 
177 #endif //__itkMLBSTrackingFilter_h_
178 
Superclass::InputImageRegionType InputImageRegionType
double FollowStreamline(itk::Point< double, 3 > pos, vnl_vector_fixed< double, 3 > dir, FiberType *fib, double tractLength, bool front)
Start streamline in one direction.
double GetRandDouble(double min=-1, double max=1)
Image< Vector< float, NumImageFeatures >, 3 > FeatureImageType
InputImageType::Pointer m_InputImage
itk::SmartPointer< Self > Pointer
mitk::PointSet::Pointer m_SamplingPointset
std::chrono::time_point< std::chrono::system_clock > m_EndTime
void ThreadedGenerateData(const InputImageRegionType &outputRegionForThread, ThreadIdType threadId) override
vtkSmartPointer< vtkCellArray > m_Cells
itk::Image< unsigned char, 3 > SeedImage
vtkSmartPointer< vtkPoints > m_Points
SmartPointer< const Self > ConstPointer
std::vector< FiberType > BundleType
vtkSmartPointer< vtkPolyData > PolyDataType
STL namespace.
void SetForestHandler(mitk::TrackingForestHandler< ShOrder > fh)
DataCollection - Class to facilitate loading/accessing structured data.
mitk::TrackingForestHandler< ShOrder > m_ForestHandler
void CalculateNewPosition(itk::Point< double, 3 > &pos, vnl_vector_fixed< double, 3 > &dir)
Calculate next integration step.
Performes deterministic streamline tracking on the input tensor image.
std::vector< PolyDataType > m_PolyDataContainer
int CheckCurvature(FiberType *fib, bool front)
mitk::PointSet::Pointer m_AlternativePointset
bool IsValidPosition(itk::Point< double, 3 > &pos)
Are we outside of the mask image?
ImageToImageFilter< VectorImage< short, 3 >, Image< double, 3 > > Superclass
vnl_vector_fixed< double, 3 > GetNewDirection(itk::Point< double, 3 > &pos, vnl_vector_fixed< double, 3 > &olddir)
Determine new direction by sample voting at the current position taking the last progression directio...
ItkUcharImgType::Pointer m_SeedImage
ItkUcharImgType::Pointer m_MaskImage
class ITK_EXPORT Image
void AfterThreadedGenerateData() override
itk::Image< double, 3 > InputImageType
std::deque< itk::Point< double > > FiberType
itk::Image< unsigned char, 3 > ItkUcharImgType
static T max(T x, T y)
Definition: svm.cpp:70
Superclass::InputImageType InputImageType
static T min(T x, T y)
Definition: svm.cpp:67
itk::Image< double, 3 > ItkDoubleImgType
itk::Image< float, 3 > ItkFloatImgType
std::chrono::time_point< std::chrono::system_clock > m_StartTime
void BeforeThreadedGenerateData() override
ItkUcharImgType::Pointer m_StoppingRegions
double RoundToNearest(double num)
SmartPointer< Self > Pointer