[vtkusers] widgets in JAVA, new vtkPanel version?

Jeff Lee jeff at cdnorthamerica.com
Mon Mar 21 14:04:55 EST 2005


Hi Lars,
Have a look at vtkCanvas.java (and other examples in Wrapping/Java)- it 
should give you a decent starting point.  I think your problem is that 
you're starting another event loop by calling Initialize and Start on 
the interactor.  This starts up an x-event loop on linux/unix, or a 
windows event loop on win32, and as a side effect, it is opening up a 
native renderwindow.  vtkPanel/vtkCanvas use java's event loop.
-Jeff

Lars Matthäus wrote:

>Dear Insiders,
>
>I try in vain to get a widget running in a vtkPanel. What I get are two windows popping up - a JAVA-Panel-window where the widget doesn't work and an OpenGL-Window in which the widget works as expected. What I want is only one window - the JAVA-Panel-one - and with widget functionality.
>
>I know that this issue was raised several times before on this list (and Jeff answered often helpfully), but the answers given where of no use for me. (I'm new to this vtk stuff.)
>
>Is there any new development on that toppic, especially a new version of the vtkPanel file, which allows for widgets in panels?
>
>Thanks for your help!
>
>Lars
>
>
>ps.: If somebody wants to have a look on what I have done:
>
>
>package visualize;
>
>import java.awt.*;
>import java.awt.event.*;
>import javax.swing.*;
>import java.util.LinkedList;
>import java.util.Observable;
>import java.util.Observer;
>import java.lang.Thread;
>
>import vtk.*;
>
>/**
> * An application that displays a JButton and several JRadioButtons. The
> * JRadioButtons determine the look and feel used by the application.
> */
>public class ShowDicomOrthogonalSlices extends JPanel implements ActionListener, Runnable {
>    static JFrame frame;
>
>    vtkPanel renWin;
>    vtkRenderWindowInteractor iact=null;
>    
>    JButton exitButton;
>
>    
>    public void run() {
>        renWin.GetRenderWindow().GetInteractor().Initialize();
>        renWin.GetRenderWindow().GetInteractor().Start();
>    }
>    
>    public ShowDicomOrthogonalSlices() {
>        setLayout(new BorderLayout());
>        renWin = new vtkPanel();
>        
>        renWin.addWindowSetObserver(new Observer() {
>            public void update(Observable o, Object arg) {
>              renWin.setSize(600, 600);
>            }
>          });
>
>        add(renWin, BorderLayout.CENTER);
>        
>
>        LinkedList dicoms = new LinkedList();
>
>        String s;
>        for (int i = 53; i <= 91; i++) {
>            if (i < 10)
>                s = "00" + i;
>            else if (i < 100)
>                s = "0" + i;
>            else
>                s = "" + i;
>            dicoms.add("C:/DICOM/DICOM-Samples/DICOM/MR_" + s
>                    + ".dcm");
>
>        }
>        double minmax[] = new double[2];
>        double d;
>
>        vtkActorCollection actorCollection = new vtkActorCollection();
>        vtkImageActor imageActor;
>        vtkDICOMImageReader dicomImage;
>        vtkImageData imageData;
>        vtkImageShiftScale imageShift;
>        vtkImageReslice imageReslice;
>        vtkImageData fullImage = new vtkImageData();
>
>        try {
>            dicomImage = new vtkDICOMImageReader();
>            dicomImage.SetFileName((String) dicoms.get(0));
>            imageData = new vtkImageData();
>            imageData = dicomImage.GetOutput();
>            imageData.Update();
>            int dim[] = imageData.GetDimensions();
>            System.out
>                    .println("" + dim[0] + "x" + dim[1] + "x" + dicoms.size());
>            double spacing[] = imageData.GetSpacing();
>            fullImage.SetDimensions(dim[0], dim[1], dicoms.size());
>            fullImage.SetSpacing(spacing[0], spacing[1], spacing[2]);
>            fullImage.SetNumberOfScalarComponents(1);
>
>            for (int i = 0; i < dicoms.size(); i++) {
>                dicomImage = new vtkDICOMImageReader();
>                dicomImage.SetFileName((String) dicoms.get(i));
>                imageData = new vtkImageData();
>                imageData = dicomImage.GetOutput();
>                imageData.Update();
>                for (int j = 0; j < dim[0]; j++)
>                    for (int k = 0; k < dim[1]; k++) {
>                        d = imageData.GetScalarComponentAsDouble(j, k, 0, 0);
>                        //                        System.out.println("j=" + j + ", k=" + k + ", i=" + i
>                        //                                + ", d=" + d);
>                        fullImage.SetScalarComponentFromDouble(j, k, i, 0, d);
>                    }
>            }
>
>            fullImage.Update();
>            minmax = fullImage.GetScalarRange();
>            System.out.println("min=" + minmax[0] + ", max=" + minmax[1]);
>
>            imageShift = new vtkImageShiftScale();
>            imageShift.SetInput(fullImage);
>            imageShift.SetShift(-1.0 * minmax[0]);
>            imageShift.SetScale(255.0 / (minmax[1] - minmax[0]));
>            imageShift.SetOutputScalarTypeToUnsignedChar();
>
>            imageShift.Update();
>            d = imageShift.GetOutput().GetScalarComponentAsDouble(0, 0, 0, 0);
>            System.out.println("d=" + d);
>            vtkImageThreshold imageThreshold = new vtkImageThreshold();
>            imageThreshold.SetInput(imageShift.GetOutput());
>            imageThreshold.SetInValue(0);
>            imageThreshold.ThresholdBetween(d - 10, d + 10);
>            imageThreshold.SetOutputScalarTypeToUnsignedChar();
>            
>            vtkLookupTable colorTable = new vtkLookupTable();
>            colorTable.SetTableRange(0,255);
>            colorTable.SetHueRange(0,0);
>            colorTable.SetSaturationRange(0,0);
>            colorTable.SetValueRange(0,1);
>            colorTable.SetRampToLinear();
>            
>            vtkCellPicker picker = new vtkCellPicker();
>            picker.SetTolerance(0.005);
>            
>            iact = renWin.GetRenderWindow().MakeRenderWindowInteractor();
>            System.out.println(""+renWin.GetRenderWindow().GetInteractor()+
>                    "\n"+iact);
>            
>            vtkImagePlaneWidget planeWidgetX = new vtkImagePlaneWidget();
>            planeWidgetX.SetInteractor(iact);
>            planeWidgetX.SetInput(imageThreshold.GetOutput());
>            planeWidgetX.UserControlledLookupTableOn();
>            planeWidgetX.SetLookupTable(colorTable);
>            planeWidgetX.SetPlaneOrientationToXAxes();
>            planeWidgetX.SetSliceIndex(32);
>            planeWidgetX.SetPicker(picker);
>            planeWidgetX.SetKeyPressActivationValue('x');
>            vtkProperty prop1 = planeWidgetX.GetPlaneProperty();
>            prop1.SetColor(1, 0, 0);
>            planeWidgetX.On();
>            
>            vtkImagePlaneWidget planeWidgetY = new vtkImagePlaneWidget();
>            planeWidgetY.SetInteractor(iact);
>            planeWidgetY.SetInput(imageThreshold.GetOutput());
>            planeWidgetY.UserControlledLookupTableOn();
>            planeWidgetY.SetLookupTable(colorTable);
>            planeWidgetY.SetPlaneOrientationToYAxes();
>            planeWidgetY.SetSliceIndex(32);
>            planeWidgetY.SetPicker(picker);
>            planeWidgetY.SetKeyPressActivationValue('y');
>            vtkProperty prop2 = planeWidgetY.GetPlaneProperty();
>            prop2.SetColor(0, 1, 0);
>            planeWidgetY.On();
>            
>            vtkImagePlaneWidget planeWidgetZ = new vtkImagePlaneWidget();
>            planeWidgetZ.SetInteractor(iact);
>            planeWidgetZ.SetInput(imageThreshold.GetOutput());
>            planeWidgetZ.UserControlledLookupTableOn();
>            planeWidgetZ.SetLookupTable(colorTable);
>            planeWidgetZ.SetPlaneOrientationToZAxes();
>            planeWidgetZ.SetSliceIndex(32);
>            planeWidgetZ.SetPicker(picker);
>            planeWidgetZ.SetKeyPressActivationValue('z');
>            vtkProperty prop3 = planeWidgetZ.GetPlaneProperty();
>            prop3.SetColor(0, 0, 1);
>            planeWidgetZ.On();
>            
>            
>
>            renWin.GetRenderer().AddActor(getCursorActor(100, 200, 50));
>            renWin.GetRenderer().SetBackground(1, 1, 1);
>            renWin.setSize(600,600);
>            
>            renWin.GetRenderer().GetCullers().RemoveAllItems();
>            
>            renWin.GetRenderer().InteractiveOn();
>            renWin.GetRenderWindow().SetInteractor(iact);    
>            
>        } catch (Exception e) {
>            System.out.println(e);
>        }
>        exitButton = new JButton("Exit");
>        exitButton.addActionListener(this);
>
>        add(renWin, BorderLayout.CENTER);
>        add(exitButton, BorderLayout.EAST);
>        
>    }
>
>
>
>    private vtkActor getCursorActor(double xLength, double yLength,
>            double zLength) {
>        vtkCursor3D cursor = new vtkCursor3D();
>        cursor.AxesOn();
>        cursor.OutlineOff();
>        cursor.XShadowsOff();
>        cursor.YShadowsOff();
>        cursor.ZShadowsOff();
>        cursor.SetModelBounds(-xLength, xLength, -yLength, yLength, -zLength,
>                zLength);
>        cursor.SetFocalPoint(0, 0, 1);
>        cursor.Update();
>        vtkPolyDataMapper mapper = new vtkPolyDataMapper();
>        mapper.SetInput(cursor.GetOutput());
>        vtkActor cursorActor = new vtkActor();
>        cursorActor.GetProperty().SetColor(1, 0, 0);
>        cursorActor.SetMapper(mapper);
>        return cursorActor;
>    }
>
>
>    /** An ActionListener that listens to the radio buttons. */
>    public void actionPerformed(ActionEvent e) {
>        if (e.getSource().equals(exitButton)) {
>            System.exit(0);
>        }
>    }
>
>    public static void main(String s[]) {
>        ShowDicomOrthogonalSlices panel = new ShowDicomOrthogonalSlices();
>
>  
>        
>        frame = new JFrame("DICOM-VTK");
>        frame.setBounds(500, 500, 0, 0);
>        frame.addWindowListener(new WindowAdapter() {
>            public void windowClosing(WindowEvent e) {
>                System.exit(0);
>            }
>        });
>        frame.getContentPane().add("Center", panel);
>        frame.pack();
>        frame.setVisible(true);
>        
>
>        new Thread(panel).start();
>    
>    }
>}
>______________________________________________________________
>Verschicken Sie romantische, coole und witzige Bilder per SMS!
>Jetzt bei WEB.DE FreeMail: http://f.web.de/?mc=021193
>
>_______________________________________________
>This is the private VTK discussion list. 
>Please keep messages on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
>Follow this link to subscribe/unsubscribe:
>http://www.vtk.org/mailman/listinfo/vtkusers
>
>
>  
>

-- 
Jeff Lee
Senior Software Engineer
Computational Dynamics North America Ltd
21 Lafayette Street, Suite 230
Lebanon NH 03766 USA
fax:   603 643 9994
phone: 603 643 9993 x109
http://www.cd-adapco.com




More information about the vtkusers mailing list