Medical Imaging Interaction Toolkit  2023.12.99-7a59bd54
Medical Imaging Interaction Toolkit
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 (DKFZ)
6 All rights reserved.
7 
8 Use of this source code is governed by a 3-clause BSD license that can be
9 found in the LICENSE file.
10 
11 ============================================================================*/
12 #ifndef __itkShortestPathImageFilter_h
13 #define __itkShortestPathImageFilter_h
14 
15 #include "itkImageToImageFilter.h"
17 #include "itkShortestPathNode.h"
18 #include <itkImageRegionIteratorWithIndex.h>
19 
20 #include <itkMacro.h>
21 
22 // ------- INFORMATION ----------
24 // void SetInput( ItkImage ) // Compulsory
25 // void SetStartIndex (const IndexType & StartIndex); // Compulsory
26 // void SetEndIndex(const IndexType & EndIndex); // Compulsory
27 // void SetFullNeighborsMode(bool) // Optional (default=false), if false N4, if true N26
28 // void SetActivateTimeOut(bool) // Optional (default=false), for debug issues: after 30s algorithms terminates. You can
29 // have a look at the VectorOrderImage to see how far it came
30 // void SetMakeOutputImage(bool) // Optional (default=true), Generate an outputimage of the path. You can also get the
31 // path directoy with GetVectorPath()
32 // void SetCalcAllDistances(bool) // Optional (default=false), Calculate Distances over the whole image. CAREFUL,
33 // algorithm time extends a lot. Necessary for GetDistanceImage
34 // void SetStoreVectorOrder(bool) // Optional (default=false), Stores in which order the pixels were checked. Necessary
35 // for GetVectorOrderImage
36 // void AddEndIndex(const IndexType & EndIndex) //Optional. By calling this function you can add several endpoints! The
37 // algorithm will look for several shortest Pathes. From Start to all Endpoints.
38 //
40 // std::vector< itk::Index<3> > GetVectorPath(); // returns the shortest path as vector
41 // std::vector< std::vector< itk::Index<3> > GetMultipleVectorPathe(); // returns a vector of shortest Pathes (which are
42 // vectors of points)
43 // GetDistanceImage // Returns the distance image
44 // GetVectorOrderIMage // Returns the Vector Order image
45 //
46 // EXAMPLE USE
47 // pleae see qmitkmitralvalvesegmentation4dtee bundle
48 
49 namespace itk
50 {
51  template <class TInputImageType, class TOutputImageType>
52  class ShortestPathImageFilter : public ImageToImageFilter<TInputImageType, TOutputImageType>
53  {
54  public:
55  // Standard Typedefs
57  typedef ImageToImageFilter<TInputImageType, TOutputImageType> Superclass;
60 
61  // Typdefs for metric
64 
65  // More typdefs for convenience
66  typedef TInputImageType InputImageType;
67  typedef typename TInputImageType::Pointer InputImagePointer;
68  typedef typename TInputImageType::PixelType InputImagePixelType;
69  typedef typename TInputImageType::SizeType InputImageSizeType;
70  typedef typename TInputImageType::IndexType IndexType;
71  typedef typename itk::ImageRegionIteratorWithIndex<InputImageType> InputImageIteratorType;
72 
73  typedef TOutputImageType OutputImageType;
74  typedef typename TOutputImageType::Pointer OutputImagePointer;
75  typedef typename TOutputImageType::PixelType OutputImagePixelType;
76  typedef typename TOutputImageType::IndexType OutputImageIndexType;
77  typedef ImageRegionIteratorWithIndex<OutputImageType> OutputImageIteratorType;
78  typedef itk::ShapedNeighborhoodIterator<TInputImageType> itkShapedNeighborhoodIteratorType;
79 
80  // New Macro for smartpointer instantiation
81  itkFactorylessNewMacro(Self);
82  itkCloneMacro(Self);
83 
84  // Run-time type information
85  itkTypeMacro(ShortestPathImageFilter, ImageToImageFilter);
86 
87  // Display
88  void PrintSelf(std::ostream &os, Indent indent) const override;
89 
90  // Compare function for A_STAR
92  {
94  };
95 
96  // \brief Set Starpoint for ShortestPath Calculation
97  void SetStartIndex(const IndexType &StartIndex);
98 
99  // \brief Adds Endpoint for multiple ShortestPath Calculation
100  void AddEndIndex(const IndexType &index);
101 
102  // \brief Set Endpoint for ShortestPath Calculation
103  void SetEndIndex(const IndexType &EndIndex);
104 
105  // \brief Set FullNeighborsMode. false = no diagonal neighbors, in 2D this means N4 Neigborhood. true = would be N8
106  // in 2D
107  itkSetMacro(FullNeighborsMode, bool);
108  itkGetMacro(FullNeighborsMode, bool);
109 
110  // \brief Set Graph_fullNeighbors. false = no diagonal neighbors, in 2D this means N4 Neigborhood. true = would be
111  // N8 in 2D
112  itkSetMacro(Graph_fullNeighbors, bool);
113 
114  // \brief (default=true), Produce output image, which shows the shortest path. But you can also get the shortest
115  // Path directly as vector with the function GetVectorPath
116  itkSetMacro(MakeOutputImage, bool);
117  itkGetMacro(MakeOutputImage, bool);
118 
119  // \brief (default=false), Store an Vector of Order, so you can call getVectorOrderImage after update
120  itkSetMacro(StoreVectorOrder, bool);
121  itkGetMacro(StoreVectorOrder, bool);
122 
123  // \brief (default=false), // Calculate all Distances to all pixels, so you can call getDistanceImage after update
124  // (warning algo will take a long time)
125  itkSetMacro(CalcAllDistances, bool);
126  itkGetMacro(CalcAllDistances, bool);
127 
128  // \brief (default=false), for debug issues: after 30s algorithms terminates. You can have a look at the
129  // VectorOrderImage to see how far it came
130  itkSetMacro(ActivateTimeOut, bool);
131  itkGetMacro(ActivateTimeOut, bool);
132 
133  // \brief returns shortest Path as vector
134  std::vector<IndexType> GetVectorPath();
135 
136  // \brief returns Multiple shortest Paths. You can call this function, when u performed a multiple shortest path
137  // search (one start, several ends)
138  std::vector<std::vector<IndexType>> GetMultipleVectorPaths();
139 
140  // \brief returns the vector order image. It shows in which order the pixels were checked. good for debugging. Be
141  // sure to have m_StoreVectorOrder=true
143 
144  // \brief returns the distance image. It shows the distances from the startpoint to all other pixels. Be sure to
145  // have m_CalcAllDistances=true
147 
148  // \brief Fill m_VectorPath
149  void MakeShortestPathVector();
150 
151  // \brief cleans up the filter
152  void CleanUp();
153 
154  itkSetObjectMacro(CostFunction,
155  CostFunctionType); // itkSetObjectMacro = set function that uses pointer as parameter
156  itkGetObjectMacro(CostFunction, CostFunctionType);
157 
158  void SetUseCostFunction(bool doUseCostFunction) { m_useCostFunction = doUseCostFunction; };
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
172  std::vector<ShortestPathNode *> m_Graph_DiscoveredNodeList;
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 
192  std::vector<IndexType> m_VectorPath;
193  std::vector<std::vector<IndexType>> m_MultipleVectorPaths;
194 
195  std::vector<NodeNumType> m_VectorOrder;
196 
198 
199  ~ShortestPathImageFilter() override;
200 
201  // \brief Create all the outputs
202  void MakeOutputs();
203 
204  // \brief Generate Data
205  void GenerateData() override;
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
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
itk::ShortestPathImageFilter::InputImagePointer
TInputImageType::Pointer InputImagePointer
Definition: itkShortestPathImageFilter.h:67
itk::ShortestPathImageFilter::CompareNodeStar
Definition: itkShortestPathImageFilter.h:91
itk::ShortestPathImageFilter::GetVectorOrderImage
OutputImagePointer GetVectorOrderImage()
itk::ShortestPathImageFilter::m_Initialized
bool m_Initialized
Definition: itkShortestPathImageFilter.h:188
itk::ShortestPathImageFilter::m_VectorOrder
std::vector< NodeNumType > m_VectorOrder
Definition: itkShortestPathImageFilter.h:195
itk::ShortestPathImageFilter::CostFunctionTypePointer
CostFunctionType::Pointer CostFunctionTypePointer
Definition: itkShortestPathImageFilter.h:63
itk::ShortestPathImageFilter::getEstimatedCostsToTarget
double getEstimatedCostsToTarget(const IndexType &a)
itk::ShortestPathImageFilter::m_StoreVectorOrder
bool m_StoreVectorOrder
Definition: itkShortestPathImageFilter.h:180
itk::ShortestPathImageFilter::OutputImagePointer
TOutputImageType::Pointer OutputImagePointer
Definition: itkShortestPathImageFilter.h:74
itk::ShortestPathImageFilter::m_ActivateTimeOut
bool m_ActivateTimeOut
Definition: itkShortestPathImageFilter.h:186
itk::ShortestPathImageFilter::m_Nodes
ShortestPathNode * m_Nodes
Definition: itkShortestPathImageFilter.h:166
itk::ShortestPathImageFilter::GetDistanceImage
OutputImagePointer GetDistanceImage()
itk::ShortestPathNode
Definition: itkShortestPathNode.h:23
itk::ShortestPathImageFilter::GenerateData
void GenerateData() override
itk::ShortestPathImageFilter::MakeOutputs
void MakeOutputs()
itk::ShortestPathImageFilter::m_Graph_StartNode
NodeNumType m_Graph_StartNode
Definition: itkShortestPathImageFilter.h:168
itk::SmartPointer< Self >
itkShortestPathCostFunction.h
itk::ShortestPathImageFilter::m_CostFunction
CostFunctionTypePointer m_CostFunction
Definition: itkShortestPathImageFilter.h:190
itk::ShortestPathImageFilter::GetMultipleVectorPaths
std::vector< std::vector< IndexType > > GetMultipleVectorPaths()
itk::ShortestPathImageFilter::CleanUp
void CleanUp()
itk::ShortestPathImageFilter::m_MakeOutputImage
bool m_MakeOutputImage
Definition: itkShortestPathImageFilter.h:179
itk::ShortestPathImageFilter::m_StartIndex
IndexType m_StartIndex
Definition: itkShortestPathImageFilter.h:191
itk::ShortestPathImageFilter::OutputImageIteratorType
ImageRegionIteratorWithIndex< OutputImageType > OutputImageIteratorType
Definition: itkShortestPathImageFilter.h:77
itk::ShortestPathImageFilter::InputImageIteratorType
itk::ImageRegionIteratorWithIndex< InputImageType > InputImageIteratorType
Definition: itkShortestPathImageFilter.h:71
itk::ShortestPathImageFilter::Pointer
SmartPointer< Self > Pointer
Definition: itkShortestPathImageFilter.h:58
itk::ShortestPathImageFilter::GetUseCostFunction
bool GetUseCostFunction()
Definition: itkShortestPathImageFilter.h:159
itkShortestPathNode.h
itk::ShortestPathImageFilter::ShortestPathImageFilter
ShortestPathImageFilter()
itk::ShortestPathImageFilter::CostFunctionType
ShortestPathCostFunction< TInputImageType > CostFunctionType
Definition: itkShortestPathImageFilter.h:62
itk::ShortestPathImageFilter::m_endPoints
std::vector< IndexType > m_endPoints
Definition: itkShortestPathImageFilter.h:159
itk::ShortestPathImageFilter::multipleEndPoints
bool multipleEndPoints
Definition: itkShortestPathImageFilter.h:184
itk::ShortestPathImageFilter::m_Graph_EndNode
NodeNumType m_Graph_EndNode
Definition: itkShortestPathImageFilter.h:169
itk::ShortestPathImageFilter::IndexType
TInputImageType::IndexType IndexType
Definition: itkShortestPathImageFilter.h:70
itk::ShortestPathImageFilter::InitGraph
void InitGraph()
itk::ShortestPathImageFilter::m_Graph_NumberOfNodes
NodeNumType m_Graph_NumberOfNodes
Definition: itkShortestPathImageFilter.h:167
itk::ShortestPathImageFilter::StartShortestPathSearch
void StartShortestPathSearch()
itk::ShortestPathImageFilter::FOREGROUND
const static int FOREGROUND
Definition: itkShortestPathImageFilter.h:176
itk::ShortestPathImageFilter::~ShortestPathImageFilter
~ShortestPathImageFilter() override
itk::ShortestPathImageFilter::m_magnitudeImage
InputImageType::Pointer m_magnitudeImage
Definition: itkShortestPathImageFilter.h:210
itk::ShortestPathImageFilter::CompareNodeStar::operator()
bool operator()(ShortestPathNode *a, ShortestPathNode *b)
Definition: itkShortestPathImageFilter.h:93
itk::ShortestPathImageFilter::m_FullNeighborsMode
bool m_FullNeighborsMode
Definition: itkShortestPathImageFilter.h:177
itk::ShortestPathImageFilter::SetUseCostFunction
void SetUseCostFunction(bool doUseCostFunction)
Definition: itkShortestPathImageFilter.h:158
itk::ShortestPathImageFilter::m_EndIndex
IndexType m_EndIndex
Definition: itkShortestPathImageFilter.h:191
itk::ShortestPathImageFilter::InputImageType
TInputImageType InputImageType
Definition: itkShortestPathImageFilter.h:66
itk::ShortestPathImageFilter::InputImageSizeType
TInputImageType::SizeType InputImageSizeType
Definition: itkShortestPathImageFilter.h:69
itk::ShortestPathImageFilter::itkShapedNeighborhoodIteratorType
itk::ShapedNeighborhoodIterator< TInputImageType > itkShapedNeighborhoodIteratorType
Definition: itkShortestPathImageFilter.h:78
itk::ShortestPathImageFilter::m_CalcAllDistances
bool m_CalcAllDistances
Definition: itkShortestPathImageFilter.h:181
itk::ShortestPathImageFilter::CoordToNode
unsigned int CoordToNode(IndexType)
itk::ShortestPathImageFilter::OutputImagePixelType
TOutputImageType::PixelType OutputImagePixelType
Definition: itkShortestPathImageFilter.h:75
itk
SET FUNCTIONS.
Definition: itkIntelligentBinaryClosingFilter.h:30
itk::ShortestPathImageFilter::OutputImageType
TOutputImageType OutputImageType
Definition: itkShortestPathImageFilter.h:73
itk::ShortestPathImageFilter::ConstPointer
SmartPointer< const Self > ConstPointer
Definition: itkShortestPathImageFilter.h:59
itk::ShortestPathImageFilter::m_VectorPath
std::vector< IndexType > m_VectorPath
Definition: itkShortestPathImageFilter.h:192
itk::ShortestPathImageFilter::GetVectorPath
std::vector< IndexType > GetVectorPath()
itk::ShortestPathImageFilter::NodeToCoord
TInputImageType::IndexType NodeToCoord(NodeNumType)
itk::ShortestPathImageFilter::BACKGROUND
const static int BACKGROUND
Definition: itkShortestPathImageFilter.h:175
itk::ShortestPathImageFilter::SetEndIndex
void SetEndIndex(const IndexType &EndIndex)
itk::ShortestPathImageFilter::AddEndIndex
void AddEndIndex(const IndexType &index)
itk::ShortestPathImageFilter::m_endPointsClosed
std::vector< IndexType > m_endPointsClosed
Definition: itkShortestPathImageFilter.h:164
itk::ShortestPathImageFilter::Superclass
ImageToImageFilter< TInputImageType, TOutputImageType > Superclass
Definition: itkShortestPathImageFilter.h:57
itk::ShortestPathImageFilter::PrintSelf
void PrintSelf(std::ostream &os, Indent indent) const override
itk::ShortestPathImageFilter::m_Graph_fullNeighbors
bool m_Graph_fullNeighbors
Definition: itkShortestPathImageFilter.h:170
itk::ShortestPathNode::distAndEst
DistanceType distAndEst
Definition: itkShortestPathNode.h:27
itk::ShortestPathImageFilter::m_Graph_DiscoveredNodeList
std::vector< ShortestPathNode * > m_Graph_DiscoveredNodeList
Definition: itkShortestPathImageFilter.h:172
itk::ShortestPathImageFilter::GetNeighbors
std::vector< ShortestPathNode * > GetNeighbors(NodeNumType nodeNum, bool FullNeighbors)
itk::ShortestPathImageFilter::MakeShortestPathVector
void MakeShortestPathVector()
itk::ShortestPathImageFilter::Self
ShortestPathImageFilter Self
Definition: itkShortestPathImageFilter.h:56
itk::ShortestPathImageFilter::SetStartIndex
void SetStartIndex(const IndexType &StartIndex)
itk::ShortestPathCostFunction
Definition: itkShortestPathCostFunction.h:23
itk::NodeNumType
unsigned int NodeNumType
Definition: itkShortestPathNode.h:21
itk::ShortestPathImageFilter::m_useCostFunction
bool m_useCostFunction
Definition: itkShortestPathImageFilter.h:171
itk::ShortestPathImageFilter
Definition: itkShortestPathImageFilter.h:52
itk::ShortestPathImageFilter::InputImagePixelType
TInputImageType::PixelType InputImagePixelType
Definition: itkShortestPathImageFilter.h:68
itk::ShortestPathImageFilter::m_MultipleVectorPaths
std::vector< std::vector< IndexType > > m_MultipleVectorPaths
Definition: itkShortestPathImageFilter.h:193
itk::ShortestPathImageFilter::OutputImageIndexType
TOutputImageType::IndexType OutputImageIndexType
Definition: itkShortestPathImageFilter.h:76
itk::ShortestPathImageFilter::operator=
void operator=(const Self &)
itk::ShortestPathImageFilter::CoordIsInBounds
bool CoordIsInBounds(IndexType)