2016-08-17 21 views
0

我是CGAL的新手。CGAL-4.8.1安排 - 貝塞爾曲線保存安排到文件錯誤

我試圖修改實例/ Arrangement_on_surfaces_2 Bezier_curves.cpp保存安排文件,如下所示:

//! \file examples/Arrangement_on_surface_2/Bezier_curves.cpp 
// Constructing an arrangement of Bezier curves. 

#include <fstream> 

#include <CGAL/basic.h> 

#ifndef CGAL_USE_CORE 
#include <iostream> 
int main() 
{ 
    std::cout << "Sorry, this example needs CORE ..." << std::endl; 
    return 0; 
} 
#else 

#include <CGAL/Cartesian.h> 
#include <CGAL/CORE_algebraic_number_traits.h> 
#include <CGAL/Arr_Bezier_curve_traits_2.h> 
#include <CGAL/Arrangement_2.h> 
#include <CGAL/IO/Arr_iostream.h> 

#include "arr_inexact_construction_segments.h" 
#include "arr_print.h" 

typedef CGAL::CORE_algebraic_number_traits    Nt_traits; 
typedef Nt_traits::Rational        NT; 
typedef Nt_traits::Rational        Rational; 
typedef Nt_traits::Algebraic       Algebraic; 
typedef CGAL::Cartesian<Rational>      Rat_kernel; 
typedef CGAL::Cartesian<Algebraic>      Alg_kernel; 
typedef Rat_kernel::Point_2        Rat_point_2; 
typedef CGAL::Arr_Bezier_curve_traits_2<Rat_kernel, Alg_kernel, Nt_traits> 
                 Traits_2; 
typedef Traits_2::Curve_2        Bezier_curve_2; 
typedef CGAL::Arrangement_2<Traits_2>     Arrangement_2; 
//typedef CGAL::Arrangement_2<Traits_2>     Arrangement; 

int main (int argc, char *argv[]) 
{ 
    // Get the name of the input file from the command line, or use the default 
    // Bezier.dat file if no command-line parameters are given. 
    const char *filename = (argc > 1) ? argv[1] : "Bezier.dat"; 
    const char *outfilename = (argc > 1) ? argv[1] : "BezierOut.dat"; 

    // Open the input file. 
    std::ifstream in_file (filename); 

    if (! in_file.is_open()) { 
    std::cerr << "Failed to open " << filename << std::endl; 
    return 1; 
    } 

    // Read the curves from the input file. 
    unsigned int    n_curves; 
    std::list<Bezier_curve_2> curves; 
    Bezier_curve_2    B; 
    unsigned int    k; 

    in_file >> n_curves; 
    for (k = 0; k < n_curves; k++) { 
    // Read the current curve (specified by its control points). 
    in_file >> B; 
    curves.push_back (B); 

    std::cout << "B = {" << B << "}" << std::endl; 
    } 
    in_file.close(); 

    // Construct the arrangement. 

    Arrangement_2     arr; 
    insert (arr, curves.begin(), curves.end()); 

    // Print the arrangement size. 
    std::ofstream out_file; 
    out_file.open(outfilename); 
    out_file << "The arrangement size:" << std::endl 
      << " V = " << arr.number_of_vertices() 
      << ", E = " << arr.number_of_edges() 
      << ", F = " << arr.number_of_faces() << std::endl; 

    out_file << arr; 
    out_file.close(); 

    return 0; 
} 

#endif 

如果我註釋掉線out_file < < ARR;它工作正常。否則它會在read_x_monotone_curve中產生C2678錯誤Arr_text_formtter.h

我正在使用Visual Studio 15 x86。

謝謝你的幫助。

回答

0

我通過在arr_print.h中將print_arrangement(arr)例程修改爲使用std :: ofstream替代std :: cout來保存_arrangement(arr)來解決此問題。

看起來< <運算符不起作用。

如果別人有更好的解決方案,我願意接受。

0

貝塞爾曲線排列中的交點不能用精確的方式表示。因此,使用默認導出(< <)運算符和標準格式不能保存此類安排。

最簡單的解決方案是存儲曲線,但這意味着每次讀取曲線時必須重新計算排列。也許可以設計其他解決方案,但它們沒有實現。