【问题标题】:CGAL doesn't recognize typeCGAL 不识别类型
【发布时间】:2017-06-19 16:01:58
【问题描述】:

对于我的论文项目,我依赖于一年前另一位学生编写的一堆 CGAL 代码。不幸的是,由于错误,我无法编译代码。以前的学生可能没有遇到这些错误,因此它们可能与我的设置有关,而不是代码本身,但我不知道直接原因是什么。

错误位于文件 CCBSegmentCalculator.h 中。代码如下:

#pragma once
#include "bezier_arrangement.h"

//Circulates around a PL_Arrrangement CCB, visiting the points between the segments that make up the CCB
//  (so smaller-scale than the build-in iterator that only visits the PL_Arrangement vertices)

// --- Could be used in more places than it is now, e.g., in the SVGHandler
class CCBSegmentCirculator
{
public:
  CCBSegmentCirculator(PL_Arrangement::Ccb_halfedge_const_circulator ccbCirculator);

  const CCBSegmentCirculator& next();
  PL_Point operator*();
  PL_Point get(); // same as operator*
  bool operator==(const CCBSegmentCirculator &other) const;

private:


  const PL_Arrangement::Ccb_halfedge_const_circulator halfedgesBegin;
  PL_Arrangement::Ccb_halfedge_const_circulator halfedge;
  //Depending on this boolean ...
  bool forward;
  //... we are either using these forward iterators ...
  // -> in which case the 'current' point is segment.source

  Polyline::Segment_const_iterator segment;
  Polyline::Segment_const_iterator segmentEnd;
  //... or these reverse iterators
  // -> in which case the 'current' point is segmentReverse.target
  Polyline::Segment_const_reverse_iterator segmentReverse;
  Polyline::Segment_const_reverse_iterator segmentReverseEnd;

  void initHalfedge();
};

文件“bezier_arrangement.h”的代码如下:

#pragma once

#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/Arrangement_with_history_2.h>
#include <CGAL/Arr_extended_dcel.h>
#include <CGAL/Iso_rectangle_2.h>
#include <CGAL/Arr_walk_along_line_point_location.h>
#include <CGAL/Arr_observer.h>
//#include <CGAL/basic.h>

#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Arr_segment_traits_2.h>
#include <CGAL/Arr_polyline_traits_2.h>

struct FaceData
{
  FaceData () 
  {
    colored = false;
    solved = false;
  };
  bool colored = false;
  bool solved = false;
};

////   Bezier curve traits  ////

typedef CGAL::CORE_algebraic_number_traits Nt_traits;
typedef Nt_traits::Rational NT;
typedef Nt_traits::Rational Rational;
typedef Nt_traits::Algebraic Algebraic;
//Simple_cartesian = for easier debugging, no ref counting, values directly in objects
typedef CGAL::Cartesian<Rational> Kernel;
typedef CGAL::Cartesian<Algebraic> Alg_kernel;
//typedef Kernel::Point_2 Rat_Point;
typedef CGAL::Arr_Bezier_curve_traits_2<Kernel, Alg_kernel, Nt_traits> Traits;

typedef Traits::Curve_2 Bezier;
typedef Traits::Point_2 Point;
typedef Kernel::Iso_rectangle_2 BoundingBox;

typedef CGAL::Arr_face_extended_dcel<Traits, FaceData> Dcel;
typedef CGAL::Arrangement_with_history_2<Traits, Dcel> Arrangement;  //Not really used anymore, because of crashes/problems/bugs



////  Polyline traits  ////

// Instantiate the traits class using a user-defined kernel
// and Segment_traits_2.
typedef CGAL::Exact_predicates_exact_constructions_kernel PL_Kernel;
typedef CGAL::Arr_segment_traits_2<PL_Kernel>             Segment_traits;
typedef CGAL::Arr_polyline_traits_2<Segment_traits>       PL_traits;
// Identical instantiation can be achieved using the default Kernel:
// typedef CGAL::Arr_polyline_traits_2<>                    Geom_traits_2;
typedef PL_traits::Point_2                            PL_Point;
typedef PL_traits::Segment_2                          Segment;
typedef PL_traits::Curve_2                            Polyline;

typedef CGAL::Arr_extended_dcel<PL_traits, bool/*not used*/, double, FaceData> PL_Dcel;
typedef CGAL::Arrangement_with_history_2<PL_traits, PL_Dcel> PL_Arrangement;  //This is now the only type of arrangement that we actually use
//Handles
typedef PL_Arrangement::Vertex_const_handle         Vertex_handle;
typedef PL_Arrangement::Halfedge_const_handle       Halfedge_handle;
typedef PL_Arrangement::Curve_const_handle          Curve_handle;

//Point location
typedef CGAL::Arr_walk_along_line_point_location<PL_Arrangement> PointLocationAlg;
typedef CGAL::Arr_point_location_result<PL_Arrangement>::Type PointLocationResult;


//Less function to use for (vertex/halfedge/face) handle sets
template <class Handle> struct HandleLess
{
  bool operator()(Handle a, Handle b)
  {
    return (a.ptr() - b.ptr() < 0);
  }
};
typedef std::set<Vertex_handle, HandleLess<Vertex_handle>> VertexHandleSet;


//Arrangement observer that keeps the face colours correct
class FaceColorObserver : public CGAL::Arr_observer<PL_Arrangement>
{
private:
  bool coloredBeforeMerge;
public:
  FaceColorObserver(PL_Arrangement& arrangement) :
    CGAL::Arr_observer<PL_Arrangement>(arrangement)
  {}

  virtual void after_split_face(Face_handle oldFace, Face_handle newFace, bool)
  {
    newFace->data().colored = oldFace->data().colored;
  }

  virtual void before_merge_face(Face_handle face1, Face_handle face2, Halfedge_handle)
  {
    //The assumption is that only same-color faces get merged
    CGAL_precondition(face1->data().colored ==  face2->data().colored);
    coloredBeforeMerge = face1->data().colored;// && face2->data().colored;
  }
  virtual void after_merge_face(Face_handle newFace)
  {
    newFace->data().colored = coloredBeforeMerge;
  }
};

//Arrangement of line segments
typedef CGAL::Arrangement_2<Segment_traits> Seg_Arrangement;

我遇到的错误与 CGAL 认为定义的折线类型没有成员 Segment_const_iterator 或根本无法正确识别该类型有关。我不确定,因为它被翻译成内部 CGAL 类型。我得到的错误是:

Error   C2039   'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>'  CurvedNonograms c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\ccbsegmentcirculator.h  39

重复包含segmentsegmentEndsegmentReversesegmentReverseEnd定义的行。

根据the documentationCurve_2 应该有一个Segment_const_iterator 的定义。

再一次,错误可能不在代码本身,而是在我在某处的 CGAL 构建/链接中。重新安装 CGAL 并没有帮助,我很确定我已经在相关的地方链接了它,但是构建软件的这部分并不是我真正的强项,所以我可能不知道所有相关的地方。

编辑:输出中给出的第一个错误是:

c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\c‌​urvednonograms\svgha‌​ndler.cpp(94): error C2039: 'begin_segments': is not a member of 'CGAL::_Curve_data_ex<CGAL::internal::X_monotone_polycurve_2‌​<CGAL::Arr_segment_2‌​<Kernel_>,CGAL::Poin‌​t_2<Kernel_>>,CGAL::‌​_Unique_list<Data_>>‌​' 2> with 2> [ 2> Kernel_=PL_Kernel, 2> Data_=CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<PL_Ker‌​nel>,CGAL::Point_2<C‌​GAL::Epeck>> * 2> ]

这与上面显示的代码文件不同,因为代码中有更多错误,但所有错误似乎都源于类似的问题。还有一些形式的警告:

2>c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(313): warning C4503: '__LINE__Var': decorated name length exceeded, name was truncated

将 CCBSegmentCalculator.h 添加到不同的项目以仅编译它会产生以下错误:

Severity    Code    Description Project File    Line    Suppression State
Error (active)      class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_iterator"  CurvedNonogramsGenerator    c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h    28  
Error (active)      class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_iterator"  CurvedNonogramsGenerator    c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h    29  
Error (active)      class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_reverse_iterator"  CurvedNonogramsGenerator    c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h    32  
Error (active)      class "CGAL::internal::Polycurve_2<CGAL::Arr_segment_2<CGAL::Exact_predicates_exact_constructions_kernel>, CGAL::Point_2<CGAL::Epeck>>" has no member "Segment_const_reverse_iterator"  CurvedNonogramsGenerator    c:\Users\DeMeessias\Documents\1. Studie\0.MasterThesis\Code\CurvedNonogramsGenerator\CurvedNonogramsGenerator\CCBSegmentCirculator.h    33  
Error   C2039   'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>'  CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    28  
Error   C3646   'segment': unknown override specifier   CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    28  
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    28  
Error   C2039   'Segment_const_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>'  CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    29  
Error   C3646   'segmentEnd': unknown override specifier    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    29  
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    29  
Error   C2039   'Segment_const_reverse_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>'  CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    32  
Error   C3646   'segmentReverse': unknown override specifier    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    32  
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    32  
Error   C2039   'Segment_const_reverse_iterator': is not a member of 'CGAL::internal::Polycurve_2<SubcurveType_2,PointType_2>'  CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    33  
Error   C3646   'segmentReverseEnd': unknown override specifier CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    33  
Error   C4430   missing type specifier - int assumed. Note: C++ does not support default-int    CurvedNonogramsGenerator    c:\users\demeessias\documents\1. studie\0.masterthesis\code\curvednonogramsgenerator\curvednonogramsgenerator\ccbsegmentcirculator.h    33  

【问题讨论】:

  • 在编译单元中准确显示第一条错误消息会有所帮助。
  • 第一个错误是c:\users\demeessias\documents\1. studie\0.masterthesis\curvednonograms-code\curvednonograms\curvednonograms\svghandler.cpp(94): error C2039: 'begin_segments': is not a member of 'CGAL::_Curve_data_ex&lt;CGAL::internal::X_monotone_polycurve_2&lt;CGAL::Arr_segment_2&lt;Kernel_&gt;,CGAL::Point_2&lt;Kernel_&gt;&gt;,CGAL::_Unique_list&lt;Data_&gt;&gt;' 2&gt; with 2&gt; [ 2&gt; Kernel_=PL_Kernel, 2&gt; Data_=CGAL::internal::Polycurve_2&lt;CGAL::Arr_segment_2&lt;PL_Kernel&gt;,CGAL::Point_2&lt;CGAL::Epeck&gt;&gt; * 2&gt; ]
  • 这和我展示的代码文件不同,但错误类型似乎基本相同,在此之前,还有一些2&gt;c:\program files (x86)\microsoft visual studio 14.0\vc\include\xutility(313): warning C4503: '__LINE__Var': decorated name length exceeded, name was truncated形式的警告
  • 您的错误与链接无关(尚未),因此无需担心那部分。在这个阶段只有标题很重要。如果您发布因编译提供的文件而导致的错误(是的,您可以编译单个文件),它也可能很有用。
  • 首先,确认您使用的是您认为正在使用的 CGAL 版本。检查您的项目设置指向的位置。如果完全卸载 CGAL,编译器会抱怨缺少文件吗?

标签: c++ cgal


【解决方案1】:

将 Segment_const_iterator 和 Segment_const_reverse_iterator 分别替换为 Subcurve_const_iterator 和 Subcurve_const_reverse_iterator。

您可能需要分别将 begin_segments() 和 end_segments() 替换为 subcurves_begin() 和 subcurves_end()。

在(我认为)4.2 版中,我们对代码进行了重大更改。其中一项更改是扩展 arr_polyline_traits_2 特征类支持的折线的定义。现在,折线可以是一串不一定是线段的线性曲线。例如,它可以有一条或两条射线作为第一条和最后一条,甚至一条线。 (官方来说,一条折线可以是任何可以由两点构成的曲线)。

【讨论】:

  • 这几乎解决了我遇到的所有错误,谢谢!原来还有一行代码仍然报错,但不是同一个问题,所以我要为它做一个新的问题线程
  • Here 是新的问题线程。这是否也是使用较新版本造成的?
  • 不,这是你的新版本造成的(对于C++11);在那里查看我的答案。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-18
  • 2016-11-22
  • 1970-01-01
  • 1970-01-01
  • 2020-01-11
相关资源
最近更新 更多