Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/154.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 对于在CGAL4.2中成功编译的代码,CGAL4.6中出现编译错误_C++_Cgal - Fatal编程技术网

C++ 对于在CGAL4.2中成功编译的代码,CGAL4.6中出现编译错误

C++ 对于在CGAL4.2中成功编译的代码,CGAL4.6中出现编译错误,c++,cgal,C++,Cgal,我有以下代码,已成功地用CGAL4.2编译和执行 cgal_交叉口.h typedef struct {double x; double y;} coordinate; int cgal(); extern "C" int find_intersections_of_curves( coordinate *curve_1, long curve_1_size, coordinate *curve_2, long curve_2_size, coordinate *in

我有以下代码,已成功地用CGAL4.2编译和执行

cgal_交叉口.h

typedef struct {double x; double y;} coordinate;

int cgal();

extern "C" int find_intersections_of_curves(
    coordinate *curve_1, long curve_1_size,
    coordinate *curve_2, long curve_2_size,
    coordinate *intersections, int max_num_of_intersections);
cgal_intersection.cpp

#include <CGAL/Cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
#include <CGAL/Sweep_line_2_algorithms.h>
#include <vector>
#include <list>

#include "cgal_intersection.h"

typedef CGAL::Cartesian<double>                    Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel>              Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits>     Traits;
typedef Traits::Point_2                                 Point;
typedef Traits::Curve_2                                 Polyline;

extern "C" int find_intersections_of_curves(
    coordinate *curve_1, long curve_1_size,
    coordinate *curve_2, long curve_2_size,
    coordinate *intersections, int max_num_of_intersections)
{

    std::vector<Point> points_1(curve_1_size);
    for (long i_1 = 0; i_1 < curve_1_size; i_1++)
        points_1[i_1] = Point(curve_1[i_1].x, curve_1[i_1].y);
    Polyline  polyline_1(points_1.begin(), points_1.end());

    std::vector<Point> points_2(curve_2_size);
    for (long i_2 = 0; i_2 < curve_2_size; i_2++)
        points_2[i_2] = Point(curve_2[i_2].x, curve_2[i_2].y);
    Polyline  polyline_2(points_2.begin(), points_2.end());

    Polyline polylines[] = {polyline_1, polyline_2};
    std::list<Point> intersection_points;
    CGAL::compute_intersection_points(polylines, polylines + 2,
                                      std::back_inserter(intersection_points));

    int num_of_intersections = intersection_points.size();
    Point intersection_point;
    for (int j = 0; j < num_of_intersections; j++){
        if (j == max_num_of_intersections)
            break;
        intersection_point = intersection_points.front();
        intersections[j].x = intersection_point.x();
        intersections[j].y = intersection_point.y();
        intersection_points.pop_front();
    }

    return num_of_intersections;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括“cgal_交叉点.h”
笛卡尔核;
typedef CGAL::Arr_段特征2段特征;
typedef CGAL::Arr_polyline_traits_2 traits;
typedef Traits::Point_2 Point;
typedef Traits::Curve_2折线;
外部“C”int查找曲线的交点(
坐标*曲线_1,长曲线_1_尺寸,
坐标*曲线2,长曲线2尺寸,
坐标*交点,整数最大交点数)
{
std::矢量点_1(曲线_1_大小);
用于(长i_1=0;i_1<曲线大小;i_1++)
点_1[i_1]=点(曲线_1[i_1].x,曲线_1[i_1].y);
多段线多段线_1(点_1.begin(),点_1.end());
std::矢量点_2(曲线_2_大小);
对于(长i_2=0;i_2<曲线大小;i_2++)
点_2[i_2]=点(曲线_2[i_2].x,曲线_2[i_2].y);
多段线多段线_2(点_2.begin(),点_2.end());
多段线多段线[]={Polyline_1,Polyline_2};
std::列出交叉点;
CGAL::计算交点(多段线,多段线+2,
标准:背向插入器(交叉点);
int num_of_crossions=交叉点。size();
点交点;
对于(int j=0;j
但是当使用CGAL4.6时,我会遇到如下编译错误:

Scanning dependencies of target cgal_intersection
[100%] Building CXX object CMakeFiles/cgal_intersection.dir/cgal_intersection.cpp.o
In file included from /home/chan/mose/mose/cgal_intersection/cgal_intersection.cpp:5:0:
/usr/include/CGAL/Sweep_line_2_algorithms.h: In instantiation of ‘OutputIterator CGAL::compute_intersection_points(CurveInputIterator, CurveInputIterator, OutputIterator, bool) [with CurveInputIterator = CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > >*; OutputIterator = std::back_insert_iterator<std::list<CGAL::Point_2<CGAL::Cartesian<double> > > >]’:
/home/chan/mose/mose/cgal_intersection/cgal_intersection.cpp:36:78:   required from here
/usr/include/CGAL/Sweep_line_2_algorithms.h:134:48: error: no type named ‘Traits’ in ‘struct CGAL::Default_arr_traits<CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > > >’
   typename Default_arr_traits<Curve>::Traits   traits;
                                                ^
/usr/include/CGAL/Sweep_line_2_algorithms.h:134:48: error: no type named ‘Traits’ in ‘struct CGAL::Default_arr_traits<CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > > >’
make[2]: *** [CMakeFiles/cgal_intersection.dir/cgal_intersection.cpp.o] Error 1
make[1]: *** [CMakeFiles/cgal_intersection.dir/all] Error 2
make: *** [all] Error 2
// Computing intersection points among curves using the sweep line.
#include <CGAL/Cartesian.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>
#include <CGAL/Sweep_line_2_algorithms.h>
#include <vector>
#include <list>

#include "cgal_intersection.h"

typedef CGAL::Cartesian<double>                         Kernel;
typedef CGAL::Arr_segment_traits_2<Kernel>              Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits>     Polyline_traits;
typedef Polyline_traits::Point_2                        Point;
typedef Polyline_traits::Curve_2                        Polyline;

extern "C" int find_intersections_of_curves(
    coordinate *curve_1, long curve_1_size,
    coordinate *curve_2, long curve_2_size,
    coordinate *intersections, int max_num_of_intersections)
{
    Polyline_traits polyline_traits;
    Polyline_traits::Construct_curve_2 construct_polyline =
        polyline_traits.construct_curve_2_object();

    int num_of_curves = 2;
    coordinate *curves[] = {curve_1, curve_2};
    long size_of_curve[] = {curve_1_size, curve_2_size};
    std::vector<Polyline> polylines;

    for(int n = 0; n < num_of_curves; n++){
        std::vector<Point> points;
        Point p_0 = Point(curves[n][0].x, curves[n][0].y);
        points.push_back(p_0);
        for(long i = 1; i < size_of_curve[n]; i++){
            Point p_i = Point(curves[n][i].x, curves[n][i].y);
            if(p_i != points.back()){
                points.push_back(p_i);
            }
        }
        polylines.push_back(construct_polyline(points.begin(), points.end()));
    }

    std::list<Point> intersection_points;
    CGAL::compute_intersection_points(polylines.begin(), polylines.end(),
                                      std::back_inserter(intersection_points),
                                      false, polyline_traits);

    int num_of_intersections = intersection_points.size();
    Point intersection_point;
    for (int j = 0; j < num_of_intersections; j++){
        if (j == max_num_of_intersections)
            break;
        intersection_point = intersection_points.front();
        intersections[j].x = intersection_point.x();
        intersections[j].y = intersection_point.y();
        intersection_points.pop_front();
    }

    return num_of_intersections;
}
扫描目标cgal\U交叉点的相关性
[100%]构建CXX对象cmakfiles/cgal_intersection.dir/cgal_intersection.cpp.o
在文件中包括从/home/chan/mose/mose/cgal_交叉点/cgal_交叉点。cpp:5:0:
/usr/include/CGAL/Sweep_line_2_algorithms.h:在“输出迭代器CGAL::计算交点(曲线输入迭代器、曲线输入迭代器、输出迭代器、bool)”的实例化中[使用曲线输入迭代器=CGAL::polyline::polyline_2*;输出迭代器=std::back\u insert\u迭代器]:
/home/chan/mose/mose/cgal_交叉口/cgal_交叉口。cpp:36:78:从这里开始需要
/usr/include/CGAL/Sweep\u line\u 2\u algorithms.h:134:48:错误:“struct CGAL::Default\u arr\u Traits”中没有名为“Traits”的类型
typename Default_arr_traits::traits traits;
^
/usr/include/CGAL/Sweep\u line\u 2\u algorithms.h:134:48:错误:“struct CGAL::Default\u arr\u Traits”中没有名为“Traits”的类型
make[2]:***[CMakeFiles/cgal_intersection.dir/cgal_intersection.cpp.o]错误1
生成[1]:***[CMakeFiles/cgal_intersection.dir/all]错误2
make:**[全部]错误2

我查看了头文件,但不明白为什么它在CGAL4.2中工作,但在CGAL4.6中失败。如果有任何帮助,我将不胜感激。

经过两次修改后,我成功地编译了代码

  • 结果表明,
    Arr\u polyline\u traits\u 2
    的API从
    CGAL4.2
    显著更改为
    CGAL4.4
    。例如,当使用
    CGAL4.6.1
    时,应使用
    构造曲线\u 2
    来构造多段线,如示例代码
    曲面上的排列\u 2/多段线.cpp
    中所述

  • 有两个重载定义的
    计算交点
    。在这里,应该明确指定正在使用的特征,即,应该使用以下描述的API:

  • 合并上述修改后的代码如下所示:

    Scanning dependencies of target cgal_intersection
    [100%] Building CXX object CMakeFiles/cgal_intersection.dir/cgal_intersection.cpp.o
    In file included from /home/chan/mose/mose/cgal_intersection/cgal_intersection.cpp:5:0:
    /usr/include/CGAL/Sweep_line_2_algorithms.h: In instantiation of ‘OutputIterator CGAL::compute_intersection_points(CurveInputIterator, CurveInputIterator, OutputIterator, bool) [with CurveInputIterator = CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > >*; OutputIterator = std::back_insert_iterator<std::list<CGAL::Point_2<CGAL::Cartesian<double> > > >]’:
    /home/chan/mose/mose/cgal_intersection/cgal_intersection.cpp:36:78:   required from here
    /usr/include/CGAL/Sweep_line_2_algorithms.h:134:48: error: no type named ‘Traits’ in ‘struct CGAL::Default_arr_traits<CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > > >’
       typename Default_arr_traits<Curve>::Traits   traits;
                                                    ^
    /usr/include/CGAL/Sweep_line_2_algorithms.h:134:48: error: no type named ‘Traits’ in ‘struct CGAL::Default_arr_traits<CGAL::polyline::Polyline_2<CGAL::Arr_segment_2<CGAL::Cartesian<double> >, CGAL::Point_2<CGAL::Cartesian<double> > > >’
    make[2]: *** [CMakeFiles/cgal_intersection.dir/cgal_intersection.cpp.o] Error 1
    make[1]: *** [CMakeFiles/cgal_intersection.dir/all] Error 2
    make: *** [all] Error 2
    
    // Computing intersection points among curves using the sweep line.
    #include <CGAL/Cartesian.h>
    #include <CGAL/Arr_segment_traits_2.h>
    #include <CGAL/Arr_polyline_traits_2.h>
    #include <CGAL/Sweep_line_2_algorithms.h>
    #include <vector>
    #include <list>
    
    #include "cgal_intersection.h"
    
    typedef CGAL::Cartesian<double>                         Kernel;
    typedef CGAL::Arr_segment_traits_2<Kernel>              Segment_traits;
    typedef CGAL::Arr_polyline_traits_2<Segment_traits>     Polyline_traits;
    typedef Polyline_traits::Point_2                        Point;
    typedef Polyline_traits::Curve_2                        Polyline;
    
    extern "C" int find_intersections_of_curves(
        coordinate *curve_1, long curve_1_size,
        coordinate *curve_2, long curve_2_size,
        coordinate *intersections, int max_num_of_intersections)
    {
        Polyline_traits polyline_traits;
        Polyline_traits::Construct_curve_2 construct_polyline =
            polyline_traits.construct_curve_2_object();
    
        int num_of_curves = 2;
        coordinate *curves[] = {curve_1, curve_2};
        long size_of_curve[] = {curve_1_size, curve_2_size};
        std::vector<Polyline> polylines;
    
        for(int n = 0; n < num_of_curves; n++){
            std::vector<Point> points;
            Point p_0 = Point(curves[n][0].x, curves[n][0].y);
            points.push_back(p_0);
            for(long i = 1; i < size_of_curve[n]; i++){
                Point p_i = Point(curves[n][i].x, curves[n][i].y);
                if(p_i != points.back()){
                    points.push_back(p_i);
                }
            }
            polylines.push_back(construct_polyline(points.begin(), points.end()));
        }
    
        std::list<Point> intersection_points;
        CGAL::compute_intersection_points(polylines.begin(), polylines.end(),
                                          std::back_inserter(intersection_points),
                                          false, polyline_traits);
    
        int num_of_intersections = intersection_points.size();
        Point intersection_point;
        for (int j = 0; j < num_of_intersections; j++){
            if (j == max_num_of_intersections)
                break;
            intersection_point = intersection_points.front();
            intersections[j].x = intersection_point.x();
            intersections[j].y = intersection_point.y();
            intersection_points.pop_front();
        }
    
        return num_of_intersections;
    }
    
    //使用扫描线计算曲线之间的交点。
    #包括
    #包括
    #包括
    #包括
    #包括
    #包括
    #包括“cgal_交叉点.h”
    笛卡尔核;
    typedef CGAL::Arr_段特征2段特征;
    typedef CGAL::Arr_polyline_traits_2 polyline_traits;
    typedef多段线特征::点2点;
    typedef Polyline_traits::Curve_2 Polyline;
    外部“C”int查找曲线的交点(
    坐标*曲线_1,长曲线_1_尺寸,
    坐标*曲线2,长曲线2尺寸,
    坐标*交点,整数最大交点数)
    {
    多段线特征多段线特征;
    多段线特征::构造多段线=
    多段线特征。构造曲线对象();
    _曲线的int num_=2;
    坐标*曲线[]={curve_1,curve_2};
    _曲线的长尺寸_[]={curve_1_size,curve_2_size};
    向量多段线;
    对于(int n=0;n