Skip to content

Commit 8c4a897

Browse files
committed
ADD-WIP: cloud to mesh distance (to plane)
1 parent 56dff2e commit 8c4a897

File tree

2 files changed

+69
-15
lines changed

2 files changed

+69
-15
lines changed

src/diffCheck.hh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#pragma once
22

33
#include <open3d/Open3D.h>
4+
#include <open3d/t/geometry/RaycastingScene.h>
5+
46
#include <loguru.hpp>
57

68
// diffCheck includes

src/diffCheckApp.cc

Lines changed: 67 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <iostream>
44
#include <fstream>
55

6+
#include <open3d/Open3D.h>
7+
// #include <open3d/t/geometry/RaycastingScene.h>
68

79
int main()
810
{
@@ -13,38 +15,88 @@ int main()
1315
= std::make_shared<diffCheck::geometry::DFMesh>();
1416

1517
// create a sphere from o3d
16-
std::string pathCloud = R"(C:\andre\Downloads\moved_04.ply)";
18+
std::string pathCloud = R"(C:\Users\andre\Downloads\moved_04.ply)";
1719
std::string pathMesh = R"(C:\Users\andre\Downloads\meshtest.ply)";
1820

19-
// dfPointCloudPtr->LoadFromPLY(pathCloud);
21+
dfPointCloudPtr->LoadFromPLY(pathCloud);
2022
dfMeshPtr->LoadFromPLY(pathMesh);
2123

2224
open3d::geometry::TriangleMesh meshO3d = *dfMeshPtr->Cvt2O3DTriangleMesh();
25+
open3d::geometry::PointCloud pointCloudO3d = *dfPointCloudPtr->Cvt2O3DPointCloud();
2326

27+
auto rayCastingScene = open3d::t::geometry::RaycastingScene();
28+
// Get the vertices of the mesh
29+
std::vector<Eigen::Vector3d> vertices = meshO3d.vertices_;
2430

25-
// convert the sphere to a diffCheck point cloud
26-
// auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);
31+
// Convert the vertices to a tensor
32+
std::vector<float> verticesPosition;
33+
for (const auto& vertex : vertices) {
34+
verticesPosition.insert(verticesPosition.end(), vertex.data(), vertex.data() + 3);
35+
}
36+
open3d::core::Tensor verticesPositionTensor(verticesPosition.data(), {static_cast<int64_t>(vertices.size()), 3}, open3d::core::Dtype::Float32);
37+
38+
std::vector<uint32_t> triangles;
39+
for (int i = 0; i < meshO3d.triangles_.size(); i++) {
40+
triangles.push_back(static_cast<uint32_t>(meshO3d.triangles_[i].x()));
41+
triangles.push_back(static_cast<uint32_t>(meshO3d.triangles_[i].y()));
42+
triangles.push_back(static_cast<uint32_t>(meshO3d.triangles_[i].z()));
43+
}
44+
open3d::core::Tensor trianglesTensor(triangles.data(), {static_cast<int64_t>(meshO3d.triangles_.size()), 3}, open3d::core::Dtype::UInt32);
45+
46+
rayCastingScene.AddTriangles(verticesPositionTensor, trianglesTensor);
47+
48+
// compute the cloud to mesh signed distance
49+
std::vector<float> cloudPoints;
50+
for (const auto& point : pointCloudO3d.points_) {
51+
cloudPoints.insert(cloudPoints.end(), point.data(), point.data() + 3);
52+
}
53+
open3d::core::Tensor cloudPointsTensor(cloudPoints.data(), {static_cast<int64_t>(pointCloudO3d.points_.size()), 3}, open3d::core::Dtype::Float32);
54+
55+
56+
open3d::core::Tensor sdf = rayCastingScene.ComputeSignedDistance(cloudPointsTensor);
57+
58+
// if true, get the absolute value of the sdf
59+
if (true) {
60+
sdf = sdf.Abs();
61+
}
62+
63+
// convert sdf to a vector
64+
std::vector<float> sdfVector(sdf.GetDataPtr<float>(), sdf.GetDataPtr<float>() + sdf.NumElements());
2765

28-
std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();
2966

30-
// compute the bounding box
31-
open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
32-
std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
33-
for (auto &pt : bboxPts)
67+
// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
68+
// compute point cloud to point cloud distance
69+
auto distances = dfPointCloudPtr->ComputeP2PDistance(dfPointCloudPtr);
70+
for (auto &dist : distances)
3471
{
35-
tightBBOX->points_.push_back(pt);
72+
std::cout << dist << std::endl;
3673
}
3774

3875

39-
dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);
76+
77+
// // convert the sphere to a diffCheck point cloud
78+
// // auto o3dPointCloud = meshO3d.SamplePointsUniformly(1000);
79+
80+
// std::shared_ptr<open3d::geometry::PointCloud> tightBBOX = std::make_shared<open3d::geometry::PointCloud>();
81+
82+
// // compute the bounding box
83+
// open3d::geometry::OrientedBoundingBox bbox = meshO3d.GetMinimalOrientedBoundingBox();
84+
// std::vector<Eigen::Vector3d> bboxPts = bbox.GetBoxPoints();
85+
// for (auto &pt : bboxPts)
86+
// {
87+
// tightBBOX->points_.push_back(pt);
88+
// }
89+
90+
91+
// dfPointCloudPtr->Cvt2DFPointCloud(tightBBOX);
4092

4193

4294

4395

44-
std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
45-
vis->AddPointCloud(dfPointCloudPtr);
46-
// vis->AddMesh(dfMeshPtr);
47-
vis->Run();
96+
// std::shared_ptr<diffCheck::visualizer::Visualizer> vis = std::make_shared<diffCheck::visualizer::Visualizer>();
97+
// vis->AddPointCloud(dfPointCloudPtr);
98+
// // vis->AddMesh(dfMeshPtr);
99+
// vis->Run();
48100

49101

50102
return 0;

0 commit comments

Comments
 (0)