2014-10-07 49 views
1

我一直在撞牆,試圖瞭解如何使用CGAL的圓內核來計算線段(Line_Arc_2)和線段一個圓圈(Circle_2)。不幸的是,循環內核的示例代碼沒有太多,我沒有找到參考手冊很多幫助。如何用CGAL計算線段和圓的交點

這裏是我想會的工作代碼,但現在它不會(使用最新的系統編譯器的Mac OS 10.9),甚至編譯:

#include <vector> 
#include <iterator> 
#include <CGAL/Exact_circular_kernel_2.h> 
#include <CGAL/Circular_kernel_intersections.h> 
#include <CGAL/intersections.h> 
#include <CGAL/result_of.h> 
#include <CGAL/iterator.h> 
#include <CGAL/point_generators_2.h> 
#include <boost/bind.hpp> 

typedef CGAL::Exact_circular_kernel_2  CircK; 
typedef CGAL::Point_2<CircK>     Pt2; 
typedef CGAL::Circle_2<CircK>    Circ2; 
typedef CGAL::Line_arc_2<CircK>    LineArc2; 
typedef CGAL::cpp11::result_of<CircK::Intersect_2(Circ2,LineArc2)>::type Res; 

int main(){ 
    int n = 0; 
    Circ2 c  = Circ2(Pt2(1,0), Pt2(0,1), Pt2(-1, 0)); 
    LineArc2 l = LineArc2(Pt2(0,-2), Pt2(0,2)); 

    std::vector<Res> result; 
    CGAL::intersection(c, l, std::back_inserter(result)); 

    return 0; 
} 

我上的result_of行的錯誤:「錯誤:在...中沒有類型命名爲「result_type」,並且第二個錯誤是「不存在可重載」='「可用於相交線。

另外,因爲這可能是後續問題,一旦這是工作:我怎麼實際上得到在交叉點放入向量? CGAL的文檔建議我「結果」應該包含一對Circular_arc_point_2和一個表示其多重性的無符號整數。這是我在這種情況下實際得到的嗎?更一般地說,有沒有人知道使用循環內核和球形內核交叉例程的好教程?

謝謝!

回答

0

因此,似乎result_of在這裏不起作用,儘管在CGAL參考手冊中提到了CircularKernel的交集函數。

這是一個不同的版本,似乎工作,並能妥善處理輸出:

#include <vector> 
#include <iterator> 
#include <CGAL/Exact_circular_kernel_2.h> 
#include <CGAL/Circular_kernel_intersections.h> 
#include <CGAL/intersections.h> 
#include <CGAL/iterator.h> 

typedef CGAL::Exact_circular_kernel_2  CircK; 
typedef CGAL::Point_2<CircK>     Pt2; 
typedef CGAL::Circle_2<CircK>    Circ2; 
typedef CGAL::Line_arc_2<CircK>    LineArc2; 
typedef std::pair<CGAL::Circular_arc_point_2<CircK>, unsigned> IsectOutput; 

using namespace std; 

int main(){ 
    int n = 0; 
    Circ2 c  = Circ2(Pt2(1.0,0.0), Pt2(0.0,1.0), Pt2(-1.0, 0.0)); 
    LineArc2 l = LineArc2(Pt2(0.0,-2.0), Pt2(0.0,2.0)); 

    std::vector<IsectOutput> output; 

    typedef CGAL::Dispatch_output_iterator< CGAL::cpp11::tuple<IsectOutput>, 
         CGAL::cpp0x::tuple< std::back_insert_iterator<std::vector<IsectOutput> > > > Dispatcher; 
    Dispatcher disp = CGAL::dispatch_output<IsectOutput>(std::back_inserter(output)); 

    CGAL::intersection(l, c, disp); 

    cout << output.size() << endl; 
    for(const auto& v : output){ 
    cout << "Point: (" << CGAL::to_double(v.first.x()) << ", " << CGAL::to_double(v.first.y()) << "), Mult: " 
    << v.second << std::endl; 
    } 


    return 0; 
} 
0

result_of是工作,但你所要求的不存在運營商,你缺少的輸出迭代器。 但是,我同意該文件具有誤導性。我會盡力修復它。

下面的代碼工作正常:

#include <vector> 
#include <iterator> 
#include <CGAL/Exact_circular_kernel_2.h> 
#include <CGAL/Circular_kernel_intersections.h> 
#include <CGAL/intersections.h> 
#include <CGAL/result_of.h> 
#include <CGAL/iterator.h> 
#include <CGAL/point_generators_2.h> 
#include <boost/bind.hpp> 

typedef CGAL::Exact_circular_kernel_2  CircK; 
typedef CGAL::Point_2<CircK>     Pt2; 
typedef CGAL::Circle_2<CircK>    Circ2; 
typedef CGAL::Line_arc_2<CircK>    LineArc2; 
typedef boost::variant<std::pair<CGAL::Circular_arc_point_2<CircK>, unsigned> > InterRes; 
typedef CGAL::cpp11::result_of<CircK::Intersect_2(Circ2,LineArc2,std::back_insert_iterator<std::vector<InterRes> >)>::type Res; 

int main(){ 
    Circ2 c  = Circ2(Pt2(1,0), Pt2(0,1), Pt2(-1, 0)); 
    LineArc2 l = LineArc2(Pt2(0,-2), Pt2(0,2)); 

    std::vector<InterRes> result; 
    CGAL::intersection(c, l, std::back_inserter(result)); 

    return 0; 
} 
+0

好,感謝澄清。更新文檔將是最有幫助的! – Sam 2014-10-09 03:38:45