程序示例精选
C++ VS Open3D点云显示颜色渲染滤波
如需安装运行环境或远程调试,可点击 博主头像进入个人主页查看博主联系方式,由专业技术人员远程协助!
前言
这篇博客针对《C++ VS Open3D点云显示颜色渲染滤波编》写代码,代码整洁,规则,易读。 学习与应用推荐首选。
运行结果
文章目录
一、所需工具软件二、使用步骤
1. 主要代码
4. 运行结果
三、在线协助
一、所需工具软件
1. VS2019, C++2. PCL点云
二、使用步骤
代码如下(示例):
#include #include "open3d/Open3D.h" using namespace open3d; void SingleObject() { // No colors, no normals, should appear unlit black auto cube = geometry::TriangleMesh::CreateBox(1, 2, 4); } void MultiObjects() { const double pc_rad = 1.0; auto pc_nocolor = MakePointCloud(100, {0.0, -2.0, 0.0}, pc_rad, false); auto pc_color = MakePointCloud(100, {3.0, -2.0, 0.0}, pc_rad, true); const double r = 0.4; auto sphere_unlit = geometry::TriangleMesh::CreateSphere(r); sphere_unlit->Translate({0.0, 1.0, 0.0}); auto sphere_colored_unlit = geometry::TriangleMesh::CreateSphere(r); sphere_colored_unlit->PaintUniformColor({1.0, 0.0, 0.0}); sphere_colored_unlit->Translate({2.0, 1.0, 0.0}); auto sphere_lit = geometry::TriangleMesh::CreateSphere(r); sphere_lit->ComputeVertexNormals(); sphere_lit->Translate({4, 1, 0}); auto sphere_colored_lit = geometry::TriangleMesh::CreateSphere(r); sphere_colored_lit->ComputeVertexNormals(); sphere_colored_lit->PaintUniformColor({0.0, 1.0, 0.0}); sphere_colored_lit->Translate({6, 1, 0}); auto big_bbox = std::make_shared( Eigen::Vector3d{-pc_rad, -3, -pc_rad}, Eigen::Vector3d{6.0 + r, 1.0 + r, pc_rad}); auto bbox = sphere_unlit->GetAxisAlignedBoundingBox(); auto sphere_bbox = std::make_shared( bbox.min_bound_, bbox.max_bound_); sphere_bbox->color_ = {1.0, 0.5, 0.0}; auto lines = geometry::LineSet::CreateFromAxisAlignedBoundingBox( sphere_lit->GetAxisAlignedBoundingBox()); auto lines_colored = geometry::LineSet::CreateFromAxisAlignedBoundingBox( sphere_colored_lit->GetAxisAlignedBoundingBox()); lines_colored->PaintUniformColor({0.0, 0.0, 1.0}); visualization::Draw({pc_nocolor, pc_color, sphere_unlit, sphere_colored_unlit, sphere_lit, sphere_colored_lit, big_bbox, sphere_bbox, lines, lines_colored}); } void Actions() { const char *SOURCE_NAME = "Source"; const char *RESULT_NAME = "Result (Poisson reconstruction)"; const char *TRUTH_NAME = "Ground truth"; auto bunny = std::make_shared(); io::ReadTriangleMesh(TEST_DIR + "/Bunny.ply", *bunny); if (bunny->vertices_.empty()) { utility::LogError( "Please download the Standford Bunny dataset using:\n" " cd /examples/python\n" " python -c 'from open3d_tutorial import *; " "get_bunny_mesh()'"); return; } bunny->PaintUniformColor({1, 0.75, 0}); bunny->ComputeVertexNormals(); auto cloud = std::make_shared(); cloud->points_ = bunny->vertices_; cloud->normals_ = bunny->vertex_normals_; cloud->PaintUniformColor({0, 0.2, 1.0}); auto make_mesh = [SOURCE_NAME, RESULT_NAME]( visualization::visualizer::O3DVisualizer &o3dvis) { std::shared_ptr source = std::dynamic_pointer_cast( o3dvis.GetGeometry(SOURCE_NAME).geometry); auto mesh = std::get<0>( geometry::TriangleMesh::CreateFromPointCloudPoisson(*source)); mesh->PaintUniformColor({1, 1, 1}); mesh->ComputeVertexNormals(); o3dvis.AddGeometry(RESULT_NAME, mesh); o3dvis.ShowGeometry(SOURCE_NAME, false); }; auto toggle_result = [TRUTH_NAME, RESULT_NAME](visualization::visualizer::O3DVisualizer &o3dvis) { bool truth_vis = o3dvis.GetGeometry(TRUTH_NAME).is_visible; o3dvis.ShowGeometry(TRUTH_NAME, !truth_vis); o3dvis.ShowGeometry(RESULT_NAME, truth_vis); }; visualization::Draw({visualization::DrawObject(SOURCE_NAME, cloud), visualization::DrawObject(TRUTH_NAME, bunny, false)}, "Open3D: Draw Example: Actions", 1024, 768, { {"Create Mesh", make_mesh}, {"Toggle truth/result", toggle_result}}); } void Selections() { std::cout << "Selection example:" << std::endl; std::cout << " One set: pick three points from the source (yellow), " << std::endl; std::cout << " then pick the same three points in the target" "(blue) cloud" << std::endl; std::cout << " Two sets: pick three points from the source cloud, " << std::endl; std::cout << " then create a new selection set, and pick the" << std::endl; std::cout << " three points from the target." << std::endl; const auto cloud0_path = TEST_DIR + "/ICP/cloud_bin_0.pcd"; const auto cloud1_path = TEST_DIR + "/ICP/cloud_bin_2.pcd"; auto source = std::make_shared(); io::ReadPointCloud(cloud0_path, *source); if (source->points_.empty()) { utility::LogError("Could not open {}", cloud0_path); return; } auto target = std::make_shared(); io::ReadPointCloud(cloud1_path, *target); if (target->points_.empty()) { utility::LogError("Could not open {}", cloud1_path); return; } source->PaintUniformColor({1.000, 0.706, 0.000}); target->PaintUniformColor({0.000, 0.651, 0.929}); const char *source_name = "Source (yellow)"; const char *target_name = "Target (blue)"; auto DoICPOneSet = [source, target, source_name, target_name](visualization::visualizer::O3DVisualizer &o3dvis) { auto sets = o3dvis.GetSelectionSets(); if (sets.empty()) { utility::LogWarning( "You must select points for correspondence before " "running ICP!"); return; } auto &source_picked_set = sets[0][source_name]; auto &target_picked_set = sets[0][target_name]; std::vector source_picked(source_picked_set.begin(), source_picked_set.end()); std::vector target_picked(target_picked_set.begin(), target_picked_set.end()); std::sort(source_picked.begin(), source_picked.end()); std::sort(target_picked.begin(), target_picked.end()); auto t = GetICPTransform(*source, *target, source_picked, target_picked); source->Transform(t); // Update the source geometry o3dvis.RemoveGeometry(source_name); o3dvis.AddGeometry(source_name, source); }; int main(int argc, char **argv) { if (!utility::filesystem::DirectoryExists(TEST_DIR)) { utility::LogError( "directory"); } SingleObject(); }
运行结果
三、在线协助:
如需安装运行环境或远程调试,可点击博主头像,进入个人主页查看博主联系方式,由专业技术人员远程协助!
1)远程安装运行环境,代码调试
2)Visual Studio, Qt, C++, Python编程语言入门指导
3)界面美化
4)软件制作