CGAL写法
Exact_predicates_exact_constructions_kernel的使用问题
#include <iostream>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; //精确谓词、精确构造的内核
typedef Kernel::Point_3 CGPoint3;
using namespace std;
int main()
{
double x = 2, y = 3, z = 4;
CGPoint3 pnt(x, y, z);
cout << pnt << endl;
double x1 = pnt.x(); //错误代码
//double x1 = CGAL::to_double(pnt.x()); //正确代码!
cout << x1 << endl;
return 0;
}
CGAL内部错误
两个空间三角形相交出错
背景:求两个空间三角形的交线
//https://doc.cgal.org/latest/Kernel_23/group__intersection__linear__grp.html
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Intersections.h>
#include <CGAL/Intersection_traits.h>
#include <iostream>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel Kernel;
typedef Kernel::Point_3 Point_3;
typedef Kernel::Triangle_3 Triangle_3;
typedef Kernel::Segment_3 Segment_3;
typedef Kernel::Intersect_3 Intersect_3;
int main(int argc, char *argv[])
{
double pnts[2][3][3] =
{
{
{-1693.639771,1086.395996,-172.870544},
{2311.891602,-938.213989,-172.870544},
{2311.891602,1086.395996,-172.870544}
},
{
{110.420000,-123.700000,-600.000000},
{786.420000,153.460000,-600.000000},
{786.420000,153.460000,200.000000}
}
};
std::vector<Point_3> APoints(3);
std::vector<Point_3> BPoints(3);
for(int i = 0; i < 3; ++i)
{
APoints[i] = Point_3(pnts[0][i][0], pnts[0][i][1], pnts[0][i][2]);
BPoints[i] = Point_3(pnts[1][i][0], pnts[1][i][1], pnts[1][i][2]);
}
Triangle_3 TriangleA(APoints[0], APoints[1], APoints[2]);
Triangle_3 TriangleB(BPoints[0], BPoints[1], BPoints[2]);
std::cout.precision(16);
std::cout << " - Tried to intersect: " << std::endl;
std::cout << " - Triangle (A) " << " : "
<< "(" << TriangleA.vertex(0) << ") "
<< "(" << TriangleA.vertex(1) << ") "
<< "(" << TriangleA.vertex(2) << ") " << std::endl;
std::cout << " - Triangle (B) " << " : "
<< "(" << TriangleB.vertex(0) << ") "
<< "(" << TriangleB.vertex(1) << ") "
<< "(" << TriangleB.vertex(2) << ") " << std::endl;
bool isIntersection = CGAL::do_intersect(TriangleA, TriangleB);
std::cout << isIntersection << std::endl;
CGAL::cpp11::result_of<Intersect_3(Triangle_3, Triangle_3)>::type
result = CGAL::intersection(TriangleA, TriangleB);
if(const Point_3 *p = boost::get<Point_3>(result.get_ptr()))
{
std::cout << p->x() << ' ' << p->y() << ' ' << p->z() << std::endl;
}
else if(const Segment_3 *s = boost::get<Segment_3>(result.get_ptr()))
{
std::cout << s->start() << "->" << s->end() << std::endl;
}
else if(const Triangle_3 *tri = boost::get<Triangle_3>(result.get_ptr()))
{
std::cout << tri->vertex(0) << '\t' << tri->vertex(1) << '\t' << tri->vertex(2) << std::endl;
}
else if(const std::vector<Point_3>* points = boost::get<std::vector < Point_3 >>(result.get_ptr()))
{
for(int i = 0; i < points->size(); ++i)
{
std::cout << points->at(i) << std::endl;
}
}
else
{
std::cout << "None intersection!" << std::endl;
}
return 0;
}
报错:之前两个案例不报错,此案例报错,并且此案列中的两个三角形一定有交线
将三角形的一个坐标最后一位改一下就能通过
代码错误
指针错误:Debug Error!
错误代码:
CGAL::cpp11::result_of<Intersect_3(Triangle_3, Triangle_3)>::type
result = CGAL::intersection(TriangleA, TriangleB);
if(const Point_3 *p = boost::get<Point_3>(&*result))
{
std::cout << "一个点" << std::endl;
std::cout << p->x() << ' ' << p->y() << ' ' << p->z() << std::endl;
}
错误情况:
正确写法:
if(const Point_3 *p = boost::get<Point_3>(result.get_ptr()))
{
std::cout << "一个点" << std::endl;
std::cout << p->x() << ' ' << p->y() << ' ' << p->z() << std::endl;
}
VS报错:C2679
【代码】
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 CGALPoint3;
typedef CGAL::Surface_mesh<CGALPoint3> CGALMesh;
typedef std::vector<CGALPoint3> CGALPolyline;
CGAL::Polygon_mesh_slicer<CGALMesh, K> slicer(mesh);
CGALPolyline polylines;
slicer(plane, std::back_inserter(polylines));
【报错】错误 C2679 二进制“=”: 没有找到接受“std::vector
【错误】传的类型错误,应该传这个
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef K::Point_3 CGALPoint3;
typedef CGAL::Surface_mesh<CGALPoint3> CGALMesh;
typedef std::vector<CGALPoint3> CGALPolyline;
typedef std::list<CGALPolyline> CGALPolylines;
CGAL::Polygon_mesh_slicer<CGALMesh, K> slicer(mesh);
CGALPolylines polylines;
slicer(plane, std::back_inserter(polylines));
VS环境错误
VS报错:error C2760
报错:语法错误:意外的令牌”(“,预期的令牌为”ID表达式”
更改VS的符合模式:
VS报错:ERROR C1128
报错:严重性 代码 说明 项目 文件 行 禁止显示状态错误 C1128 节数超过对象文件格式限制: 请使用 /bigobj 进行编译。
说明:默认情况下,对象文件最多可存放 65,536 (2^16) 个可寻址的节。/bigobj将该地址容量增加至 4,294,967,296 (2^32)。大多数模块将从来不会生成包含数超过 65,536 的 .obj 文件。但是,计算机生成的代码或大量使用模板库的代可能需要可存放更多节的 .obj 文件。只有 Visual C++ 2005(或更高版本)中供的链接器才能使用通过 /bigobj 生成的 .obj 文件。Visual C++ 2005 之前的版本中所提供的链接器不能读取使用 /bigobj 生成的 .obj 文件。在 Visual Studio 开发环境中设置此编译器选项。
解决方案:C++项—>命令行—>在“附加选项”框中键入编译器选项,添加/bigobj