我想为CGAL安排中的每个面生成一个多边形(原因:请参阅我的related问题)
作为输入,我添加了多次调用的折线曲线:
std::list<Point_2> points;
(.. add points ..)
Polyline_2 pi1 (points.begin(), points.end());
insert (arr, pi1);
然而,当我输出面部时:
std::ofstream ofs ("cgal_output.txt", std::ofstream::out);
template<class Arrangement>
void print_ccb (typename Arrangement::Ccb_halfedge_const_circulator circ)
{
typename Arrangement::Ccb_halfedge_const_circulator curr = circ;
do
{
typename Arrangement::Halfedge_const_handle he = curr;
ofs << he->curve() << std::endl;
} while (++curr != circ);
ofs << "#" << std::endl; // end of face mark
return;
}
曲线的点不会以某种方式遍历,可以用坐标绘制一致的缠绕多边形轮廓。
我该如何解决这个问题?
答案 0 :(得分:0)
我认为在Arrangement_2
演示中有代码可以执行您想要的操作。从单个面创建多边形的方法位于demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h:311
(注意,正在使用一些Qt对象,可以用std::vector
和CGAL::Point_2
替换):
QVector< QPointF > pts; // holds the points of the polygon
typename X_monotone_curve_2::const_iterator pt_itr;
typename X_monotone_curve_2::const_reverse_iterator pt_rev_itr;
X_monotone_curve_2 cv;
/* running with around the outer of the face and generate from it
* polygon
*/
Ccb_halfedge_circulator cc = f->outer_ccb();
do {
cv = cc->curve();
bool curve_has_same_direction =
( *(cc->curve().begin()) == cc->source()->point() );
if ( curve_has_same_direction )
{
for( pt_itr = cv.begin() , ++pt_itr ; pt_itr != cv.end(); ++pt_itr)
{
double x = CGAL::to_double((*pt_itr).x());
double y = CGAL::to_double((*pt_itr).y());
QPointF coord_source(x , y);
pts.push_back(coord_source );
}
}
else
{
for (pt_rev_itr = cv.rbegin() , ++pt_rev_itr; pt_rev_itr != cv.rend();
++pt_rev_itr)
{
double x = CGAL::to_double((*pt_rev_itr).x());
double y = CGAL::to_double((*pt_rev_itr).y());
QPointF coord_source(x , y);
pts.push_back(coord_source );
}
}
//created from the outer boundary of the face
} while (++cc != f->outer_ccb());
// make polygon from the outer ccb of the face 'f'
QPolygonF pgn( pts );
基本上,您需要做的额外工作是检查折线中的线段是否反转,然后相应地反转点。