Skip to content

ImageTracerWidgetNonPlanar

vtk-examples/Java/Widgets/ImageTracerWidgetNonPlanar

Description

vtkImageTracerWidget object is designed for manually tracing over image data.

The button actions and key modifiers are as follows for controlling the widget:

1) Left button click over the image, hold and drag draws a free hand line.

2) Left button click and release erases the widget line, if it exists, and repositions the first handle.

3) Middle button click starts a snap drawn line. The line is terminated by clicking the middle button while depressing the ctrl key.

4) When tracing a continuous or snap drawn line, if the last cursor position is within a specified tolerance to the first handle, the widget line will form a closed loop.

5) Right button clicking and holding on any handle that is part of a snap drawn line allows handle dragging: existing line segments are updated accordingly. If the path is open and AutoClose is set to On, the path can be closed by repositioning the first and last points over one another.

6) Ctrl key + right button down on any handle will erase it: existing snap drawn line segments are updated accordingly. If the line was formed by continuous tracing, the line is deleted leaving one handle.

7) Shift key + right button down on any snap drawn line segment will insert a handle at the cursor position. The line segment is split accordingly.

Other languages

See (Cxx)

Question

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

Code

ImageTracerWidgetNonPlanar.java

import vtk.vtkNativeLibrary;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkNamedColors;
import vtk.vtkRenderWindow;
import vtk.vtkRenderer;
import vtk.vtkPolyDataMapper;
import vtk.vtkActor;
import vtk.vtkImageTracerWidget;
import vtk.vtkInteractorStyleTrackball;
import vtk.vtkSphereSource;

public class ImageTracerWidgetNonPlanar 
{
  // -----------------------------------------------------------------
  // Load VTK library and print which library was not properly loaded
  static 
  {
    if (!vtkNativeLibrary.LoadAllNativeLibraries()) 
    {
      for (vtkNativeLibrary lib : vtkNativeLibrary.values()) 
      {
        if (!lib.IsLoaded()) 
        {
          System.out.println(lib.GetLibraryName() + " not loaded");
        }
      }
    }
    vtkNativeLibrary.DisableOutputWindow(null);
  }
  // -----------------------------------------------------------------

  public static void main(String s[]) 
  {

    vtkNamedColors Color = new vtkNamedColors(); 

    //For Renderer Background Color
    double BgColor[] = new double[4];

    //Change Color Name to Use your own Color for Renderer Background
    Color.GetColor("LightCoral",BgColor);

    //Create a Sphere
    vtkSphereSource Sphere = new vtkSphereSource();
    Sphere.Update();

    //Create a Mapper and Actor
    vtkPolyDataMapper Mapper = new vtkPolyDataMapper();
    Mapper.SetInputConnection(Sphere.GetOutputPort());

    vtkActor Actor = new vtkActor();
    Actor.SetMapper(Mapper);

    // Create the renderer, render window and interactor.
    vtkRenderer ren = new vtkRenderer();
    vtkRenderWindow renWin = new vtkRenderWindow();
    renWin.AddRenderer(ren);
    ren.AddActor(Actor);

    // An interactor
    vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
    iren.SetRenderWindow(renWin);

    vtkInteractorStyleTrackball Style = new vtkInteractorStyleTrackball();
    iren.SetInteractorStyle(Style);  

    vtkImageTracerWidget TracerWidget = new vtkImageTracerWidget();
    TracerWidget.SetInteractor(iren);
    TracerWidget.SetViewProp(Actor);
    TracerWidget.On();

    ren.SetBackground(BgColor);
    renWin.SetSize(300, 300);
    renWin.Render();

    iren.Start();
    iren.Initialize();

  }
}