[vtkusers] vtkPointPicker

Chris Hood Chris.Hood at noaa.gov
Tue Jun 1 13:56:41 EDT 2004


At 02:56 PM 5/25/2004, Mathieu Malaterre wrote:
>         Could you please provide a sample code that reproduce the bug you 
> are mentionning. Also keep in mind that we don't always knows everybody's 
> problems, so please make some references to your previous emails. This is 
> also a good idea to read:

Here's a small program that can reproduce some of the problems.
- When clicking on the inner sphere (actor0), only one point is returned 
there should be 2 (if I understand the documentation right), one as it 
enters and one as it leaves.
- When clicking on the inner sphere the distance from the origin should 
always be 30 since the radius is 30, but its not.
- When clicking on the plane (flattened cylinder) it returns in some spots, 
but not right since the y value should be 0.
- When clicking on the plane when it is not in the pick list, some spots 
near the inner sphere sometime return a point.
- When clicking on the outer sphere (actor2), it is ok from original angle, 
but when rotated it only works in some spots

I can't get it to reproduce the totally random extra points.


package vtknurse2;

import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import vtk.*;
import java.math.*;

public class Frame extends JFrame {
    JPanel contentPane;
    JToolBar jToolBar = new JToolBar();
    JButton jButton1 = new JButton(), jButton2 = new JButton();
    JLabel statusBar = new JLabel();
    BorderLayout borderLayout1 = new BorderLayout();

    static {
       System.loadLibrary("vtkCommonJava");
       System.loadLibrary("vtkFilteringJava");
       System.loadLibrary("vtkIOJava");
       System.loadLibrary("vtkImagingJava");
       System.loadLibrary("vtkGraphicsJava");
       System.loadLibrary("vtkRenderingJava");
       System.loadLibrary("vtkParallelJava");
       }

    vtkPanel renPanel = new vtkPanel();
    vtkPointPicker pointPicker = new vtkPointPicker();
    vtkActor actor0 = new vtkActor(), actor1 = new vtkActor(), actor2 = new 
vtkActor();

    public Frame()  {
       enableEvents(AWTEvent.WINDOW_EVENT_MASK);
       try {jbInit();}  catch(Exception e) {e.printStackTrace();}
       }

    private void jbInit() throws Exception  {
       contentPane = (JPanel) this.getContentPane();
       contentPane.setLayout(borderLayout1);
       this.setSize(new Dimension(400, 300));
       this.setTitle("VTK NurseShark 2");

       jButton1.setText("1");
       jButton2.setText("2");
       statusBar.setText(" ...");
       jToolBar.add(jButton1);
       jToolBar.add(jButton2);

       vtkInit();

       contentPane.add(jToolBar, BorderLayout.NORTH);
       contentPane.add(renPanel, BorderLayout.CENTER);
       contentPane.add(statusBar, BorderLayout.SOUTH);
       }


    public void vtkInit() {
       renPanel.addMouseListener(new java.awt.event.MouseAdapter() {
          public void mouseClicked(MouseEvent e) {PointPick(e);
             }});


       vtkSphereSource sphere0 = new vtkSphereSource();
       sphere0.SetRadius(30.0);
       sphere0.SetThetaResolution(30);
       sphere0.SetPhiResolution(30);
       vtkPolyDataMapper mapper0 = new vtkPolyDataMapper();
       mapper0.SetInput(sphere0.GetOutput());
       actor0.SetMapper(mapper0);
       actor0.GetProperty().SetColor(.5,0,1);
       renPanel.GetRenderer().AddActor(actor0);

       actor2.SetMapper(mapper0);
       actor2.GetProperty().SetColor(0,0,1);
       actor2.SetPosition(150,0,150);
       renPanel.GetRenderer().AddActor(actor2);

       vtkCylinderSource cylinder1 = new vtkCylinderSource();
       cylinder1.SetRadius(205.0);
       cylinder1.SetHeight(2);
       cylinder1.SetResolution(40);
       vtkPolyDataMapper mapper1 = new vtkPolyDataMapper();
       mapper1.SetInput(cylinder1.GetOutput());
       actor1.SetOrientation(0, 0, 0);
       actor1.SetMapper(mapper1);
       actor1.GetProperty().SetColor(.1,.5,1);
       renPanel.GetRenderer().AddActor(actor1);
       }

    public void jMenuFileExit_actionPerformed(ActionEvent e) {System.exit(0);}
    protected void processWindowEvent(WindowEvent e) {
       super.processWindowEvent(e);
       if (e.getID() == WindowEvent.WINDOW_CLOSING) {System.exit(0);}
       }

    void PointPick (MouseEvent e) {
       int x=e.getX(), y=e.getY();
       double[] a;
       pointPicker = new vtkPointPicker();
       pointPicker.AddPickList(actor0);
       pointPicker.AddPickList(actor1);
       pointPicker.AddPickList(actor2);
       pointPicker.PickFromListOn();
       pointPicker.Pick(x,y,0,renPanel.GetRenderer());
       int noOfPoints = pointPicker.GetPickedPositions().GetNumberOfPoints();
       System.out.println("Number of Points: " + noOfPoints);
//      a = pointPicker.GetPickPosition();
//      System.out.println("PickPosition:   "  +a[0] + ",  " + a[1] + ",  " 
+ a[2]);
//      System.out.println(pointPicker.GetPointId());

       for(int i=0;i<noOfPoints;i++){
          a = pointPicker.GetPickedPositions().GetPoint(i);
          System.out.println("Point " + i +":   "  +a[0] + ",  " + a[1] + 
",  " + a[2]);
          System.out.println("   Distance from origin: " + 
Math.sqrt(a[0]*a[0] + a[1]*a[1] + a[2]*a[2]));
          }
       System.out.println("\n");
       }

    }



____________________________________
Chris Hood
Graduate Student Research Assistant
University of Colorado, Boulder
Space Environment Center - NOAA 




More information about the vtkusers mailing list