vedo icon indicating copy to clipboard operation
vedo copied to clipboard

Isosurface smoothing problems

Open omaralvarez opened this issue 6 months ago • 4 comments

I am trying to render the isosurface of a CFD dataset, but the isosurface reconstruction does not look smooth:

               vol_size = (
                    xp.array([ts.sim.grid.width, ts.sim.grid.height, ts.sim.grid.depth])
                    * 5
                )

                # Create a 3D grid for vorticity data
                x_coords = xp.linspace(
                    ts.sim.grid.xinterpmin, ts.sim.grid.xinterpmax, vol_size[0]
                )
                y_coords = xp.linspace(
                    ts.sim.grid.yinterpmin, ts.sim.grid.yinterpmax, vol_size[1]
                )
                z_coords = xp.linspace(
                    ts.sim.grid.zinterpmin, ts.sim.grid.zinterpmax, vol_size[2]
                )

                x_grid, y_grid, z_grid = xp.meshgrid(x_coords, y_coords, z_coords)

                x_sp = (ts.sim.grid.xinterpmax - ts.sim.grid.xinterpmin) / vol_size[0]
                y_sp = (ts.sim.grid.yinterpmax - ts.sim.grid.yinterpmin) / vol_size[1]
                z_sp = (ts.sim.grid.zinterpmax - ts.sim.grid.zinterpmin) / vol_size[2]

                x_o = ts.sim.grid.xinterpmin
                y_o = ts.sim.grid.yinterpmin
                z_o = ts.sim.grid.zinterpmin

                vol = griddata(
                    (x, y, z),
                    fields["vorticity_mag"].ravel(),
                    (x_grid, y_grid, z_grid),
                    method="nearest",
                ).swapaxes(0, 1)
                # ic(vol.shape)

                colormap = "jet"
                thresh = 500

                # vol = xp.clip(vol, 0, 1000)

                # Create a vedo Volume from the vorticity data
                volume = Volume(vol, spacing=[x_sp, y_sp, z_sp], origin=[x_o, y_o, z_o])

                iso = (
                    # volume.legosurface(vmin=thresh, vmax=fields["vorticity_mag"].max())
                    volume.isosurface(value=xp.linspace(100, 1000, 10))
                    .smooth(niter=100)
                    .cmap(colormap, vmin=thresh, vmax=1000)
                    .add_scalarbar3d()
                )

Image

Any ideas on how to get better results?

With legosurface everything looks normal, but I want a smooth mesh.

omaralvarez avatar May 16 '25 21:05 omaralvarez

Define "better results" :)

The isosurface will produce a rough surface if the underlying scalar is noisy..

marcomusy avatar May 29 '25 12:05 marcomusy

You are right, there might be noise in the scalar. Is there a way to smooth the result further? When I turn up smoothing it does not seem to have much effect on the final result.

Additionally I would like to color the isosurface based on a second scalar that was not used to create the isosurface but also has the same spatial distribution. Is this possible?

omaralvarez avatar May 29 '25 15:05 omaralvarez

You are right, there might be noise in the scalar. Is there a way to smooth the result further? When I turn up smoothing it does not seem to have much effect on the final result.

Yes - you can do it at the level of the Volume object instead of the polygonal surface by cutting off high-freq noise. Check out example vedo -r lowpassfilter

Additionally I would like to color the isosurface based on a second scalar that was not used to create the isosurface but also has the same spatial distribution. Is this possible?

Yes of course, check out example vedo -r multiscalars

marcomusy avatar May 29 '25 15:05 marcomusy

I will test both and let you know how it goes. Thanks!

omaralvarez avatar May 29 '25 15:05 omaralvarez