2013-12-23 123 views
2

我想生成在CGAL安排每個面多邊形(原因:看我related問題)CGAL設置面多邊形

作爲輸入,我增加折線曲線與多個呼叫:

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; 
} 

的曲線的點在某種程度上也不會運行,一個consistantly嗦多邊形輪廓可以用座標繪製秒。

我該如何解決這個問題?

回答

1

我認爲在Arrangement_2演示中有代碼可以做你想做的事情。創建從一個人的臉多邊形的方法位於demo/Arrangement_on_surface_2/ArrangementGraphicsItem.h:311(只注意有正在使用的一些Qt的對象,你可以用std::vectorCGAL::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); 

基本上,額外的工作,你需要做的是檢查多段線中的線段是否相反,然後相應地反轉點。