Original Status

The initial scene looks like the following image. I will rotate cone around point (1, 0, 0) and direction (0, 0, 1).

Code

#include <vtkActor.h>
#include <vtkCleanPolyData.h>
#include <vtkDistancePolyDataFilter.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkPointData.h>
#include <vtkPolyDataMapper.h>
#include <vtkPolyDataReader.h>
#include <vtkProperty.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkScalarBarActor.h>
#include <vtkSmartPointer.h>
#include <vtkSphereSource.h>
#include <vtkSTLReader.h>
#include <vtkConeSource.h>
#include <vtkXMLPolyDataReader.h>
#include <vtkPLYReader.h>
#include <vtkAxesActor.h>
#include <vtkTransform.h>
#include <vtkParametricTorus.h>
#include <vtkParametricFunctionSource.h>

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


int main()
{
    setbuf( stdout, nullptr );
    vtkSPtrNew( cone, vtkConeSource );
    cone->SetCenter( 0.5, 0, 0 );

    vtkSPtrNew( coneMapper, vtkPolyDataMapper );
    coneMapper->SetInputConnection( cone->GetOutputPort() );

    vtkSPtrNew( coneActor, vtkActor );
    coneActor->SetMapper( coneMapper );

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

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

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

    vtkSPtrNew( axes, vtkAxesActor );
    axes->SetTotalLength( 1, 1, 1 ); // change length of three axis
    vtkSPtrNew(parametricTorus, vtkParametricTorus);
    parametricTorus->SetRingRadius(1);
    parametricTorus->SetCrossSectionRadius(0.1);

    vtkSPtrNew(parametricFunctionSource, vtkParametricFunctionSource);
    parametricFunctionSource->SetParametricFunction(parametricTorus);
    parametricFunctionSource->Update();

    vtkSPtrNew( parametricMapper, vtkPolyDataMapper );
    parametricMapper->SetInputData( parametricFunctionSource->GetOutput() );

    vtkSPtrNew( zRingActor, vtkActor );
    zRingActor->SetMapper( parametricMapper );
    zRingActor->GetProperty()->SetOpacity( 0.5 );

    renderer->AddActor( zRingActor );
    renderer->AddActor( axes );
    renderer->AddActor( coneActor );

    renderer->ResetCamera();
    renderWindow->Render();

    vtkSPtrNew( coneTrans, vtkTransform );
//    double len = 0.5;
//    coneTrans->Translate( len, 0, 0 );
//    coneTrans->RotateWXYZ( 45, 0, 0, 1 );
//    coneTrans->Translate( -len, 0, 0 );
//    coneTrans->Update();

    coneActor->SetUserTransform( coneTrans );

    renderWindowInteractor->Start();
    return 0;
}

Rotatint Implementation: vtkTransform concatenate

    double len = 1;
    vtkSPtrNew( moveTrans, vtkTransform );
    moveTrans->Translate( len, 0, 0 );
    vtkSPtrNew( rotateTrans, vtkTransform );
    rotateTrans->RotateWXYZ( 45, 0, 0, 1 );
    vtkSPtrNew( moveTransInv, vtkTransform );
    moveTransInv->Translate( -len, 0, 0 );

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

    coneActor->SetUserTransform( coneTrans );

Rotatint Implementation: vtkTransform built-in method

    vtkSPtrNew( coneTrans, vtkTransform );
    double len = 1;
    coneTrans->Translate( len, 0, 0 );
    coneTrans->RotateWXYZ( 45, 0, 0, 1 );
    coneTrans->Translate( -len, 0, 0 );
    coneTrans->Update();

    coneActor->SetUserTransform( coneTrans );

Rotate Around Object’s Center

It can go back perfectly.

    vtkSPtrNew( coneTrans, vtkTransform );
    double len = 0.5;
    coneTrans->Translate( len, 0, 0 );
    coneTrans->RotateWXYZ( 45, 0, 0, 1 );
    coneTrans->Translate( -len, 0, 0 );
    coneTrans->Update();

    coneActor->SetUserTransform( coneTrans );
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