本文整理汇总了C++中Triangulation::edges_begin方法的典型用法代码示例。如果您正苦于以下问题:C++ Triangulation::edges_begin方法的具体用法?C++ Triangulation::edges_begin怎么用?C++ Triangulation::edges_begin使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Triangulation
的用法示例。
在下文中一共展示了Triangulation::edges_begin方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: triangulate
void triangulate( Rand &prng, Graph &graph )
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Edge_iterator Edge_iterator;
typedef Triangulation::Vertex_handle Vertex_handle;
typedef Triangulation::Point Point;
typedef std::map<Vertex_handle, int> VertexIndexMap;
const static int minEdgeWeight = 1;
const static int maxEdgeWeight = 20;
// create the delaunay triangulation
Triangulation triangulation;
VertexIndexMap vertexIndexMap;
// dump all of the BGL vertices into CGAL
Graph::vertices_size_type numVertices = boost::num_vertices( graph );
for ( int idx = 0; idx < numVertices; ++idx )
{
const VertexInfo &vertexInfo = boost::get( VertexInfoTag(), graph, idx );
Point position( vertexInfo.position.x, vertexInfo.position.y );
Vertex_handle handle = triangulation.insert( position );
vertexIndexMap[ handle ] = idx;
}
// edge weight property map
auto edgeWeightMap = boost::get( boost::edge_capacity, graph );
// read out the edges and add them to BGL
EdgeReverseMap edgeReverseMap = boost::get( boost::edge_reverse, graph );
Edge_iterator ei_end = triangulation.edges_end();
for (Edge_iterator ei = triangulation.edges_begin();
ei != ei_end; ++ei)
{
int idxSourceInFace = ( ei->second + 2 ) % 3;
int idxTargetInFace = ( ei->second + 1 ) % 3;
Vertex_handle sourceVertex = ei->first->vertex( idxSourceInFace );
Vertex_handle targetVertex = ei->first->vertex( idxTargetInFace );
int idxSource = vertexIndexMap[ sourceVertex ];
int idxTarget = vertexIndexMap[ targetVertex ];
EdgeHandle forwardEdge = boost::add_edge( idxSource, idxTarget, graph );
EdgeHandle backwardEdge = boost::add_edge( idxTarget, idxSource, graph );
edgeReverseMap[ forwardEdge.first ] = backwardEdge.first;
edgeReverseMap[ backwardEdge.first ] = forwardEdge.first;
int edgeWeight = prng.nextInt( 1, 20 );
edgeWeightMap[ forwardEdge.first ] = edgeWeight;
edgeWeightMap[ backwardEdge.first ] = edgeWeight;
}
}
示例2: main
int main( )
{
std::ifstream in("data/voronoi.cin");
std::istream_iterator<Point> begin(in);
std::istream_iterator<Point> end;
Triangulation T;
T.insert(begin, end);
int ns = 0;
int nr = 0;
Edge_iterator eit =T.edges_begin();
for ( ; eit !=T.edges_end(); ++eit) {
CGAL::Object o = T.dual(eit);
if (CGAL::object_cast<K::Segment_2>(&o)) {++ns;}
else if (CGAL::object_cast<K::Ray_2>(&o)) {++nr;}
}
std::cout << "The Voronoi diagram has " << ns << " finite edges "
<< " and " << nr << " rays" << std::endl;
return 0;
}