# Display both 3D polydata and 2D "projected" images preserving the geometrical relations

**URL:** https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926
**Category:** Support
**Created:** [May 8, 2019, 2:09am UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926 "2019-05-08T02:09:53Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sdobashi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@sdobashi](https://discourse.vtk.org/u/sdobashi)
#### Post date: [May 8, 2019, 2:09am UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926/1 "2019-05-08T02:09:53Z")

</div>

Hello everyone,

I have one 3D poly-data and several related 2D images obtained by some projection from certain angles, like X-ray images.  
(2D images are not constructed directly from the 3D poly-data but provided from the outside.)  
I want to display both 3D and 2D images in the same render window interactively preserving the geometrical relations:  
I attached an image to illustrate the desired situation.

Specifically, if a 2D image is to be obtained by some projection operation from the direction  
v = [sin(t)cos(u), sin(t) sin(u), sin(t)],  
the 2D image should be placed so that its normal vector is parallel to v.  
Also, in the interaction, both 3D and 2D are expected to move consistently.

I could display both 3D poly data and the projected 2D image  
if the projection direction is X-, Y-, or Z- direction by using vtkPolyDataMapper and vtkDataSetMapper.  
However, I want to place several 2D projected images  
with each normal vector being any given projection directions.

Is there a way to realize such a display style in VTK?

I appreciate any suggestion.  
Thanks in advance.

 ![3D_poly_and_2D_projected_images](https://discourse.vtk.org/uploads/default/original/1X/9980faf8728d23e510cf000a4385de55abbf36a2.png)

---

<div class="post-metadata">

### Author: ![lassoan](https://discourse.vtk.org/user_avatar/discourse.vtk.org/lassoan/32/50_2.png) [@lassoan](https://discourse.vtk.org/u/lassoan)
#### Post date: [May 8, 2019, 1:45pm UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926/2 "2019-05-08T13:45:18Z")

</div>

These all look very doable using VTK. Read the [VTK textbook](https://lorensen.github.io/VTKExamples/site/VTKBook/00Preface/) and check out [VTK examples](https://lorensen.github.io/VTKExamples/site/) to see exactly how you can set this up.

---

<div class="post-metadata">

### Author: ![marcomusy](https://discourse.vtk.org/user_avatar/discourse.vtk.org/marcomusy/32/95_2.png) [@marcomusy](https://discourse.vtk.org/u/marcomusy)
#### Post date: [May 8, 2019, 6:04pm UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926/3 "2019-05-08T18:04:35Z")

</div>

…i have a very similar example in [vtkplotter](https://github.com/marcomusy/vtkplotter) if your happy to work with python:

```python
from vtkplotter import *

vp = Plotter(axes=3, bg='white')
vp.load(datadir+"bunny.obj").scale(3000).pos(300,-300,-10)

for i in range(18):
    a = vp.load(datadir+"images/dog.jpg")
    a.crop(bottom=0.2).alpha(0.5).rotateX(20*i) # crop 20%

vp.show()

```

 ![Screenshot%20from%202019-05-08%2019-56-26](https://discourse.vtk.org/uploads/default/original/1X/1708117ed5a78381e6a3c2cc072e8d890a431450.jpeg)

---

<div class="post-metadata">

### Author: ![sdobashi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@sdobashi](https://discourse.vtk.org/u/sdobashi)
#### Post date: [May 8, 2019, 10:37pm UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926/4 "2019-05-08T22:37:15Z")

</div>

Thank you very much for your response.

I found the method vtkImageData::SetDirectionMatrix in the GitHub version (maybe not yet implemented in VTK 8.2).  
This method was the key to achieve my aim.

---

<div class="post-metadata">

### Author: ![sdobashi](https://discourse.vtk.org/letter_avatar_proxy/v4/letter/s/e9c0ed/32.png) [@sdobashi](https://discourse.vtk.org/u/sdobashi)
#### Post date: [May 8, 2019, 10:39pm UTC](https://discourse.vtk.org/t/display-both-3d-polydata-and-2d-projected-images-preserving-the-geometrical-relations/926/5 "2019-05-08T22:39:40Z")

</div>

Thank you very much for your help.

This is exactly what I wanted to, though I’m now developing in C++.

The vtkplotter seems very useful for prototyping and to provide working examples.

Many thanks!
