[vtk-developers] new test case for coordinate conversions

Steve M. Robbins steven.robbins at videotron.ca
Wed Nov 23 13:53:40 EST 2005


Howdy,

I've been trying to understand/debug coordinate conversion code in
VTK.  In particular, I need to understand the world<-->screen mapping
under a parallel-projection camera.  After a few rounds on this list (see
http://public.kitware.com/pipermail/vtk-developers/2005-November/003823.html),
David Gobbi and I continued in private mail and he convinced me that I
should set the parallel scale to "height/2" rather than "(height-1)/2"
as I was proposing.

Along the way, I converted my test code from Java to C++ and switched
to using vtkRenderer directly, rather than using vtkCoordinate.
Examining the methods provided by the two classes shows that there are
multiple ways to do conversion; e.g. there are two ways to convert
from world->view, two to convert from world->display, *three* to
convert from view->world, etc.

Ultimately I discovered that the conversions are not all consistent.

Working from the tip of CVS branch VTK-5-0, I wrote a test case 
Rendering/Testing/Cxx/coordinateConversion.cxx (attached) that 
compares the results of all equivalent conversions.

It turns out that 

    vtkRenderer::WorldToDisplay()
    vtkRenderer::DisplayToWorld()
    vtkRenderer::ViewToDisplay()

disagree with their vtkCoordinate counterparts.

David Gobbi feels that the view<-->normalized viewport conversion
is incorrect.  Indeed, looking at the code in vtkViewport, it
appears to me that it doesn't take into account the change from
pixel-edge convention of the screen and view coordinates to the
pixel-centre convention of the viewport and world coordinates.


I hope one of the developers has time to check my test case.
Feel free to incorporate it into VTK.  I've had one go at fixing
vtkViewport::ViewToNormalizedViewport(), but didn't succeed.


Cheers,
-Steve
-------------- next part --------------
A non-text attachment was scrubbed...
Name: coordinateConversion.cxx
Type: text/x-c++src
Size: 10217 bytes
Desc: not available
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20051123/8dd06452/attachment-0001.cxx>
-------------- next part --------------
Start testing: Wed Nov 23 13:49:39 EST 2005
----------------------------------------------------------
1/1 Test: coordinateConversion
Command: "/usr/local/src/visualization/VTK-cvs-kitware-build/bin/RenderingCxxTests" "coordinateConversion" 
Directory: /usr/local/src/visualization/VTK-cvs-kitware-build/Rendering/Testing/Cxx
"coordinateConversion" start time: Wed Nov 23 13:49:39 EST 2005
Output:
----------------------------------------------------------
Parallel projection, 5x5 window
[0,0] maps to [0.5,0.5] using vtkRenderer::WorldToDisplay(), but to [0.9,0.9] using vtkCoordinate::WorldToDisplay
[0,0] maps to [-0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [-1.125,-1.125] using vtkCoordinate::DisplayToWorld
[1,0] maps to [1.5,0.5] using vtkRenderer::WorldToDisplay(), but to [1.7,0.9] using vtkCoordinate::WorldToDisplay
[1,0] maps to [5,2.5] using vtkRenderer::ViewToDisplay(), but to [4.5,2.5] using vtkCoordinate::ViewToDisplay
[1,0] maps to [0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [0.125,-1.125] using vtkCoordinate::DisplayToWorld
[0,1] maps to [0.5,1.5] using vtkRenderer::WorldToDisplay(), but to [0.9,1.7] using vtkCoordinate::WorldToDisplay
[0,1] maps to [2.5,5] using vtkRenderer::ViewToDisplay(), but to [2.5,4.5] using vtkCoordinate::ViewToDisplay
[0,1] maps to [-0.5,0.5] using vtkRenderer::DisplayToWorld(), but to [-1.125,0.125] using vtkCoordinate::DisplayToWorld
Parallel projection, 5x15 window
[0,0] maps to [0.5,0.5] using vtkRenderer::WorldToDisplay(), but to [0.9,0.966667] using vtkCoordinate::WorldToDisplay
[0,0] maps to [-0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [-1.125,-1.03571] using vtkCoordinate::DisplayToWorld
[1,0] maps to [1.5,0.5] using vtkRenderer::WorldToDisplay(), but to [1.7,0.966667] using vtkCoordinate::WorldToDisplay
[1,0] maps to [5,7.5] using vtkRenderer::ViewToDisplay(), but to [4.5,7.5] using vtkCoordinate::ViewToDisplay
[1,0] maps to [0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [0.125,-1.03571] using vtkCoordinate::DisplayToWorld
[0,1] maps to [0.5,1.5] using vtkRenderer::WorldToDisplay(), but to [0.9,1.9] using vtkCoordinate::WorldToDisplay
[0,1] maps to [2.5,15] using vtkRenderer::ViewToDisplay(), but to [2.5,14.5] using vtkCoordinate::ViewToDisplay
[0,1] maps to [-0.5,0.5] using vtkRenderer::DisplayToWorld(), but to [-1.125,0.0357143] using vtkCoordinate::DisplayToWorld
Parallel projection, 15x5 window
[0,0] maps to [0.5,0.5] using vtkRenderer::WorldToDisplay(), but to [0.966667,0.9] using vtkCoordinate::WorldToDisplay
[0,0] maps to [-0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [-1.03571,-1.125] using vtkCoordinate::DisplayToWorld
[1,0] maps to [1.5,0.5] using vtkRenderer::WorldToDisplay(), but to [1.9,0.9] using vtkCoordinate::WorldToDisplay
[1,0] maps to [15,2.5] using vtkRenderer::ViewToDisplay(), but to [14.5,2.5] using vtkCoordinate::ViewToDisplay
[1,0] maps to [0.5,-0.5] using vtkRenderer::DisplayToWorld(), but to [0.0357143,-1.125] using vtkCoordinate::DisplayToWorld
[0,1] maps to [0.5,1.5] using vtkRenderer::WorldToDisplay(), but to [0.966667,1.7] using vtkCoordinate::WorldToDisplay
[0,1] maps to [7.5,5] using vtkRenderer::ViewToDisplay(), but to [7.5,4.5] using vtkCoordinate::ViewToDisplay
[0,1] maps to [-0.5,0.5] using vtkRenderer::DisplayToWorld(), but to [-1.03571,0.125] using vtkCoordinate::DisplayToWorld
----------------------------------------------------------
"coordinateConversion" end time: Wed Nov 23 13:49:39 EST 2005
"coordinateConversion" time elapsed: 00:00:00
----------------------------------------------------------

End testing: Wed Nov 23 13:49:39 EST 2005


More information about the vtk-developers mailing list