Giter Club home page Giter Club logo

Comments (6)

JeffreyWardman avatar JeffreyWardman commented on July 3, 2024

An 8 gets created for the LHS but not RHS in this example even though points are only assigned labels 0 or 9.

import numpy as np
import vedo

sphere = vedo.Sphere()
sphere.pointdata["Labels"] = np.zeros(sphere.npoints).astype(np.uint16)
sphere.copy().cut_with_plane(origin=(0, 0, 0), normal=(0, 0, -1))

xmin, xmax, ymin, ymax, zmin, zmax = sphere.bounds()

sphere.pointdata["Labels"][np.nonzero(sphere.vertices[:, 1] > (ymin + ymax) / 2)[0]] = 0
sphere.pointdata["Labels"][np.nonzero(sphere.vertices[:, 1] <= (ymin + ymax) / 2)[0]] = 9


sphere.cmap("jet", sphere.pointdata["Labels"])

vedo.show(sphere, axes=1).close()

left = sphere.copy().cut_with_plane(
    origin=((xmin + xmax) / 2 + 0.001, (ymin + ymax) / 2 + 0.001, (zmin + zmax) / 2 + 0.001), normal=(1, 0, 0)
)
l_labels = left.pointdata["Labels"]
print(np.unique(l_labels))

left.show().close()


right = sphere.copy().cut_with_plane(
    origin=sphere.vertices[0],
    normal=(1, 0, 0),
    invert=True,
)
r_labels = right.pointdata["Labels"]
print(np.unique(r_labels))
right.show().close()

The reason seems to be if cut_with_plane has some value that the vertices don't directly touch, therefore the algorithm generates new faces for some reason.

from vedo.

marcomusy avatar marcomusy commented on July 3, 2024

Hi - yes this is how VTK works, it interpolates the values to the new created vertices (which must be created to match the cutting plane surface):

import numpy as np
import vedo

vedo.settings.interpolate_scalars_before_mapping = False

sphere = vedo.Sphere(res=12).lw(1)
sphere.pointdata["Labels"] = np.zeros(sphere.npoints).astype(np.uint16)

xmin, xmax, ymin, ymax, zmin, zmax = sphere.bounds()

ids0 = np.nonzero(sphere.vertices[:, 1]  > 0)[0]
ids9 = np.nonzero(sphere.vertices[:, 1] <= 0)[0]
sphere.pointdata["Labels"][ids0] = 0
sphere.pointdata["Labels"][ids9] = 9
print(np.unique(sphere.pointdata["Labels"]))

sphere.cmap("jet", "Labels", vmin=0, vmax=9)
# vedo.show(sphere, axes=1).close()

left = sphere.copy().cut_with_plane(origin=[0.1,0,0])
l_labels = left.pointdata["Labels"]
print(np.unique(l_labels))
left.show(axes=1).close()

Screenshot from 2024-04-03 21-05-36

[0 9]
[0 3 4 5 6 9]

this is an expected behavior..

from vedo.

JeffreyWardman avatar JeffreyWardman commented on July 3, 2024

Is there a way to cut_with_plane without creating the new points and faces? Or to customise the interpolation method/get the newly generated point IDs?

from vedo.

marcomusy avatar marcomusy commented on July 3, 2024

you can grab the resulting array and threshold it manually in python/numpy.
Or check out examples:
examples/basic/mesh_threshold.py

from vedo.

JeffreyWardman avatar JeffreyWardman commented on July 3, 2024

Is it possible to output the ids of the new vertices to make it a bit simpler? Or to assign them a pointdata?

from vedo.

marcomusy avatar marcomusy commented on July 3, 2024

the only thing that comes up to my mind is again the .add_ids() ...

from vedo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.