[vtkusers] vtkPicker returned actor

David Gobbi david.gobbi at gmail.com
Tue Feb 23 13:17:05 EST 2016


Seems strange.  When you do the picks, log xPtr[0] and yPtr[0] to make sure
that the picks are occurring at the expected location.

On Tue, Feb 23, 2016 at 11:11 AM, Lonni Besançon <lonni.besancon at gmail.com>
wrote:

> Hello everyone,
>
> I'm facing a weird issue.
> I've followed the vtkPicker example given  here
> <http://www.itk.org/Wiki/VTK/Examples/Cxx/Interaction/Picking>   to suit
> my
> needs.
>
> I have a scene, with one renderer and two actors.
> One of them is removed from the scene at some point (it's a volume) so it
> does not count when I'm using the picker.
> The other one is a vtkActor containing a plane.
>
> Now I'm using android and based on the VolumeRender code, I added a small
> chunk of code to the onMotionEvent native function (called when fingers are
> placed on the screen of the device).
>
> In case you don't want to browse through the examples and the code, here is
> what the native function does:
>
> /JNIEXPORT void JNICALL
> Java_com_kitware_VolumeRender_VolumeRenderLib_onMotionEvent(JNIEnv * env,
> jobject obj, jlong udp,
>       jint action,
>       jint eventPointer,
>       jint numPtrs,
>       jfloatArray xPos, jfloatArray yPos,
>       jintArray ids, jint metaState)
> {
>   struct userData *foo = (userData *)(udp);
>
>   int xPtr[VTKI_MAX_POINTERS];
>   int yPtr[VTKI_MAX_POINTERS];
>   int idPtr[VTKI_MAX_POINTERS];
>
>   /*vtkSmartPointer<vtkTransform> t = vtkSmartPointer<vtkTransform>::New();
>   double * origin = foo->plane->GetOrigin();
>   origin[2] += 0.3 ;
>   foo->plane->SetOrigin(origin);*/
>
>   // only allow VTKI_MAX_POINTERS touches right now
>   if (numPtrs > VTKI_MAX_POINTERS)
>     {
>     numPtrs = VTKI_MAX_POINTERS;
>     }
>
>   // fill in the arrays
>   jfloat *xJPtr = env->GetFloatArrayElements(xPos, 0);
>   jfloat *yJPtr = env->GetFloatArrayElements(yPos, 0);
>   jint *idJPtr = env->GetIntArrayElements(ids, 0);
>   for (int i = 0; i < numPtrs; ++i)
>   {
>     xPtr[i] = (int)xJPtr[i];
>     yPtr[i] = (int)yJPtr[i];
>     idPtr[i] = idJPtr[i];
>   }/
>
> So I just added this small piece of code to try and detect when the user is
> placing his/her finger on my planeActor:
>
> /vtkSmartPointer<vtkPropPicker>  picker
> =vtkSmartPointer<vtkPropPicker>::New();
>       int* clickPos = foo->Interactor->GetEventPosition();
>       picker->Pick(xPtr[0], yPtr[0], 0, foo->Renderer);
>
>       if(picker->GetActor() == foo->planeActor){
>         LOGW("Plane Picked ********************");
>         // Case of the seeding point positionning
>       }
> else{
>         LOGW("#################### Outside of plane");
> }/
>
> Now when I check my logcat while having my finger on the plane I get
> something like:
> /W/NativeVTK(29678): Plane Picked ********************
> W/NativeVTK(29678): #################### Outside of plane
> W/NativeVTK(29678): #################### Outside of plane
> W/NativeVTK(29678): #################### Outside of plane
> W/NativeVTK(29678): Plane Picked ********************/
>
> When my finger is not located on my plane, this is correctly detected, but
> it's on it would appear to trigger both events.
>
> Would you mind giving me some explanations on that matter?
>
> Thanks in advance
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160223/2728376c/attachment.html>


More information about the vtkusers mailing list