11#include " diffCheck/geometry/DFMesh.hh"
22#include " diffCheck/IOManager.hh"
33
4+ #include < open3d/t/geometry/RaycastingScene.h>
5+
46
57namespace diffCheck ::geometry
68{
@@ -145,4 +147,39 @@ namespace diffCheck::geometry
145147 this ->NormalsFace = tempMesh_ptr->NormalsFace ;
146148 this ->ColorsFace = tempMesh_ptr->ColorsFace ;
147149 }
150+
151+ std::vector<float > DFMesh::ComputeDistance (const diffCheck::geometry::DFPointCloud &targetCloud, bool useAbs)
152+ {
153+ auto rayCastingScene = open3d::t::geometry::RaycastingScene ();
154+
155+ std::vector<Eigen::Vector3d> vertices = this ->Vertices ;
156+ std::vector<float > verticesPosition;
157+ for (const auto & vertex : vertices) {
158+ verticesPosition.insert (verticesPosition.end (), vertex.data (), vertex.data () + 3 );
159+ }
160+ open3d::core::Tensor verticesPositionTensor (verticesPosition.data (), {static_cast <int64_t >(vertices.size ()), 3 }, open3d::core::Dtype::Float32);
161+ std::vector<uint32_t > triangles;
162+ for (int i = 0 ; i < this ->Faces .size (); i++) {
163+ triangles.push_back (static_cast <uint32_t >(this ->Faces [i].x ()));
164+ triangles.push_back (static_cast <uint32_t >(this ->Faces [i].y ()));
165+ triangles.push_back (static_cast <uint32_t >(this ->Faces [i].z ()));
166+ }
167+ open3d::core::Tensor trianglesTensor (triangles.data (), {static_cast <int64_t >(this ->Faces .size ()), 3 }, open3d::core::Dtype::UInt32);
168+ rayCastingScene.AddTriangles (verticesPositionTensor, trianglesTensor);
169+
170+ auto pointCloudO3dCopy = targetCloud;
171+ std::shared_ptr<open3d::geometry::PointCloud> pointCloudO3d_ptr = pointCloudO3dCopy.Cvt2O3DPointCloud ();
172+ std::vector<float > cloudPoints;
173+ for (const auto & point : pointCloudO3d_ptr->points_ ) {
174+ cloudPoints.insert (cloudPoints.end (), point.data (), point.data () + 3 );
175+ }
176+ open3d::core::Tensor cloudPointsTensor (cloudPoints.data (), {static_cast <int64_t >(pointCloudO3d_ptr->points_ .size ()), 3 }, open3d::core::Dtype::Float32);
177+
178+ open3d::core::Tensor sdf = rayCastingScene.ComputeSignedDistance (cloudPointsTensor);
179+ if (useAbs)
180+ sdf = sdf.Abs ();
181+ std::vector<float > sdfVector (sdf.GetDataPtr <float >(), sdf.GetDataPtr <float >() + sdf.NumElements ());
182+
183+ return sdfVector;
184+ }
148185} // namespace diffCheck::geometry
0 commit comments