How to implement a custom reader plugin in C++?

Hi,

So far, I managed to set up the build system for my ParaView plugin. The plugin compiles and I can load it in ParaView. When I try to open a file with .meshb extension, for which I develop this plugin, ParaView quits with the following message:
vtkSIProxy.cxx:402 ERR| vtkSISourceProxy (0x3dd25350): Failed to create ‘gmfReader’. This typically means that ParaView does not know about the request class to create an instance of if. Ensure that it has been correctly wrapped using the client-server wrappers and the wrapping has been initialized. Note class names are case-sensitive. Check for typos. Aborting for debugging purposes.

Currently, my custom reader contains no relevant code because first I wanted to understand how the plugin structure works. Could you help me writing a minimal header and source file, or pointing me to an existing MWE, that does not make ParaView segfault? I already looked at a lot of examples, but:

  • either the example wraps an existing reader (e.g. MyPNGReader example), so there is no C++ code that implements the reader
  • or it is part of a complex project (e.g. LidarView), from which I do not understand what is strictly necessary on the C++ side to implement a custom reader. For instance, how does ParaView know which method of my C++ reader class to call when I open a .meshb file in the GUI?

As I would like to read a file into a vtkUnstructuredGrid object and wrap it in a ParaView plugin, it makes me think that I should subclass vtkUnstructuredGridAlgorithm. Am I right?

I can share my plugin file, my module file, my XML file, etc. if you need further input.

Thank you

This is the typical error when the client server wrapping failed to generate, you need to check the generated files.

For instance, how does ParaView know which method of my C++ reader class to call when I open a .meshb file in the GUI?

The XML file contains all that info

it makes me think that I should subclass vtkUnstructuredGridAlgorithm

You can, but there are dedicated reader class you can inherit to avoid boiler plate code

Could you help me writing a minimal header and source file, or pointing me to an existing MWE, that does not make ParaView segfault?

RegistrationName example plugin does more than that but it does declare a C++ class which is a reader.

you need to check the generated files

Many directories and files are generated. Which files should I check? Is it documented somewhere? The problem is that I didn’t find documentation about the generated files (e.g what is the trailing “CS” in the file names?) and the structure of ServerManagerConfiguration in the XML file. Currently, I try to find something similar in Remoting/Application/Resources/ to start with, but in case of an error I have no idea what goes wrong.

but there are dedicated reader class you can inherit to avoid boiler plate code

Which class is it, the vtkDataReader? I want modularity in the sense that my VTK module can read our mesh format (i.e. create a vtkUnstructuredGrid object) without any knowledge of ParaView. Then the ParaView plugin is a lightweight wrapper around it. I think I am on the good track:

  1. vtk_module_scan and vtk_module_build to build the shared library
  2. I defined a CMake option, GMFREADER_BUILD_PV_PLUGIN. When ON, I call paraview_plugin_scan and paraview_plugin_build on the VTK module I built in step 1.

Both steps work, now I have to

  • implement the actual logic of reading our mesh format
  • write the client-server wrapping in the XML file

RegistrationName example plugin

It subclasses vtkPNGReader. For my use case, which base class would you choose? I looked at the class diagram of vtkUnstructuredGridAlgorithm.html and saw that several file readers (GAMBIT, Nektar5000, Chaco, etc.) subclass it, that’s why I thought about it. But you said it has boilerplate…

Many directories and files are generated. Which files should I check?

[build_dir]/[PluginName]/CMakeFiles/[vtkModuleName]CS/[vtkFilterName]ClientServer.cxx

Which class is it, the vtkDataReader?

Nevermind, in your case vtkUnstructuredGridAlgorithm makes sense.