How to create a Resource from a file I loaded with a custom ParaView reader?

Hi,

I ported my reader-type ParaView plugin to CMB without any change. It works fine, but the imported mesh does not appear in the “Resources” panel. How can I implement a plugin that imports the mesh in the resources, each mesh part (e.g. a block corresponding to a boundary segment) appears in the resources? As far as I understand, this is needed so that I can work with SMTK.

I would like to mimic the behaviour when I open, for instance, a .mesh file in Truchas, it offers to import it into smtk::session::vtk::Resource. Opening the same file in ParaView, I see that it was the IOSS reader that loaded it as a vtkPartitionedDataSetCollection object.

You would need to modify the Import operation of SMTK’s VTK session (or other resource types, such as the markup resource) to use your VTK reader and create SMTK components for each piece of geometry you want to be its own object.

Is it documented or is there an example somewhere? I guess this is the most important step; if I don’t have my mesh represented as a Resource, I cannot use most of the functionalities of SMTK/CMB.

After investigating more, I would have further questions:

  1. What is the difference between ImportResource and ReadResource? One can read this in the tutorial:
    Standard practice would use the SMTK ImportResource or ReadResource operations to load attribute and other resources.
    
  2. How can I import/read from memory instead of a file? My ParaView reader plugin read my file type as a vtkUnstructuredGrid object; this is what I would like to represent as a resource.
  3. Can we import/read from multiple files (or preferably: VTK objects in memory) into the same resource? Use case: probably I will represent the different parts of a body (subdomains, boundary surfaces) as separate vtkUnstructuredGrid objects. Then I would like to combine them in a single resource, i.e. they are in the same tree of the Resources panel of CMB.

A resource is not a VTK data object. A resource is an SMTK object representing a “document.” Resources hold zero or more components (also SMTK objects, not VTK objects). SMTK resources are stored as JSON. An operation that reads a resource parses JSON data in SMTK format to create an in-memory version of the document (resource plus its components). An operation that imports into a resource parses data in some non-SMTK format to populate components into either a new or an existing SMTK resource. You would not use a read operation to load data that is not in SMTK’s JSON format.

SMTK components may each own VTK objects.

You cannot use VTK objects as SMTK resources. You can create SMTK resources that own VTK objects.

In CMB, you would not use ParaView to load the data directly; instead, you would define an import operation that instantiates your reader, constructs a resource (if one is not provided to the operation by association), and then constructs a component for each VTK object of concern. For example, your reader might produce a vtkPartitionedDataSetCollection, but instead of creating a single output SMTK component, you might create an SMTK component for each entry of the vtkPartitionedDataSet instances. Or you might use the vtkDataAssembly of the partitioned dataset collection to create components and associate multiple VTK data objects to each component. On the other hand, if your reader produces a vtkUnstructuredGrid, you might produce a single component.

Yes. Depending on how your import operation is called, the result is that you can have multiple VTK objects from different files in a single resource or spread across multiple resources.

Thank you for the detailed reply, now I understand the distinction between import and read. So the JSON file is the .smtk file, which, as I noticed, contains reference to the actual mesh file.

Resources hold zero or more components

What is a resource component in SMTK?

In CMB, you would not use ParaView to load the data directly; instead, you would define an import operation that instantiates your reader

OK, so it means that I need to write an additional layer that wraps my existing reader. Can you point to me example(s)? I found use cases for ImportResource, but not on what you wrote previously:

You would need to modify the Import operation of SMTK’s VTK session (or other resource types, such as the markup resource) to use your VTK reader

if one is not provided to the operation by association

What do you mean by association?

I will try to find (or write) an example in the next day or two, but have some deadlines to deal with right now.

I am getting closer to it, as shown in How to import a .vtu file programmatically? - #2 by CsatiZoltan
Is there a way to extend (subclassing or other way) smtk::markup::Import (the VTK session cannot import a .vtu file, as I noted in my other post) instead of modifying the source code (that way, I would have to be up-to-date with the SMTK git repo)?