# Python Algorithm Plugins and Applying Textures

**URL:** https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786
**Category:** Development
**Tags:** python
**Created:** [October 24, 2018, 8:31pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786 "2018-10-24T20:31:30Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/banesullivan/32/11714_2.png) [@banesullivan](https://discourse.paraview.org/u/banesullivan)
#### Post date: [October 24, 2018, 8:31pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/1 "2018-10-24T20:31:30Z")

</div>

In [**PVGeo**](http://pvgeo.org), I am implementing a few file readers as [Python Algorithm Plugins](https://gitlab.kitware.com/paraview/paraview/blob/master/Examples/Plugins/PythonAlgorithm/PythonAlgorithmExamples.py) that read files containing spatial discretization, data values, and textures that can be applied to the surfaces defined.

I am curious if it is possible to directly apply the loaded texture to a VTK data object on the pipeline. I can easily create/add the texture mapping via: `vtkobj.GetPointData().SetTCoords(tcoords)`

But is it possible to actually associate a texture with this data object? Would I need to place a `vtkTexture` object on a second output port? I’d prefer to be able to explicitly define the texture for the given data object though.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [October 24, 2018, 8:47pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/2 "2018-10-24T20:47:43Z")

</div>

I am afraid not. The texture is a “rendering” property which is intentionally separate from the data itself.

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/banesullivan/32/11714_2.png) [@banesullivan](https://discourse.paraview.org/u/banesullivan)
#### Post date: [October 24, 2018, 8:50pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/3 "2018-10-24T20:50:57Z")

</div>

> [@utkarsh.ayachit](#):
>
> The texture is a “rendering” property which is intentionally separate from the data itself.

I figured this was intentionally seperated.

Would it be possible to create a second source on the pipeline that the dropdown menu for the texture picker would recognize?

 ![33%20PM](https://discourse.paraview.org/uploads/default/original/1X/9e88f0b34b839c82672c27c76cf675eb8333e51f.png)

---

<div class="post-metadata">

### Author: ![jourdain](https://discourse.paraview.org/user_avatar/discourse.paraview.org/jourdain/32/11_2.png) [@jourdain](https://discourse.paraview.org/u/jourdain)
#### Post date: [October 24, 2018, 9:26pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/4 "2018-10-24T21:26:36Z")

</div>

I’m not sure that’s your question but if you try to figure out how to load and assign texture in Python for ParaView, you can look at that code snippet.

[Create textures from files](https://github.com/Kitware/vtk-js/blob/master/Utilities/ParaView/obj-mtl-importer.py#L244-L247)

[Assign texture to a representation](https://github.com/Kitware/vtk-js/blob/master/Utilities/ParaView/obj-mtl-importer.py#L249)

HTH,

Seb

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/banesullivan/32/11714_2.png) [@banesullivan](https://discourse.paraview.org/u/banesullivan)
#### Post date: [October 24, 2018, 9:43pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/5 "2018-10-24T21:43:44Z")

</div>

Oh, awesome! I think I could implement a similar routine as `paraview.servermanager` is available when the `vtkPythonAlgorithm` is executed on the pipeline.

**My new question would be:** _could I use an already loaded data array as the texture instead of a file?_ i.e. I would like to skip loading a new file but use some data already loaded as a 2D numpy array which I could convert to a VTK data object via the `vtk.util.numpy_support` module.

If this isn’t possible, then I could use Python’s native `shutil` and `tempfile` to temporarily write out the texture as a JPEG then delete the file after ParaView loads it up. The only issue I see with this is that there might be some strange behavior when saving/loading ParaView states.

---

<div class="post-metadata">

### Author: ![utkarsh.ayachit](https://discourse.paraview.org/user_avatar/discourse.paraview.org/utkarsh.ayachit/32/39_2.png) [@utkarsh.ayachit](https://discourse.paraview.org/u/utkarsh.ayachit)
#### Post date: [October 25, 2018, 1:15pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/6 "2018-10-25T13:15:53Z")

</div>

> [@banesullivan](#):
>
> Oh, awesome! I think I could implement a similar routine as `paraview.servermanager` is available when the `vtkPythonAlgorithm` is executed on the pipeline.

Don’t :)! vtkPythonAlgorithm should never import `paraview.servermanager`. They are operating in different environments and you’ll run into crazy issues if you do so.

Conceptually, ParaVIew has two Python environments: (a) one under which the data processing code executes and (b) for scripting client-side logic to build pipelines etc (things one does in the GUI). PythonAlgorithm operates in (a) while the `paraview.servermanager`, `paraview.simple` APIs operate in (b). The two should not be mixed.

---

<div class="post-metadata">

### Author: ![banesullivan](https://discourse.paraview.org/user_avatar/discourse.paraview.org/banesullivan/32/11714_2.png) [@banesullivan](https://discourse.paraview.org/u/banesullivan)
#### Post date: [October 25, 2018, 3:49pm UTC](https://discourse.paraview.org/t/python-algorithm-plugins-and-applying-textures/786/7 "2018-10-25T15:49:28Z")

</div>

> [@utkarsh.ayachit](#):
>
> Don’t :)! vtkPythonAlgorithm should never import `paraview.servermanager` . They are operating in different environments and you’ll run into crazy issues if you do so.

Shucks! So I suppose I am out of options for this unless there might be a way to push the texture out on one of the `vtkPythonAlgorithm`’s output ports?
