Medical Imaging Interaction Toolkit  2016.11.0
Medical Imaging Interaction Toolkit
mitkConnectomicsNetworkCreator.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 #ifndef mitkConnectomicsNetworkCreator_h
18 #define mitkConnectomicsNetworkCreator_h
19 
20 #include <itkObject.h>
21 #include <itkObjectFactory.h>
22 #include <itkMacro.h>
23 
24 #include "mitkCommon.h"
25 #include "mitkImage.h"
26 
27 #include "mitkFiberBundle.h"
29 
30 #include <MitkConnectomicsExports.h>
31 
32 namespace mitk
33 {
34 
42  class MITKCONNECTOMICS_EXPORT ConnectomicsNetworkCreator : public itk::Object
43  {
44  public:
45 
49  {
53  PrecomputeAndDistance
54  };
55 
60  itkFactorylessNewMacro(Self)
61  itkCloneMacro(Self)
62 
63 
65  typedef itk::Image<int, 3 > ITKImageType;
66 
68  typedef itk::Point<float,3> PointType;
69  typedef itk::VectorContainer<unsigned int, PointType> TractType;
70  typedef itk::VectorContainer< unsigned int, TractType::Pointer > TractContainerType; //init via smartpointer
71 
72 
74  typedef mitk::ConnectomicsNetwork::VertexDescriptorType VertexType;
75  typedef mitk::ConnectomicsNetwork::EdgeDescriptorType EdgeType;
77  typedef std::pair< VertexType, VertexType > ConnectionType;
78 
80  typedef int ImageLabelType;
81  typedef std::pair< ImageLabelType, ImageLabelType > ImageLabelPairType;
82 
84  void CreateNetworkFromFibersAndSegmentation();
85  void SetFiberBundle(mitk::FiberBundle::Pointer fiberBundle);
86  void SetSegmentation(mitk::Image::Pointer segmentation);
87 
88  mitk::ConnectomicsNetwork::Pointer GetNetwork();
89 
90  itkSetMacro(MappingStrategy, MappingStrategy);
91  itkSetMacro(EndPointSearchRadius, double);
92  itkSetMacro(ZeroLabelInvalid, bool);
93 
100  void CalculateCenterOfMass();
101 
102  protected:
103 
106  ConnectomicsNetworkCreator( mitk::Image::Pointer segmentation, mitk::FiberBundle::Pointer fiberBundle );
107  ~ConnectomicsNetworkCreator();
108 
110  void AddConnectionToNetwork(ConnectionType newConnection);
111 
113  VertexType ReturnAssociatedVertexForLabel( ImageLabelType label );
114 
116  ConnectionType ReturnAssociatedVertexPairForLabelPair( ImageLabelPairType labelpair );
117 
119  ImageLabelPairType ReturnLabelForFiberTract( TractType::Pointer singleTract, MappingStrategy strategy );
120 
122  void SupplyVertexWithInformation( ImageLabelType& label, VertexType& vertex );
123 
125  std::string LabelToString( ImageLabelType& label );
126 
128  bool IsNonWhiteMatterLabel( int labelInQuestion );
129 
131  bool IsBackgroundLabel( int labelInQuestion );
132 
137  void LinearExtensionUntilGreyMatter( std::vector<int> & indexVectorOfPointsToUse, TractType::Pointer singleTract,
138  int & label, itk::Index<3> & mitkIndex );
139 
143  void RetractionUntilBrainMatter( bool retractFront, TractType::Pointer singleTract,
144  int & label, itk::Index<3> & mitkIndex );
145 
149  std::vector< double > GetCenterOfMass( int label );
150 
152  itk::Point<float, 3> GetItkPoint(double point[3]);
153 
159  void CreateNewNode( int label, itk::Index<3>, bool useIndex );
160 
162 
167  ImageLabelPairType EndElementPositionLabel( TractType::Pointer singleTract );
168 
173  ImageLabelPairType PrecomputeVertexLocationsBySegmentation( TractType::Pointer singleTract );
174 
178  ImageLabelPairType JustEndPointVerticesNoLabelTest( TractType::Pointer singleTract );
179 
185  ImageLabelPairType EndElementPositionLabelAvoidingWhiteMatter( TractType::Pointer singleTract );
186 
188 
189  void FiberToSegmentationCoords( mitk::Point3D& fiberCoord, mitk::Point3D& segCoord );
191  void SegmentationToFiberCoords( mitk::Point3D& segCoord, mitk::Point3D& fiberCoord );
192 
194  mitk::FiberBundle::Pointer m_FiberBundle;
195  mitk::Image::Pointer m_Segmentation;
196  ITKImageType::Pointer m_SegmentationItk;
197 
198  // the graph itself
200 
201  // the id counter
202  int idCounter;
203 
204  // the map mapping labels to vertices
205  std::map< ImageLabelType, VertexType > m_LabelToVertexMap;
206 
207  // mapping labels to additional information
208  std::map< ImageLabelType, NetworkNode > m_LabelToNodePropertyMap;
209 
210  // toggles whether edges between a node and itself can exist
211  bool allowLoops;
212 
213  // toggles whether to use the center of mass coordinates
214  bool m_UseCoMCoordinates;
215 
216  // stores the coordinates of labels
217  std::map< int, std::vector< double> > m_LabelsToCoordinatesMap;
218 
219  // the straty to use for mapping
220  MappingStrategy m_MappingStrategy;
221 
222  // search radius for finding a non white matter/background area. Should be in mm
223  double m_EndPointSearchRadius;
224 
225  // toggles whether a node with the label 0 may be present
226  bool m_ZeroLabelInvalid;
227 
228  // used internally to communicate a connection should not be added if the a problem
229  // is encountered while adding it
230  bool m_AbortConnection;
231 
233 
234  // These IDs are the freesurfer ids used in parcellation
235 
236  static const int freesurfer_Left_Cerebral_White_Matter = 2;
237  static const int freesurfer_Left_Cerebellum_White_Matter = 7;
238  static const int freesurfer_Left_Cerebellum_Cortex = 8;
239  static const int freesurfer_Brain_Stem = 16;
240  static const int freesurfer_Right_Cerebral_White_Matter = 41;
241  static const int freesurfer_Right_Cerebellum_White_Matter = 46;
242  static const int freesurfer_Right_Cerebellum_Cortex = 47;
243 
244 
245  };
246 
247 }// end namespace mitk
248 
249 #endif // _mitkConnectomicsNetworkCreator_H_INCLUDED
itk::VectorContainer< unsigned int, TractType::Pointer > TractContainerType
mitk::ConnectomicsNetwork::EdgeDescriptorType EdgeType
std::pair< ImageLabelType, ImageLabelType > ImageLabelPairType
itk::VectorContainer< unsigned int, PointType > TractType
STL namespace.
DataCollection - Class to facilitate loading/accessing structured data.
Creates connectomics networks from fibers and parcellation.
std::pair< VertexType, VertexType > ConnectionType
#define mitkClassMacroItkParent(className, SuperClassName)
Definition: mitkCommon.h:53
Image class for storing images.
Definition: mitkImage.h:76
Base Class for Fiber Bundles;.
mitk::ConnectomicsNetwork::VertexDescriptorType VertexType
Connectomics Network Class.