# AnnotatedCubeActor

VTKExamples/Cxx/Visualization/AnnotatedCubeActor

Other Languages

See (Java)

### Code

AnnotatedCubeActor.cxx

    #include <vtkSmartPointer.h>
    #include <vtkAnnotatedCubeActor.h>
    #include <vtkCamera.h>
    #include <vtkProperty.h>
    #include <vtkRenderer.h>
    #include <vtkRenderWindow.h>
    #include <vtkRenderWindowInteractor.h>
    #include <vtkNamedColors.h>

    int main( int, char *[] )
    {
      vtkSmartPointer<vtkAnnotatedCubeActor> cube =
        vtkSmartPointer<vtkAnnotatedCubeActor>::New();
      cube->SetFaceTextScale( 0.666667 );

      // set up the renderer, window, and interactor
      //
      vtkSmartPointer<vtkNamedColors> colors =
        vtkSmartPointer<vtkNamedColors>::New();

      vtkSmartPointer<vtkRenderer> renderer =
        vtkSmartPointer<vtkRenderer>::New();
      renderer->SetBackground(colors->GetColor3d("Wheat").GetData());

      vtkSmartPointer<vtkRenderWindow> renderWindow =
        vtkSmartPointer<vtkRenderWindow>::New();
      renderWindow->AddRenderer( renderer );
      renderWindow->SetSize(640, 480);

      vtkSmartPointer<vtkRenderWindowInteractor> interactor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
      interactor->SetRenderWindow( renderWindow );

      // anatomic labelling
      //
      cube->SetXPlusFaceText ( "A" );
      cube->SetXMinusFaceText( "P" );
      cube->SetYPlusFaceText ( "L" );
      cube->SetYMinusFaceText( "R" );
      cube->SetZPlusFaceText ( "S" );
      cube->SetZMinusFaceText( "I" );

      // change the vector text colors
      //
      cube->GetTextEdgesProperty()->SetColor(colors->GetColor3d("Black").GetData());
      cube->GetTextEdgesProperty()->SetLineWidth(4);

      vtkProperty *property;
      property = cube->GetXPlusFaceProperty();
      property->SetColor(colors->GetColor3d("Turquoise").GetData());
      property = cube->GetXMinusFaceProperty();
      property->SetColor(colors->GetColor3d("Turquoise").GetData());
      property = cube->GetYPlusFaceProperty();
      property->SetColor(colors->GetColor3d("Mint").GetData());
      property = cube->GetYMinusFaceProperty();
      property->SetColor(colors->GetColor3d("Mint").GetData());
      property = cube->GetZPlusFaceProperty();
      property->SetColor(colors->GetColor3d("Tomato").GetData());
      property = cube->GetZMinusFaceProperty();
      property->SetColor(colors->GetColor3d("Tomato").GetData());

      renderer->AddActor(cube);

      // set up an interesting view
      //
      vtkCamera* camera = renderer->GetActiveCamera();
      camera->SetViewUp( 0, 0, 1 );
      camera->SetFocalPoint( 0, 0, 0 );
      camera->SetPosition( 4.5, 4.5, 2.5 );
      renderer->ResetCamera();
      camera->Dolly(1.3);
      renderer->ResetCameraClippingRange();

      renderWindow->Render();
      interactor->Start();

      return EXIT_SUCCESS;
    }

### CMakeLists.txt

    cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

    project(AnnotatedCubeActor)

    find_package(VTK COMPONENTS
      vtkCommonColor
      vtkCommonCore
      vtkInteractionStyle
      vtkRenderingAnnotation
      vtkRenderingCore
      vtkRenderingFreeType
      vtkRenderingOpenGL2 QUIET)
    if (NOT VTK_FOUND)
      message("Skipping AnnotatedCubeActor: ${VTK_NOT_FOUND_MESSAGE}")
      return ()
    endif()
    message (STATUS "VTK_VERSION: ${VTK_VERSION}")
    if (VTK_VERSION VERSION_LESS "8.90.0")
      # old system
      include(${VTK_USE_FILE})
      add_executable(AnnotatedCubeActor MACOSX_BUNDLE AnnotatedCubeActor.cxx )
      target_link_libraries(AnnotatedCubeActor PRIVATE ${VTK_LIBRARIES})
    else ()
      # include all components
      add_executable(AnnotatedCubeActor MACOSX_BUNDLE AnnotatedCubeActor.cxx )
      target_link_libraries(AnnotatedCubeActor PRIVATE ${VTK_LIBRARIES})
      # vtk_module_autoinit is needed
      vtk_module_autoinit(
        TARGETS AnnotatedCubeActor
        MODULES ${VTK_LIBRARIES}
        )
    endif ()

### Download and Build AnnotatedCubeActor

Click here to download AnnotatedCubeActor and its CMakeLists.txt file. Once the tarball AnnotatedCubeActor.tar has been downloaded and extracted,

    cd AnnotatedCubeActor/build

If VTK is installed:

    cmake ..

If VTK is not installed but compiled on your system, you will need to specify the path to your VTK build:

    cmake -DVTK_DIR:PATH=/home/me/vtk_build ..

Build the project:

    make

and run it:

    ./AnnotatedCubeActor

WINDOWS USERS

Be sure to add the VTK bin directory to your path. This will resolve the VTK dll's at run time.