vtk how to disable memory extra cost when call render()?

Hi All,
after load a vtkdataset,should use the renderWindow->Render()。but i found it will have a extra memory cost when the data is more than 100mb。 for example:a vtkdataset size is 500mb ,it’ll cost from 500mb to 1.5G and then fall back to 500mb when render() function called。 although the final memory cost is 500mb,but it will touch 1.5G memory cost . and i found There’s no such thing in paraview.

the only solution I can found is to separate a dataset to vtkMultiBlockDataSet。but i havent test the effects to others(filter:clip slice streamline etc)。

thanks!

Do you have any filters in your pipeline ?
You may have a look at the Release Data Flag option, which allows to release the output of a filter after execution. Of course, re-computation will be needed to get the output of this filter once again, even if no parameters has been changed.

no filters in my pipeline yet,the dataset type is a unstructedgrid,i found use the vtkGeometryFilter can littly reduce the extra memory cost ,but not completely.

vtkNew<vtkNamedColors> colors;
    vtkNew<vtkDataSetReader> fileReader;
  
    // Read unstructedgrid .vtk file,can replace in your vtk name
    fileReader->SetFileName("direction_3_5000.vtk");
  
    fileReader->Update();

    vtkNew<vtkDataSetMapper> mapper;
    mapper->SetInputData(fileReader->GetOutput());
    vtkSmartPointer<vtkActor> actor = vtkSmartPointer<vtkActor>::New();
    actor->SetMapper(mapper);

    vtkNew<vtkRenderer> renderer;
    vtkNew<vtkRenderWindow> renderWindow;
    renderWindow->AddRenderer(renderer);
    renderWindow->SetWindowName("test");

    vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
    renderWindowInteractor->SetRenderWindow(renderWindow);

    renderer->AddActor(actor);
    renderer->SetBackground(colors->GetColor3d("DarkOliveGreen").GetData());

    renderWindow->Render();
    renderWindowInteractor->Start();

    return EXIT_SUCCESS;

You may want to replace this line:

By:

mapper->SetInputConnection(fileReader->GetOutputPort());

This is the right VTK way to connect filters. Also, this way you can remove the manual fileReader->Update() as it will be called automatically by the render. For supported file type, this could allow the reader to only produce a sub-part of the data, the one required for the rendering. I am not sure this will be the case for a .vtk file though.

Finally, using fileReader->SetReleaseDataFlagOn() , you should clear the output of the reader after it has been used by the mapper.

it seemings works for polydata but not works for unstructedgrid data type by my test。and when read unstructedgrid data,fileReader->ReleaseDataFlagOn(); will cause the
obj disappear。

thanks a lot!Things look like they’re about to settle. i have the last question is about the normal way to deal with unstructedgrid,shall i use the vtkgeometryfilter to extract surface polydata to surface rendering and use the original dataset(unstructedgrid type) to deal with filters(slice,cut,streamline,glyph,resamplewithdataset,etc)?and when use unstructedgrid vtkdataset, it looks like i should use vtkgeometryfilter to extract polydata tosurface rendering everytime when the filter output is not polydata? thanks again.

@ch_zeng
You are right, you should use the unstructured grid as input for your processing filters, whenever you need to process the full 3D domain.
The geometry filter is a way to get a simple surface (polydata) suited for surface rendering. So when you want to do surface rendering, having a geometry filter and a polydata mapper is indeed the way to go.

One example of rendering that would not work with the geometry filter, would be volumic rendering.