MEPP2 Project
utils_retrieve_edge.h
Go to the documentation of this file.
1 // Copyright (c) 2012-2019 University of Lyon and CNRS (France).
2 // All rights reserved.
3 //
4 // This file is part of MEPP2; you can redistribute it and/or modify
5 // it under the terms of the GNU Lesser General Public License as
6 // published by the Free Software Foundation; either version 3 of
7 // the License, or (at your option) any later version.
8 //
9 // This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
10 // WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11 #pragma once
12 
13 #include <boost/fusion/iterator/next.hpp>
14 #include <boost/fusion/include/next.hpp>
15 #include <boost/next_prior.hpp> // for boost::next(T x, Distance n)
16 #include <boost/graph/graph_traits.hpp>
17 
18 /*
19  * \brief Utility functions that retrieves the edge out
20  * of its source and destination indexes.
21  * \tparam MutableFaceGraph Any mesh type having a boost::graph_traits
22  * specialisation.
23  * \param g The graph which which to search for.
24  * \param sourceIndex The index of the source vertex.
25  * \param targetIndex The index of the target vertex.
26  * \return When found, the edge going from source to target.
27  */
28 template< typename MutableFaceGraph >
29 typename boost::graph_traits< MutableFaceGraph >::edge_descriptor
30 retrieve_edge(MutableFaceGraph &g, int source_index, int target_index)
31 {
32  typedef boost::graph_traits< MutableFaceGraph > GraphTraits;
33  typedef typename GraphTraits::vertex_iterator vertex_iterator;
35  typedef typename GraphTraits::edge_descriptor edge_descriptor;
36 
37  vertex_iterator v =
38  vertices(g).first; // g.vertices_begin() cannot be used here, because it
39  // is not defined in any concept
40 
41  vertex_descriptor src = *boost::next(v, source_index);
42  vertex_descriptor dst = *boost::next(v, target_index);
43 
44  edge_descriptor result;
45  bool found = false;
46  boost::tie(result, found) = edge(src, dst, g);
47  if(!found)
48  {
49  return GraphTraits::null_edge();
50  }
51 
52  return result;
53 }
54 
55 /*
56  * \brief Utility functions that retrieves the edge out
57  * of its index.
58  * \tparam MutableFaceGraph Any mesh type having a boost::graph_traits
59  * specialisation.
60  * \param g The graph which which to search for.
61  * \param edge_index The index of the edge.
62  * \return When found, the edge with index edge_index.
63  */
64 template<typename MutableFaceGraph>
65 typename boost::graph_traits<MutableFaceGraph>::edge_descriptor
66 retrieve_edge(MutableFaceGraph& g,
67  int edge_index)
68 {
69  typedef boost::graph_traits<MutableFaceGraph> GraphTraits;
70  typedef typename GraphTraits::edge_iterator edge_iterator;
71  typedef typename GraphTraits::edge_descriptor edge_descriptor;
72 
73  edge_iterator e = edges(g).first;
74 
75  edge_descriptor result = *boost::next(e, edge_index);
76 
77  return result;
78 }
FEVV::DataStructures::AIF::vertices
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::vertex_iterator > vertices(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the vertices of the mesh.
Definition: Graph_traits_aif.h:172
FEVV::DataStructures::AIF::next
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor next(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the next halfedge around its face.
Definition: Graph_traits_aif.h:599
FEVV::DataStructures::AIF::edges
std::pair< typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator, typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_iterator > edges(const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the iterator range of the edges of the mesh.
Definition: Graph_traits_aif.h:238
retrieve_edge
boost::graph_traits< MutableFaceGraph >::edge_descriptor retrieve_edge(MutableFaceGraph &g, int source_index, int target_index)
Definition: utils_retrieve_edge.h:30
FEVV::DataStructures::AIF::edge
boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::edge_descriptor edge(typename boost::graph_traits< FEVV::DataStructures::AIF::AIFMesh >::halfedge_descriptor h, const FEVV::DataStructures::AIF::AIFMesh &sm)
Returns the edge corresponding to h and opposite(h).
Definition: Graph_traits_aif.h:345
msdm2::vertex_descriptor
boost::graph_traits< MeshT >::vertex_descriptor vertex_descriptor
Definition: msdm2_surfacemesh.h:33