MCPcopy Create free account
hub / github.com/JeremyBYU/polylidar / main

Function main

examples/cpp/polylidar-full-example.cpp:37–136  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

35}
36
37int main(int argc, char const* argv[])
38{
39 std::cout << "A more complete example of using Polylidar3D with 3D Data. Needs Open3D and FastGA." << std::endl;
40
41 // Load Point Cloud Data
42 std::vector<unsigned long> shape;
43 bool fortran_order;
44 std::vector<double> data;
45 std::cout << "Loading previously captured Organized Point Cloud from an L515 Camera." << std::endl;
46 try
47 {
48 std::cout << "Attempting to load OPC file from ./fixtures/realsense/opc_example_one/L515_OPC.npy" << std::endl;
49 npy::LoadArrayFromNumpy("./fixtures/realsense/opc_example_one/L515_OPC.npy", shape, fortran_order, data);
50 }
51 catch (const std::exception& e)
52 {
53 try
54 {
55 std::cout << "Last chance. Trying to load OPC file from ../fixtures/realsense/opc_example_one/L515_OPC.npy"
56 << std::endl;
57 npy::LoadArrayFromNumpy("../fixtures/realsense/opc_example_one/L515_OPC.npy", shape, fortran_order, data);
58 }
59 catch (const std::exception& e)
60 {
61 std::cout << "Can't find L515_OPC.npy file. Exiting..." << std::endl;
62 std::exit(1);
63 }
64 }
65
66 // Create Matrix Wrapper around Point Cloud Data (no copy)
67 std::cout << "Shape of Point Cloud is: " << shape << std::endl;
68 auto num_points = shape[0] * shape[1];
69 auto cols = shape[2]; // 3
70 // Expected to be a num_points X 3 array but **organized* in memory
71 Polylidar::Matrix<double> opc(data.data(), num_points, cols);
72
73 // Visualize Point Cloud
74 std::cout << "Visualizing Point Cloud. Rotate View. Close Open3D window when satisfied..." << std::endl;
75 auto pcd_eigen = VisUtility::MapEigen<Eigen::Vector3d>(opc);
76 std::shared_ptr<open3d::geometry::PointCloud> pointcloud_ptr(new open3d::geometry::PointCloud(pcd_eigen));
77 open3d::visualization::DrawGeometries({pointcloud_ptr});
78
79 // Create Mesh From Point Cloud
80 std::cout << "Creating Mesh and smoothing. NOT using optimized filters, see OrganizedPointFilters" << std::endl;
81 Polylidar::MeshHelper::HalfEdgeTriangulation tri_mesh;
82 Polylidar::VUI valid_idx;
83 std::tie(tri_mesh, valid_idx) =
84 Polylidar::MeshHelper::ExtractTriMeshFromOrganizedPointCloud(opc, shape[0], shape[1], 1, true);
85 Polylidar::MeshHelper::LaplacianFilterVertices(tri_mesh, 3, 1.0);
86 tri_mesh.ComputeTriangleNormals();
87 Polylidar::MeshHelper::BilateralFilterNormals(tri_mesh, 5, 0.2, 0.25);
88
89 // Visualize Mesh
90 std::cout << "Visualizing mesh. Rotate View." << std::endl;
91 auto o3d_mesh = VisUtility::CreateOpen3DMesh(tri_mesh);
92 open3d::visualization::DrawGeometries({o3d_mesh});
93
94 // Find Dominant Plane Normals

Callers

nothing calls this directly

Calls 11

LaplacianFilterVerticesFunction · 0.85
BilateralFilterNormalsFunction · 0.85
CreateOpen3DMeshFunction · 0.85
DownSampleNormalsFunction · 0.85
ConvertMatX3dtoMatrixFunction · 0.85
NextColorFunction · 0.85
PaintPlaneFunction · 0.85
CreateLineSetFromPolygonFunction · 0.85

Tested by

no test coverage detected