[vtkusers] why the world coordinate of vtkRenderer is different from the coordinate of vtkCoordinate

Liu_tj tjlp at netease.com
Sun Jun 5 06:26:11 EDT 2016


Hi,

I use vtkBorderWidget to select area of DICOM image on vtkImageViewer2. I want to set the initial left-bottom and right-top position of the vtkBorderWidget. Take the Coronal view for example, I get the display bounds of the image actor. These display bounds forms the left-bottom and right-top world coordinate. And then I call the vtkRenderer.WorldToView() to transform the world coordinate to view coordinate; with these 2 view coordinates, the vtkBorderWidget displays correctly.

The value of the display bounds is: MinX: 0, MaxX: 228.552734375, MinY: 114.052734375, MaxY: 114.052734375, MinZ: 0, MaxZ: 151.19

But, I use the methods of vtkBorderWidget to get the world coordinate of the left-bottom and right-top, the value is different from display bounds. The value is: x1 1.142763671875, x2 114.2763671875, y1 108.75879924706, y2 108.75879924706, z1 0.75595,   z2 75.595

Interesting thing is: x2 is half of MaxX, x1 is 1% of x2; z2 is half of MaxZ, z1 is 1% of z2. There might be some misunderstanding of VTK coordinate system.

My C# code is as follow. Where do I make mistake?

vtkImageActor actor = m_imageViewer.GetImageActor();
IntPtr boundsptr = actor.GetDisplayBounds();
double[] displaybounds= new double[ 6 ];
Marshal.Copy( boundsptr, displaybounds, 0, displaybounds.Length ); //Here I get the display bounds of vtkIamgeActor.

m_renderer.SetWorldPoint( displaybounds[ 1 ], displaybounds[ 3 ], displaybounds[ 5 ], 1 );
m_renderer.WorldToView();
double[] viewpint1 = m_renderer.GetViewPoint(); //Transform the world coordinate of right-top to view coordinate
m_renderer.SetWorldPoint( displaybounds[ 0 ], displaybounds[ 2 ], displaybounds[ 4 ], 1 );
m_renderer.WorldToView();
double[] viewpint = m_renderer.GetViewPoint(); //Transform the world coordinate of left-bottom to view coordinate
borderrep.GetPositionCoordinate().SetCoordinateSystemToView();
borderrep.GetPosition2Coordinate().SetCoordinateSystemToView();
borderrep.SetPosition( viewpint[ 0 ], viewpint[ 1 ] );
borderrep.SetPosition2( viewpint1[ 0 ], viewpint1[ 1 ] );

vtkCoordinate lowerleftCorr = borderrep.GetPositionCoordinate();
double[] lowerleft = lowerleftCorr.GetComputedWorldValue(m_renderer);
vtkCoordinate upperRightCorr = borderrep.GetPosition2Coordinate();
double[] upperright = upperRightCorr.GetComputedWorldValue(m_renderer);

displaybounds is: MinX: 0, MaxX: 228.552734375, MinY: 114.052734375, MaxY: 114.052734375, MinZ: 0, MaxZ: 151.19
lowerleft and upperright is: x1 1.142763671875, x2 114.2763671875, y1 108.75879924706, y2 108.75879924706, z1 0.75595, z2 75.595

Any tips on that? Thanks very much.

Liu Peng
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/vtkusers/attachments/20160605/863027a9/attachment.html>


More information about the vtkusers mailing list