# Looking for optimal 3D grid with regular Z axis and arbitrary XY

**URL:** https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539
**Category:** Support
**Created:** [June 12, 2020, 6:50pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539 "2020-06-12T18:50:05Z")
**Posts on this page:** 9
**Page:** 1

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [June 12, 2020, 6:50pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/1 "2020-06-12T18:50:05Z")

</div>

Hi,

I have a dataset wich has regular **Z** axis and arbytrary **X** and **Y** axes. If **Z** axis were also arbitrary then to display my dataset I would use `vtkStructuredGrid` and in this case I would need to set `X,Y,Z` coordinates for each point.  
But since **Z** is regular (i.e. Z = Z\_start, Z\_start+dZ, …, Z\_end) it is enough to set **X, Y** coordinates for each **Z-series** to define all coordinates of my dataset.

Is there something like `vtkImageData` where I set **X,Y** coordinates for each **Z-series** (Z series is a single vector from Z\_start to Z\_end) and **Z** is defined as **Z\_start, dZ, Z\_end**?

 ![VTK](https://discourse.vtk.org/uploads/default/original/2X/9/959f09544209226305669e25ce66e17e924e9549.png)

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [June 12, 2020, 10:18pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/2 "2020-06-12T22:18:46Z")

</div>

The simple answer is no, there isn’t. It would be necessary to generate all the extra points and use either vtkStructuredGrid or vtkUnstructuredGrid.

---

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [June 12, 2020, 10:39pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/3 "2020-06-12T22:39:00Z")

</div>

@dgobbi thank you!  
And if every axis **X,Y,Z** has regular spacing so it could almost be visualized via `vtkImageData` but there are some missing data (missing some **Z-series** ) at some **XY** coordinates. Do I need to somehow restore missing **Z-series** to display it as a `vtkImageData` or use `vtkStructuredGrid` or there is some more elegant way?

---

<div class="post-metadata">

### Author: ![dgobbi](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dgobbi/32/18_2.png) [@dgobbi](https://discourse.vtk.org/u/dgobbi)
#### Post date: [June 12, 2020, 11:25pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/4 "2020-06-12T23:25:22Z")

</div>

So it’s essentially a sparse image, with sparsity only in XY? The solution is going to depend on how you want to visualize it. Typically, VTK uses vtkUnstructuredGrid to represent sparse data but that’s not ideal (especially for volume rendering). It almost sounds like you want something like a masked vtkImageData.

Probably the most straightforward thing it to create a vtkImageData, and set all the unused values to some special value that doesn’t appear anywhere in your data. For example, for 16-bit data a value of -32678. For float, you could even use NAN. Then, when you display the data, use a lookup table that maps your special value to “transparent” (i.e. alpha value of zero). This might not work perfectly due to interpolation, but it might be worth a try.

---

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [June 13, 2020, 12:15am UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/5 "2020-06-13T00:15:26Z")

</div>

Thank you!

> [@dgobbi](#):
>
> So it’s essentially a sparse image, with sparsity only in XY?

Yes. At some XY points there are no Z-series (like a vertical gaps).  
I’m trying to avoid using `vtkStructuredGrid` beacause it should take about 4 times more than `vtkImageData`.  
Probably transparency for NAN values may help.

---

<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: [June 13, 2020, 3:14pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/6 "2020-06-13T15:14:27Z")

</div>

I don’t know whether I understood what you want, but if have something similar:

 ![image](https://discourse.vtk.org/uploads/default/original/2X/8/8b2e4594d242d04890dcf5e8f8ad96036424a129.png)

These are sparse columns containing z-series. I used `vtkPolyData` for data set and `vtkTubeFilter` to turn the series into tubes. Of course you can `SetNumberOfSides( 4 )` to achieve a blocky grid-like appearance.

---

<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: [June 13, 2020, 3:18pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/7 "2020-06-13T15:18:20Z")

</div>

The code to render tubes from poly lines is here: [https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/view3dbuilders.cpp](https://github.com/PauloCarvalhoRJ/gammaray/blob/master/viewer3d/view3dbuilders.cpp) . Look for a method called `buildForAttributeFromSegmentSet`.

---

<div class="post-metadata">

### Author: ![kerim](https://discourse.vtk.org/user_avatar/discourse.vtk.org/kerim/32/1175_2.png) [@kerim](https://discourse.vtk.org/u/kerim)
#### Post date: [June 13, 2020, 3:53pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/8 "2020-06-13T15:53:35Z")

</div>

@Paulo_Carvalho Thank you! I’m definately going to try it

---

<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: [June 13, 2020, 6:48pm UTC](https://discourse.vtk.org/t/looking-for-optimal-3d-grid-with-regular-z-axis-and-arbitrary-xy/3539/9 "2020-06-13T18:48:40Z")

</div>

You can also `vtkTubeFilter::SetCapping( true )` to give a solid appearance to the columns.
