[vtkusers] Window->Image coordinate conversions?

David Doria daviddoria+vtk at gmail.com
Thu Oct 22 22:15:00 EDT 2009


On Thu, Oct 22, 2009 at 6:48 PM,  <itkvtk123 at gmx.net> wrote:
> You can do this easily with vtkImageActorPointPlacer.
>
> This class will allow you to transform display coordinates to the corresponding image coordinates on the ImageActor.
>
> For the actual conversion you use the method ComputeWorldPosition(...)
>
> Where display position is the coordinate in the renderwindow and world position is the coordinate on the ImageActor.


Here is my selection changed callback for my rubberband selection - it
segfaults - can anyone see the problem? Looking at this function,
would you want to rephrase your "easily" comment? hahaha. I am trying
to get the world coordinate of the first corner of the rubberband.


void SelectionChangedCallbackFunction ( vtkObject* caller, long
unsigned int eventId, void* clientData, void* callData )
{
  vtkstd::cout << "Selection changed callback" << vtkstd::endl;

  unsigned int* rect = reinterpret_cast<unsigned int*> ( callData );
  unsigned int pos1X = rect[0];
  unsigned int pos1Y = rect[1];
  unsigned int pos2X = rect[2];
  unsigned int pos2Y = rect[3];

  vtkstd::cout << "Start x: " << pos1X << " Start y: " << pos1Y << "
End x: " << pos2X << " End y: " << pos2Y << vtkstd::endl;

  vtkRenderWindow* ren = reinterpret_cast<vtkRenderWindow*>(caller);
  vtkRendererCollection* RendererCollection = ren->GetRenderers();
  vtkRenderer* renderer = RendererCollection->GetFirstRenderer();

  vtkActorCollection* ActorCollection = renderer->GetActors();
  vtkActor* actor = ActorCollection->GetNextActor();
  vtkImageActor* ImageActor = reinterpret_cast<vtkImageActor*>(actor);

  vtkSmartPointer<vtkImageActorPointPlacer> ImageActorPointPlacer =
vtkSmartPointer<vtkImageActorPointPlacer>::New();
  ImageActorPointPlacer->SetImageActor(ImageActor);

  double displayPos[2];
  displayPos[0] = pos1X;
  displayPos[1] = pos1Y;

  double worldPos[3];
  double worldOrient[9];

  ImageActorPointPlacer->ComputeWorldPosition(renderer, displayPos,
worldPos, worldOrient);

  vtkstd::cout << "World pos: " << worldPos[0] << " " << worldPos[1]
<< " " << worldPos[2] << vtkstd::endl;

}

Also, can anyone comment on the image->world coordinate mapping? Are
world coordinates (snapped to the nearest integer) the same as image
coordinates when using these interactors? If not, this still has not
accomplished getting the pixel index in the original image, right?

Thanks,

David



More information about the vtkusers mailing list