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

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

Hello,

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

regards,

Paulo

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:


This is mine:

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

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?

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

1 Like