Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkFiberBundle.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 #ifndef _MITK_FiberBundle_H
19 #define _MITK_FiberBundle_H
20 
21 //includes for MITK datastructure
22 #include <mitkBaseData.h>
23 #include <MitkFiberTrackingExports.h>
24 #include <mitkImage.h>
25 #include <mitkDataStorage.h>
26 #include <mitkPlanarFigure.h>
27 #include <mitkPixelTypeTraits.h>
29 
30 
31 //includes storing fiberdata
32 #include <vtkSmartPointer.h>
33 #include <vtkPolyData.h>
34 #include <vtkPoints.h>
35 #include <vtkDataSet.h>
36 #include <vtkTransform.h>
37 #include <vtkFloatArray.h>
38 
39 
40 namespace mitk {
41 
44 class MITKFIBERTRACKING_EXPORT FiberBundle : public BaseData
45 {
46 public:
47 
48  typedef itk::Image<unsigned char, 3> ItkUcharImgType;
49 
50  // fiber colorcodings
51  static const char* FIBER_ID_ARRAY;
52 
53  virtual void UpdateOutputInformation() override;
54  virtual void SetRequestedRegionToLargestPossibleRegion() override;
55  virtual bool RequestedRegionIsOutsideOfTheBufferedRegion() override;
56  virtual bool VerifyRequestedRegion() override;
57  virtual void SetRequestedRegion(const itk::DataObject*) override;
58 
60  itkFactorylessNewMacro(Self)
61  itkCloneMacro(Self)
62  mitkNewMacro1Param(Self, vtkSmartPointer<vtkPolyData>) // custom constructor
63 
64  // colorcoding related methods
65  void ColorFibersByCurvature(bool minMaxNorm=true);
66  void ColorFibersByScalarMap(mitk::Image::Pointer, bool opacity);
67  template <typename TPixel>
68  void ColorFibersByScalarMap(const mitk::PixelType pixelType, mitk::Image::Pointer, bool opacity);
69  void ColorFibersByOrientation();
70  void SetFiberOpacity(vtkDoubleArray *FAValArray);
71  void ResetFiberOpacity();
72  void SetFiberColors(vtkSmartPointer<vtkUnsignedCharArray> fiberColors);
73  void SetFiberColors(float r, float g, float b, float alpha=255);
74  vtkSmartPointer<vtkUnsignedCharArray> GetFiberColors() const { return m_FiberColors; }
75 
76  // fiber compression
77  void Compress(float error = 0.0);
78 
79  // fiber resampling
80  void ResampleSpline(float pointDistance=1);
81  void ResampleSpline(float pointDistance, double tension, double continuity, double bias );
82 
83  bool RemoveShortFibers(float lengthInMM);
84  bool RemoveLongFibers(float lengthInMM);
85  bool ApplyCurvatureThreshold(float minRadius, bool deleteFibers);
86  void MirrorFibers(unsigned int axis);
87  void RotateAroundAxis(double x, double y, double z);
88  void TranslateFibers(double x, double y, double z);
89  void ScaleFibers(double x, double y, double z, bool subtractCenter=true);
90  void TransformFibers(double rx, double ry, double rz, double tx, double ty, double tz);
91  void RemoveDir(vnl_vector_fixed<double,3> dir, double threshold);
92  itk::Point<float, 3> TransformPoint(vnl_vector_fixed< double, 3 > point, double rx, double ry, double rz, double tx, double ty, double tz);
93  itk::Matrix< double, 3, 3 > TransformMatrix(itk::Matrix< double, 3, 3 > m, double rx, double ry, double rz);
94 
95  // add/subtract fibers
96  FiberBundle::Pointer AddBundle(FiberBundle* fib);
97  FiberBundle::Pointer SubtractBundle(FiberBundle* fib);
98 
99  // fiber subset extraction
100  FiberBundle::Pointer ExtractFiberSubset(DataNode *roi, DataStorage* storage);
101  std::vector<long> ExtractFiberIdSubset(DataNode* roi, DataStorage* storage);
102  FiberBundle::Pointer ExtractFiberSubset(ItkUcharImgType* mask, bool anyPoint, bool invert=false, bool bothEnds=true);
103  FiberBundle::Pointer RemoveFibersOutside(ItkUcharImgType* mask, bool invert=false);
104 
105  vtkSmartPointer<vtkPolyData> GeneratePolyDataByIds( std::vector<long> ); // TODO: make protected
106  void GenerateFiberIds(); // TODO: make protected
107 
108  // get/set data
109  vtkSmartPointer<vtkFloatArray> GetFiberWeights() const { return m_FiberWeights; }
110  float GetFiberWeight(unsigned int fiber);
111  void SetFiberWeights(float newWeight);
112  void SetFiberWeight(unsigned int fiber, float weight);
113  void SetFiberWeights(vtkSmartPointer<vtkFloatArray> weights);
114  void SetFiberPolyData(vtkSmartPointer<vtkPolyData>, bool updateGeometry = true);
115  vtkSmartPointer<vtkPolyData> GetFiberPolyData() const;
116  itkGetMacro( NumFibers, int)
117  //itkGetMacro( FiberSampling, int)
118  int GetNumFibers() const {return m_NumFibers;}
119  itkGetMacro( MinFiberLength, float )
120  itkGetMacro( MaxFiberLength, float )
121  itkGetMacro( MeanFiberLength, float )
122  itkGetMacro( MedianFiberLength, float )
123  itkGetMacro( LengthStDev, float )
124  itkGetMacro( UpdateTime2D, itk::TimeStamp )
125  itkGetMacro( UpdateTime3D, itk::TimeStamp )
126  void RequestUpdate2D(){ m_UpdateTime2D.Modified(); }
127  void RequestUpdate3D(){ m_UpdateTime3D.Modified(); }
128  void RequestUpdate(){ m_UpdateTime2D.Modified(); m_UpdateTime3D.Modified(); }
129 
130  unsigned long GetNumberOfPoints();
131 
132  // copy fiber bundle
133  mitk::FiberBundle::Pointer GetDeepCopy();
134 
135  // compare fiber bundles
136  bool Equals(FiberBundle* fib, double eps=0.0001);
137 
138  itkSetMacro( ReferenceGeometry, mitk::BaseGeometry::Pointer )
139  itkGetConstMacro( ReferenceGeometry, mitk::BaseGeometry::Pointer )
140 
141 protected:
142 
143  FiberBundle( vtkPolyData* fiberPolyData = nullptr );
144  virtual ~FiberBundle();
145 
146  itk::Point<float, 3> GetItkPoint(double point[3]);
147 
148  // calculate geometry from fiber extent
149  void UpdateFiberGeometry();
150 
151 private:
152 
153  // actual fiber container
154  vtkSmartPointer<vtkPolyData> m_FiberPolyData;
155 
156  // contains fiber ids
157  vtkSmartPointer<vtkDataSet> m_FiberIdDataSet;
158 
159  int m_NumFibers;
160 
161  vtkSmartPointer<vtkUnsignedCharArray> m_FiberColors;
162  vtkSmartPointer<vtkFloatArray> m_FiberWeights;
163  std::vector< float > m_FiberLengths;
164  float m_MinFiberLength;
165  float m_MaxFiberLength;
166  float m_MeanFiberLength;
167  float m_MedianFiberLength;
168  float m_LengthStDev;
169  int m_FiberSampling;
170  itk::TimeStamp m_UpdateTime2D;
171  itk::TimeStamp m_UpdateTime3D;
172  mitk::BaseGeometry::Pointer m_ReferenceGeometry;
173 };
174 
175 } // namespace mitk
176 
177 #endif /* _MITK_FiberBundle_H */
Data management class that handles 'was created by' relations.
static const char * FIBER_ID_ARRAY
#define mitkNewMacro1Param(classname, type)
Definition: mitkCommon.h:76
Base of all data objects.
Definition: mitkBaseData.h:39
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
itk::Image< unsigned char, 3 > ItkUcharImgType
vtkSmartPointer< vtkFloatArray > GetFiberWeights() const
#define mitkClassMacro(className, SuperClassName)
Definition: mitkCommon.h:44
Image class for storing images.
Definition: mitkImage.h:76
Base Class for Fiber Bundles;.
MITKCORE_EXPORT const ScalarType eps
BaseGeometry Describes the geometry of a data object.
Class for nodes of the DataTree.
Definition: mitkDataNode.h:66
Class for defining the data type of pixels.
Definition: mitkPixelType.h:55