[Paraview-developers] Reading PVD file from code

rclaveria rclaveria at dim.uchile.cl
Wed May 30 18:13:13 EDT 2018


Hello,

I'm writing a Paraview plugin in C++ (a source, to be precise) where I 
generate a mesh from external code and save it in PVD format. Then I 
have to read the newly created file and load it into the output, in 
order to display the mesh on the main Paraview screen.

I've written other source algorithms which rely on reading files but 
I've always read .vtk format so far. That was not a problem since I can 
read them with vtkGenericDataObjectReader within the  RequestData 
function:

         vtkSmartPointer<vtkGenericDataObjectReader> reader =
            vtkSmartPointer<vtkGenericDataObjectReader>::New();
         std::string inputFilename = dir.toStdString() + "file.vtk";
         reader->SetFileName(inputFilename.c_str());
         reader->Update();
         vtkUnstructuredGrid* outputreader = 
reader->GetUnstructuredGridOutput();
	output->DeepCopy(outputreader);

With pvd files, however, is not equally simple to load a file into the 
output. The following piece of code works well for the reading part:

         vtkSmartPointer<vtkPVDReader> reader =
            vtkSmartPointer<vtkPVDReader>::New();
         std::string inputFilename = dir.toStdString() + "file.pvd";
	reader->SetFileName(inputFilename.c_str());
	reader->Update();

But I don't know how to show the first file of the collection on the 
screen (pvd is a list of objects rather than a single file) and activate 
the "animation" on the VCR menu (one can put plays and the whole 
sequence displays). In other words, my code intends to replicate what 
happens when the user opens a .pvd file from the "File -> Open" menu, 
but I don't manage to do it. The following piece of code doesn't even 
compile:

         vtkDataObject* outputreader = reader->SetUpOutput();
         output->DeepCopy(outputreader);

I'd be grateful to get some help with this issue.

Regards,
R


More information about the Paraview-developers mailing list