Skip to content

Commit

Permalink
add another example for create_isosurfaces() (#7068)
Browse files Browse the repository at this point in the history
  • Loading branch information
benjaminum authored Nov 27, 2024
1 parent b65896f commit 4c3fc34
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion cpp/open3d/t/geometry/TriangleMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -598,7 +598,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).
Expand Down
23 changes: 21 additions & 2 deletions cpp/pybind/t/geometry/trianglemesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -586,11 +586,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(
Expand Down

0 comments on commit 4c3fc34

Please sign in to comment.