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

**URL:** https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242
**Category:** Support
**Tags:** code
**Created:** [July 16, 2024, 3:27am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242 "2024-07-16T03:27:04Z")
**Posts on this page:** 10
**Page:** 1

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 16, 2024, 3:27am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/1 "2024-07-16T03:27:04Z")

</div>

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？

```auto
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

```auto
    // 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!

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [July 16, 2024, 5:07pm UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/2 "2024-07-16T17:07:23Z")

</div>

Try to use vtkGeometryFilter and vtkPolydataMapper instead of just vtkDatasetMapper.

---

<div class="post-metadata">

### Author: ![Paulo\_Carvalho](https://discourse.vtk.org/user_avatar/discourse.vtk.org/paulo_carvalho/32/370_2.png) [@Paulo\_Carvalho](https://discourse.vtk.org/u/Paulo_Carvalho)
#### Post date: [July 16, 2024, 9:12pm UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/3 "2024-07-16T21:12:01Z")

</div>

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

---

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 17, 2024, 7:41am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/4 "2024-07-17T07:41:51Z")

</div>

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 ❓, 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

---

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 17, 2024, 8:16am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/5 "2024-07-17T08:16:57Z")

</div>

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 🙃

---

<div class="post-metadata">

### Author: ![spyridon97](https://discourse.vtk.org/user_avatar/discourse.vtk.org/spyridon97/32/7069_2.png) [@spyridon97](https://discourse.vtk.org/u/spyridon97)
#### Post date: [July 17, 2024, 9:28am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/6 "2024-07-17T09:28:31Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 17, 2024, 9:34am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/7 "2024-07-17T09:34:18Z")

</div>

I see, thank you for your answer patiently

---

<div class="post-metadata">

### Author: ![jaswantp](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jaswantp/32/10046_2.png) [@jaswantp](https://discourse.vtk.org/u/jaswantp)
#### Post date: [July 17, 2024, 1:54pm UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/8 "2024-07-17T13:54:52Z")

</div>

> [@jie\_baoer](#):
>
> is there a drawing way to draw the vtkUnstructuredGrid object directly?

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

---

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 18, 2024, 3:20am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/9 "2024-07-18T03:20:27Z")

</div>

> [@Paulo\_Carvalho](#):
>
> If you’re not using a debugger or profiler during execution;

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

---

<div class="post-metadata">

### Author: ![jie\_baoer](https://discourse.vtk.org/user_avatar/discourse.vtk.org/jie_baoer/32/7202_2.png) [@jie\_baoer](https://discourse.vtk.org/u/jie_baoer)
#### Post date: [July 18, 2024, 3:23am UTC](https://discourse.vtk.org/t/is-there-a-better-way-to-reduce-the-time-spent-on-render/14242/10 "2024-07-18T03:23:22Z")

</div>

Look forward to it 👁
