编译和运行 CGAL 三角测量演示
Compiling and Running CGAL Triangulation Demo
我正在尝试使用 CGAL 库来显示 2D Delaunay 三角测量,如这里的例子所示
我的代码如下所示:
#include <iostream>
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/draw_triangulation_2.h>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Triangulation;
typedef Triangulation::Point Point;
int main(void){
Point a(1,1), b(2,1), c(2,2), d(1,2);
Triangulation T;
T.insert(a);
T.insert(b);
T.insert(c);
T.insert(d);
CGAL::draw(T);
return 0;
}
当我尝试编译此代码时g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp
程序成功编译,但在运行时我得到Impossible to draw because CGAL_USE_BASIC_VIEWER is not defined
通过在谷歌上搜索,我发现有人建议使用g++ -o cgalTest.exe cgalTest.cpp -lCGAL -lgmp -DCGAL_USE_BASIC_VIEWER
,这在编译时会产生以下错误:/usr/include/CGAL/Qt/Basic_viewer_qt.h:30:10: fatal error: QApplication: No such file or directory #include <QApplication>
我使用的是 ubuntu 19.04,所以我使用sudo apt-get install libcgal-dev
和sudo apt-get install libcgal-qt5-dev
安装了 CGAl
我也尝试安装sudo apt-get install libqt5svg5-dev libqt5opengl5-dev
来解决错误,但无济于事。
是否需要安装其他库?也许编译必须以不同的方式进行?
谢谢
好的,对于遇到相同问题的任何人来说,这是我如何解决的:
首先,我使用locate QApplication
命令查找系统上QApplication
头文件的位置。请务必在使用locate
之前运行sudo updatedb
。如果locate
找不到QApplication
的位置,那么您就缺少了qt库。尝试sudo apt-get install qt5-default
和我在问题中提到的其他库,运行sudo updatedb
并再次尝试locate QApplication
。
找到QApplication
路径时,只需使用-I
选项指示编译器使用它。这是一个示例g++ -o delaunayTest delaunayTest.cpp -lCGAL -lgmp -lCGAL_Qt5 -DCGAL_USE_BASIC_VIEWER -I/usr/include/x86_64-linux-gnu/qt5/QtWidgets/
(因为就我而言,QApplication
在目录中/usr/include/x86_64-linux-gnu/qt5/QtWidgets/
尝试使用它进行编译,您可能会收到另一个头文件错误。使用locate
重复相同的过程,直到不再出现头文件错误。
此时,您可能会遇到undefined reference to symbol
错误。
要解决此问题,请再次使用locate
查找导致错误的文件的位置(例如libQt5OpenGL.so.5
),并按原样将路径添加到编译命令(例如g++ -o delaunayTest delaunayTest.cpp /usr/lib/x86_64-linux-gnu/libQt5OpenGL.so.5
)以及所有前面的选项。
您可能还会遇到几个undefined reference to symbol
错误。只需继续使用相同的方法,直到您没有得到任何方法。
此时,程序应正确编译并正常运行。
请注意,如果您安装了多个版本的qt,则上述方法可能无法正常工作(例如,如果您的系统中安装了使用QT的软件,例如MATLAB或anaconda。你会知道的,因为locate
会在上述步骤中为每个文件生成许多路径)。在这种情况下,我建议构建虚拟机,下载CGAL库和qt5-default
并按照上述步骤进行操作,因为这很可能在具有多个qt安装的系统中不起作用。
使用 CMake 的另一种选择(也许是最简单的)是使用内置脚本生成文件:
- 从源文件目录中,运行
cgal_create_CMakeLists -c Qt5
- 编辑生成的
CMakeLists.txt
添加行add_definitions(-DCGAL_USE_BASIC_VIEWER)
我生成和编辑CMakeLists.txt
:
# Created by the script cgal_create_CMakeLists
# This is the CMake script for compiling a set of CGAL applications.
cmake_minimum_required(VERSION 3.1...3.15)
project( tmp_cgal )
# CGAL and its components
find_package( CGAL QUIET COMPONENTS Qt5 )
if ( NOT CGAL_FOUND )
message(STATUS "This project requires the CGAL library, and will not be compiled.")
return()
endif()
add_definitions(-DCGAL_USE_BASIC_VIEWER) # <==== I've added this
# Boost and its components
find_package( Boost REQUIRED )
if ( NOT Boost_FOUND )
message(STATUS "This project requires the Boost library, and will not be compiled.")
return()
endif()
# include for local directory
# include for local package
# Creating entries for all C++ files with "main" routine
# ##########################################################
create_single_source_cgal_program( "b.cpp" )
- 创建一个
build
目录:mkdir build
- 更改目录:
cd build
- 生成构建文件:
cmake ..
- 版本:
make
- 运行二进制文件。对我来说,这很
./b
,因为我的源文件b.cpp
环境:
这些说明应该适用于安装了软件包的 Ubuntu 20.04.1(或类似版本),libcgal-dev
、libcgal-qt5-dev
和qtbase5-dev
(当然,还有cmake
、make
和g++
)。
主要参考资料:
文档 1 和文档 2
- 如何访问CGAL三维三角测量中的面
- CGAL 3D 周期性德劳内三角测量与信息的问题
- Fixed_alpha_shape_3() 会破坏或修改原始三角测量吗?
- 编译和运行 CGAL 三角测量演示
- CGAL没有计算完整的德劳内三角测量
- 优化德劳奈三角测量算法
- 如何使用每个顶点的自定义信息创建CGAL约束的delaunay三角测量
- CGAL 2.5D 三角测量 附加顶点信息
- 计算从德劳内三角测量获得的三角形的边长
- 在二维三角测量中添加约束时出错
- 在二维德劳奈三角测量中插入顶点时出错
- 视觉Opencv;C++;从线性三角测量法矩阵中提取点云点(x,y,z)
- visual有人在C++项目中使用过Triangle/Tangle++库吗?(delaunay三角测量)
- CGAL - 在德劳奈三角测量后检索顶点索引
- 如何对圆进行德劳内三角测量
- 如何从Subdiv2D Delaunay三角测量中获取顶点索引
- 配置 VS2010 用于贪婪投影三角测量
- 为什么opencv的三角测量点返回错误的结果?
- OpenCV:如何进行 Delaunay 三角测量并返回邻接矩阵
- OpenCV,C++:Missing Triangles in Delaunay三角测量