[vtkusers] Display a STL file with vtk and Java _ vtkSTLReader

Mark Hervagault mark.hervagault at gmail.com
Tue May 27 03:52:25 EDT 2014


Hi Daniel,

thank you for your help.
I managed a program that loads and displays two STL files in the same
reference (the name of my projekt is JavaApplicationsVTK3D):

package javaapplicationsvtk3d;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;
import vtk.vtkActor;
import vtk.vtkLight;
import vtk.vtkNativeLibrary;
import vtk.vtkPanel;
import vtk.vtkPolyDataMapper;
import vtk.vtkSTLReader;

/**
 *
 * @author mark
 */
public class JavaApplicationsVTK3D extends JPanel /*implements
ActionEvent*/{

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 JavaApplicationsVTK3D() {
        super(new BorderLayout());
 
        // build VTK Pipeline
        vtkSTLReader reader = new vtkSTLReader();
        reader.SetFileName("porsche.stl");
                
        vtkPolyDataMapper Mapper = new vtkPolyDataMapper();
        Mapper.SetInputConnection(reader.GetOutputPort());
 
        vtkActor actor = new vtkActor();
        actor.SetMapper(Mapper);
 
        vtkSTLReader reader2 = new vtkSTLReader();
        reader2.SetFileName("peace.stl");
                
        vtkPolyDataMapper Mapper2 = new vtkPolyDataMapper();
        Mapper2.SetInputConnection(reader2.GetOutputPort());
 
        vtkActor actor2 = new vtkActor();
        actor2.SetMapper(Mapper2);
        
        vtkLight lum = new vtkLight();
        lum.SetColor(1,0.456 , 1);
        lum.SetIntensity(0.5);
        
        renWin = new vtkPanel();
        renWin.GetRenderer().AddActor(actor);
        renWin.GetRenderer().AddActor(actor2);
        renWin.GetRenderer().AddLight(lum);        
        
        exitButton = new JButton("Exit");
        
        add(renWin, BorderLayout.CENTER);
        add(exitButton, BorderLayout.SOUTH);
        
    }
 
    
    /** An actionPerformed(ActionEvent e) {*/
    public void actionPerformed(ActionEvent e) {
        exitButton = (JButton) e.getSource();
        if (e.getSource()==exitButton) {
            System.exit(0);
        }
    }
        
    public static void main(String[] args) {
        SwingUtilities.invokeLater(new Runnable() {
            @Override
            public void run() {
                JFrame frame = new JFrame("JavaApplicationsVTK3D");
                frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                frame.getContentPane().setLayout(new BorderLayout());
                frame.getContentPane().add(new JavaApplicationsVTK3D(),
BorderLayout.CENTER);
                frame.setSize(1200, 800);
                frame.setLocationRelativeTo(null);
                frame.setVisible(true);
            }
        });
    
    }
}


The button "exit" is not finish.
Mark.



------LIVE HAPPY------





--
View this message in context: http://vtk.1045678.n5.nabble.com/Display-a-STL-file-with-vtk-and-Java-vtkSTLReader-tp5727234p5727245.html
Sent from the VTK - Users mailing list archive at Nabble.com.


More information about the vtkusers mailing list