LightActor
Repository source: LightActor
Description¶
Java Program to demonstrate the use of vtkLightActor.
Other languages
See (Cxx)
Question
If you have a question about this example, please use the VTK Discourse Forum
Code¶
LightActor.java
import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import vtk.vtkLight;
import vtk.vtkLightActor;
import vtk.vtkNativeLibrary;
import vtk.vtkPanel;
public class LightActor extends JPanel implements ActionListener {
private static final long serialVersionUID = 1L;
private vtkPanel renWin;
private JButton exitButton;
// -----------------------------------------------------------------
// 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 LightActor() {
super(new BorderLayout());
// Display where the light is
vtkLight Light = new vtkLight();
Light.SetPositional(1);
vtkLightActor LightActor = new vtkLightActor();
LightActor.SetLight(Light);
renWin = new vtkPanel();
renWin.GetRenderer().AddActor(LightActor);
renWin.GetRenderer().AddViewProp(LightActor);
renWin.resetCamera();
// Add Java UI components
exitButton = new JButton("Exit");
exitButton.addActionListener(this);
add(renWin, BorderLayout.CENTER);
add(exitButton, BorderLayout.SOUTH);
}
/** An ActionListener that listens to the button. */
public void actionPerformed(ActionEvent e) {
if (e.getSource().equals(exitButton)) {
System.exit(0);
}
}
public static void main(String s[]) {
SwingUtilities.invokeLater(new Runnable() {
public void run() {
JFrame frame = new JFrame("Light Actor");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.getContentPane().setLayout(new BorderLayout());
frame.getContentPane().add(new LightActor(), BorderLayout.CENTER);
frame.setSize(400, 400);
frame.setLocationRelativeTo(null);
frame.setVisible(true);
}
});
}
}