我正在使用 PCL 运行测试。这是我的 CMakeLists.txt:
cmake_minimum_required(VERSION 3.2)
project(pcl_test)
set(Boost_LIBRARY_DIR /opt/homebrew/lib)
set(Qt5_DIR /Users/kevislin/Qt/5.15.0/clang_64/lib/cmake/Qt5)
find_package(PCL 1.7 REQUIRED)
list (REMOVE_ITEM PCL_LIBRARIES "vtkproj4")
#set(PCL_DIR /usr/lib/x86_64-linux-gnu/cmake/pcl)
include_directories(${PCL_INCLUDE_DIRS})
link_directories(${PCL_LIBRARY_DIRS})
add_definitions(${PCL_DEFINITIONS})
add_executable(pcl_test pcl_test.cpp)
target_link_libraries (pcl_test ${PCL_LIBRARIES})
install(TARGETS pcl_test RUNTIME DESTINATION bin)
因为pcl中的VTK需要依赖Qt5,所以我下载了Qt5并设置了Qt5_DIR(我不使用Xcode,但是我有clang)。
这是我的cpp代码:
#include <pcl/common/common_headers.h>
#include <pcl/io/pcd_io.h>
#include <pcl/visualization/pcl_visualizer.h>
#include <pcl/visualization/cloud_viewer.h>
#include <pcl/console/parse.h>
int main(int argc, char **argv) {
std::cout << "Test PCL !!!" << std::endl;
pcl::PointCloud<pcl::PointXYZRGB>::Ptr point_cloud_ptr (new pcl::PointCloud<pcl::PointXYZRGB>);
uint8_t r(255), g(15), b(15);
for (float z(-1.0); z <= 1.0; z += 0.05)
{
for (float angle(0.0); angle <= 360.0; angle += 5.0)
{
pcl::PointXYZRGB point;
point.x = 0.5 * cosf (pcl::deg2rad(angle));
point.y = sinf (pcl::deg2rad(angle));
point.z = z;
uint32_t rgb = (static_cast<uint32_t>(r) << 16 |
static_cast<uint32_t>(g) << 8 | static_cast<uint32_t>(b));
point.rgb = *reinterpret_cast<float*>(&rgb);
point_cloud_ptr->points.push_back (point);
}
if (z < 0.0)
{
r -= 12;
g += 12;
}
else
{
g -= 12;
b += 12;
}
}
point_cloud_ptr->width = (int) point_cloud_ptr->points.size ();
point_cloud_ptr->height = 1;
pcl::visualization::CloudViewer viewer ("test");
viewer.showCloud(point_cloud_ptr);
while (!viewer.wasStopped()){ };
return 0;
}
CMake 可以给我一个正确的 Makefile ,命令 make 没有问题。我得到了可执行文件,但是当我运行它时,它抛出了一个异常:
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'NSWindow drag regions should only be invalidated on the Main Thread!'
我不明白。所有代码都在 main 函数中,但 CloudViewer 似乎在子线程中运行。我认为这可能与我的 Xcode 事情有关。这是我的电脑配置:
- 操作系统:大苏尔
- 苹果硅