Skip to content

AngleWidget2D

Repository source: AngleWidget2D


Description

The arc is still visible?

Other languages

See (PythonicAPI), (Java)

Question

If you have a question about this example, please use the VTK Discourse Forum

Code

AngleWidget2D.cxx

#include <vtkAngleRepresentation2D.h>
#include <vtkAngleWidget.h>
#include <vtkNamedColors.h>
#include <vtkNew.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>

int main(int /* argc */, char* /* argv */[])
{
  vtkNew<vtkNamedColors> colors;

  // A renderer and render window
  vtkNew<vtkRenderer> renderer;
  vtkNew<vtkRenderWindow> renderWindow;
  renderWindow->AddRenderer(renderer);
  renderWindow->SetWindowName("AngleWidget2D");

  // An interactor
  vtkNew<vtkRenderWindowInteractor> renderWindowInteractor;
  renderWindowInteractor->SetRenderWindow(renderWindow);

  double pos1[3] = {50.0, 200.0, 0.0};
  double pos2[3] = {200.0, 20.0, 0.0};
  double center[3] = {100.0, 100.0, 0.0};
  vtkNew<vtkAngleRepresentation2D> rep;
  rep->ArcVisibilityOff();

  vtkNew<vtkAngleWidget> angleWidget;
  angleWidget->CreateDefaultRepresentation();
  angleWidget->SetRepresentation(rep);
  angleWidget->SetInteractor(renderWindowInteractor);

  renderWindow->Render();

  renderer->SetBackground(colors->GetColor3d("MidnightBlue").GetData());

  renderWindowInteractor->Initialize();
  renderWindow->Render();
  angleWidget->On();
  rep->SetPoint1DisplayPosition(pos1);
  rep->SetPoint2DisplayPosition(pos2);
  rep->SetCenterDisplayPosition(center);
  rep->Ray1VisibilityOn();
  rep->Ray2VisibilityOn();
  rep->ArcVisibilityOn();

  // Begin mouse interaction
  renderWindowInteractor->Start();

  return EXIT_SUCCESS;
}

CMakeLists.txt

cmake_minimum_required(VERSION 3.12 FATAL_ERROR)

project(AngleWidget2D)

find_package(VTK COMPONENTS 
  CommonColor
  CommonCore
  InteractionStyle
  InteractionWidgets
  RenderingContextOpenGL2
  RenderingCore
  RenderingFreeType
  RenderingGL2PSOpenGL2
  RenderingOpenGL2
)

if (NOT VTK_FOUND)
  message(FATAL_ERROR "AngleWidget2D: Unable to find the VTK build folder.")
endif()

# Prevent a "command line is too long" failure in Windows.
set(CMAKE_NINJA_FORCE_RESPONSE_FILE "ON" CACHE BOOL "Force Ninja to use response files.")
add_executable(AngleWidget2D MACOSX_BUNDLE AngleWidget2D.cxx )
  target_link_libraries(AngleWidget2D PRIVATE ${VTK_LIBRARIES}
)
# vtk_module_autoinit is needed
vtk_module_autoinit(
  TARGETS AngleWidget2D
  MODULES ${VTK_LIBRARIES}
)

Download and Build AngleWidget2D

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

cd AngleWidget2D/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:

./AngleWidget2D

WINDOWS USERS

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