tkeskita / BVtkNodes

Create and execute VTK pipelines in Blender Node Editor
GNU General Public License v3.0
111 stars 19 forks source link

Triangle elements in VTK Unstructured Grids convert incorrectly #20

Open topabs61 opened 3 years ago

topabs61 commented 3 years ago

Hello. I'm doing Scientific Visualization with VTK and Paraview. I'm so glad to find your add-on that works with Blender. However, when I open VTK or VTU, the mesh connectivity is distorted as shown below.

I upload corresponding screenshot. This example comes from below URL. If there is something wrong or there is a solution, please let me know. [1] (https://lorensen.github.io/VTKExamples/site/Cxx/IO/ReadLegacyUnstructuredGrid/) image

image

tkeskita commented 3 years ago

Hi, I think you need to add vtkGeometryFilter in between, please check this example in the documentation.

topabs61 commented 3 years ago

Thanks for the response! Most of the meshes seem to be connected properly. Only one element type is still distorted.

image

tkeskita commented 3 years ago

Thanks for testing! Looks like vtkPolyLine (or vtkTriangle?) and vtkTriangleStrip are converted incorrectly.

tkeskita commented 3 years ago

Some of the incorrect conversion might be due to vtkGeometryFilter, according to docs it

assumes that the input dataset is composed of either: 0D cells OR 1D cells OR 2D and/or 3D cells. In other words, the input dataset cannot be a combination of different dimensional cells with the exception of 2D and 3D cells

The main cause is the current surface mesh conversion routine vtkdata_to_blender(), which does mesh conversion simply by connecting lists of vertices (as-is) to create faces, without considering VTK cell types and their vertex semantics. Therefore it produces wrong results if plugged in directly as in your first example.

I'm thinking about rewriting a new Blender surface mesh conversion routine which would convert all native linear + polyhedron VTK cell types directly to Blender mesh. Needs some thinking first.. maybe always exclude internal faces.. Also could optionally include internal vertices in conversion, sometimes I've wanted that.

tkeskita commented 3 years ago

Here's my plan for a new VTK To Blender Mesh node, which would extract surface meshes directly from linear + polyhedron VTK cells, without need for vtkGeometryFilter in between.

Node would have boolean options:

Technical implementation: Process all VTK cells, and separate each face of 3D cells into a list of face vertices. Face verts would be added into an extraction list, unless same vertices are already in the list, which means face is internal. In that case face would be instead removed from list. This results in only boundary face verts remaining in the list, and it's possible to generate mesh from those. Implementation of this in Python will likely be much slower than current VTK To Blender, at least for typical unstructured grids containing many internal cells, so at least the first version couldn't replace VTK To Blender.

tkeskita commented 3 years ago

FYI I've added all linear cells' conversion to VTK To Blender Mesh node, now it should work correctly in latest add-on version.