20 std::pair<VertexDescriptorType, VertexDescriptorType>(boost::graph_traits<GraphType>::null_vertex(),
21 boost::graph_traits<GraphType>::null_vertex());
38 std::vector<TubeDescriptorType> shortestPath;
72 typedef std::map<VertexDescriptorType, EdgeDescriptorType> EdgeMap;
73 typedef boost::associative_property_map<EdgeMap> PredecessorMap;
74 typedef boost::edge_predecessor_recorder<PredecessorMap, boost::on_tree_edge> PredecessorVisitor;
75 typedef boost::dfs_visitor<std::pair<PredecessorVisitor, boost::null_visitor>> DFSVisitor;
78 PredecessorMap predecessorMap(edgesMap);
80 PredecessorVisitor predecessorVisitor(predecessorMap);
81 boost::null_visitor nullVisitor;
82 DFSVisitor visitor = boost::make_dfs_visitor(std::make_pair(predecessorVisitor, nullVisitor));
84 std::map<VertexDescriptorType, boost::default_color_type> vertexColorMap;
85 std::map<EdgeDescriptorType, boost::default_color_type> edgeColorMap;
87 boost::undirected_dfs(
88 m_Graph, visitor, make_assoc_property_map(vertexColorMap), make_assoc_property_map(edgeColorMap), startTube.second);
90 std::vector<TubeDescriptorType> solutionPath;
91 solutionPath.push_back(endTube);
95 MITK_INFO <<
"Source: [" << startTube.first <<
"," << startTube.second <<
"] Target: [" << endTube.first <<
","
96 << endTube.second <<
"]";
97 MITK_INFO <<
"tube [" << endTube.first <<
"," << endTube.second <<
"]";
100 if (pathEdgeSource == 10393696)
103 pathEdgeSource = boost::source(edge, m_Graph);
104 pathEdgeTarget = boost::target(edge, m_Graph);
106 MITK_INFO <<
"tube [" << tube.first <<
"," << tube.second <<
"]";
107 solutionPath.push_back(tube);
108 }
while (pathEdgeSource != startTube.second);
116 std::vector<mitk::TubeGraph::TubeDescriptorType> pathToPeriphery;
118 if (m_RootTube == ErrorId)
120 m_RootTube = this->GetThickestTube();
121 if (m_Root == m_RootTube.first)
122 m_Root = m_RootTube.second;
124 m_Root = m_RootTube.first;
132 pathToPeriphery.push_back(startTube);
133 this->GetOutEdgesOfAVertex(startTube.second, directedGraph, pathToPeriphery);
135 return pathToPeriphery;
140 std::vector<mitk::TubeGraph::TubeDescriptorType> &pathToPeriphery)
142 typedef boost::graph_traits<DirectedGraphType>::out_edge_iterator OutEdgeIteratorType;
143 std::pair<OutEdgeIteratorType, OutEdgeIteratorType> outEdges = boost::out_edges(vertex, directedGraph);
144 for (; outEdges.first != outEdges.second; ++outEdges.first)
146 TubeDescriptorType tube;
147 tube.first = boost::source(*outEdges.first, directedGraph);
148 tube.second = boost::target(*outEdges.first, directedGraph);
150 if (std::find(pathToPeriphery.begin(), pathToPeriphery.end(), tube) == pathToPeriphery.end())
152 pathToPeriphery.push_back(tube);
153 this->GetOutEdgesOfAVertex(tube.second, directedGraph, pathToPeriphery);
161 float tubeDiameter = 0.0;
165 boost::tie(iterator, end) = boost::edges(m_Graph);
167 for (; iterator != end; ++iterator)
171 std::pair<TubeGraphVertex, TubeGraphVertex> soureTargetPair = this->GetVerticesOfAnEdge(*iterator);
174 if (tempDiameter > tubeDiameter)
176 tubeDiameter = tempDiameter;
177 thickestTube.first = this->GetVertexDescriptor(soureTargetPair.first);
178 thickestTube.second = this->GetVertexDescriptor(soureTargetPair.second);
188 boost::breadth_first_search(m_Graph, startVertex, visitor(vis));
189 return directedGraph;
196 std::map<VertexDescriptorType, VertexDescriptorType> vertexDescriptorOldToNewMap;
199 for (
auto it = subGraphTubes.begin(); it != subGraphTubes.end(); it++)
202 if (vertexDescriptorOldToNewMap.find(it->first) == vertexDescriptorOldToNewMap.end())
207 vertexDescriptorOldToNewMap.insert(
208 std::pair<VertexDescriptorType, VertexDescriptorType>(it->first, newVertexDescriptor));
211 if (vertexDescriptorOldToNewMap.find(it->second) == vertexDescriptorOldToNewMap.end())
214 vertexDescriptorOldToNewMap.insert(
215 std::pair<VertexDescriptorType, VertexDescriptorType>(it->second, newVertexDescriptor));
218 EdgeDescriptorType edgeDescriptor = this->GetEdgeDescriptorByVerices(it->first, it->second);
230 EdgeDescriptorType newEdgeDescriptor = subGraph->AddEdge(sourceVertex, targetVertex, this->GetEdge(edgeDescriptor));
232 subGraph->CopyInformation(
this);
235 geometry->Initialize();
236 subGraph->SetGeometry(geometry);
245 for (
auto it = deletedTubes.begin(); it != deletedTubes.end(); it++)
251 this->RemoveEdge(edge);
253 if (this->GetAllEdgesOfAVertex(source).size() == 0)
255 this->RemoveVertex(source);
257 if (this->GetAllEdgesOfAVertex(target).size() == 0)
259 this->RemoveVertex(target);
270 if (m_Root == root.first)
271 m_Root = root.second;
boost::adjacency_list< boost::vecS, boost::vecS, boost::directedS > DirectedGraphType
static const TubeDescriptorType ErrorId
void RemoveSubGraph(std::vector< TubeDescriptorType > deletedTubes)
Base Class for Tube Graphs.
Base Class for Tube Graph Vertices.
void SetRoot(const VertexDescriptorType &root)
std::vector< TubeDescriptorType > SearchAllPathBetweenVertices(const TubeDescriptorType &startTube, const TubeDescriptorType &endTube)
float GetEdgeAverageDiameter(TubeGraphVertex &source, TubeGraphVertex &target)
std::vector< TubeDescriptorType > SearchPathToPeriphery(const TubeDescriptorType &startTube)
boost::graph_traits< GraphType >::edge_descriptor EdgeDescriptorType
std::pair< VertexDescriptorType, VertexDescriptorType > TubeDescriptorType
TubeGraph::Pointer CreateSubGraph(std::vector< TubeDescriptorType > subGraphTubes)
TubeDescriptorType GetThickestTube()
boost::graph_traits< GraphType >::edge_iterator EdgeIteratorType
TubeDescriptorType GetRootTube()
Base Class for Tube Graph Edges.
DirectedGraphType GetDirectedGraph(VertexDescriptorType startVertex)
Template class for undirected graphs.Paramters should be the vertex and edge classes, which contains the information.
boost::graph_traits< GraphType >::vertex_descriptor VertexDescriptorType
UndirectedGraph< VertexType, EdgeType > & operator=(const UndirectedGraph< VertexType, EdgeType > &rhs)
std::vector< TubeDescriptorType > SearchShortestPath(const TubeDescriptorType &startTube, const TubeDescriptorType &endTube)
void SetRootTube(const TubeDescriptorType &root)
VertexDescriptorType GetRootVertex()
TubeGraph & operator=(const TubeGraph &rhs)