Is there a better way to reduce the time spent on Render?

I initialize the vtkUnstructuredGrid object with the following code. The test model has about 1 million VTK_HEXAHEDRON cells. When executing vtkRenderer->Render(), it takes about 10 seconds.Is there a better way to reduce the time spent on Render?

std::vector<double> coordinates;        
std::vector<vtkIdType> cellData;
std::vector<vtkIdType> offsetData;
std::vector<int> intCellTypes;
std::vector<int> ptModelShowData;       // PointData 0: hide 1:show
// Assume it is initialized

vtkNew<vtkDoubleArray> pDataArray;
pDataArray->SetNumberOfComponents(3);
pDataArray->SetArray(coordinates.data(), coordinates.size(), 1);

vtkNew<vtkPoints> pPoints;
pPoints->SetData(pDataArray);

vtkNew<vtkIdTypeArray> idArray;
idArray->SetNumberOfComponents(1);
idArray->SetArray(cellData.data(), cellData.size(), 1);


vtkNew<vtkIdTypeArray> offsetArray;
offsetArray->SetNumberOfComponents(1);
offsetArray->SetArray(offsetData.data(), offsetData.size(), 1);

vtkNew<vtkCellArray> pCellArray;
pCellArray->SetData(offsetArray, idArray);


const vtkIdType ncells = intCellTypes.size();
vtkNew<vtkUnsignedCharArray> cellTypes;
cellTypes->SetNumberOfTuples(ncells);
auto typeRange = vtk::DataArrayValueRange<1>(cellTypes);
std::transform(intCellTypes.data(), intCellTypes.data() + ncells, typeRange.begin(),
    [](int t) -> unsigned char { return static_cast<unsigned char>(t); });

vtkNew<vtkUnstructuredGrid> pGrid;
pGrid->SetPoints(pPoints);
pGrid->SetCells(cellTypes, pCellArray);

vtkNew<vtkIntArray> ptDataArray;
ptDataArray->SetNumberOfComponents(1);
ptDataArray->SetArray(ptModelShowData.data(), ptModelShowData.size(), 1);

pGrid->GetPointData()->SetAttribute(ptDataArray, 0);

vtkNew<vtkLookupTable> pModelLookupTable;
pModelLookupTable->SetNumberOfTableValues(2);
pModelLookupTable->SetTableRange(0, 1);
pModelLookupTable->SetTableValue(0, 0, 0, 0, 0);
pModelLookupTable->SetTableValue(1, 0, 1, 1, 1);
pModelLookupTable->Build();

vtkNew<vtkDataSetMapper> pMapper;
pMapper->SetInputData(pGrid);
pMapper->SetLookupTable(pModelLookupTable);
pMapper->Update();

vtkNew<vtkActor> actor;
actor->SetMapper(pMapper);

vtkRenderer->AddActor(actor);
vtkRenderer->Render();

I have two questions:
1.Is there a better way to reduce the time spent on Render?
2.When I update PointData to control the display of the cell, it still takes 10 seconds, which confuses me, and I think it should take less time, but I don’t know what to do

    // PointData 0: hide 1:show
    ptModelShowData[8] = 0;
    ptModelShowData[9] = 0;
    ptModelShowData[10] = 0;
    ptModelShowData[11] = 0;
    ptModelShowData[12] = 0;
    ptModelShowData[13] = 0;
    ptModelShowData[14] = 0;
    ptModelShowData[15] = 0;

    ptDataArray->Modified();

    vtkRenderer->Render();

Thanks you for your reply!

Try to use vtkGeometryFilter and vtkPolydataMapper instead of just vtkDatasetMapper.

1 Like

Hello,

I use vtkDataSetMapper with vtkUnstructuredGrid to render reservoir models with millions of cells. Such grids take a while to load, but interaction goes very smooth once everything is in the graphics hardware. Things to check:

  1. If you’re not using software emulation;
  2. If you’re not using a debugger or profiler during execution;
  3. If your graphics card driver is up to date;
  4. If you’re remotely rendering, check your network speed.

If you keep changing the input data, I believe there will be lag because the entire pipeline should be executed again.

regards,

PC

1 Like

Hi Spiros,
Thanks for reply. I replaced vtkDatasetMappe with vtkGeometryFilter and vtkPolydataMapper, which improved rendering speed by about 50% for 1 million meshes.
I also noticed that vtkDatasetMappe internally handles the grid by using vtkDataSetSurfaceFilter. vtkGeometryFilter does process faster than vtkDataSetSurfaceFilter.In fact, I don’t understand why this step is necessary :question:, both of them consume memory and time, is there a drawing way to draw the vtkUnstructuredGrid object directly? Even if the drawing has more than one common face

Hello Paulo,

Yes, I know it will take some time to initialize the model, the model interaction after loading is very smooth, I just want to find out if there is any way to load faster

As for modifying the input data, I just modified the PointData value, and the model node and cell connection relationships did not change. The pipeline refresh time was almost the same as initializing the build model. I thought I could save pipeline refresh time in this way, but it didn’t :upside_down_face:

For every unstructured grid, you need to first extract its polygon external facelist and then render it . There is no other way, unless you want to provide the external facelist to the polydata mapper yourself.

I see, thank you for your answer patiently

Right now, no there isn’t. However, it can be made possible in the future by offloading the face extraction to compute pipelines.

Under the release version, the speed has been increased by five times, which is acceptable, thanks again for your answer :coffee:

1 Like

Look forward to it :eye: