# Unable to Set Transfer2DYAxisArray to "Curvature"

**URL:** https://discourse.vtk.org/t/unable-to-set-transfer2dyaxisarray-to-curvature/12067
**Category:** Support
**Tags:** python, code
**Created:** [July 31, 2023, 2:52pm UTC](https://discourse.vtk.org/t/unable-to-set-transfer2dyaxisarray-to-curvature/12067 "2023-07-31T14:52:29Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![DMelenberg](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmelenberg/32/6926_2.png) [@DMelenberg](https://discourse.vtk.org/u/DMelenberg)
#### Post date: [July 31, 2023, 2:52pm UTC](https://discourse.vtk.org/t/unable-to-set-transfer2dyaxisarray-to-curvature/12067/1 "2023-07-31T14:52:29Z")

</div>

Dear vtk Community ☀,

during my project to construct a volume renderer using vtk i am facing the challenge to define the curvature data of the volume as the y-axis of the 2D transfer function.

According to vtk documentation the input must be of type char.

```cpp
SetTransfer2DYAxisArray()
virtual void vtkGPUVolumeRayCastMapper::SetTransfer2DYAxisArray	(const char *)
// Set/Get the transfer 2D Y axis array.

```

My approach was to use numpy to calculate the curvature on the entire volume and then create a vtkImageData object with its “Name” set to “Curvature”.

```python
        from vtkmodules.util import numpy_support
        curvature_np_array = compute_curvature(array_from_image(self.itk_img)) # Curvature as np.array

        vtkarr = numpy_support.numpy_to_vtk(curvature_np_array.ravel(), deep=True, array_type=vtk.VTK_FLOAT)
        vtkarr.SetNumberOfComponents(1)
        vtkarr.SetNumberOfTuples(curvature_np_array.ravel().shape[0])
        vtkarr.SetName("Curvature")

        self.volume_mapper.SetTransfer2DYAxisArray(vtkarr.GetName())

```

The compute\_curvature function calculates the mean curvature using the “itk.EigenFilter”.

Unfortunately the VolumeMapper ignores this and the Y-axis remains “gradient”.

Can someone help me with this?

David

---

<div class="post-metadata">

### Author: ![sankhesh](https://discourse.vtk.org/user_avatar/discourse.vtk.org/sankhesh/32/73_2.png) [@sankhesh](https://discourse.vtk.org/u/sankhesh)
#### Post date: [July 31, 2023, 3:13pm UTC](https://discourse.vtk.org/t/unable-to-set-transfer2dyaxisarray-to-curvature/12067/2 "2023-07-31T15:13:35Z")

</div>

Could you please post a complete script that you use?

Are you setting the transfer function mode via `vtkVolumeProperty::SetTransferFunctionMode` to `TF_2D`?

---

<div class="post-metadata">

### Author: ![DMelenberg](https://discourse.vtk.org/user_avatar/discourse.vtk.org/dmelenberg/32/6926_2.png) [@DMelenberg](https://discourse.vtk.org/u/DMelenberg)
#### Post date: [August 2, 2023, 6:39am UTC](https://discourse.vtk.org/t/unable-to-set-transfer2dyaxisarray-to-curvature/12067/3 "2023-08-02T06:39:55Z")

</div>

Hi @sankhesh,  
thank you very much for your answer. So soon we hear each other again. 😃

Unfortunately I can’t send the complete script. But I will extract pieces from my pipeline in appropriate order.

I initialize my class with the following field variables:

```py
    def __init__ (self):
        self.two_dimensional_tf = vtk.vtkImageData()
        self.volume = vtk.vtkVolume()
        self.volume_property = vtk.vtkVolumeProperty()
        self.volume_mapper = vtk.vtkOpenGLGPUVolumeRayCastMapper()
        self.renderer = vtk.vtkOpenGLRenderer()
        self.render_window = vtk.vtkRenderWindow()
        self.interactor = vtk.vtkRenderWindowInteractor()

```

After reading the dataset  
I calculate its curvature with

```python
curvature_np_array = compute_curvature(array_from_image(self.itk_img)) 

```

This has the same size as the itk\_volume:

```python
>>> print(curvature_np_array.shape)
(423, 548, 548)
>>> print(self.itk_img.shape)
(423, 548, 548)

```

I then convert this to a vtkFloatArray:

```python
Curvature = numpy_support.numpy_to_vtk(curvature_np_array.ravel(), deep=True, array_type=vtk.VTK_FLOAT)
Curvature.SetNumberOfComponents(1)
Curvature.SetNumberOfTuples(curvature_np_array.ravel().shape[0])
Curvature.SetName("Curvature")
Curvature.Modified()

```

I have tried to set `SetTransferFunctionModeTo2D()` already here.

Then:

```python
self.volume_mapper.SetTransfer2DYAxisArray(Curvature.GetName())
# Or with same result
self.volume_mapper.SetTransfer2DYAxisArray("Curvature")

```

Afterwards I put the input into the `VolumeMapper`.

```py
# Before that I converted the itk to the vtk_image
self.volume_mapper.SetInputData(self.vtk_image)

```

Then I set the `VolumeProperty`:

```py
self.volume_property.SetTransferFunctionModeTo2D()
self.volume_property.SetTransferFunction2D(0, self.two_dimensional_tf)

```

… The volume Actor:

```py
self.volume_mapper.Update()
self.volume_property.Modified()
self.volume.SetMapper(self.volume_mapper)
self.volume.SetProperty(self.volume_property)

```

And finally add the volume to the renderer.
