[vtkusers] Question About selecting a point in vtkCanvas -- Java.

Sebastien Jourdain sebastien.jourdain at kitware.com
Mon Jun 11 13:29:59 EDT 2012


The setSize call did not go through.
Just to make sure this is the issue, try to manually resize your
window and try to pick again.

Seb

On Mon, Jun 11, 2012 at 1:27 PM, satyanarayana reddy
<satyajanga at gmail.com> wrote:
> Hi Seb,
>         I have a 3D box with the dimensions (0 200,0 200, 0 200) rendered
> through a class inherited from vtkCanvas. My requirement is to pick a point
> from the mouse click and display a sphere at that point. I am checking about
> the vtkPointPicker.
> And I am using the following code to pick the point.  It is not giving the
> correct position.  Is there any mistake in what I am doing.
>
> @Override
> public void mousePressed(MouseEvent e)
>     {
>         vtkPointPicker picker = new vtkPointPicker();
>         picker.SetTolerance(0.01);
>         int result = picker.Pick(e.getX(), e.getY(), 0.0,
> this.GetRenderer());
>
>         double[] pick;
>         if(result!=0)
>             pick = picker.GetPickPosition();
>
>         System.out.println(pick[0] + " " + pick[1]+ " " + pick[2]);
>         sphereActor.SetPosition(pick[0],pick[1],pick[2]);
>         this.GetRenderer().AddActor(sphereActor);
> }
>
> Thanks for your time
>
> -Satya.
>
>
> On Mon, Jun 11, 2012 at 1:16 PM, Sebastien Jourdain
> <sebastien.jourdain at kitware.com> wrote:
>>
>> I don't know what should be the Z value, but I guess that depend what
>> you try to achieve.
>>
>> Seb
>>
>> On Mon, Jun 11, 2012 at 11:58 AM, satyanarayana reddy
>> <satyajanga at gmail.com> wrote:
>> > Hi Seb,
>> >        Thank you for the reply. what should be the value of Z?
>> >
>> > -Satya.
>> >
>> >
>> > On Mon, Jun 11, 2012 at 11:56 AM, Sebastien Jourdain
>> > <sebastien.jourdain at kitware.com> wrote:
>> >>
>> >> I guess it's because you said that the point is at z=0 so the z will
>> >> still be wrong after your convert ion. On the other hand, point and
>> >> cell picker do work in Java as I remember doing it a while ago.
>> >> By default its the "p" key that you need to hit to trigger the
>> >> picking...
>> >>
>> >> On Mon, Jun 11, 2012 at 11:36 AM, satyanarayana reddy
>> >> <satyajanga at gmail.com> wrote:
>> >> >
>> >> >
>> >> > Dear vtkusers,
>> >> >             I have a requirement in which I need to select a point(
>> >> > by
>> >> > mouse
>> >> > click) in Cube. I am not using vtkPointPicker/vtkCellPicker as they
>> >> > does
>> >> > not
>> >> > seem to compatible in Java.
>> >> >   I am creating a class which extends vtkCanvas to render the cube
>> >> > and I
>> >> > am
>> >> > overriding the mouse listeners in vtkCanvas  to pick the event
>> >> > position
>> >> > and
>> >> > converting it to World Coordinates using the following code as I am
>> >> > not
>> >> > sure
>> >> > how to use the static methods in vtkInteractorObserver(in Java
>> >> > wrapped
>> >> > vtk),
>> >> >
>> >> >     double[] GetDisplayToWorldCoordinates(double x, double y)
>> >> >     {
>> >> > /* x,y represent the event position*/
>> >> >         double[] coordinates = new double[3];
>> >> >         coordinates[0]=(double)x;
>> >> >         coordinates[1]=(double)y;
>> >> >         coordinates[2]=0;
>> >> >         double[] worldCord = new double[3];
>> >> >
>> >> >         this.GetRenderer().SetDisplayPoint(coordinates);
>> >> >         this.GetRenderer().DisplayToView();
>> >> >         this.GetRenderer().ViewToWorld();
>> >> >         worldCord=    this.GetRenderer().GetWorldPoint();
>> >> >
>> >> >        return worldCord;
>> >> >    }
>> >> >
>> >> >
>> >> > My box source is (0,200,0,200,0,200). But the worldCord returned from
>> >> > the
>> >> > function is not what I expected. They are not even coming in the
>> >> > extent.
>> >> >
>> >> > Please check If I am doing anything wrong. Or suggest how to convert
>> >> > the
>> >> > event position in object coordinate system.
>> >> >
>> >> >
>> >> > Thanks in advance,
>> >> >
>> >> > Best Regards,
>> >> > Satya.
>> >> >
>> >> >
>> >> >
>> >> >
>> >
>> >
>
>



More information about the vtkusers mailing list