[vtkusers] vtkCoordinate question

Dean Inglis dean.inglis at camris.ca
Fri Feb 11 16:48:49 EST 2011


Im using vtkBorderWidget/Representation to define a square ROI on an image.
vtkBorderRepresentation constructs its vtkPolyData geometry in display 
coordinates
by taking a unit square with lower left corner set at 0, 0 in its local 
model space
and then transforming the points to display coordinates internally by 
translating and scaling.
I would like to recover the world coordinates of the four corners of the 
border.

currently I do:

  vtkSmartPointer<vtkActor2DCollection> pc = 
vtkSmartPointer<vtkActor2DCollection>::New();
  borderRep->GetActors2D( pc );
  vtkPolyData* borderPoly = 
vtkPolyDataMapper2D::SafeDownCast(pc->GetLastActor2D()->GetMapper())->GetInput();

  vtkSmartPointer<vtkCoordinate> cr1 = 
vtkSmartPointer<vtkCoordinate>::New();
  vtkSmartPointer<vtkCoordinate> cr2 = 
vtkSmartPointer<vtkCoordinate>::New();
  cr1->SetCoordinateSystemToDisplay();
  cr2->SetCoordinateSystemToDisplay();
  cr1->SetViewport( renderer );
  cr2->SetViewport( renderer );

  vtkSmartPointer<vtkCoordinate> c1 = vtkSmartPointer<vtkCoordinate>::New();
  vtkSmartPointer<vtkCoordinate> c2 = vtkSmartPointer<vtkCoordinate>::New();
  c1->SetReferenceCoordinate( cr1 );
  c1->SetViewport( renderer );
  c2->SetReferenceCoordinate( cr2 );
  c2->SetViewport( renderer );

  cr1->SetValue( borderPoly->GetPoints()->GetPoint(0) );
  cr2->SetValue( borderPoly->GetPoints()->GetPoint(2) );

  double* worldPt1 = c1->GetComputedWorldValue(0);
  double* worldPt2 = c2->GetComputedWorldValue(0);

I can set the z coordinate of these points to the z location of the image 
actor displaying the image,
 however, the world points do not match up.  Please see attached jpeg.   The 
darker
rectangular region in the image should be the same size as the border 
widget's rep.  The border
widget sets up the coordinates for a vtkLassooStencilSource in an image 
stenciling pipeline.
Ive tried all sorts of variants on this but Im stymied as to why there is a 
translation
and scale effect.

Dean

-------------- next part --------------
A non-text attachment was scrubbed...
Name: roiTest.jpg
Type: image/jpeg
Size: 10413 bytes
Desc: not available
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110211/c8571eec/attachment.jpg>


More information about the vtkusers mailing list