Advertisement
Guest User

with interactor

a guest
Jul 2nd, 2015
30
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.78 KB | None
  1. import java.awt.*;
  2.  
  3. import javax.swing.*;
  4.  
  5. import vtk.*;
  6.  
  7. public class JFrameRenderer extends JFrame
  8. {
  9.  
  10.   static {
  11.     for (vtkNativeLibrary lib : vtkNativeLibrary.values()) {
  12.         try {  
  13.                  System.loadLibrary(lib.GetLibraryName());
  14.             } catch(UnsatisfiedLinkError e) {
  15.             }
  16.     }
  17.   }
  18.  
  19.   public JFrameRenderer()
  20.   {
  21.     // Create a sphere source
  22.     vtkCubeSource cube = new vtkCubeSource();
  23.  
  24.     // Create a sphere mapper
  25.     vtkPolyDataMapper cubeMapper = new vtkPolyDataMapper();
  26.     cubeMapper.SetInputConnection(cube.GetOutputPort());
  27.  
  28.     //create sphere actor
  29.     vtkActor cubeActor = new vtkActor();
  30.     cubeActor.SetMapper(cubeMapper);
  31.  
  32.     // Create a render window panel to display the sphere
  33.     vtkRenderWindowPanel renderWindowPanel = new vtkRenderWindowPanel();
  34.     renderWindowPanel.setPreferredSize(new Dimension(600, 600));
  35.     renderWindowPanel.setInteractorStyle(new vtkInteractorStyleTrackballCamera());
  36.  
  37.     add(renderWindowPanel, BorderLayout.CENTER);
  38.  
  39.     renderWindowPanel.GetRenderer().AddActor(cubeActor);
  40.    
  41.     // Let's add an interactor to make it render properly.
  42.     renderWindowPanel.getRenderWindowInteractor().Start();
  43.   }
  44.  
  45.   public static void main(String[] args)
  46.   {
  47.     try
  48.     {
  49.       javax.swing.SwingUtilities.invokeLater(new Runnable()
  50.       {
  51.         public void run()
  52.         {
  53.           JPopupMenu.setDefaultLightWeightPopupEnabled(false);
  54.           ToolTipManager.sharedInstance().setLightWeightPopupEnabled(false);
  55.  
  56.           JFrame frame = new JFrameRenderer();
  57.           frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  58.           frame.pack();
  59.           frame.setVisible(true);
  60.         }
  61.       });      
  62.     }
  63.     catch (Exception e)
  64.     {
  65.       e.printStackTrace();
  66.     }
  67.   }
  68. }
Advertisement
RAW Paste Data Copied
Advertisement