The affine transform in the 3D world can be represented by a 4×4 matrix.

    \[T =  \begin{pmatrix} a_{1,1} & a_{1,2} & a_{1,3} & b_1\\ a_{2,1} & a_{2,2} & a_{2,3} & b_2\\ a_{3,1} & a_{3,2} & a_{3,3} & b_3\\ 0 & 0 & 0 & 1 \end{pmatrix} = \begin{pmatrix} A & \vec{B} \\ \vec{0} & 1 \end{pmatrix}\]

If there is no scale in the affine transform, the vector \vec{B} is translate vector and A is the rotate matrix.

The original point’s position is representing by M, the changed point’s position is M’.

    \[M^{'} = TM\]

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

using namespace std;

int main()
{
    vtkSPtrNew( trans, vtkTransform );
    trans->RotateX( 30 );
    trans->Translate( 0, 3, 2 );
    //trans->Scale( 2, 3, 4 );
    trans->Translate( 1, 0, 0 );
    trans->RotateY( 45 );
    //trans->Scale( 2, 3, 4 );
    trans->Update();

    trans->PrintSelf( std::cout, vtkIndent() );

    vtkSPtrNew( moveTrans, vtkTransform );
    moveTrans->Translate( 1, 1.59808, 3.23205 );
    moveTrans->Update();
    moveTrans->PrintSelf( std::cout, vtkIndent() );

    double elements[16] = {
        0.707107    ,0          ,0.707107   ,0,
        0.353553    ,0.866025   ,-0.353553  ,0,
        -0.612372   ,0.5        ,0.612372   ,0,
        0           ,0          ,0          ,1
    };
    vtkSPtrNew( rotateTrans, vtkTransform );
    rotateTrans->SetMatrix( elements );
    rotateTrans->Update();

    vtkSPtrNew( testTrans, vtkTransform );
    testTrans->Concatenate( moveTrans );
    testTrans->Concatenate( rotateTrans );
    testTrans->Update();

    testTrans->PrintSelf( std::cout, vtkIndent() ); //the matrix is same with the trans's.
    return 0;
}

/*
    0.707107    0           0.707107    1
    0.353553    0.866025    -0.353553   1.59808
    -0.612372   0.5         0.612372    3.23205
    0           0           0           1
*/

Categories: MathVTK

0 0 votes
Article Rating
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Image Processing: support to flip your image.

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