[vtkusers] vtkPicker in Java

Alexander MacLennan alex.maclennan at gmail.com
Mon Jul 3 02:57:59 EDT 2006


Hi all,

I am having trouble extracting cell ids from my picker. I am trying to
select a single cell for the moment, but will then use this to select
an entire region for my application.

I get 0,0,0 as the point and no cell info at all

Here is my code: Any ideas??
The OOGLToVtkPolyData class works ok for loading and viewing OOGL files



 vtkPolyData pd = null;

    vtkPolyDataMapper pdm = null;

    vtkActor actor = null;

    vtkCanvas renWin = null;

    vtkCellPicker picker = null;

    public void run(OOGLObject o) {

        this.pd = (new OOGLtoVtkPolyData().getPolyData(o));
        this.pdm = new vtkPolyDataMapper();
        this.actor = new vtkActor();
        this.renWin = new vtkCanvas();
        this.picker = new vtkCellPicker();

        pdm.SetInput(pd);

        actor.SetPickable(1);
        actor.SetMapper(pdm);

        vtkCanvas canvas = new vtkCanvas();
        canvas.GetRenderer().AddActor(actor);

        vtkCellPicker picker = new vtkCellPicker();
        picker.SetTolerance(0.005);

        // Set up the event handler
        vtkRenderWindowInteractor iren = new vtkRenderWindowInteractor();

        iren.SetRenderWindow(canvas.GetRenderWindow());
        iren.SetPicker(picker);

        picker.AddObserver("EndPickEvent", this, "annotatePick");

        iren.Initialize();
        iren.Start();

    }

    /**
     * Function to create the text for the text mapper used to display the
     * results of picking.
     */
    public void annotatePick() {
            System.err.println("Cell ID " + picker.GetCellId());
            double[] pos = picker.GetPCoords();
            System.err.print("Picker coordinates ");
            for (double d : pos)
                System.err.print(d + " ");
            System.err.println();
            double[] mpos = picker.GetSelectionPoint();
            for (double d : mpos)
                System.err.print(d + " ");
            System.err.println();
            vtkPoints p  = picker.GetPickedPositions();
            System.err.println(p.toString());

    }



cheers

alex



More information about the vtkusers mailing list