LegendScaleActor
vtk-examples/Java/Visualization/LegendScaleActor
Description¶
vtkLegendScaleActor object is used to annotate the render window. Its basic goal is to provide an indication of the scale of the scene. Four axes surrounding the render window indicate (in a variety of ways) the scale of what the camera is viewing. An option also exists for displaying a scale legend.
The axes can be programmed either to display distance scales or x-y coordinate values. By default, the scales display a distance. However, if you know that the view is down the z-axis, the scales can be programmed to display x-y coordinate values.
Other languages
See (Cxx)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
LegendScaleActor.java
import vtk.vtkActor;
import vtk.vtkNamedColors;
import vtk.vtkNativeLibrary;
import vtk.vtkPolyDataMapper;
import vtk.vtkRenderWindow;
import vtk.vtkRenderWindowInteractor;
import vtk.vtkRenderer;
import vtk.vtkSphereSource;
import vtk.vtkLegendScaleActor;
public class LegendScaleActor
{
// -----------------------------------------------------------------
// 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 args[])
{
vtkNamedColors colors = new vtkNamedColors();
//Renderer Background Color
double Bgcolor[] = new double[4];
colors.GetColor("DarkSlateBlue", Bgcolor);
vtkSphereSource sphereSource = new vtkSphereSource();
sphereSource.Update();
vtkPolyDataMapper sphereMapper = new vtkPolyDataMapper();
sphereMapper .SetInputData (sphereSource.GetOutput());
vtkActor sphereActor = new vtkActor();
sphereActor.SetMapper(sphereMapper);
// Create the renderer, render window and interactor.
vtkRenderer ren = new vtkRenderer();
vtkRenderWindow renWin = new vtkRenderWindow();
renWin.AddRenderer(ren);
vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();
iren.SetRenderWindow(renWin);
vtkLegendScaleActor legendScaleActor = new vtkLegendScaleActor();
// Visualize
ren.AddActor(sphereActor);
ren.AddActor(legendScaleActor);
ren.SetBackground(Bgcolor);
renWin.SetSize(640, 480);
renWin.Render();
iren.Initialize();
iren.Start();
}
}