[vtkusers] How to get cursor position and image intensity when we move the mouse
Jafari, Kourosh
kjafari at rad.hfh.edu
Thu Feb 17 23:42:51 EST 2011
Dear all,
I am trying to display the cursor position and image intensity in that position as I move the mouse in a window displaying a 2D image. I use vtkImageReslice to display a 2D cut of a 3D image with vtkImageData format using the following code. I am able to find the display coordinates of the cursor. I also use vtkInteractorObserver::ComputeWorldToDisplay to convert the display coordinates to world coordinates in order to get the image intensity. But there are the problems:
1) I have separately added two interactions for rotation and translation of the image using left and right clicking by manipulating the matrix of vtkImageReslice. The problem is that the above function always gives the same world coordinates for similar display coordinates even if I rotate/translate the image. This does not make sense and is not useful.
2) vtkInteractorObserver::ComputeWorldToDisplay requires x, y, and z of the display coordinates. I have x and y which are the display coordinates. But what is z?
Also, do I have to find the correct coordinates of a pixel in the original vtkImageData in order to find the intensity?
Note that only the initial values of vtkImageReslice is determined from axialElements in the following code. The matrix changes as I interact with the image and in fact it may display an oblique plane.
Thanks a lot,
Kourosh
static double axialElements[16] = {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 1, 0,
0, 0, 0, 1 };
int extent[6];
double spacing[3];
double origin[3];
connector->GetOutput()->GetWholeExtent(extent);
connector->GetOutput()->GetSpacing(spacing);
connector->GetOutput()->GetOrigin(origin);
double center[3];
center[0] = origin[0] + spacing[0] * 0.5 * (extent[0] + extent[1]);
center[1] = origin[1] + spacing[1] * 0.5 * (extent[2] + extent[3]);
center[2] = origin[2] + spacing[2] * 0.5 * (extent[4] + extent[5]);
/////////////////////////////////////////////
// Axial reslicer
// Set the slice orientation
AxialResliceAxes = vtkSmartPointer<vtkMatrix4x4>::New();
AxialResliceAxes->DeepCopy(axialElements);
// Set the point through which to slice
AxialResliceAxes->SetElement(0, 3, center[0]);
AxialResliceAxes->SetElement(1, 3, center[1]);
AxialResliceAxes->SetElement(2, 3, center[2]);
// Extract a slice in the desired orientation
AxialReslice = vtkSmartPointer<vtkImageReslice>::New();
AxialReslice->SetInput(connector->GetOutput());
AxialReslice->SetOutputDimensionality(2);
AxialReslice->SetResliceAxes(AxialResliceAxes);
AxialReslice->SetInterpolationModeToLinear();
// Map the image through the lookup table
Axialcolor = vtkSmartPointer<vtkImageMapToColors>::New();
Axialcolor->SetLookupTable(table);
Axialcolor->SetInputConnection(AxialReslice->GetOutputPort());
AxialActor = vtkSmartPointer<vtkImageActor>::New();
AxialActor->SetInput(Axialcolor->GetOutput());
// Renderer
AxialRenderer = vtkSmartPointer<vtkRenderer>::New();
AxialRenderer->AddActor(AxialActor);
AxialRenderer->AddViewProp(AxialAnnotation);
AxialRenderer->SetViewport(0,0,1,1);
DisplayWidgetAxialPlane->GetRenderWindow()->AddRenderer(AxialRenderer);
DisplayWidgetAxialPlane->GetRenderWindow()->Render();
More information about the vtkusers
mailing list