CGAL static_cast 失败
CGAL static_cast failing
在我的论文中,我使用了另一名学生一年前编写的一些 CGAL 代码。但是,我无法构建它。
给出错误的函数如下:
std::set<Curve_handle> originatingCurves(PL_Arrangement arrangement, VertexHandleSet vertices)
{
std::set<Curve_handle> curves;
for (Vertex_handle vertex : vertices)
{
auto heStart = vertex->incident_halfedges();
auto heCurrent = vertex->incident_halfedges();
do
{
Halfedge_handle handle = static_cast<Halfedge_handle>(heCurrent);
//Unless the halfedge represents a piece of overlap between curves, it has only one originating curve
for (auto curve = arrangement.originating_curves_begin(handle); curve != arrangement.originating_curves_end(handle); curve++)
{
curves.emplace(static_cast<Curve_handle>(curve));
}
heCurrent++;
} while (heCurrent != heStart);
}
return curves;
}
第 curves.emplace(static_cast<Curve_handle>(curve));
行给出以下错误:
Severity Code Description Project File Line Suppression State
Error C2672 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::emplace': no matching overloaded function found CurvedNonograms c:\users\demeessias\documents. studie[=12=].masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
Error C2440 'static_cast': cannot convert from 'CGAL::Arrangement_on_surface_with_history_2<GeomTraits_,CGAL::Arr_bounded_planar_topology_traits_2<GeomTraits_,Dcel>>::Originating_curve_iterator' to 'Curve_handle' CurvedNonograms c:\users\demeessias\documents. studie[=12=].masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
像Curve_handle
这样的用户定义类型定义在下面的头文件中:
#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 版本比原来的学生更新,所以我怀疑这也可能是这里的问题,但我不知道我应该如何替换代码行。
CGAL::Arrangement_on_surface_with_history_2::Originating_curve_iterator
inherits from I_Dereference_iterator
.
一个Curve_handle
是一个:PL_Arrangement::Curve_const_handle
。并且由于它不继承自 CGAL::Arrangement_on_surface_with_history_2::Originating_curve_iterator
或 I_Dereference_iterator
,因此您不能在两者之间 static_cast
。static_cast
只能用于继承层次结构中的 down/up 强制转换.
Arrangement::Originating_curve_iterator(也定义为 Arrangement::Originating_curve_handle)有一个 user-defined 转换为 Arrangement::Curve_handle,另一个转换为 Arrangement::Curve_const_handle,所以有
语句没有问题
curves.emplace(static_cast<Curve_handle>(curve));
然而,在
for (auto curve = arrangement.originating_curves_begin(handle);
curve != arrangement.originating_curves_end(handle); curve++)
编译器假定 curve 是一个 non-const 迭代器,因此只需将 'auto' 替换为 'Curve_handle'(定义为 PL_Arrangement::Curve_const_handle)。
在我的论文中,我使用了另一名学生一年前编写的一些 CGAL 代码。但是,我无法构建它。
给出错误的函数如下:
std::set<Curve_handle> originatingCurves(PL_Arrangement arrangement, VertexHandleSet vertices)
{
std::set<Curve_handle> curves;
for (Vertex_handle vertex : vertices)
{
auto heStart = vertex->incident_halfedges();
auto heCurrent = vertex->incident_halfedges();
do
{
Halfedge_handle handle = static_cast<Halfedge_handle>(heCurrent);
//Unless the halfedge represents a piece of overlap between curves, it has only one originating curve
for (auto curve = arrangement.originating_curves_begin(handle); curve != arrangement.originating_curves_end(handle); curve++)
{
curves.emplace(static_cast<Curve_handle>(curve));
}
heCurrent++;
} while (heCurrent != heStart);
}
return curves;
}
第 curves.emplace(static_cast<Curve_handle>(curve));
行给出以下错误:
Severity Code Description Project File Line Suppression State
Error C2672 'std::_Tree<std::_Tset_traits<_Kty,_Pr,_Alloc,false>>::emplace': no matching overloaded function found CurvedNonograms c:\users\demeessias\documents. studie[=12=].masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
Error C2440 'static_cast': cannot convert from 'CGAL::Arrangement_on_surface_with_history_2<GeomTraits_,CGAL::Arr_bounded_planar_topology_traits_2<GeomTraits_,Dcel>>::Originating_curve_iterator' to 'Curve_handle' CurvedNonograms c:\users\demeessias\documents. studie[=12=].masterthesis\curvednonograms-code\curvednonograms\curvednonograms\curve_manipulation.cpp 222
像Curve_handle
这样的用户定义类型定义在下面的头文件中:
#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::Arrangement_on_surface_with_history_2::Originating_curve_iterator
inherits from I_Dereference_iterator
.
一个Curve_handle
是一个:PL_Arrangement::Curve_const_handle
。并且由于它不继承自 CGAL::Arrangement_on_surface_with_history_2::Originating_curve_iterator
或 I_Dereference_iterator
,因此您不能在两者之间 static_cast
。static_cast
只能用于继承层次结构中的 down/up 强制转换.
Arrangement::Originating_curve_iterator(也定义为 Arrangement::Originating_curve_handle)有一个 user-defined 转换为 Arrangement::Curve_handle,另一个转换为 Arrangement::Curve_const_handle,所以有
语句没有问题curves.emplace(static_cast<Curve_handle>(curve));
然而,在
for (auto curve = arrangement.originating_curves_begin(handle);
curve != arrangement.originating_curves_end(handle); curve++)
编译器假定 curve 是一个 non-const 迭代器,因此只需将 'auto' 替换为 'Curve_handle'(定义为 PL_Arrangement::Curve_const_handle)。