Giter Club home page Giter Club logo

Comments (3)

flutefreak7 avatar flutefreak7 commented on May 21, 2024

Figured it out!

When I separated things out and used SetNumpyPoints and SetNumpyFaces, I got a useful error:

Exception: First column should contain the number of points per face

...which I wasn't doing with my faces array. The following now works as expected:

import vtkInterface
import numpy as np
from vtkInterface import PolyData


verts = np.array([[0, 0, 0],
                  [0, 0, 1],
                  [0, 1, 0],
                  [1, 0, 1]], dtype=np.float64)
faces = np.array([[3, 0, 1, 2],
                  [3, 1, 2, 3]], dtype=np.int64)

polydata = PolyData(verts, faces)

polydata.Plot()

As for the example code, which of course does do the faces correctly, the faces refer to a vertex index 4 that doesn't exist... adding that 5th vertex allows the example to not crash:

import numpy as np
import vtkInterface

# mesh points
vertices = np.array([[0, 0, 0],
                     [1, 0, 0],
                     [1, 1, 0],
                     [0, 1, 0],
                     [0.5, 0.5, 1.0]])

# mesh faces
faces = np.hstack([[4, 0, 1, 2, 3],  # square
                   [3, 0, 1, 4],     # triangle
                   [3, 1, 2, 4]])    # triangle

surf = vtkInterface.PolyData(vertices, faces)

# plot each face with a different color
surf.Plot(scalars=np.arange(3))

from pyvista.

akaszynski avatar akaszynski commented on May 21, 2024

Thanks for pointing this out.

I probably should add some error checking code that gives the user a useful error rather than just crashing the interpreter. Doing this check will probably be slow, so I might just implement it in Cython. There's a bunch of other functions that I've been meaning to move over from some of my internal work into vtkInterface, so maybe this is a good chance for me to do it.

Any other recommendations?

from pyvista.

akaszynski avatar akaszynski commented on May 21, 2024

Finally cleaned up the code. Thanks for pointing this out.

from pyvista.

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.