BVtkNodes icon indicating copy to clipboard operation
BVtkNodes copied to clipboard

Extracting multiple meshes from a single vtk file

Open Alexxkrehmen opened this issue 3 years ago • 9 comments

Hi,

I have a big vtk file (6.3 GB) which takes ages to parse and I would like to automate the extraction of multiple meshes from it.

The file is containing voxels with ids of different cellular bodies. In total I have 53 items to extracts from this file. Some of them have neighbouring voxels, so when extracting everything in one row, they are glued together in the same mesh, and I have to manually seperate them and fill the gaps, which is quite tedious.

I've found a way to extract each mesh one by one, using this setup :

image

In the vtkThreshold node I use the int id - 0.5 and id + 0.5 values to isolate the item I want to extract (so here, 12.5 and 13.5 to get the item with id 13)

This gives the expected result for this item... But it takes several minutes. So, unless a better (and faster) solution is available, I would like to automate this process to extract all the 53 meshes.

I've tried to write this little script :


import bpy
import time

for value in range(1,53):
    print(value)
    bpy.data.node_groups["NodeTree"].nodes["vtkThreshold"].m_Value1 = value - 0.5
    bpy.data.node_groups["NodeTree"].nodes["vtkThreshold"].m_Value2 = value + 0.5

    bpy.data.node_groups["NodeTree"].nodes["VTK To Blender Mesh"].m_Name = "mesh"+str(value)

    bpy.ops.node.bvtk_node_update(node_path="bpy.data.node_groups['NodeTree'].nodes['VTK To Blender Mesh']")

But it is not working as expected : the bvtk_node_update() function seems to be asynchronous, and so the "for" loop is continuing to run while the first mesh is still not generated.

What should be done here ? Thanks for your help !

Alexxkrehmen avatar Nov 27 '20 19:11 Alexxkrehmen