关于CMake生成包含PCL库和CGAL库的工程时出现“无法解析的外部符号”的错误

博客讲述了在Windows 8环境下,使用CMake结合VS2013配置PCL 1.8.0和CGAL 4.10.2时遇到的“无法解析的外部符号”错误。经过尝试,发现解决方案是通过VS2013新建空项目,手动导入头文件和配置文件,并分别针对Debug和Release模式设置项目属性表,包括包含目录、库目录、附加依赖项等,最终成功运行程序。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

前言

博主之前安装了PCL 1.8.0库(教程链接:PCL-1.8.0-AllInOne VS2013 Win8 X64 安装配置及部分问题解决方法)和CGAL库(教程链接:在Win8,VS2013中配置CGAL库),最近需要把两个库用在同一个工程,所以用CMake-gui来生成包含这两个库的VS2013工程。结果出现“无法解析的外部符号”的错误。

在经历了10个小时左右的资料搜索、询问求助之后,该问题还是没有得到根本解决,但是采取了一种“软着陆”的解决方案,程序能够运行了。

先记录博主的报错现象以及排错过程,一是可以给遇到相同情况的朋友些许借鉴,二是为自己日后填坑做前景记录。


环境

Win 8-4

VS 2013

CMake 3.10.2-x64

PCL 1.8.0-x64

CGAL 4.10.2-x64


问题

  • 利用CMake-gui生成只包含PCL库的工程——运行正常。
cmake_minimum_required(VERSION 3.0.0)

project(ISS_RoPS)

# PCL 1.8.0
find_package(PCL 1.8.0 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

add_executable(ISS_RoPS test.cpp)
target_link_libraries(ISS_RoPS ${PCL_LIBRARIES})
  • 利用CMake-gui生成只包含CGAL库的工程——运行正常。
# 仿照CGAL/demo的CMakeLists.txt  
cmake_minimum_required(VERSION 3.0.0) 

project(ISS_RoPS)  
  
# CGAL 4.10.2   
find_package(CGAL QUIET)  
  
if ( CGAL_FOUND )  
  
  include( ${CGAL_USE_FILE} )  
  
  include( CGAL_CreateSingleSourceCGALProgram )  
    
  message(STATUS "Find CGAL successfully.")  
  
else()  
    
    message(STATUS "This program requires the CGAL library, and will not be compiled.")  
    
endif()  
  
add_executable(ISS_RoPS test.cpp)  
  
target_link_libraries(ISS_RoPS ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES}) 

# 仿照CGAL/example的CMakeLists.txt

project( ISS_RoPS )

cmake_minimum_required(VERSION 3.0.0)

find_package(CGAL QUIET)

if ( CGAL_FOUND )

  include( ${CGAL_USE_FILE} )

  include( CGAL_CreateSingleSourceCGALProgram )

  include_directories (BEFORE "../../include")

  # create a target per cppfile
  file(GLOB cppfiles RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp)
  foreach(cppfile ${cppfiles})
    create_single_source_cgal_program( "${cppfile}" )
  endforeach()

else()
  
    message(STATUS "This program requires the CGAL library, and will not be compiled.")
  
endif()
  • 利用CMake-gui生成包含PCL和CGAL库的工程——报错:“无法解析的外部符号”
make_minimum_required(VERSION 3.0.0)

project(ISS_RoPS)

# PCL 1.8.0
find_package(PCL 1.8.0 REQUIRED)

include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})

# CGAL 4.10.2 
find_package(CGAL QUIET)

if ( CGAL_FOUND )

  include( ${CGAL_USE_FILE} )

  include( CGAL_CreateSingleSourceCGALProgram )
  
  message(STATUS "Find CGAL successfully.")

else()
  
    message(STATUS "This program requires the CGAL library, and will not be compiled.")
  
endif()

add_executable(ISS_RoPS test.cpp)
target_link_libraries(ISS_RoPS ${PCL_LIBRARIES})
#target_link_libraries(ISS_RoPS ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})


(看错误提示,貌似是两个库依赖的Boost库冲突或者Boost库的lib配置不完整导致的)


排错过程

1.Boost库在CMakeLists.txt中单独添加的相关测试。

(1)原版的测试:Boost库可以找到,但是Boost_LIBRARY_DIRS和Boost_LIBRAIRES不输出。程序依然报错。

cmake_minimum_required(VERSION 3.0.0)  
  
project(ISS_RoPS) 

# PCL 1.8.0  
find_package(PCL 1.8.0 REQUIRED)  
  
include_directories(${PCL_INCLUDE_DIRS})  
link_directories(${PCL_LIBRARY_DIRS})  
add_definitions(${PCL_DEFINITIONS})  
  
# CGAL 4.10.2   
find_package(CGAL QUIET)  
  
if ( CGAL_FOUND )  
  
  include( ${CGAL_USE_FILE} )  
  
  include( CGAL_CreateSingleSourceCGALProgram )  
    
  message(STATUS "Find CGAL successfully.")  
  
else()  
    
    message(STATUS "This program requires the CGAL library, and will not be compiled.")  
    
endif()  
  
# BOOST 1.59.0  
find_package(Boost 1.59.0 REQUIRED)  
include_directories(${Boost_INCLUDE_DIRS})  
link_directories(${Boost_LIBRARY_DIRS})  
add_definitions(${PCL_DEFINITIONS})  

# 此处可以输出“Boost_INCLUDE_DIRS”,但不输出“Boost_LIBRARY_DIRS”和“Boost_LIBRARIES”  
message(STATUS "${Boost_INCLUDE_DIRS}:" ${Boost_INCLUDE_DIRS})  
  
message(STATUS "${Boost_LIBRARY_DIRS}:" ${Boost_LIBRARY_DIRS})  
  
message(STATUS "${Boost_LIBRARIES}: " ${Boost_LIBRARIES})  

# 显示成功找到Boost  
if( Boost_FOUND )
message(STATUS "Find Boost successfully.")  
else()  
    message(STATUS "This program requires the Boost library, and will not be compiled.")  
endif()  
  
add_executable(ISS_RoPS test.cpp)  
target_link_libraries(ISS_RoPS ${PCL_LIBRARIES})  
target_link_libraries(ISS_RoPS ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES})  
target_link_libraries(ISS_RoPS ${Boost_LIBRARIES})

(2)手动set设置Boost_LIBRARY_DIRS和Boost_LIBRARIES的路径:

1)变量输出,但程序generate报错:Boost_LIBRARIES应该对应的是链接库文件,不是路径;

2)去掉Boost_LIBRARIES的路径set后Boost_LIBRARY_DIRS变量输出,但Boost_LIBRARIES路径不输出。

3)程序依然报错。

[变量名的差异以及根据什么目的对谁进行设置set,如何设置,多参考CMake的FindBoost.cmake]

cmake_minimum_required(VERSION 3.0.0)  
  
project(ISS_RoPS)  
  
# PCL 1.8.0  
find_package(PCL 1.8.0 REQUIRED)  
  
include_directories(${PCL_INCLUDE_DIRS})  
link_directories(${PCL_LIBRARY_DIRS})  
add_definitions(${PCL_DEFINITIONS})  
  
# CGAL 4.10.2   
find_package(CGAL QUIET)  
  
if ( CGAL_FOUND )  
  
  include( ${CGAL_USE_FILE} )  
  
  include( CGAL_CreateSingleSourceCGALProgram )  
    
  message(STATUS "Find CGAL successfully.")  
  
else()  
    
    message(STATUS "This program requires the CGAL library, and will not be compiled.")  
    
endif()  
  
#BOOST 1.59.0  
find_package(Boost 1.59.0 REQUIRED)  
set(Boost_LIBRARY_DIRS "C:/dev/boost_1_59_0/lib64-msvc-12.0")  
#set(Boost_LIBRARIES "C:/dev/boost_1_59_0/lib64-msvc-12.0")  
include_directories(${Boost_INCLUDE_DIRS}})  
link_directories(${Boost_LIBRARY_DIRS})  
  
if( Boost_FOUND )  
    message(STATUS "Find Boost successfully.")  
else()  
    message(STATUS "This program requires the Boost library, and will not be compiled.")  
endif()  
  
message(STATUS "${Boost_INCLUDE_DIRS}:" ${Boost_INCLUDE_DIRS})  
  
message(STATUS "${Boost_LIBRARY_DIRS}:" ${Boost_LIBRARY_DIRS})  
  
message(STATUS "${Boost_LIBRARIES}: " ${Boost_LIBRARIES})  
  
if( Boost_FOUND )  
    message(STATUS "Find Boost successfully.")  
else()  
    message(STATUS "This program requires the Boost library, and will not be compiled.")  
endif()  
  
message(STATUS "Boost_INCLUDE_DIRS:" ${Boost_INCLUDE_DIRS})  
message(STATUS "Boost_LIBRARY_DIRS:" ${Boost_LIBRARY_DIRS}) 
message(STATUS "Boost_LIBRARIES" ${Boost_LIBRARIES})  

add_executable(ISS_RoPS test.cpp)  
target_link_libraries(ISS_RoPS ${PCL_LIBRARIES})  
target_link_libraries(ISS_RoPS ${Boost_LIBRARIES})


2.PCL库包含过程中Boost库的检查:boost输出正确。

cmake_minimum_required(VERSION 3.0.0)

project(ISS_RoPS)

FIND_PACKAGE(PCL REQUIRED)
INCLUDE_DIRECTORIES(${PCL_INCLUDE_DIRS})
ADD_DEFINITIONS(${PCL_DEFINITIONS})

add_executable(ISS_RoPS pointTransform.cpp)
target_link_libraries(ISS_RoPS ${Boost_LIBRARIES})

message(STATUS "Boost_INCLUDE_DIRS:" ${Boost_INCLUDE_DIRS})
message(STATUS "Boost_LIBRARY_DIRS:" ${Boost_LIBRARY_DIRS})
message(STATUS "Boost_LIBRARIES" ${Boost_LIBRARIES})


解决方案

1.CMake整合源文件生成包含PCL库的VS2013工程然后在工程中加入CGAL库的配置文件。

——失败:无法解析的外部符号。

2.CMake整合源文件生成一个不包含库的VS2013工程然后在工程中加入CGAL库的配置文件。

——失败:无法解析的外部符号。

3.VS2013新建一个空项目,添入相应源文件,再加入CGAL库的配置文件。

——成功。

4.VS2013新建一个空项目,添入相应源文件,再加入CGAL库的配置文件以及PCL库分别的Debug版本配置文件和Release版本配置文件。(本质:把利用CMake生成工程的方式变成利用VS2013生成新的空工程然后把源文件和两个库的对应配置文件导进来的方式)

——Debug和Release下都成功运行。


解决方案具体过程

1.在VS2013中新建空项目并进行活动平台修改。



注意VS2013中配置管理器(Configuration Manager)默认活动平台(Active Solution plantform)是win32,如果安装的是x64的PCL,需要将其改成x64,否则编译的时候会出现奇怪的问题。


修改方法如下

打开“解决方案资源管理器”视图 -> 右键目标项目("PCLTest"为例) -> 选择“属性”,进入程序属性页 -> 点击“配置管理器” -> 下拉“平台”按钮,点击“新建” -> 新建平台“x64”,从此处复制设置选“空”,创建新的解决方案平台打钩 -> 完成。




2.项目属性表的建立

其中Debug模式下加CGAL的配置文件和PCL的Debug版本配置文件,Realese版本下加CGAL的配置文件和PCL的Release配置文件。(配置文件生成一次后保存好,后面可以直接添加利用)

(1)PCL项目属性表的建立(Debug版本和Release版本只是链接器输入的依赖项不同,其余设置一致)

切换到“属性管理器”视图,解决方案资源管理器(Propert

<think>我们计划结合PCL(点云CGAL(计算几何算法)来实现投影在XZ平面的2.5DDelaunay三角网生成。2.5DDelaunay三角网是指将三维点投影到某个平面(这里是XZ平面)上进行二维Delaunay三角剖分,然后将三角形提升回三维(保留原始Z坐标)得到的三维三角网。步骤:1.使用PCL读取点云数据(或直接生成示例数据)。2.将点云投影到XZ平面:忽略Y坐标,使用XZ坐标进行二维三角剖分。3.使用CGAL的投影特征(Projection_traits_xz_3)进行Delaunay三角剖分。4.生成的二维三角剖分(以三维点表示,但Y坐标被忽略)提升回三维:使用原始点的Y坐标(如果有的话)或者保持Y=0?但是注意,我们想要的是原始三维点的三角网,所以实际上我们使用原始点的坐标来构造三角形。注意:在投影到XZ平面后,我们使用CGAL::Projection_traits_xz_3作为二维三角剖分的特征类。这个特征类将三维点视为二维点(使用XZ坐标),但保留原始点的三维表示。因此,在三角剖分中,每个点仍然是三维点,但在计算距离方位只使用XZ坐标。然后,我们遍历所有的三角形面片,用原始的三维点构造三角形(因为投影特征类中的点就是原始点,只是比较用了XZ坐标)。具体实现:1.包含必要的头文件。2.定义内核投影特征类型。3.定义Delaunay三角剖分类型。4.读取点云(使用PCL或直接使用CGAL的点)。5.创建三角剖分对象并插入点。6.遍历所有的有限面,将每个面转换为由三个顶点组成的三角形(使用原始三维点)。但是,这里有一个问题:在投影到XZ平面,我们忽略了Y坐标。然而,在生成三角形,我们仍然使用原始点的三维坐标,因此每个三角形都是三维空间中的三角形。因此,最终得到的三角网是一个三维三角网,但它是在XZ平面上的投影满足Delaunay性质的。另外,如果我们想要可视化,可以使用PCL的可视化工具来显示三角网,或者使用CGAL的可视化(但CGAL的可视化通常需要转换为其他格式,如VTK)。下面我们将给出一个结合PCLCGAL的示例代码。注意,PCL主要用于点云的输入输出可视化,而CGAL用于三角剖分。由于PCLCGAL都是基于模板的,我们需要确保点类型兼容。这里我们使用CGAL的点类型,但也可以将PCL的点转换为CGAL的点。代码结构:1.读取点云(假设为PCL格式的pcl::PointXYZ点云)。2.PCL点云转换为CGAL点云(std::vector<CGAL::Point_3>)。3.使用CGAL在XZ平面进行Delaunay三角剖分。4.生成的三角网转换为PCL的PolygonMesh以便可视化(或者直接使用CGAL的可视化工具)。但是,PCL的PolygonMesh要求三角形面片由顶点索引表示,而CGAL的三角剖分中每个面片由三个顶点(点对象)表示。因此,我们需要建立顶点索引映射。另一种做法是:我们生成三角网后,将每个三角形的三个顶点直接添加到PCL的PolygonMesh中,但这样会导致重复的顶点。为了优化,我们可以先建立点集到索引的映射。然而,为了简化,我们可以直接使用重复的顶点(这样比较简单,但会占用更多内存,但对于小型点云可以接受)。或者,我们可以使用CGAL提供的将三角剖分转换为OpenMesh或PolygonMesh的功能,然后再转换为PCL的格式,但这比较复杂。这里,我们将采用简单的方法:为每个三角形单独添加三个顶点,然后添加该三角形面片。步骤:1.将每个三角形面片的三个顶点依次加入PolygonMesh的cloud中。2.为每个三角形添加一个多边形,包含三个顶点的索引(按添加顺序,每个三角形的三个顶点是连续添加的)。注意:这样每个三角形的顶点都是独立添加的,所以即使两个三角形共享一个顶点,也会被重复存储。因此,这种方法会导致顶点数据冗余。但对于演示目的,这是可以接受的。我们也可以先建立所有点的集合(通过遍历三角剖分的所有顶点),然后为每个顶点分配一个索引,再构建多边形。这样避免重复。但这里为了简单,我们使用重复顶点。代码示例:注意:需要安装PCLCGAL,并在编译链接相应的。以下代码将实现:-生成一个示例点云(或从文件读取)-使用CGAL在XZ平面进行Delaunay三角剖分-将三角网转换为PCL的PolygonMesh-使用PCL的可视化工具显示结果我们开始编写代码:</think># 使用PCLCGAL生成XZ平面2.5D Delaunay三角网 我将详细介绍如何结合PCLCGAL实现XZ平面上的2.5D Delaunay三角网生成,包括点云处理、三角剖分可视化。 ## 完整解决方案 ```cpp #include <pcl/point_cloud.h> #include <pcl/point_types.h> #include <pcl/io/pcd_io.h> #include <pcl/visualization/pcl_visualizer.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Projection_traits_xz_3.h> #include <CGAL/Delaunay_triangulation_2.h> #include <CGAL/Triangulation_vertex_base_with_info_2.h> #include <vector> #include <iostream> // 定义PCL点云类型 typedef pcl::PointXYZ PointT; typedef pcl::PointCloud<PointT> PointCloud; // 定义CGAL内核投影特征 typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Projection_traits_xz_3<K> Projection_traits; // XZ平面投影 typedef CGAL::Triangulation_vertex_base_with_info_2<int, Projection_traits> Vb; typedef CGAL::Triangulation_face_base_2<Projection_traits> Fb; typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds; typedef CGAL::Delaunay_triangulation_2<Projection_traits, Tds> Delaunay; // 转换PCL点云到CGAL点云 std::vector<K::Point_3> convertPCLToCGAL(const PointCloud::ConstPtr& cloud) { std::vector<K::Point_3> points; for (const auto& p : *cloud) { points.push_back(K::Point_3(p.x, p.y, p.z)); } return points; } // 在XZ平面生成Delaunay三角网 void generateXZDelaunayMesh(const std::vector<K::Point_3>& points, PointCloud::Ptr& mesh_vertices, std::vector<pcl::Vertices>& mesh_faces) { // 创建Delaunay三角剖分对象 Delaunay dt; // 插入点并记录索引 int index = 0; for (const auto& p : points) { Delaunay::Vertex_handle vh = dt.insert(p); vh->info() = index++; } // 提取顶点面 mesh_vertices->clear(); mesh_faces.clear(); // 添加所有顶点到mesh_vertices for (auto it = dt.finite_vertices_begin(); it != dt.finite_vertices_end(); ++it) { K::Point_3 p = it->point(); mesh_vertices->push_back(PointT(static_cast<float>(p.x()), static_cast<float>(p.y()), static_cast<float>(p.z()))); } // 添加三角形面 for (auto it = dt.finite_faces_begin(); it != dt.finite_faces_end(); ++it) { pcl::Vertices face; face.vertices.resize(3); for (int i = 0; i < 3; ++i) { face.vertices[i] = it->vertex(i)->info(); } mesh_faces.push_back(face); } } // 可视化点云三角网 void visualizePointCloudAndMesh(const PointCloud::Ptr& cloud, const PointCloud::Ptr& mesh_vertices, const std::vector<pcl::Vertices>& mesh_faces) { pcl::visualization::PCLVisualizer::Ptr viewer(new pcl::visualization::PCLVisualizer("3D Viewer")); viewer->setBackgroundColor(0, 0, 0); // 添加原始点云(红色) pcl::visualization::PointCloudColorHandlerCustom<PointT> cloud_color(cloud, 255, 0, 0); viewer->addPointCloud<PointT>(cloud, cloud_color, "original_cloud"); viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 3, "original_cloud"); // 添加三角网格(绿色) pcl::PolygonMesh mesh; mesh.cloud = *mesh_vertices; mesh.polygons = mesh_faces; viewer->addPolygonMesh(mesh, "delaunay_mesh"); viewer->setRepresentationToWireframeForAllActors(); viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0, 1, 0, "delaunay_mesh"); // 添加坐标轴 viewer->addCoordinateSystem(1.0); while (!viewer->wasStopped()) { viewer->spinOnce(100); } } int main(int argc, char** argv) { // 加载点云数据(或创建示例数据) PointCloud::Ptr cloud(new PointCloud); if (argc > 1) { // 从PCD文件加载点云 if (pcl::io::loadPCDFile<PointT>(argv[1], *cloud) == -1) { std::cerr << "无法读取文件: " << argv[1] << std::endl; return -1; } } else { // 生成示例点云(平面上的随机点) for (int i = 0; i < 100; ++i) { float x = static_cast<float>(rand()) / RAND_MAX * 10.0f; float z = static_cast<float>(rand()) / RAND_MAX * 10.0f; cloud->push_back(PointT(x, 0.0f, z)); // Y坐标固定为0(2.5D特征) } } std::cout << "加载点云: " << cloud->size() << " 个点" << std::endl; // 转换PCL点云到CGAL点云 std::vector<K::Point_3> cgal_points = convertPCLToCGAL(cloud); // 在XZ平面生成Delaunay三角网 PointCloud::Ptr mesh_vertices(new PointCloud); std::vector<pcl::Vertices> mesh_faces; generateXZDelaunayMesh(cgal_points, mesh_vertices, mesh_faces); std::cout << "生成三角网: " << mesh_faces.size() << " 个三角形" << std::endl; // 可视化结果 visualizePointCloudAndMesh(cloud, mesh_vertices, mesh_faces); // 保存结果(可选) pcl::io::savePCDFile("delaunay_vertices.pcd", *mesh_vertices); pcl::PolygonMesh mesh; mesh.cloud = *mesh_vertices; mesh.polygons = mesh_faces; pcl::io::savePLYFile("delaunay_mesh.ply", mesh); return 0; } ``` ## 关键技术原理 ### 1. 2.5D Delaunay三角剖分 在XZ平面上的2.5D Delaunay三角剖分满足Delaunay准则: $$ \forall \Delta ABC \in \mathcal{T}, \quad \text{其外接圆不包含其他顶点} $$ 其中$\mathcal{T}$是三角剖分结果[^1]。 使用CGAL的`Projection_traits_xz_3`特性类实现: ```cpp typedef CGAL::Projection_traits_xz_3<K> Projection_traits; typedef CGAL::Delaunay_triangulation_2<Projection_traits> Delaunay; ``` ### 2. PCLCGAL数据转换 PCL点云与CGAL点云之间的转换: $$ \text{PCL PointXYZ} \rightarrow \text{CGAL Point\_3} $$ 实现核心函数: ```cpp std::vector<K::Point_3> convertPCLToCGAL(const PointCloud::ConstPtr& cloud) { std::vector<K::Point_3> points; for (const auto& p : *cloud) { points.push_back(K::Point_3(p.x, p.y, p.z)); } return points; } ``` ### 3. 三角网顶点索引管理 使用`Triangulation_vertex_base_with_info_2`存储顶点索引: ```cpp typedef CGAL::Triangulation_vertex_base_with_info_2<int, Projection_traits> Vb; ``` ### 4. PCL可视化 通过PCL可视化工具显示结果: ```cpp void visualizePointCloudAndMesh(...) { // 创建可视化器 // 添加点云(红色) // 添加三角网(绿色线框) } ``` ## 工作流程 ```mermaid graph TD A[加载PCL点云] --> B[转换到CGAL点云] B --> C[在XZ平面进行Delaunay剖分] C --> D[提取顶点三角形] D --> E[转换为PCL网格结构] E --> F[可视化结果] F --> G[保存结果] ``` ## 编译与运行 ### 编译命令(CMakeLists.txt) ```cmake cmake_minimum_required(VERSION 3.5) project(PCL_CGAL_Delaunay) find_package(PCL 1.8 REQUIRED) find_package(CGAL REQUIRED) include_directories(${PCL_INCLUDE_DIRS} ${CGAL_INCLUDE_DIRS}) link_directories(${PCL_LIBRARY_DIRS} ${CGAL_LIBRARY_DIRS}) add_definitions(${PCL_DEFINITIONS} ${CGAL_DEFINITIONS}) add_executable(delaunay_xz delaunay_xz.cpp) target_link_libraries(delaunay_xz ${PCL_LIBRARIES} ${CGAL_LIBRARIES}) ``` ### 运行命令 ```bash # 生成示例点云 ./delaunay_xz # 处理真实点云数据 ./delaunay_xz input_cloud.pcd ``` ## 应用场景 1. **地形建模**:从LiDAR点云生成数字高程模型[^1] 2. **工业检测**:平面零件表面重建 3. **机器人导航**:环境地图构建 4. **医学影像**:器官表面重建 5. **计算机视觉**:三维重建中的表面生成 ## 优化与扩展 ### 1. 添加边界约束 ```cpp #include <CGAL/Constrained_Delaunay_triangulation_2.h> typedef CGAL::Constrained_Delaunay_triangulation_2<Projection_traits> CDT; CDT cdt; cdt.insert_constraint(v0, v1); // 添加约束边 ``` ### 2. 处理离群点 ```cpp #include <pcl/filters/statistical_outlier_removal.h> pcl::StatisticalOutlierRemoval<PointT> sor; sor.setInputCloud(cloud); sor.setMeanK(50); sor.setStddevMulThresh(1.0); sor.filter(*filtered_cloud); ``` ### 3. 网格平滑 ```cpp #include <pcl/surface/mls.h> pcl::MovingLeastSquares<PointT, PointT> mls; mls.setInputCloud(cloud); mls.setSearchRadius(0.03); mls.process(*smoothed_cloud); ``` ### 4. 法线估计(用于3D重建) ```cpp #include <pcl/features/normal_3d.h> pcl::NormalEstimation<PointT, pcl::Normal> ne; ne.setInputCloud(cloud); pcl::search::KdTree<PointT>::Ptr tree(new pcl::search::KdTree<PointT>()); ne.setSearchMethod(tree); ne.setRadiusSearch(0.1); ne.compute(*normals); ``` ## 常见问题解答 ### 1. 如何处理非平面点云? 对于非平面点云,应先投影到XZ平面: ```cpp // 投影到XZ平面(忽略Y坐标) PointCloud::Ptr projected_cloud(new PointCloud); for (const auto& p : *cloud) { projected_cloud->push_back(PointT(p.x, 0, p.z)); } ``` ### 2. 如何提高大规模点云的处理效率? - 使用空间分区加速: ```cpp CGAL::spatial_sort(points.begin(), points.end()); ``` - 并行化处理: ```cpp #include <CGAL/Triangulation_hierarchy_2.h> typedef CGAL::Triangulation_hierarchy_2<Delaunay> Delaunay_hierarchy; ``` ### 3. 如何评估三角网质量? 计算三角形质量指标: ```cpp for (const auto& face : mesh_faces) { const PointT& p1 = mesh_vertices->points[face.vertices[0]]; const PointT& p2 = mesh_vertices->points[face.vertices[1]]; const PointT& p3 = mesh_vertices->points[face.vertices[2]]; // 计算边长 float a = pcl::geometry::distance(p2, p3); float b = pcl::geometry::distance(p1, p3); float c = pcl::geometry::distance(p1, p2); // 计算最小内角 float min_angle = compute_min_angle(a, b, c); } ``` ### 4. 如何添加自定义特征? 扩展顶点属性: ```cpp struct VertexInfo { int original_index; float curvature; }; typedef CGAL::Triangulation_vertex_base_with_info_2<VertexInfo, Projection_traits> CustomVb; ```
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值