Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add another example for create_isosurfaces() #7068

Merged
merged 1 commit into from
Nov 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cpp/open3d/t/geometry/TriangleMesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -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).
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 @@ -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(
Expand Down
Loading