There are two methods to create coordinate system in vkt, one this create a object which type is vtkAxesActor and another is create a object which type is vtkOrientationMarkerWidget.
The reference of the former locates at vtkAxesActor method, and the latter is vtkOrientationMarkerWidget method .
source code contains two method:
#include <vtkVersion.h>
#include <vtkPolyDataMapper.h>
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkPolyData.h>
#include <vtkSphereSource.h>
#include <vtkOrientationMarkerWidget.h>
#include <vtkAxesActor.h>
#include <vtkPropAssembly.h>
#include <vtkSmartPointer.h>
#include <vtkSTLReader.h>
#include <vtkTransform.h>
#include <vtkProperty.h>
#include "vtkCaptionActor2D.h"
int main(int argc, char *argv[])
{
std::string ExePath(_pgmptr);
ExePath = ExePath.substr(0, ExePath.find_last_of("\\"));
std::string inputFilename = ExePath + "\\cuboid.stl";
vtkSmartPointer<vtkSTLReader> reader =
vtkSmartPointer<vtkSTLReader>::New();
reader->SetFileName(inputFilename.c_str());
reader->Update();
// Visualize
vtkSmartPointer<vtkPolyDataMapper> mapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
mapper->SetInputData(reader->GetOutput());
// Create an actor
vtkSmartPointer<vtkActor> actor =
vtkSmartPointer<vtkActor>::New();
actor->SetMapper(mapper);
actor->GetProperty()->SetOpacity(0.5);
// A renderer and render window
vtkSmartPointer<vtkRenderer> renderer =
vtkSmartPointer<vtkRenderer>::New();
vtkSmartPointer<vtkRenderWindow> renderWindow =
vtkSmartPointer<vtkRenderWindow>::New();
renderWindow->AddRenderer(renderer);
// An interactor
vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
vtkSmartPointer<vtkRenderWindowInteractor>::New();
renderWindowInteractor->SetRenderWindow(renderWindow);
// Add the actors to the scene
renderer->AddActor(actor);
renderer->SetBackground(.2, .3, .4);
//create the axes locates the center of the cuboid
vtkSmartPointer<vtkTransform> transform = vtkSmartPointer<vtkTransform>::New();
//transform->Translate(0.0, 0.0, 0.0); // translate along the x axes with 3 unit step
vtkSmartPointer<vtkAxesActor> axes1 = vtkSmartPointer<vtkAxesActor>::New();
axes1->SetTotalLength(3, 3, 3); //set three axes length
// The axes are positioned with a user transform
axes1->SetUserTransform(transform);
renderer->AddActor(axes1);
//create the axes locates the lower left of the renderWindow
vtkSmartPointer<vtkAxesActor> axes2 = vtkSmartPointer<vtkAxesActor>::New();// axes actor
vtkSmartPointer<vtkOrientationMarkerWidget> orientationWidget =
vtkSmartPointer<vtkOrientationMarkerWidget>::New();
orientationWidget->SetOutlineColor(0.9300, 0.5700, 0.1300);
orientationWidget->SetOrientationMarker(axes2);
orientationWidget->SetInteractor(renderWindowInteractor); //binding the interactor
orientationWidget->SetViewport(0.0, 0.0, 0.4, 0.4);
orientationWidget->SetEnabled(1);
orientationWidget->InteractiveOn();
renderer->ResetCamera();
renderWindow->Render();
// Begin mouse interaction
renderWindowInteractor->Start();
return EXIT_SUCCESS;
}
The CMAKELIST.txt will also be given.
cmake_minimum_required(VERSION 2.8)
PROJECT(DisplayAexs)
find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
add_executable(DisplayAexs MACOSX_BUNDLE DisplayAexs.cxx )
target_link_libraries(DisplayAexs ${VTK_LIBRARIES})
The ultimate effect shows as the following photo.