2013-10-02 3 views
0

부스트에 폴리곤이 있습니다. 폴리곤의 세그먼트를 추출하고 세그먼트를 만드는 데 사용 된 점을 저장하려고합니다. Boost 라이브러리를 C++로 사용하고 있습니다.부스트 라이브러리에서 references_segment의 포인트를 추출하는 방법

어떻게하면됩니까?

나는 해결책을 발견
typedef boost::tuple<double, double> point; 
typedef boost::geometry::model::polygon<point> polygon; 
typedef boost::geometry::model::referring_segment<point> segment; 

template<typename Segment> 
void get_segments(Segment const& s) { 

    std::cout << "Segment is "<<dsv(s) << std::endl; 
    std::cout << "Points of this segments are :"; 
     //Extract the points of this segment somehow 


} 


int main() { 

    polygon poly; 
    boost::geometry::read_wkt(
      "polygon((2.0 1.3, 2.4 1.7, 2.8 1.8, 3.4 1.2, 3.7 1.6, 3.4 2.0, 4.1 3.0, 5.3 2.6, 5.4 1.2, 4.9 0.8, 2.9 0.7, 2.0 1.3))", 
      poly); 

    polygon hull; 
    boost::geometry::convex_hull(poly, hull); 

    // Now I know I can `dsv()` and print to the screen like this: 

    std::cout << "hull: " << dsv(hull) << std::endl; 

    boost::geometry::for_each_segment(boost::geometry::exterior_ring(hull), 
      get_segments<segment>); 


    return 0; 
} 

답변

1

, 나는 (세그먼트)

template<typename Segment> 
void get_segments(Segment const& s) { 

    std::cout << "Segment is "<<dsv(s) << std::endl; 
    std::cout << "1st Point"<<get<0,0>(s)<<","<<get<0,1>(s)<<std::endl; 
    std::cout << "2nd Point"<<get<1,0>(s)<<","<<get<1,1>(s)<<std::endl; 
GET을 사용