# Vtkimage data over vtkstrcturedgrid (performance)

**URL:** <https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524>\
**Category:** Development\
**Created:** [April 9, 2021, 2:11pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524 "2021-04-09T14:11:23Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 9, 2021, 2:11pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/1 "2021-04-09T14:11:23Z")

</div>

Hello, i’m having issues with vtk, as i’m learning it i was asked to make some performance tests, and so i made this little program.  
It createsa vtkstructuredgrid with different sizes and displays the rendering time, but i have an issue, i’m forced to create a points array. It takes a lot of memory space, so i tried to swap from vtkstructuredgrid to vtkimagedata.  
There’s an issue, it seems to be the best alternative because it doesn’t require the point array, and seems to cost less memory, on the other hand i can’t quite find how to blank cells or the pixel equivalents in vtkImage data.  
Is there a way to do so? Or is there another alternative to vtkstructuredgrid that does the same and uses less memory?  
(A screen capture of a render example of the code that is linked to the post)

 ![Capture d’écran 2021-04-09 à 15.48.24](https://discourse.vtk.org/uploads/default/original/2X/a/a5bae65847854ec53056c995c1d45eecacf62787.jpeg) [image\_data.cxx](https://discourse.vtk.org/uploads/short-url/n4jL2KwK2oaR3e3B0YDdfqc6DiL.cxx) (5.3 KB)

---

<div class="post-metadata">

**Author:** ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)\
**Post date:** [April 9, 2021, 2:41pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/2 "2021-04-09T14:41:39Z")

</div>

If you want to do blanking, you should use `vtkUniformGrid`. It is a `vtkImageData` with a blanking API. See [here](https://vtk.org/doc/nightly/html/classvtkUniformGrid.html).

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 12, 2021, 8:32am UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/3 "2021-04-12T08:32:47Z")

</div>

Thanks for the answer, i tried your solution but the blanking doesn’t seem to work, instead the cells that should be blanked are still visible and i can’t quite find why it does so?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 12, 2021, 12:35pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/4 "2021-04-12T12:35:46Z")

</div>

So after testing a few possibilities, i’m stuck, when i use directly an UniformGrid i have the result on the screen attached, (code attached too) but when i use a geometryfilter on it i can see that the cell are blanked but the result is still not as expected, as i would like it to be blanking cells like with vtksctructuredgrid but with less rendering time.[uniform\_grid.cxx](https://discourse.vtk.org/uploads/short-url/cuzHlrnUbKbPKaLdRtC0HB0laxn.cxx) (4.9 KB)

 ![Capture d’écran 2021-04-12 à 14.29.56](https://discourse.vtk.org/uploads/default/original/2X/0/0c1476d92cafb6a22ddcc2edca8fc614eac720ef.jpeg)  
^With uniformgrid alone  
 ![Screenshot from 2021-04-12 14-35-06](https://discourse.vtk.org/uploads/default/original/2X/9/9c0c4c5ff7c0f013a9a55550c1cd423a69ef032a.png)  
^With uniform grid + geometry filter

---

<div class="post-metadata">

**Author:** ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)\
**Post date:** [April 12, 2021, 1:32pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/5 "2021-04-12T13:32:05Z")

</div>

I think I see where the problem comes from. I’m going to try to write a fix. Do you mind using VTK master for your case?

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 12, 2021, 2:10pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/6 "2021-04-12T14:10:37Z")

</div>

I’m not really used to the master of VTK, but if you could just send me the fix you may be able to write, it would be awesome, thanks a lot anyway!  
Sorry, i’m a bit of a newbie on vtk, i’m a trainee and i’m learning it at the moment.

---

<div class="post-metadata">

**Author:** ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)\
**Post date:** [April 12, 2021, 3:59pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/7 "2021-04-12T15:59:54Z")

</div>

See this [issue](https://gitlab.kitware.com/vtk/vtk/-/issues/18171)

I’ll give you a link to a Merge Request with the fix. I don’t know if you can just plug it on your local VTK and make it work. You’ll have to try it yourself.

---

<div class="post-metadata">

**Author:** ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)\
**Post date:** [April 12, 2021, 4:22pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/8 "2021-04-12T16:22:16Z")

</div>

Here’s a [fix](https://gitlab.kitware.com/vtk/vtk/-/merge_requests/7844).

When you visualize your `vtkImageData` or your `vtkUniformGrid`, you should use `vtkDataSetSurfaceFilter` right before using the mapper.

---

<div class="post-metadata">

**Author:** ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)\
**Post date:** [April 12, 2021, 11:19pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/9 "2021-04-12T23:19:49Z")

</div>

I’m curious Yohann, is there an explicit reason why you recommend vtkDataSetSurfaceFilter? With the changes I made in the last year, vtkGeometryFilter is typically much faster than vtkDataSetSurfaceFilter (especially when SMP threading is enabled - although this varies based on the type of dataset). Any feedback is welcome…

---

<div class="post-metadata">

**Author:** ![Yohann\_Bearzi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/yohann_bearzi/32/671_2.png) [@Yohann\_Bearzi](https://discourse.vtk.org/u/Yohann_Bearzi)\
**Post date:** [April 13, 2021, 12:00pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/10 "2021-04-13T12:00:31Z")

</div>

I am recommending `vtkDataSetSurfaceFilter` for this case because when I read the code I found an easy fix to make the blanking work. But you’re right, in the long run we should also make the geometry filter work correctly with blanked cells, and use SMP threading if possible.

---

<div class="post-metadata">

**Author:** ![will.schroeder](https://discourse.vtk.org/user_avatar/discourse.vtk.org/will.schroeder/32/233_2.png) [@will.schroeder](https://discourse.vtk.org/u/will.schroeder)\
**Post date:** [April 13, 2021, 12:12pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/11 "2021-04-13T12:12:07Z")

</div>

Thanks, I’ll add this to the TODO list based on what you did

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 13, 2021, 12:59pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/12 "2021-04-13T12:59:52Z")

</div>

Hmmm there are a few things that disturb me, it took me quite a long time with my it at work to install the master vtk and so, even if i don’t use the filter i still have the blank cells with the uniform grid, which is what i wanted and the rendering times a way faster than with a structuredgrid, but i lost all my colors, even if i still plug in my lookuptable, the cells are all blue 😕 i don’t quite know why, have you got any idea? By the way, a big thanks for all the work you put to make this fix that fast!

---

<div class="post-metadata">

**Author:** ![Guillaume\_Gillet](https://discourse.vtk.org/user_avatar/discourse.vtk.org/guillaume_gillet/32/3114_2.png) [@Guillaume\_Gillet](https://discourse.vtk.org/u/Guillaume_Gillet)\
**Post date:** [April 14, 2021, 12:16pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/13 "2021-04-14T12:16:56Z")

</div>

Ok nevermind, i corrected it and finally have what i wanted with a correct blanking and colors, thanks for everything!

---

<div class="post-metadata">

**Author:** ![Perseval](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/p/6bbea6/32.png) [@Perseval](https://discourse.vtk.org/u/Perseval)\
**Post date:** [June 21, 2021, 1:06pm UTC](https://discourse.vtk.org/t/vtkimage-data-over-vtkstrcturedgrid-performance/5524/14 "2021-06-21T13:06:30Z")

</div>

Hello, would it be possible (even wiser) to use a vtkSelection to obtain the same result as seen in the first message of this topic ?
