We can find that vtkImageActor object will display image with controling its position with the bottom left corner of the image by the default way.
Test project:
#include <vtkTransformFilter.h>
#include <vtkImageData.h>
#include <iostream>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkActor.h>
#include <vtkConeSource.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkPolyDataMapper.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkTextSource.h>
#include <vtkAxesActor.h>
#include <vtkImageActor.h>
#include <vtkPNGReader.h>
#include <vtkTransform.h>
#include <vtkFollower.h>
#include <vtkImageMapper.h>
#include <vtkBillboardTextActor3D.h>
#include <vtkJPEGReader.h>
#include <vtkImageSlice.h>
#include <vtkImageMapper3D.h>
#include <vtkCamera.h>
#include <vtkImageProperty.h>
#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();
using namespace std;
int main()
{
vtkSPtrNew( reader, vtkPNGReader );
reader->SetFileName( "screenshot.png" );
reader->Update();
vtkSmartPointer<vtkImageData> imgData = reader->GetOutput();
vtkSPtrNew( imgActor, vtkImageActor );
imgActor->SetInputData( imgData );
imgActor->SetScale( 0.1 );
vtkSmartPointer<vtkAxesActor> axes = vtkSmartPointer<vtkAxesActor>::New();
axes->AxisLabelsOff();
axes->SetTotalLength( 3, 3, 3 );
vtkSPtrNew( renderer, vtkRenderer );
renderer->AddActor( axes );
renderer->AddActor( imgActor );
renderer->SetBackground( 0, 0, 0 );
vtkSPtrNew( renderWindow, vtkRenderWindow );
renderWindow->AddRenderer( renderer );
vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
renderWindowInteractor->SetRenderWindow( renderWindow );
renderer->ResetCamera();
renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}
Result:
How to make the image’s center as actor’s position? Just as rewrite 3D model to make center as (0,0,0), related post: https://www.weiy.city/2022/01/rewrite-file-to-move-3d-model-to-origin-point/
Let’s change imageData:
vtkSmartPointer<vtkImageData> imgData = reader->GetOutput();
double *bds = imgData->GetBounds();
imgData->SetOrigin( -(bds[0]+bds[1])*0.5, -(bds[2]+bds[3])*0.5, -(bds[4]+bds[5])*0.5 );
New result: