2016-08-17 22 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

贝塞尔曲线排列中的交点不能用精确的方式表示。因此,使用默认导出(< <)运算符和标准格式不能保存此类安排。

最简单的解决方案是存储曲线,但这意味着每次读取曲线时必须重新计算排列。也许可以设计其他解决方案,但它们没有实现。