Discussion:
[vtkusers] VtkResliceImageViewer cordinate system (world and display)
sfaisalali91
2018-11-20 13:51:17 UTC
Permalink
Hey Guys,

Can someone please help me with understanding of display cordinates and
world cordinates on the image plane represented in vtkResliceImageViewer.

I am trying to add a node(restricted to a particular slice) on sagittal view
and replicate the same on coronal and axial views , based on others opinions
i tried two approaches ,


*1) using vtkCordinate*

int pickPosition[2];
vtkRenderWindowInteractor *rwi = dynamic_cast< vtkRenderWindowInteractor *
(caller);
rwi->GetEventPosition(pickPosition);

vtkSmartPointer<vtkCoordinate> coordinate =
vtkSmartPointer<vtkCoordinate>::New();
coordinate->SetCoordinateSystemToDisplay();
coordinate->SetValue(pickPosition[0], pickPosition[1], 0);

double* world =
coordinate->GetComputedWorldValue(this->RIW[0]->GetRenderer());
int* Display =
coordinate->GetComputedDisplayValue(this->RIW[0]->GetRenderer());
std::cout << "Mouse World coordinate: " << world[0] << ", " << world[1] <<
", " << world[2] << std::endl;
std::cout << "Mouse Display coordinate: " << Display[0] << ", " <<
Display[1] << ", " << Display[2] << std::endl;


*2) using vtkPropPicker*

vtkImageActor* actor = this->RIW[0]->GetImageActor();
vtkSmartPointer<vtkPropPicker> m_propPicker =
vtkSmartPointer<vtkPropPicker>::New();
m_propPicker->PickFromListOn();
m_propPicker->AddPickList(actor);
this->RIW[0]->GetImageActor()->InterpolateOff();
m_propPicker->Pick(pickPosition[0], pickPosition[1], 0.0,
this->RIW[0]->GetRenderer());

vtkAssemblyPath* path = m_propPicker->GetPath();
bool validPick = false;
if (path)
{
vtkCollectionSimpleIterator sit;
path->InitTraversal(sit);
vtkAssemblyNode *node;
for (int i = 0; i < path->GetNumberOfItems() && !validPick; ++i)
{
node = path->GetNextNode(sit);
if (actor == vtkImageActor::SafeDownCast(node->GetViewProp()))
{validPick = true;}
}
}
if (!validPick){return;}

double pos[3];
m_propPicker->GetPickPosition(pos);
std::cout << "Picker World coordinate: " << pos[0] << ", " << pos[1] << ", "
<< pos[2] << std::endl;


I am able to achieve the conversion from display to world, but there is a
shift in points when visualized in other two views, to fix this i
implemented the logic below. I believe that always first slice cordinates
are being considered rather than the current slice.


int image_coordinate[3];
int axis = this->RIW[0]->GetSliceOrientation();
switch (axis)
{
case vtkImageViewer2::SLICE_ORIENTATION_XZ:
image_coordinate[0] = vtkMath::Round(pos[0]);
image_coordinate[1] = this->RIW[1]->GetSlice();
image_coordinate[2] = vtkMath::Round(pos[2]);
break;

case vtkImageViewer2::SLICE_ORIENTATION_YZ:
image_coordinate[0] =
(this->RIW[0]->GetSliceMax())-(this->RIW[0]->GetSlice());
image_coordinate[1] = vtkMath::Round(pos[1]);
image_coordinate[2] = vtkMath::Round(pos[2]);
break;

default: // vtkImageViewer2::SLICE_ORIENTATION_XY
image_coordinate[0] = vtkMath::Round(pos[0]);
image_coordinate[1] = vtkMath::Round(pos[1]);
image_coordinate[2] = this->RIW[2]->GetSlice();
break;
}


Still no luck, please can someone guide me with what have i been missing in
this logic!?
*Note* - Reslice cursor widget is disabled in all views.*


Thank you for the help in advance.

Regards
Syed Faisal Ali





--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
sfaisalali91
2018-11-21 13:30:08 UTC
Permalink
I modified my call back to pick a point and add a node on it , strangely i
realized that when ever i click on the image, the prop picker returns NULL!
Please can any one help me with this, i am using 3 vtkResliceImageViewers
with orientations set to axial, coronal and saggital. and below is my call
back for picking a point on sagittal view.

if (ev == vtkCommand::LeftButtonPressEvent)
{
vtkRenderWindowInteractor *rwi = dynamic_cast< vtkRenderWindowInteractor
* >(caller);
int X = rwi->GetEventPosition()[0];
int Y = rwi->GetEventPosition()[1];

// Okay, making sure that the pick is in the current renderer
if (!this->RIW[0]->GetRenderer() ||
!this->RIW[0]->GetRenderer()->IsInViewport(X, Y))
{ return; }

//PropPicker Initialized earlier
this->PropPicker->Pick(X, Y, 0.0, this->RIW[0]->GetRenderer());
vtkAssemblyPath* path = this->PropPicker->GetPath();

int found = 0;
int i;
if (path != NULL)
{
// lets consider the possibility that we may be using a shared picker
vtkCollectionSimpleIterator sit;
path->InitTraversal(sit);
vtkAssemblyNode *node;
for (i = 0; i < path->GetNumberOfItems() && !found; ++i)
{
node = path->GetNextNode(sit);
if (node->GetViewProp() == this->Prop)
{
found = 1;
}
}
}

if (found)
{
double q[3];
this->PropPicker->GetPickPosition(q);

for (int i = 0; i < 3; i++)
{
NodeCreation(this->RIW[i], q[0], q[1], q[2]);
this->RIW[i]->Render();
}
}
else
{
// the above implementation Always returns Null with no paths
detected! why ???
return;
}
}

Please can some one help me with this, Thank you.


Regards

Ali



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers
sfaisalali91
2018-11-27 10:04:29 UTC
Permalink
I guess i got the solution :) took a while for understanding the
implementation. here is the solution to convert image cordinates to world
cordinates.


vtkIdType ptId = this->ImageData->FindPoint(q);

if (ptId == -1)
{
return 0;
}

double closestPt[3];
this->ImageData->GetPoint(ptId, closestPt);

double origin[3];
this->ImageData->GetOrigin(origin);
double spacing[3];
this->ImageData->GetSpacing(spacing);
int extent[6];
this->ImageData->GetExtent(extent);

int iq[3];
int iqtemp;
for (int i = 0; i < 3; ++i)
{
// compute world to image coords
iqtemp = vtkMath::Round((closestPt[i] - origin[i]) / spacing[i]);

// we have a valid pick already, just enforce bounds check
iq[i] = (iqtemp < extent[2 * i]) ? extent[2 * i] : \
((iqtemp > extent[2 * i + 1]) ? extent[2 * i + 1] : iqtemp);

// compute image to world coords
q[i] = iq[i] * spacing[i] + origin[i];
CurrentWorldPosition[i] = q[i];


this->CurrentPosition[i] = iq[i];
}


std::cout << "Image to world:" << q[0] << ", " << q[1] << ", " << q[2] <<
std::endl;

vtkImageCoordinateWidget helped me with the implementation :) Thank you.



--
Sent from: http://vtk.1045678.n5.nabble.com/VTK-Users-f1224199.html
_______________________________________________
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:
https://public.kitware.com/mailman/listinfo/vtkusers

Loading...