Discussion:
[vtkusers] vtkPicker returned actor
Lonni Besançon
2016-02-23 18:11:02 UTC
Permalink
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



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-23 18:17:05 UTC
Permalink
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.
Post by Lonni Besançon
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
/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
/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
/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
Lonni Besançon
2016-02-23 22:40:28 UTC
Permalink
Hi David,

Thanks for the help.

So here is the added LOG:

/W/NativeVTK( 8366): xPtr[0] = 1360 ;; yPtdr[0] = 475
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1362 ;; yPtdr[0] = 476
W/NativeVTK( 8366): #################### Outside of plane
W/NativeVTK( 8366): xPtr[0] = 1367 ;; yPtdr[0] = 477
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1373 ;; yPtdr[0] = 479
W/NativeVTK( 8366): #################### Outside of plane
W/NativeVTK( 8366): xPtr[0] = 1377 ;; yPtdr[0] = 479
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1387 ;; yPtdr[0] = 480
W/NativeVTK( 8366): #################### Outside of plane
/

Starting from y = 480 i'm on on the plane anymore so I just get the log
staying that I'm outside of it.




--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736773.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-23 23:06:28 UTC
Permalink
Hmm... it definitely seems to alternate between picking the plane, and not
picking the plane. I wonder if the picking issue might be related to the
rendering somehow. Can you try using vtkCellPicker instead?
Post by Lonni Besançon
Hi David,
Thanks for the help.
/W/NativeVTK( 8366): xPtr[0] = 1360 ;; yPtdr[0] = 475
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1362 ;; yPtdr[0] = 476
W/NativeVTK( 8366): #################### Outside of plane
W/NativeVTK( 8366): xPtr[0] = 1367 ;; yPtdr[0] = 477
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1373 ;; yPtdr[0] = 479
W/NativeVTK( 8366): #################### Outside of plane
W/NativeVTK( 8366): xPtr[0] = 1377 ;; yPtdr[0] = 479
W/NativeVTK( 8366): Plane Picked ********************
W/NativeVTK( 8366): xPtr[0] = 1387 ;; yPtdr[0] = 480
W/NativeVTK( 8366): #################### Outside of plane
/
Starting from y = 480 i'm on on the plane anymore so I just get the log
staying that I'm outside of it.
Lonni Besançon
2016-02-23 23:27:14 UTC
Permalink
I tried the the CellPicker and it apparently works (pretty late here already
so I did not fully test it, but I have the feeling it's working just fine).
Would you happen to know why this picker is working while the default one
was not (or at least not completely)?

Thanks again for the help :)



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736775.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-24 00:25:33 UTC
Permalink
The vtkPropPicker is a hardware picker. When you pick with it, the GPU
renders the scene into a hidden buffer, where each Prop in the scene is
rendered as a different color and with no shading. So the pick simply
reads this "pick" buffer to see what Prop is under the cursor, and then it
reads the depth buffer to get the depth coordinate.

The vtkCellPicker is a software picker. It goes through the list of props
that are attached to the renderer, and inspects the data for each prop. It
essentially shoots a view ray from the camera position, and checks to see
what props are intersected by that ray.

I like the vtkCellPicker because it returns a very precise depth coordinate
(it can do so because it doesn't rely on the depth buffer). Some people
like the vtkPropPicker because it gives pixel-perfect accuracy, since the
picking exactly matches the rendering. Some people also insist that the
vtkPropPicker is faster, but that depends on what is in the scene.

- David
Post by Lonni Besançon
I tried the the CellPicker and it apparently works (pretty late here already
so I did not fully test it, but I have the feeling it's working just fine).
Would you happen to know why this picker is working while the default one
was not (or at least not completely)?
Thanks again for the help :)
Lonni Besançon
2016-02-24 00:37:35 UTC
Permalink
While reading your answer I was about to ask about speed and performance of
both but you actually gave me the answer in the end :).

One more quick question about the pickers then. So my vtkPlane is actually a
slice of a bigger dataset (imageReslice). My question is, with the help of
the pickers, is it possible to go from my screen coordinates to my dataset
coordinates? For instance if I wanted to get on which point X,Y,Z my finger
is placed when I'm touching the slice?

Thanks again for the additional information and the initial help you have
provided.

Lonni



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736777.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-24 00:55:32 UTC
Permalink
If you want to interrogate your data, then the vtkCellPicker is the way to
go.
It provides tons of information about the pick point, such as:

The (x,y,z) pick coordinate in world coords and in data coords (use the
method
GetMapperPosition() to get the point in data coords).

The PointId, CellId, and SubId, and PCoords for any data set that was
picked.

For images, it provides the CellIJK indices and the PointIJK indices (you
want
the latter if you want to know what voxel was picked). This works
regardless
of whether you render the image as slices, or as a volume rendering, or if
the
image is a texture on a vtkPolyData.

It even has a method called GetDataSet() so that you can directly get the
image data that was picked (you'll have to use vtkImageData::SafeDownCast()
to verify that the data is actually image data).

- David
Post by Lonni Besançon
While reading your answer I was about to ask about speed and performance of
both but you actually gave me the answer in the end :).
One more quick question about the pickers then. So my vtkPlane is actually a
slice of a bigger dataset (imageReslice). My question is, with the help of
the pickers, is it possible to go from my screen coordinates to my dataset
coordinates? For instance if I wanted to get on which point X,Y,Z my finger
is placed when I'm touching the slice?
Thanks again for the additional information and the initial help you have
provided.
Lonni
Lonni Besançon
2016-02-28 17:02:01 UTC
Permalink
Hi David,

I just thought you might be able to help me again.
I use the GetMapperPosition() to get the position of my finger on the slice.
It gives me a x and y position comprised between -0.5 and 0.5.
From there I would like to get the position of this point in the dataset
which I slice from.
So basically I have a volume with 3 dimensions, and the slice on which my
finger is on is just a slice of width 1 of this dataset. At anytime I know
the UserMatrix of my volume and of my plane. I also know at which depth is
my plane.

What I initially tried is: userMatrixVolume.inverse() * matrixPlane *
positionOfFinger

The position of my finger is initialised thanks to GetMapperPosition() + the
depth of the plane, the matrixPlane by the current matrix of the plane and
the userMatrixVolume.inverse() is simply the inverse of my userMatrix of the
volume.

I thought this would work right away because " userMatrixVolume.inverse() *
matrixPlane" is what I use to create a matrix to use in SetResliceAxes() to
update my slice when the volume or the plane is moved.
However, it does not seem to in that case.

Would you know what I may be doing wrong here?
That's more of a math issue I guess in my case than a general VTK issue
though.



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736899.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-28 17:12:35 UTC
Permalink
Hi Lonni,

Give me a quick overview of your pipeline, because currently your
explanation doesn't quite make sense. For example, you say that
GetMapperPosition() returns x,y but it should return x,y,z. What
mapper are you using? I don't yet have enough info to give you an
answer.

- David
Post by Lonni Besançon
Hi David,
I just thought you might be able to help me again.
I use the GetMapperPosition() to get the position of my finger on the slice.
It gives me a x and y position comprised between -0.5 and 0.5.
From there I would like to get the position of this point in the dataset
which I slice from.
So basically I have a volume with 3 dimensions, and the slice on which my
finger is on is just a slice of width 1 of this dataset. At anytime I know
the UserMatrix of my volume and of my plane. I also know at which depth is
my plane.
What I initially tried is: userMatrixVolume.inverse() * matrixPlane *
positionOfFinger
The position of my finger is initialised thanks to GetMapperPosition() + the
depth of the plane, the matrixPlane by the current matrix of the plane and
the userMatrixVolume.inverse() is simply the inverse of my userMatrix of the
volume.
I thought this would work right away because " userMatrixVolume.inverse() *
matrixPlane" is what I use to create a matrix to use in SetResliceAxes() to
update my slice when the volume or the plane is moved.
However, it does not seem to in that case.
Would you know what I may be doing wrong here?
That's more of a math issue I guess in my case than a general VTK issue
though.
Lonni Besançon
2016-02-28 17:30:42 UTC
Permalink
Yes right sorry about the bad explanations.

So I have a Volume and a slicing plane. Both of them can move and rotate in
the 3D space. The slicing plane gives me a rendering the a slice of the
volume according to their positions. I actually always display this slice at
the same position and orientation on screen.
That's why I do not use the z-value returned by GetMapperPosition() which is
always 0 in my case.
Indeed, in my case the mapper is the mapper of my slicing plane, which is
always displayed on my screen as parallel to the screen.

My screen only shows the slice of the volumetric data. The volume itself is
not pickable. However I would like to know where, knowing where the slicing
plane and the volume are, exactly where in the volumetric data is located
the point under my finger.

For instance, imagine that my dataset is in its original position (no
rotation or translation applied to it), and my plane is parallel to my
screen at a given depth d in my volume.
Let's say pos is the vector representing the position of my finger given by
GetMapperPosition().
By simply multiplying pos.x and pos.y by the dimensions of my data along the
x and y axis, and then setting pos.z with the depth d, I can locate my
finger's position in my volumetric data.

However this is not so simple if we consider a case where both the plane and
the volume have moved.

Hope it's not too complicated and it got clearer now.

Thanks again for the help



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736902.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-28 17:38:17 UTC
Permalink
Post by Lonni Besançon
Yes right sorry about the bad explanations.
So I have a Volume and a slicing plane.
I need to know what classes you are using.

- David
Lonni Besançon
2016-02-28 17:41:35 UTC
Permalink
I'm using
- vtkVolume with a vtkOpenGLGPUVolumeRayCastMapper mapper
- vtkImageReslice for the slicing plane



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736905.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-28 17:52:28 UTC
Permalink
Post by Lonni Besançon
I'm using
- vtkVolume with a vtkOpenGLGPUVolumeRayCastMapper mapper
- vtkImageReslice for the slicing plane
So if you are picking the vtkVolume, i.e. if picker->GetVolume() returns
a vtkVolume, then GetMapperCoords() returns the actual data coords in
the volume.

For the slice, I still don't have enough info to give you an answer. You
need to give me the names of all the VTK classes in your pipeline and
tell me specifically how they are connected. You still haven't even told
me what mapper you are using to display the slice.

- David
Lonni Besançon
2016-02-28 18:00:28 UTC
Permalink
Problem is I am not picking the volume, I am picking only the plane. The
volume is not rendered at the time when the picking happens, only the plane
is rendered and represents a slice of the volume.

Thus, the volume and the plane are connected, whenever one of them is moved
or rotated, I compute the reslice axes necessary from the matrices of the
plane actor and the volume and use SetResliceAxes();
with the computed and appropriate matrix.

So the plane is a vtkActor with a vtkPolyDataMapper. The mapper uses a
vtkPlaneSource as an input connection.







--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736907.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-28 18:37:30 UTC
Permalink
Post by Lonni Besançon
Problem is I am not picking the volume, I am picking only the plane. The
volume is not rendered at the time when the picking happens, only the plane
is rendered and represents a slice of the volume.
Thus, the volume and the plane are connected, whenever one of them is moved
or rotated, I compute the reslice axes necessary from the matrices of the
plane actor and the volume and use SetResliceAxes();
with the computed and appropriate matrix.
So the plane is a vtkActor with a vtkPolyDataMapper. The mapper uses a
vtkPlaneSource as an input connection.
So you are connecting the output of vtkImageReslice to the vtkActor via
a vtkTexture? As I told you, I need all the specifics of your pipeline.
Don't
make me guess.

Also, why not just use the vtkImageResliceMapper?

- David
David Gobbi
2016-02-28 19:07:49 UTC
Permalink
If you are using a vtkTexture and if you want to pick the image
data for the texture, you can tell the picker to do this:

picker->PickTextureDataOn();

Then GetMapperPosition() will return the data coords for the
image that is the input to the vtkTexture.

If the input to vtkTexture is the output from vtkImageReslice,
and if you want to convert the position into the data coords
for the input of vtkImageReslice, then use the ResliceAxes
matrix to do this:

volumePosition = axes->MultiplyPoint(mapperPosition);

Do not invert the matrix. Also, do not use the actor's matrix.
You would need the actor's matrix if you were getting world
coords, but you aren't. Your getting mapper coords (which
are data coords).

If you're using the vtkImageReslice ResliceTransform, then
you'll have to use it to transform the position.

Hope this answers your original question.

- David
Lonni Besançon
2016-02-29 14:18:27 UTC
Permalink
Hello David,

Sorry I omitted this detail. Indeed that's exactly what I'm doing.
Here the complete pipeline:
/vtkSmartPointer<vtkImageData> ima = reslice->GetOutput();
vtkSmartPointer<vtkDataArray> data = ima->GetPointData()->GetScalars();
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
texture->SetInputData(ima);
texture->InterpolateOn();
....
vtkSmartPointer<vtkPolyDataMapper> planeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
planeMapper->SetInputConnection(plane->GetOutputPort());
...
vtkSmartPointer<vtkActor> planeActor = vtkSmartPointer<vtkActor>::New();
planeActor->SetTexture(texture);
planeActor->SetMapper(planeMapper);/

I tried your solution with the following code:
/if(picker->GetActor() == foo->planeActor){
picker->PickTextureDataOn();
double position[3];
picker->GetMapperPosition(position);
LOGW("Point position Initial = %f ::: %f :::
%f",position[0],position[1],position[2]);
double point[4];
point[0] = position[0] ;
point[1] = position[1] ;
point[2] = position[2] ;
point[3] = 1 ;
resliceAxes->MultiplyPoint(point, point); // My reslice axes matrix
LOGW("Position in Volume = %f ;; %f ;; %f ;;
%f",point[0],point[1],point[2],point[3] );

}
/

Yet the values I get are weird. I tried having the plane parallel to the
screen at a given depth d, and the volume actor not moved at all. The first
log is ok though, it gives me values such as:
0.125766 ::: 0.176741 ::: 0.000000
However the values I get after the multiplication do not seem so good, no
matter where I trick to "click" I always get X value between 51.5 and 52.5 (
X = 51.5 is the middle of the x dimension of my data ), and Y values between
47 and 48 (similarly 47 is the middle of the y dimension of my data).
The depth value I get however correspond very well to the position of my
plane, so I'm guessing this value is good.

Am I doing something wrong? Or maybe the pipeline description I gave you was
not enough.

Thanks again for your help



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736920.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 14:52:54 UTC
Permalink
The PickTextureDataOn() method must be called before the Pick.
Post by Lonni Besançon
Hello David,
Sorry I omitted this detail. Indeed that's exactly what I'm doing.
/vtkSmartPointer<vtkImageData> ima = reslice->GetOutput();
vtkSmartPointer<vtkDataArray> data = ima->GetPointData()->GetScalars();
vtkSmartPointer<vtkTexture> texture = vtkSmartPointer<vtkTexture>::New();
texture->SetInputData(ima);
texture->InterpolateOn();
....
vtkSmartPointer<vtkPolyDataMapper> planeMapper =
vtkSmartPointer<vtkPolyDataMapper>::New();
planeMapper->SetInputConnection(plane->GetOutputPort());
...
vtkSmartPointer<vtkActor> planeActor = vtkSmartPointer<vtkActor>::New();
planeActor->SetTexture(texture);
planeActor->SetMapper(planeMapper);/
/if(picker->GetActor() == foo->planeActor){
picker->PickTextureDataOn();
double position[3];
picker->GetMapperPosition(position);
%f",position[0],position[1],position[2]);
double point[4];
point[0] = position[0] ;
point[1] = position[1] ;
point[2] = position[2] ;
point[3] = 1 ;
resliceAxes->MultiplyPoint(point, point); // My reslice axes matrix
LOGW("Position in Volume = %f ;; %f ;; %f ;;
%f",point[0],point[1],point[2],point[3] );
}
/
Yet the values I get are weird. I tried having the plane parallel to the
screen at a given depth d, and the volume actor not moved at all. The first
0.125766 ::: 0.176741 ::: 0.000000
However the values I get after the multiplication do not seem so good, no
matter where I trick to "click" I always get X value between 51.5 and 52.5 (
X = 51.5 is the middle of the x dimension of my data ), and Y values between
47 and 48 (similarly 47 is the middle of the y dimension of my data).
The depth value I get however correspond very well to the position of my
plane, so I'm guessing this value is good.
Am I doing something wrong? Or maybe the pipeline description I gave you was
not enough.
Thanks again for your help
--
http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736920.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
http://www.vtk.org/Wiki/VTK_FAQ
Search the list archives at: http://markmail.org/search/?q=vtkusers
http://public.kitware.com/mailman/listinfo/vtkusers
Lonni Besançon
2016-02-29 14:59:04 UTC
Permalink
Alright changed it but I get similar values.



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736923.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 15:50:48 UTC
Permalink
Post by Lonni Besançon
Alright changed it but I get similar values.
Check to make sure it is really picking the texture: picker->GetDataSet()
should be returning a vtkImageData (it should return the input to the
texture). Also, call picker->GetPointIJK() to see if it returns sensible
values.

- David
Lonni Besançon
2016-02-29 16:09:10 UTC
Permalink
I just did.
It does return the input to the texture and IJK seem to make sense (I values between 0 and 103 and my dimension along x is [0;103], similarly J values between 0 and 94).

Best / Cordialement,
Post by Lonni Besançon
Alright changed it but I get similar values.
Check to make sure it is really picking the texture: picker->GetDataSet() should be returning a vtkImageData (it should return the input to the texture). Also, call picker->GetPointIJK() to see if it returns sensible values.
- David
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ <http://www.vtk.org/Wiki/VTK_FAQ>
Search the list archives at: http://markmail.org/search/?q=vtkusers <http://markmail.org/search/?q=vtkusers>
http://public.kitware.com/mailman/listinfo/vtkusers <http://public.kitware.com/mailman/listinfo/vtkusers>
http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736927.html <http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736927.html>
To unsubscribe from vtkPicker returned actor, click here <http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5736763&code=bG9ubmkuYmVzYW5jb25AZ21haWwuY29tfDU3MzY3NjN8MTcxODAwMTkxOA==>.
NAML <http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736929.html
Sent from the VTK - Users mailing list archive at Nabble.com.
Lonni Besançon
2016-02-29 16:14:50 UTC
Permalink
Dunno if you received my previous answer so here it is again:
I just made sure that I'm really picking the texture with GetDataSet().
It does return the input to the texture and IJKPoint seem to make sense (I
values between 0 and 103 and my dimension along x is [0;103], similarly J
values between 0 and 94).



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736930.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 16:25:42 UTC
Permalink
Post by Lonni Besançon
I just made sure that I'm really picking the texture with GetDataSet().
It does return the input to the texture and IJKPoint seem to make sense (I
values between 0 and 103 and my dimension along x is [0;103], similarly J
values between 0 and 94).
If the IJK makes sense, then the next step is to check if it agrees with
the value returned by GetMapperPosition(), taking the origin and spacing
of the data (the texture's input data) into account.
Lonni Besançon
2016-02-29 16:39:11 UTC
Permalink
The spacing is 1 along the three axis.
The origin is -51,-46,0.

GetMapperPosition is always between -0.5 and 0.5 and therefore the
computation I make afterwards as you suggested with the resliceAxesMatrix is
always comprised between 50.5 and 51.5 for the X axis, and 46.5 and 47.5 for
the y axis.



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736932.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 16:54:43 UTC
Permalink
Post by Lonni Besançon
The spacing is 1 along the three axis.
The origin is -51,-46,0.
GetMapperPosition is always between -0.5 and 0.5 and therefore the
computation I make afterwards as you suggested with the resliceAxesMatrix is
always comprised between 50.5 and 51.5 for the X axis, and 46.5 and 47.5 for
the y axis.
It seems to me that the value returned by GetMapperPosition() is wrong (at
least,
its wrong for when PickTextureDataOn()). And if that is wrong, then the
result
from resliceAxesMatrix->MultiplyPoint() will also be wrong. So I will look
into
this when I have a break from work.

In the meantime, you can compute an "approximate" position from the IJK
values,
by multiplying by the Spacing and adding the Origin.

- David
Lonni Besançon
2016-02-29 18:11:29 UTC
Permalink
I just tried your workaround. It kind of works.
If I do not take into account the imprecision, I have exploitable results as
long as my original volume is not translated or rotated.
However, whenever I rotate my original volume or my plane, the results I
obtain are not usable anymore and axis get mixed up. For instance, if we
take the initial volume, moving my finger to the left results in appropriate
position changes along the X axis. However, if I perform a rotation of my
volume by 90 degrees for instance, and move my finger to the left again, the
resulting change is on the z or y axis (depending on the axis of the
rotation).
Is that normal?



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736935.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 18:39:30 UTC
Permalink
So when you say you "rotate the volume by 90 degrees", do you mean
that you use vtkImageReslice to do a 90 degree multi-planar reformat
on the image data? Or do you mean that you apply a 90 degree rotation
to the actor? To the camera? Give me names of classes, their inputs
and outputs, and the methods that you are calling, because if I don't
know these specific details, I can't help. Take your time so you're sure
that I get all the information that I might need. I know that I must sound
like a broken record by now.

- David
Post by Lonni Besançon
I just tried your workaround. It kind of works.
If I do not take into account the imprecision, I have exploitable results as
long as my original volume is not translated or rotated.
However, whenever I rotate my original volume or my plane, the results I
obtain are not usable anymore and axis get mixed up. For instance, if we
take the initial volume, moving my finger to the left results in appropriate
position changes along the X axis. However, if I perform a rotation of my
volume by 90 degrees for instance, and move my finger to the left again, the
resulting change is on the z or y axis (depending on the axis of the
rotation).
Is that normal?
Lonni Besançon
2016-02-29 18:45:59 UTC
Permalink
Don't worry, I don't mind the fact that you repeat it, since you're helping a
lot I really don't mind.

So when I'm talking about rotation I'm talking about performing the
rotations on the vtkVolume class, not on the data. I'm guessing that is the
reason why I am getting problems because the dataset itself stays the same.

The rotation and/or translation that I apply are only applied to the
planeActor (vtkActor) or the volume that I render (vtkVolume).
I perform these by computing from my sensors in the tablet the correct
transformation matrix and then using actor->SetUserMatrix(myMatrix).
Of course, when I do so, I make sure tu update my reslice axes with the
setResliceAxes(). The matrix I give to this method is the result of
matrixVolume.inverse() * matrixPlane.

The fact that I'm only transforming my actors was the reason why I was
applying matrix and inverse multiplication in the first place.

Overall, it's a research project and the code is kinda messy since I'm still
learning how to use VTK and have to combine it with other frameworks that
I'm using as well. Sorry if I forget details, it's just that I don't want to
go into lengthy details about things coming from other frameworks.




--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736937.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
Lonni Besançon
2016-02-29 22:34:05 UTC
Permalink
I'm guessing there is something to do with the actors' matrices otherwise I'm
not sure the VTK pipeline would directly allow me to transform the
coordinates that I get in the plane coordinate system into coordinates in
the transformed volume coordinate systems.

I believe I gave you enough information on the classes and methods that I
use but if that's not the case please let me know.

Thanks again for the help and explanations so far.

Best

Lonni



--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736941.html
Sent from the VTK - Users mailing list archive at Nabble.com.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ

Search the list archives at: http://markmail.org/search/?q=vtkusers

Follow this link to subscribe/unsubscribe:
http://public.kitware.com/mailman/listinfo/vtkusers
David Gobbi
2016-02-29 23:19:07 UTC
Permalink
Hi Lonni,

Regarding picker->PickTextureOn(), I looked through the code and the
docs, and it only moves the results of GetPointIJK(), GetCellIJK(), and
GetPCoords() into the vtkTexture input data space. GetMapperPoint() still
returns the coord in the vtkPolyDataMapper input space.

So to get the data coords in the texture's data space, you'd have to do
something like this pseudocode:

ix, iy, iz = picker->GetCellIJK()
px, py, pz = picker->GetPCoords()
x = origin[0] + (ix + px - 0.5)*spacing[0]
y = origin[1] + (iy + py - 0.5)*spacing[1]
z = origin[2] + (iz + pz - 0.5)*spacing[2]

The above should give accurate data coords within the image space of
the vtkTexture's input.


Moving on to your latest email:

If you are getting the position with picker->GetMapperPosition(), and if I
understand your pipeline properly, then the only matrix you need to apply
to that position is the ResliceAxes matrix. If that's not working, then
maybe
I still don't completely understand your pipeline (but I'm getting
exhausted).

If you were getting the position in world coordinates, with
GetPickPosition(),
then you would have to apply the inverse of the actor matrix to move from
world coordinates to data coordinates. But rather than use
GetPickPosition(),
I believe it is better to instead get the data coords as I outlined above.

- David
Lonni Besançon
2016-02-29 23:41:22 UTC
Permalink
Hi David,

Thanks a lot for everything.
I will try that tomorrow morning. Getting kinda late here. I’ll keep you posted.

Thanks again.

Have a good evening(?)


Best
Post by David Gobbi
Hi Lonni,
Regarding picker->PickTextureOn(), I looked through the code and the
docs, and it only moves the results of GetPointIJK(), GetCellIJK(), and
GetPCoords() into the vtkTexture input data space. GetMapperPoint() still
returns the coord in the vtkPolyDataMapper input space.
So to get the data coords in the texture's data space, you'd have to do
ix, iy, iz = picker->GetCellIJK()
px, py, pz = picker->GetPCoords()
x = origin[0] + (ix + px - 0.5)*spacing[0]
y = origin[1] + (iy + py - 0.5)*spacing[1]
z = origin[2] + (iz + pz - 0.5)*spacing[2]
The above should give accurate data coords within the image space of
the vtkTexture's input.
If you are getting the position with picker->GetMapperPosition(), and if I
understand your pipeline properly, then the only matrix you need to apply
to that position is the ResliceAxes matrix. If that's not working, then maybe
I still don't completely understand your pipeline (but I'm getting exhausted).
If you were getting the position in world coordinates, with GetPickPosition(),
then you would have to apply the inverse of the actor matrix to move from
world coordinates to data coordinates. But rather than use GetPickPosition(),
I believe it is better to instead get the data coords as I outlined above.
- David
_______________________________________________
Powered by www.kitware.com
Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html <http://www.kitware.com/opensource/opensource.html>
Please keep messages on-topic and check the VTK FAQ at: http://www.vtk.org/Wiki/VTK_FAQ <http://www.vtk.org/Wiki/VTK_FAQ>
Search the list archives at: http://markmail.org/search/?q=vtkusers <http://markmail.org/search/?q=vtkusers>
http://public.kitware.com/mailman/listinfo/vtkusers <http://public.kitware.com/mailman/listinfo/vtkusers>
http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736943.html <http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736943.html>
To unsubscribe from vtkPicker returned actor, click here <http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=unsubscribe_by_code&node=5736763&code=bG9ubmkuYmVzYW5jb25AZ21haWwuY29tfDU3MzY3NjN8MTcxODAwMTkxOA==>.
NAML <http://vtk.1045678.n5.nabble.com/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
--
View this message in context: http://vtk.1045678.n5.nabble.com/vtkPicker-returned-actor-tp5736763p5736944.html
Sent from the VTK - Users mailing list archive at Nabble.com.

Loading...