As we know, we can create a linear transform to change model to the special orientation and position. Refer to The Releationship Between Local Transform And Pose Transform.

Let’s define orientation and position by three axis and point. , , and origin = .

The matrix for the linear transform is

If we want to flip 3D model on the X direction, let’s just change xDir to -xDir.

Code snippet:

#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 <vtkTransform.h>

#include "point.hpp"

#define vtkSPtr vtkSmartPointer
#define vtkSPtrNew(Var, Type) vtkSPtr<Type> Var = vtkSPtr<Type>::New();

using namespace std;

int main()
{

vtkSPtrNew( mapper, vtkPolyDataMapper );

Point xDir( 0.997799, 0, -0.0663169 );
Point yDir( 0.121576, 0, -0.992582 );
Point zDir( 0, 0.982335, 0 );
Point origin( 2.12698, 1.19844, 3.15008 );
double elements[16] = { -xDir[0], yDir[0], zDir[0], origin[0],
-xDir[1], yDir[1], zDir[1], origin[1],
-xDir[2], yDir[2], zDir[2], origin[2],
0, 0, 0, 1 };
vtkSPtrNew( trans, vtkTransform );
trans->SetMatrix( elements );
trans->Update();

vtkSPtrNew( actor, vtkActor );
actor->SetMapper( mapper );
actor->SetUserTransform( trans );

vtkSPtrNew( renderer, vtkRenderer );
renderer->SetBackground( 0, 0, 0 );

vtkSPtrNew( renderWindow, vtkRenderWindow );

vtkSPtrNew( renderWindowInteractor, vtkRenderWindowInteractor );
renderWindowInteractor->SetRenderWindow( renderWindow );

renderer->ResetCamera();
renderWindow->Render();
renderWindowInteractor->Start();
return 0;
}

Categories: VTK

Article Rating
Subscribe
Notify of