I use VTK on visual studio 2010, I would like apply an image on the cube faces.
Code to read my image :
// Read JPG image
vtkSmartPointer<vtkJPEGReader> JPEGReader = vtkSmartPointer<vtkJPEGReader>::New();
JPEGReader->SetFileName(argv[1]);
JPEGReader->Update();
// Image actor
vtkSmartPointer<vtkImageActor> imageActor = vtkSmartPointer<vtkImageActor>::New();
imageActor->GetMapper()->SetInputData(JPEGReader->GetOutput());
Setup cube code :
// Setup cube
vtkSmartPointer<vtkCubeSource> cubeSource = vtkSmartPointer<vtkCubeSource>::New();
cubeSource->Update();
vtkSmartPointer<vtkPolyDataMapper> cubeMapper = vtkSmartPointer<vtkPolyDataMapper>::New();
cubeMapper->SetInputConnection(cubeSource->GetOutputPort());
vtkSmartPointer<vtkActor> cubeActor = vtkSmartPointer<vtkActor>::New();
cubeActor->SetMapper(cubeMapper);
cubeActor->GetProperty()->SetDiffuseColor(.3, .6, .4);
How I do that ?
You need to use a texture and a texture map to achieve what you want. I adapted a small example from this one (although in python) that can help you with a starting point. In this case,
vtkTextureMapToPlane
is not the ideal one, because it only covers 2 faces of the cube (check out the image below). However, I thinkvtkTextureMapToBox
, as in this link, should be able to do the trick (I could not use it because I am using VTK 5.8).Code:
Result: