tkeskita / BVtkNodes

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

Feature Request: TTK Support #89

Closed JonasLukasczyk closed 1 year ago

JonasLukasczyk commented 2 years ago

Hi everyone, I'm a senior developer of the Topology ToolKit (TTK) and I'm wondering how complex it would be to get TTK filters to work with BVtkNodes. To oversimplify: TTK is basically a collection of additional VTK filters which can even be accessed through python (using VTK's python binding mechanism). It is possible to install ttk via anaconda, but unfortunately not via pip. Can you give me some pointers on how that could be achieved? An analogous question would be on how to integrate a homegrown VTK filter written in C++ which is not part of the VTK repository but uses VTK as a library.

Best Jonas

tkeskita commented 2 years ago

Hi,

I'm not sure. The idea of BVTKNodes is that it allows VTK objects to be handled from the Blender Node tree via Python. The VTK elevation filter is a simple example, here's the automatically generated code for the node class. I think if you have a Python class which inherits from vtkAlgorithm you might be able to bind it to BVTKNodes in similar fashion, and maybe it works like any other filter in the pipeline? You can test it if you add such a class definition to e.g. file custom_nodes/VTKFilters.py. There you'll also find more examples of customized nodes.

Another alternative might be to add the Python code to Custom Filter Node, but that code is currently run quite often in Blender, so it may be very slow to use.

BR, Tuomo

JonasLukasczyk commented 2 years ago

Thank you, that is helpful!

It would be perfect if we could auto-generate the nodes for the ttk filters in the same way it is currently done for VTK filters. How do you determine the python classes (vtk filters) that are going to be processed? Could we simply add the ttk filters to that list either manually or instruct BVTKNodes to search the ttk python namespace for ttk filters (all of them inherit from vtkAlgorithm)?

Best Jonas

tkeskita commented 2 years ago

Hello,

yes, you could modify the code parsing of vtk classes (see files in generate folder: populate_db.py and vtk_info.py, finally generate.py creates the files in generated_nodes folder from the db). The parsing heuristics is layed out in vtk_info.py. It's not perfect but it goes so far it works for most VTK classes (thanks to the original developer who did this!).

JonasLukasczyk commented 1 year ago

Hi all, I just want to record my findings if someone is interested in this in the future.

It is possible to feed all ttkAlgorithm classes to the parsing procedure that iterates over all vtkAlgorithm classes to create BVTK nodes. This only requires small changes such as also enabling the ttk classname prefix instead of just vtk. But unfortunately it is not possible to derive all class properties automatically just by introspection. For instance, almost all ttkAlgorithm classes uses the SetInputArrayToProcess method provided by vtkAlgorithm. By just looking at the python classes it is not possible to determine how many arrays actually need to be set; thus it is not possible to automatically provide all required node properties. I guess this is a problem that already became apparent by processing the vtk classes and was solved by providing specific instructions for certain vtk classes. ParaView solves this issue in the same way by actually requiring an xml file that lists all properties of a filter and how they need to rendered (e.g., by also providing min/max values or hiding one property when another is enabled and so on). If I were to pursue this further, I would try to parse these xml files to generate BVTK nodes instead of providing (in some sense redundant) instructions inside BVTK.

I guess I will close this request for now, but I still would be curious what you (@tkeskita) think.

Best Jonas

tkeskita commented 1 year ago

Hi,

yes setting up arrays to process is not trivial. For this purpose there is the Custom Code capability to work around this issue. But it is not super convenient. Some single nodes have been manually customized to be user friendly, but vast majority stand as-is-generated. Already now upgrading the custom nodes when VTK changes happen is a burden, so manual fixes is not a good solution in the long run.

I'm not familiar with how Paraview works internally, maybe that kind of processing would work.

Aside: One of the issues I have with Paraview is that it assumes I want to "process nth field", while what I really would like it to do is "process field named velocity". This is an issue when field numbering changes e.g. between time steps, or when you want to pre-define the field to be processed prior to knowing which fields are available. Therefore I've made some custom nodes to require explicit field names.