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. xDir = (X_0, X_1, X_2), yDir = (Y_0, Y_1, Y_2), zDir = (Z_0, Z_1, Z_2) and origin = (O_0, O_1, O_2).

The matrix for the linear transform is

    \[M = \begin{pmatrix} X_0 & Y_0 & Z_0 & O_0 \\ X_1 & Y_1 & Z_1 & O_1 \\ X_2 & Y_2 & Z_2 & O_2 \\ 0 & 0 & 0 & 1 \end{pmatrix}\]

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

    \[M = \begin{pmatrix} -X_0 & Y_0 & Z_0 & O_0 \\ -X_1 & Y_1 & Z_1 & O_1 \\ -X_2 & Y_2 & Z_2 & O_2 \\ 0 & 0 & 0 & 1 \end{pmatrix}\]

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 <vtkSTLReader.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( reader, vtkSTLReader );
    reader->SetFileName( "data.STL" );
    reader->Update();

    vtkSPtrNew( mapper, vtkPolyDataMapper );
    mapper->SetInputConnection( reader->GetOutputPort() );

    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->AddActor(actor);
    renderer->SetBackground( 0, 0, 0 );

    vtkSPtrNew( renderWindow, vtkRenderWindow );
    renderWindow->AddRenderer( renderer );

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

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

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments

Tex To PDF
: convert the Latex file which suffix is tex to a PDF file

X
0
Would love your thoughts, please comment.x
()
x