CGAL 5.1 - CGAL and the Boost Graph Library
BGL_polyhedron_3/incident_vertices.cpp
#include <CGAL/Simple_cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/boost/graph/iterator.h>
#include <iostream>
#include <fstream>
typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
typedef boost::graph_traits<Polyhedron> GraphTraits;
typedef GraphTraits::vertex_descriptor vertex_descriptor;
typedef CGAL::Halfedge_around_target_iterator<Polyhedron> halfedge_around_target_iterator;
template <typename OutputIterator>
OutputIterator
adjacent_vertices_V1(const Polyhedron& g,
vertex_descriptor vd,
OutputIterator out)
{
typename GraphTraits::halfedge_descriptor hb = halfedge(vd,g), done(hb);
do {
*out++ = source(hb,g);
hb = opposite(next(hb,g),g);
} while(hb!= done);
return out;
}
template <typename OutputIterator>
OutputIterator
adjacent_vertices_V2(const Polyhedron& g,
vertex_descriptor vd,
OutputIterator out)
{
halfedge_around_target_iterator hi, he;
for(boost::tie(hi, he) = halfedges_around_target(halfedge(vd,g),g); hi != he; ++hi)
{
*out++ = source(*hi,g);
}
return out;
}
int main(int argc, char** argv)
{
std::ifstream in((argc>1)?argv[1]:"cube.off");
Polyhedron P;
in >> P;
GraphTraits::vertex_iterator vi = vertices(P).first;
std::list<vertex_descriptor> V;
adjacent_vertices_V1(P, *vi, std::back_inserter(V));
++vi;
adjacent_vertices_V2(P, *vi, std::back_inserter(V));
std::cerr << "done\n";
return 0;
}
VertexListGraph::vertices
std::pair< boost::graph_traits< VertexListGraph >::vertex_iterator, boost::graph_traits< VertexListGraph >::vertex_iterator > vertices(const VertexListGraph &g)
CGAL::Halfedge_around_target_iterator
Definition: iterator.h:287
EdgeListGraph::source
boost::graph_traits< EdgeListGraph >::vertex_descriptor source(boost::graph_traits< EdgeListGraph >::edge_descriptor e, const EdgeListGraph &g)
Kernel
FaceGraph::halfedge
boost::graph_traits< FaceGraph >::halfedge_descriptor halfedge(boost::graph_traits< FaceGraph >::face_descriptor f, const FaceGraph &g)
CGAL::Polyhedron_3
CGAL::halfedges_around_target
Iterator_range< Halfedge_around_target_iterator< Graph > > halfedges_around_target(typename boost::graph_traits< Graph >::halfedge_descriptor h, const Graph &g)
Definition: iterator.h:838
HalfedgeGraph::opposite
boost::graph_traits< HalfedgeGraph >::halfedge_descriptor opposite(boost::graph_traits< HalfedgeGraph >::halfedge_descriptor h, const HalfedgeGraph &g)
HalfedgeGraph::next
boost::graph_traits< HalfedgeGraph >::halfedge_descriptor next(boost::graph_traits< HalfedgeGraph >::halfedge_descriptor h, const HalfedgeGraph &g)
CGAL::Simple_cartesian