Hi everyone,
I’m TTK developer and we are currently restructuring the VTK layer of TTK to simplify and standardize things. To this end, we want to create a new ‘ttkAlgorithm’ class that inherits from ‘vtkDataSetAlgorithm’ from which all VTK filters in TTK should inherit from in the future. So for an example filter called ‘ttkFilter’ we would have the following inheritance structure:
class VTKFILTERSGENERAL_EXPORT ttkAlgorithm : public vtkDataSetAlgorithm {…}
class VTKFILTERSCORE_EXPORT ttkFilter : public ttkAlgorithm {…}
The problem is that as soon as ‘ttkFilter’ inherits from ‘ttkAlgorithm’ the filter is no longer linked in the TTK plugin as a shared library (even if ‘ttkAlgorithm’ only inherits from ‘vtkDataSetAlgorithm’ without changing/adding anything). However, if ‘ttkFilter’ directly inherits from ‘vtkDataSetAlgorithm’ the filter is correctly linked in the plugin. Is it possible that we use the wrong export macros or what could be the issue here?
Thanks for your quick reply! Currently all TTK filters use the VTKFILTERSCORE_EXPORT macro, but I was not the one who pushed that into TTK so I don’t know why we didn’t write our own macros. But are you confirming that this is the source of the problem?
We discussed this actually yesterday in person and we both got stuck there. It is my understanding that these macros are just needed for cross-platform support (i.e., Windows). If I delete these macros I can observe the same described behavior (as expected I guess since I’m trying this out on linux).
We are currently looking into the macros, but we also found another interesting example where this does not work:
If ‘ttkFilter’ inherits from ‘vtkTableReader’ the filter is not linked in the plugin, but if it instead inherits from ‘vtkTableAlgorithm’ it works. Maybe we need to also adjust something in the vtk.module file:
NAME
ttkFilter
DEPENDS
VTK::FiltersCore
PRIVATE_DEPENDS
VTK::CommonCore
You can use that macro, but because you are not VTK::FiltersCore, the class will not be exported. The name for the macro given your module name will be TKKFILTER_MODULE instead (in a ttkFilterModule.h header).
As for the class differences, vtkTableReader is indeed in VTK::IOLegacy which is not in your list.
I’m sorry but I’m still not able to get this to work, but I think I boiled it down to the following problem:
class ttkAlgorithm : public vtkUnstructuredGridAlgorithm {
public:
static ttkAlgorithm* New();
vtkTypeMacro(ttkAlgorithm, vtkUnstructuredGridAlgorithm);
};
class VTKFILTERSCORE_EXPORT ttkFilter : public ttkAlgorithm {
public:
static ttkFilter* New();
vtkTypeMacro(ttkFilter, ttkAlgorithm);
};
These two classes are defined in the same header file (I tried to see if it is indeed a linking problem) and if ttkFilter directly inherits from vtkUnstructuredGridAlgorithm then it works, with the intermediate class it fails with the following error when I execute the filter:
vtkPVSessionCore (0x2603300): Object type: ttkFilter, could not find requested method: "SetInputConnection".
So it seems the inheritance is screwed up somehow. Maybe I forgot to do something in regard to VTK’s strict single inheritance checks?
I also randomly tried different export macro commands in front of ttkAlgorithm but to no effect. I have actually not a clear understanding what these do, can I read this up somewhere?
It does !?! So I guess this issue is still related to the vtk.module file.
To clarify: it only works if ttkAlgorithm and ttkFilter are separate files that are referenced in the same vtk.module file. If I split them in two modules I run into the original issue.
Each class having its own header makes sense; the wrappers (I think) really only expect a single class per header. As for them being in different modules, could you point me to full source code? This works inside VTK and ParaView.
Charles and I got it to work. As you suggested we now have our own export macro for each filter/module.
We will let you know when we updated the ttk repo with the new structure and it would be great if you could have a quick look if it is possible to further simplify things.