# I want to display an image in a 3d rectangle with four corner points,

**URL:** https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850
**Category:** Support
**Tags:** training
**Created:** [February 16, 2022, 11:51am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850 "2022-02-16T11:51:29Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![loufear](https://discourse.vtk.org/user_avatar/discourse.vtk.org/loufear/32/3150_2.png) [@loufear](https://discourse.vtk.org/u/loufear)
#### Post date: [February 16, 2022, 11:51am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/1 "2022-02-16T11:51:29Z")

</div>

I used tkTexture but it doesn’t work well, I need help thanks

---

<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: [February 16, 2022, 9:08pm UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/2 "2022-02-16T21:08:23Z")

</div>

Hello,

Can you post an image of what you’re getting and describe what you were expecting?

regards,

Paulo

---

<div class="post-metadata">

### Author: ![loufear](https://discourse.vtk.org/user_avatar/discourse.vtk.org/loufear/32/3150_2.png) [@loufear](https://discourse.vtk.org/u/loufear)
#### Post date: [February 17, 2022, 1:16am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/3 "2022-02-17T01:16:20Z")

</div>

This is my code:  
auto pts\_ap = vtkSmartPointer::New();  
auto polygon = vtkSmartPointer::New();  
polygon-\>GetPointIds()-\>SetNumberOfIds(4);  
for (size\_t i = 0; i \< 4; i++)  
{  
pts\_ap-\>InsertNextPoint(m\_pTracker-\>AP\_pos[i \* 3 + 0], m\_pTracker-\>AP\_pos[i \* 3 + 1],  
m\_pTracker-\>AP\_pos[i \* 3 + 2]);  
polygon-\>GetPointIds()-\>SetId(i, i);  
}  
auto cells = vtkSmartPointer::New();  
cells-\>InsertNextCell(polygon);

```
auto rect_ap = vtkSmartPointer<vtkPolyData>::New();
rect_ap->SetPoints(pts_ap);
rect_ap->SetPolys(cells);

auto texture_ap = vtkSmartPointer<vtkTexture>::New();
texture_ap->SetInputData(ap);
texture_ap->SetRepeat(false);
texture_ap->SetEdgeClamp(true);
texture_ap->SetColorModeToMapScalars();
texture_ap->SetLookupTable(color_table);

auto texturemap_ap = vtkSmartPointer<vtkTextureMapToPlane>::New();
texturemap_ap->SetInputData(rect_ap);

auto transformTexture_ap = vtkSmartPointer<vtkTransformTextureCoords>::New();
transformTexture_ap->SetInputConnection(texturemap_ap->GetOutputPort());
transformTexture_ap->SetScale(1, 1, 0);

auto mapper_ap = vtkSmartPointer<vtkPolyDataMapper>::New();
mapper_ap->SetInputConnection(transformTexture_ap->GetOutputPort());

auto actor_ap = vtkSmartPointer<vtkActor>::New();
actor_ap->SetMapper(mapper_ap);
    actor_ap->SetTexture(texture_ap);
actor_ap->SetPickable(false);

m_RenWin->GetRenderers()->GetFirstRenderer()->AddActor(actor_ap);

```

This is the original:

 ![dcm](https://discourse.vtk.org/uploads/default/original/2X/d/dca7c7826036d76b7cd36e1fb3945c5f1f257d4c.png)  
This is mine:  
 ![image](https://discourse.vtk.org/uploads/default/original/2X/a/ad9b5a43125e60578f2d7e1a54225b11f55b1a34.png)

---

<div class="post-metadata">

### Author: ![loufear](https://discourse.vtk.org/user_avatar/discourse.vtk.org/loufear/32/3150_2.png) [@loufear](https://discourse.vtk.org/u/loufear)
#### Post date: [February 17, 2022, 5:49am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/4 "2022-02-17T05:49:56Z")

</div>

I’ve got the right result. should do SetOrigin, SetPoint1,SetPoint2 to get a right sysytem

---

<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: [February 17, 2022, 11:57am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/5 "2022-02-17T11:57:52Z")

</div>

Can you, please, share the fixed code (with the calls to `SetOrigin()`, `SetPoint1()` and `SentPoint2()`) so others of the community with the same problem can benefit from it?

---

<div class="post-metadata">

### Author: ![loufear](https://discourse.vtk.org/user_avatar/discourse.vtk.org/loufear/32/3150_2.png) [@loufear](https://discourse.vtk.org/u/loufear)
#### Post date: [February 18, 2022, 1:23am UTC](https://discourse.vtk.org/t/i-want-to-display-an-image-in-a-3d-rectangle-with-four-corner-points/7850/6 "2022-02-18T01:23:21Z")

</div>

well.  
auto texturemap\_ap = vtkSmartPointer::New();  
texturemap\_ap-\>SetInputData(rect\_ap);  
texturemap\_ap-\>SetOrigin(m\_pTracker-\>AP\_pos[3], m\_pTracker-\>AP\_pos[4], m\_pTracker-\>AP\_pos[5]);  
texturemap\_ap-\>SetPoint1(m\_pTracker-\>AP\_pos[6], m\_pTracker-\>AP\_pos[7], m\_pTracker-\>AP\_pos[8]);  
texturemap\_ap-\>SetPoint2(m\_pTracker-\>AP\_pos[0], m\_pTracker-\>AP\_pos[1], m\_pTracker-\>AP\_pos[2]);  
used Setorigin to set the lower left corner of the image as the origin, the lower right corner as the positive direction of the first axis, and the upper left corner as the positive direction of the second axis
