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
itkShortestPathImageFilter.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 #ifndef __itkShortestPathImageFilter_h
17 #define __itkShortestPathImageFilter_h
18 
19 #include "itkImageToImageFilter.h"
21 #include "itkShortestPathNode.h"
22 #include <itkImageRegionIteratorWithIndex.h>
23 
24 #include <itkMacro.h>
25 
26 // ------- INFORMATION ----------
28 // void SetInput( ItkImage ) // Compulsory
29 // void SetStartIndex (const IndexType & StartIndex); // Compulsory
30 // void SetEndIndex(const IndexType & EndIndex); // Compulsory
31 // void SetFullNeighborsMode(bool) // Optional (default=false), if false N4, if true N26
32 // void SetActivateTimeOut(bool) // Optional (default=false), for debug issues: after 30s algorithms terminates. You can
33 // have a look at the VectorOrderImage to see how far it came
34 // void SetMakeOutputImage(bool) // Optional (default=true), Generate an outputimage of the path. You can also get the
35 // path directoy with GetVectorPath()
36 // void SetCalcAllDistances(bool) // Optional (default=false), Calculate Distances over the whole image. CAREFUL,
37 // algorithm time extends a lot. Necessary for GetDistanceImage
38 // void SetStoreVectorOrder(bool) // Optional (default=false), Stores in which order the pixels were checked. Necessary
39 // for GetVectorOrderImage
40 // void AddEndIndex(const IndexType & EndIndex) //Optional. By calling this function you can add several endpoints! The
41 // algorithm will look for several shortest Pathes. From Start to all Endpoints.
42 //
44 // std::vector< itk::Index<3> > GetVectorPath(); // returns the shortest path as vector
45 // std::vector< std::vector< itk::Index<3> > GetMultipleVectorPathe(); // returns a vector of shortest Pathes (which are
46 // vectors of points)
47 // GetDistanceImage // Returns the distance image
48 // GetVectorOrderIMage // Returns the Vector Order image
49 //
50 // EXAMPLE USE
51 // pleae see qmitkmitralvalvesegmentation4dtee bundle
52 
53 namespace itk
54 {
55  template <class TInputImageType, class TOutputImageType>
56  class ShortestPathImageFilter : public ImageToImageFilter<TInputImageType, TOutputImageType>
57  {
58  public:
59  // Standard Typedefs
61  typedef ImageToImageFilter<TInputImageType, TOutputImageType> Superclass;
64 
65  // Typdefs for metric
68 
69  // More typdefs for convenience
70  typedef TInputImageType InputImageType;
73  typedef typename TInputImageType::SizeType InputImageSizeType;
74  typedef typename TInputImageType::IndexType IndexType;
75  typedef typename itk::ImageRegionIteratorWithIndex<InputImageType> InputImageIteratorType;
76 
77  typedef TOutputImageType OutputImageType;
80  typedef typename TOutputImageType::IndexType OutputImageIndexType;
81  typedef ImageRegionIteratorWithIndex<OutputImageType> OutputImageIteratorType;
82  typedef itk::ShapedNeighborhoodIterator<TInputImageType> itkShapedNeighborhoodIteratorType;
83 
84  // New Macro for smartpointer instantiation
85  itkFactorylessNewMacro(Self) itkCloneMacro(Self)
86 
87  // Run-time type information
88  itkTypeMacro(ShortestPathImageFilter, ImageToImageFilter)
89 
90  // Display
91  void PrintSelf(std::ostream &os, Indent indent) const;
92 
93  // Compare function for A_STAR
95  {
97  };
98 
99  // \brief Set Starpoint for ShortestPath Calculation
100  void SetStartIndex(const IndexType &StartIndex);
101 
102  // \brief Adds Endpoint for multiple ShortestPath Calculation
103  void AddEndIndex(const IndexType &index);
104 
105  // \brief Set Endpoint for ShortestPath Calculation
106  void SetEndIndex(const IndexType &EndIndex);
107 
108  // \brief Set FullNeighborsMode. false = no diagonal neighbors, in 2D this means N4 Neigborhood. true = would be N8
109  // in 2D
110  itkSetMacro(FullNeighborsMode, bool);
111  itkGetMacro(FullNeighborsMode, bool);
112 
113  // \brief Set Graph_fullNeighbors. false = no diagonal neighbors, in 2D this means N4 Neigborhood. true = would be
114  // N8 in 2D
115  itkSetMacro(Graph_fullNeighbors, bool)
116 
117  // \brief (default=true), Produce output image, which shows the shortest path. But you can also get the shortest
118  // Path directly as vector with the function GetVectorPath
119  itkSetMacro(MakeOutputImage, bool);
120  itkGetMacro(MakeOutputImage, bool);
121 
122  // \brief (default=false), Store an Vector of Order, so you can call getVectorOrderImage after update
123  itkSetMacro(StoreVectorOrder, bool);
124  itkGetMacro(StoreVectorOrder, bool);
125 
126  // \brief (default=false), // Calculate all Distances to all pixels, so you can call getDistanceImage after update
127  // (warning algo will take a long time)
128  itkSetMacro(CalcAllDistances, bool);
129  itkGetMacro(CalcAllDistances, bool);
130 
131  // \brief (default=false), for debug issues: after 30s algorithms terminates. You can have a look at the
132  // VectorOrderImage to see how far it came
133  itkSetMacro(ActivateTimeOut, bool);
134  itkGetMacro(ActivateTimeOut, bool);
135 
136  // \brief returns shortest Path as vector
137  std::vector<IndexType> GetVectorPath();
138 
139  // \brief returns Multiple shortest Paths. You can call this function, when u performed a multiple shortest path
140  // search (one start, several ends)
141  std::vector<std::vector<IndexType>> GetMultipleVectorPaths();
142 
143  // \brief returns the vector order image. It shows in which order the pixels were checked. good for debugging. Be
144  // sure to have m_StoreVectorOrder=true
145  OutputImagePointer GetVectorOrderImage();
146 
147  // \brief returns the distance image. It shows the distances from the startpoint to all other pixels. Be sure to
148  // have m_CalcAllDistances=true
149  OutputImagePointer GetDistanceImage();
150 
151  // \brief Fill m_VectorPath
152  void MakeShortestPathVector();
153 
154  // \brief cleans up the filter
155  void CleanUp();
156 
157  itkSetObjectMacro(CostFunction,
158  CostFunctionType); // itkSetObjectMacro = set function that uses pointer as parameter
159  itkGetObjectMacro(CostFunction, CostFunctionType);
160 
161  protected:
162  std::vector<IndexType>
163  m_endPoints; // if you fill this vector, the algo will not rest until all endPoints have been reached
164  std::vector<IndexType> m_endPointsClosed;
165 
166  ShortestPathNode *m_Nodes; // main list that contains all nodes
170  unsigned int m_ImageDimensions;
173  ShortestPathImageFilter(Self &); // intentionally not implemented
174  void operator=(const Self &); // intentionally not implemented
175  const static int BACKGROUND = 0;
176  const static int FOREGROUND = 255;
178 
180  bool m_StoreVectorOrder; // Store an Vector of Order, so you can call getVectorOrderImage after update
181  bool m_CalcAllDistances; // Calculate all Distances, so you can call getDistanceImage after update (warning algo
182  // will take a long time)
183 
185 
186  bool m_ActivateTimeOut; // if true, then i search max. 30 secs. then abort
187 
189 
190  CostFunctionTypePointer m_CostFunction;
192  std::vector<IndexType> m_VectorPath;
193  std::vector<std::vector<IndexType>> m_MultipleVectorPaths;
194 
196 
198 
200 
201  // \brief Create all the outputs
202  void MakeOutputs();
203 
204  // \brief Generate Data
205  void GenerateData();
206 
207  // \brief gets the estimate costs from pixel a to target.
208  double getEstimatedCostsToTarget(const IndexType &a);
209 
210  typename InputImageType::Pointer m_magnitudeImage;
211 
212  // \brief Convert a indexnumber of a node in m_Nodes to image coordinates
213  typename TInputImageType::IndexType NodeToCoord(NodeNumType);
214 
215  // \brief Convert image coordinate to a indexnumber of a node in m_Nodes
216  unsigned int CoordToNode(IndexType);
217 
218  // \brief Returns the neighbors of a node
219  std::vector<ShortestPathNode *> GetNeighbors(NodeNumType nodeNum, bool FullNeighbors);
220 
221  // \brief Check if coords are in bounds of image
222  bool CoordIsInBounds(IndexType);
223 
224  // \brief Initializes the graph
225  void InitGraph();
226 
227  // \brief Start ShortestPathSearch
229  };
230 
231 } // end of namespace itk
232 
233 #include "itkShortestPathImageFilter.txx"
234 
235 #endif
std::vector< std::vector< IndexType > > GetMultipleVectorPaths()
bool CoordIsInBounds(IndexType)
itk::SmartPointer< Self > Pointer
std::vector< std::vector< IndexType > > m_MultipleVectorPaths
void SetEndIndex(const IndexType &EndIndex)
SmartPointer< const Self > ConstPointer
void PrintSelf(std::ostream &os, Indent indent) const
std::vector< IndexType > GetVectorPath()
TInputImageType::PixelType InputImagePixelType
TInputImageType::Pointer InputImagePointer
STL namespace.
unsigned int CoordToNode(IndexType)
itk::ShapedNeighborhoodIterator< TInputImageType > itkShapedNeighborhoodIteratorType
void SetStartIndex(const IndexType &StartIndex)
std::vector< ShortestPathNode * > GetNeighbors(NodeNumType nodeNum, bool FullNeighbors)
OutputImagePointer GetVectorOrderImage()
std::vector< NodeNumType > m_VectorOrder
TInputImageType::SizeType InputImageSizeType
TInputImageType::IndexType IndexType
void AddEndIndex(const IndexType &index)
CostFunctionType::Pointer CostFunctionTypePointer
double getEstimatedCostsToTarget(const IndexType &a)
bool operator()(ShortestPathNode *a, ShortestPathNode *b)
TOutputImageType::PixelType OutputImagePixelType
ImageRegionIteratorWithIndex< OutputImageType > OutputImageIteratorType
std::vector< ShortestPathNode * > m_Graph_DiscoveredNodeList
TOutputImageType::IndexType OutputImageIndexType
std::vector< IndexType > m_endPointsClosed
ImageToImageFilter< TInputImageType, TOutputImageType > Superclass
TInputImageType::IndexType NodeToCoord(NodeNumType)
unsigned short PixelType
TOutputImageType::Pointer OutputImagePointer
OutputImagePointer GetDistanceImage()
InputImageType::Pointer m_magnitudeImage
ShortestPathCostFunction< TInputImageType > CostFunctionType
unsigned int NodeNumType
itk::ImageRegionIteratorWithIndex< InputImageType > InputImageIteratorType