marcomusy / vedo

A python module for scientific analysis of 3D data based on VTK and Numpy
https://vedo.embl.es
MIT License
2.06k stars 267 forks source link

vtkUnstructuredGrid not directly supported #368

Closed niveshd closed 3 years ago

niveshd commented 3 years ago

vedo.mesh.Mesh class doesn't accept 'vtk.vtkUnstructuredGrid' as input, contrary to the documentation.

class Mesh(Points):
    """
    Build an instance of object ``Mesh`` derived from ``PointCloud``.

    Input can be ``vtkPolyData``, ``vtkActor``, or a python list of [vertices, faces].

    If input is any of ``vtkUnstructuredGrid``, ``vtkStructuredGrid`` or ``vtkRectilinearGrid``
    the geometry is extracted.
    In this case the original VTK data structures can be accessed with: ``mesh.inputdata()``.

From the source code, the case doesn't seem to be considered. Is this a bug or the documentation needs to be updated?

elif isinstance(inputobj, (vtk.vtkStructuredGrid, vtk.vtkRectilinearGrid)):
    if vedo.settings.visibleGridEdges:
        gf = vtk.vtkExtractEdges()
        gf.SetInputData(inputobj)
    else:
        gf = vtk.vtkGeometryFilter()
        gf.SetInputData(inputobj)
    gf.Update()
    self._polydata = gf.GetOutput()

Please let me know if you need more info. I just started using vedo (version 2021.0.2) and am rather new to how it works.

If you have any advice on the recommended way to use unstructured grid, please let me know. I couldn't find anything directly in the examples, other than a reference to Fenics which I don't want to use just for visualization. I found that vedo seamlessly support visualization on jupyter and normal python scripts. So I would be glad to somehow make this work!

marcomusy commented 3 years ago

Hi - thanks for spotting that... indeed the documentation is incorrect. You can use the class UGrid for unstructured grids. Find examples in the examples/volumetric/ area Note that this class is still a bit experimental..

vedo seamlessly support visualization on jupyter and normal python scripts

it's not quite seamless :) indeed various functionalities of the native vtk renderer are not available in jupyter.

niveshd commented 3 years ago

Thanks for the response. UGrid did work. I guess my requirements for the Jupyter visualization are rather modest! I am happy that it works without me fiddling with the code.