[vtkusers] Window->Image coordinate conversions?

Bill Lorensen bill.lorensen at gmail.com
Thu Oct 22 23:32:45 EDT 2009


You may need to:
ActorCollection->InitTraversal();
before:
 vtkActor* actor = ActorCollection->GetNextActor();



On Thu, Oct 22, 2009 at 10:15 PM, David Doria <daviddoria+vtk at gmail.com> wrote:
> 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
> _______________________________________________
> 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
>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>



More information about the vtkusers mailing list