Symmetry-preserving mesh from marching cube in python

119 Views Asked by At

I want to obtain a mesh from a marching cube that preserves the mirror symmetries along x, along y and z of my object. The position of the vertices do preserve these symmetries, but not the faces. How can I manage this?

Here is an example below for a sphere. One can see that the faces do not respect these symmetries.

Sphere marching cube

import numpy as np
from skimage.measure import marching_cubes
import trimesh
import pyvista as pv

# Define the resolution of the marching cubes grid
grid_resolution = 10

# Create a binary mask of the sphere using skimage's marching_cubes
x, y, z = np.ogrid[-1:1:grid_resolution*1j, -1:1:grid_resolution*1j, -1:1:grid_resolution*1j]
sphere_mask = x**2 + y**2 + z**2 <= 1.0

# Extract vertices and faces from the marching cubes result
vertices, faces, _, _ = marching_cubes(sphere_mask, level=0)

# Create a trimesh object
mesh = trimesh.Trimesh(vertices=vertices, faces=faces)

# Plot the sphere using pyvista
plotter = pv.Plotter()
plotter.add_mesh(mesh, color='lightblue', show_edges=True)
plotter.show()
0

There are 0 best solutions below