From f93c6d8247d86c0377c113beb9789fcd7d11b29d Mon Sep 17 00:00:00 2001 From: Benjamin Ummenhofer Date: Thu, 21 Nov 2024 07:21:47 -0800 Subject: [PATCH] add another example for create_isosurfaces() --- cpp/open3d/t/geometry/TriangleMesh.h | 2 +- cpp/pybind/t/geometry/trianglemesh.cpp | 23 +++++++++++++++++++++-- 2 files changed, 22 insertions(+), 3 deletions(-) diff --git a/cpp/open3d/t/geometry/TriangleMesh.h b/cpp/open3d/t/geometry/TriangleMesh.h index e1ad2625b4b..d93a2ddbf26 100644 --- a/cpp/open3d/t/geometry/TriangleMesh.h +++ b/cpp/open3d/t/geometry/TriangleMesh.h @@ -597,7 +597,7 @@ class TriangleMesh : public Geometry, public DrawableGeometry { const core::Device &device = core::Device("CPU:0")); /// Create a mesh from a 3D scalar field (volume) by computing the - /// isosurface. This method uses the Flying Edges dual contouring method + /// isosurface. This method uses the Flying Edges dual contouring method /// that computes the isosurface similar to Marching Cubes. The center of /// the first voxel of the volume is at the origin (0,0,0). The center of /// the voxel at index [z,y,x] will be at (x,y,z). diff --git a/cpp/pybind/t/geometry/trianglemesh.cpp b/cpp/pybind/t/geometry/trianglemesh.cpp index 7d81279d25d..1578049d563 100644 --- a/cpp/pybind/t/geometry/trianglemesh.cpp +++ b/cpp/pybind/t/geometry/trianglemesh.cpp @@ -584,11 +584,30 @@ This example shows how to create a sphere from a volume:: import open3d as o3d import numpy as np - coords = np.stack(np.meshgrid(*3*[np.linspace(-1,1,num=64)], indexing='ij'), axis=-1) - vol = np.linalg.norm(coords, axis=-1) - 0.5 + grid_coords = np.stack(np.meshgrid(*3*[np.linspace(-1,1,num=64)], indexing='ij'), axis=-1) + vol = 0.5 - np.linalg.norm(grid_coords, axis=-1) mesh = o3d.t.geometry.TriangleMesh.create_isosurfaces(vol) o3d.visualization.draw(mesh) + +This example shows how to convert a mesh to a signed distance field (SDF) and back to a mesh:: + + import open3d as o3d + import numpy as np + + mesh1 = o3d.t.geometry.TriangleMesh.create_torus() + grid_coords = np.stack(np.meshgrid(*3*[np.linspace(-2,2,num=64, dtype=np.float32)], indexing='ij'), axis=-1) + + scene = o3d.t.geometry.RaycastingScene() + scene.add_triangles(mesh1) + sdf = scene.compute_signed_distance(grid_coords) + mesh2 = o3d.t.geometry.TriangleMesh.create_isosurfaces(sdf) + + # Flip the triangle orientation for SDFs with negative values as "inside" and positive values as "outside" + mesh2.triangle.indices = mesh2.triangle.indices[:,[2,1,0]] + + o3d.visualization.draw(mesh2) + )"); triangle_mesh.def(