[vtkusers] Problems with Pickers

Carlos Martinez Burgos cmarbur at iti.upv.es
Wed Apr 4 06:31:53 EDT 2001


Hi again.

I have tryed to use the pickers as you say but this is not a good solution
to me.

First, if I use vtkPicker instead of vtkCellPicker I get the same
results. I have done a program to show what happends to me. It is done in
Java. Run it and press 'r' key one time. Move the mouse to point
to the cone at (465,350) or left. Push 'u' and what is the result? The
cone is pointed but the sphere is selected and its bounding box is not
intersected. What is the problem? Should I use another picker?

Second, I need to use vtkPointPicker because I need the point ID, to
link it with my data, and this method is not present in vtkPropPicker.

Could somebody send me a solution?

Thanks.


On Tue, 3 Apr 2001, Will Schroeder wrote:

> Hi Carlos-
> 
> At 06:56 PM 4/3/2001 +0200, Carlos Martinez Burgos wrote:
> 
> >I use a CellPicker and when I run the Pick method on the renderer, it
> >picks on the first actor whose bounding box has hited. If I have a big
> >actor in front of a smaller one and I point to the smaller the first is
> >picked because its bounding box is in front.
> 
> This is the behavior of vtkPicker, not vtkCellPicker. Are you assigning the picker to the vtkRenderWindowInteractor?
> 
> 
> >I use a PointPicker to select points from a point cloud (polydata). When I
> >run the Pick method I get ids but there are no points around in some
> >distance.
> 
> You probably want to use vtkPropPicker...it uses hardware picking (warning: sometimes the drivers do not work right, especially on PC's).
> 
> Will
> 
> 
> Dr. William J. Schroeder
> Kitware, Inc.
> 469 Clifton Corporate Parkway
> Clifton Park, NY 12065
> will.schroeder at kitware.com
> 1-518-371-3971 (Phone & Fax)
> 

-- 
----------------------------------------------------------------------
Carlos Martínez Burgos      |     Instituto Tecnológico de Informática
Ingeniero Informático       |      Universidad Politécnica de Valencia
Tlf: +34 963877237          |                        Camí de Vera, S/N
cmarbur at iti.upv.es          |                   46071 Valencia - Spain
www.iti.upv.es/~cmarbur     |                           www.iti.upv.es
----------------------------------------------------------------------
-------------- next part --------------
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import vtk.*;

public class Prueba extends JFrame implements KeyListener,MouseListener,MouseMotionListener {
    MyVTKPanel panelVTK;

    vtkConeSource cone;
    vtkOutlineFilter coneOutline;
    vtkPolyDataMapper coneMapper,coneOutlineMapper;
    vtkActor coneActor,coneOutlineActor;

    vtkSphereSource sphere;
    vtkOutlineFilter sphereOutline;
    vtkPolyDataMapper sphereMapper,sphereOutlineMapper;
    vtkActor sphereActor,sphereOutlineActor;

    int lastX,lastY;

    public Prueba() {
	super("Prueba");

	addWindowListener(new WindowAdapter() {
		public void windowClosing(WindowEvent e) {
		    System.exit(0);
		}
	    });

	panelVTK=new MyVTKPanel();
	panelVTK.setSize(700,700);
	panelVTK.LightFollowCameraOn();
	panelVTK.getRenderer().SetBackground(1,1,1);
	panelVTK.addKeyListener(this);
	panelVTK.addMouseListener(this);
	panelVTK.addMouseMotionListener(this);
	getContentPane().add(panelVTK,BorderLayout.CENTER);

	cone=new vtkConeSource();

	vtkPolyDataMapper coneMapper=new vtkPolyDataMapper();
	coneMapper.SetInput(cone.GetOutput());

	coneActor=new vtkActor();
	coneActor.SetMapper(coneMapper);
	//coneActor.SetPickMethod(this,"picked");

	coneOutline=new vtkOutlineFilter();
	coneOutline.SetInput(cone.GetOutput());

	coneOutlineMapper=new vtkPolyDataMapper();
	coneOutlineMapper.SetInput(coneOutline.GetOutput());

	coneOutlineActor=new vtkActor();
	coneOutlineActor.SetMapper(coneOutlineMapper);
	coneOutlineActor.GetProperty().SetColor(0,0,0);
	coneOutlineActor.PickableOff();
	coneOutlineActor.VisibilityOff();

	panelVTK.getRenderer().AddActor(coneActor);
	panelVTK.getRenderer().AddActor(coneOutlineActor);

	sphere=new vtkSphereSource();

	sphereMapper=new vtkPolyDataMapper();
	sphereMapper.SetInput(sphere.GetOutput());

	sphereActor=new vtkActor();
	sphereActor.SetMapper(sphereMapper);
	sphereActor.SetPosition(1,0,0);
	//sphereActor.SetPickMethod(this,"picked");

	sphereOutline=new vtkOutlineFilter();
	sphereOutline.SetInput(sphere.GetOutput());

	sphereOutlineMapper=new vtkPolyDataMapper();
	sphereOutlineMapper.SetInput(sphereOutline.GetOutput());

	sphereOutlineActor=new vtkActor();
	sphereOutlineActor.SetMapper(sphereOutlineMapper);
	sphereOutlineActor.GetProperty().SetColor(0,0,0);
	sphereOutlineActor.SetPosition(1,0,0);
	sphereOutlineActor.PickableOff();
	sphereOutlineActor.VisibilityOff();

	panelVTK.getRenderer().AddActor(sphereActor);
	panelVTK.getRenderer().AddActor(sphereOutlineActor);
    }

    public void updatePipeline() {
	panelVTK.Render();
    }

    public void picked() {
	vtkPicker picker=new vtkPicker();
	System.out.println("Selection point: ("+lastX+","+lastY+")");
	picker.Pick(lastX,getSize().getHeight()-lastY,0,panelVTK.getRenderer());
	vtkActor actor=picker.GetActor();
	if (actor==coneActor) {
	    pickedCone();
	}
	else if (actor==sphereActor) {
	    pickedSphere();
	}
    }

    public void pickedCone() {
	if (coneOutlineActor.GetVisibility()==0) 
	    coneOutlineActor.VisibilityOn();
	else
	    coneOutlineActor.VisibilityOff();
    }

    public void pickedSphere() {
	if (sphereOutlineActor.GetVisibility()==0) 
	    sphereOutlineActor.VisibilityOn();
	else
	    sphereOutlineActor.VisibilityOff();
    }

    public void keyPressed(KeyEvent e) {
	if (e.getKeyChar()=='u') {
	    picked();
	}
	else if (e.getKeyChar()=='r') {
	    panelVTK.getCamera().Azimuth(130);
	    panelVTK.getCamera().OrthogonalizeViewUp();
	    panelVTK.getLight().SetPosition(panelVTK.getCamera().GetPosition());
	    panelVTK.getLight().SetFocalPoint(panelVTK.getCamera().GetFocalPoint());
	    System.out.println("Now point to the cone at left of position (465,350) and pick with key 'u'");
	}
	panelVTK.Render();
    }
    public void keyReleased(KeyEvent e) {}
    public void keyTyped(KeyEvent e) {}

    public void mouseEntered(MouseEvent e) {
	lastX=e.getX();
	lastY=e.getY();
	System.out.println("Mouse point: ("+lastX+","+lastY+")");
    }
    public void mouseExited(MouseEvent e) {}
    public void mousePressed(MouseEvent e) {}
    public void mouseReleased(MouseEvent e) {
	lastX=e.getX();
	lastY=e.getY();	
	System.out.println("Mouse point: ("+lastX+","+lastY+")");
    }
    public void mouseClicked(MouseEvent e) {}
    public void mouseDragged(MouseEvent e) {}
    public void mouseMoved(MouseEvent e) {
	lastX=e.getX();
	lastY=e.getY();
	System.out.println("Mouse point: ("+lastX+","+lastY+")");
    }

    public static void main(String args[]) {
	Prueba frame=new Prueba();
	frame.pack();
	frame.setVisible(true);
    }

    class MyVTKPanel extends vtkPanel {
	public MyVTKPanel() {
	    super();
	}

	public vtkCamera getCamera() {
	    return cam;
	}

	public vtkLight getLight() {
	    return lgt;
	}
    }
}


More information about the vtkusers mailing list