[vtk-developers] world->display coordinate conversion trouble

Steve M. Robbins steve at sumost.ca
Fri Aug 3 02:20:20 EDT 2007


Hi,

I'd like to appeal to the developers who understand coordinate
conversions done by vtkRenderer and vtkCoordinate.  

The test program (below) is intended to convert world coordinate
(1,0,0) to display coordinates first using vtkRenderer and then using
vtkCoordinate.  I expected the same result, but got:

  World->Display vtkRenderer: (1,0) --> (1.5,0.5)
  World->Display vtkCoordinate: (1,0) --> (1.7,0.9)

when built against CVS VTK on my linux machine.

I'd like to know whether the test program is indeed correct and,
if so, which conversion to believe.


Thanks,
-Steve

P.S. I tried to raise this a couple of years ago
 [http://public.kitware.com/pipermail/vtk-developers/2005-November/003848.html]
and again recently in 
 [http://www.vtk.org/Bug/bug.php?op=show&bugid=5111]


/*
 * Test coordinate conversions.
 */

#include <iostream>
#include <cmath>

#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkCamera.h>
#include <vtkCoordinate.h>

using namespace std;




void convertWorldToDisplay1( vtkRenderer* renderer, double x, double y )
{
    renderer->SetWorldPoint( x, y, 0, 1 );
    renderer->WorldToDisplay();
    double result[3];
    renderer->GetDisplayPoint( result );
    cout << "World->Display vtkRenderer: "
	 << "(" << x << "," << y << ")"
	 << " --> "
	 << "(" << result[0] << "," << result[1] << ")\n";
}

void convertWorldToDisplay2( vtkRenderer* renderer, double x, double y )
{
    vtkCoordinate* coordinate = vtkCoordinate::New();
    coordinate->SetCoordinateSystemToWorld();
    coordinate->SetValue( x, y, 0 );

    double* result = coordinate->GetComputedDoubleDisplayValue( renderer );
    cout << "World->Display vtkCoordinate: "
	 << "(" << x << "," << y << ")"
	 << " --> "
	 << "(" << result[0] << "," << result[1] << ")\n";
}

// Set up world->display transform so that it maps
// an image of specified width and height to a render
// window of the same size.
// This should result in a world->display transformation
// that is a translation by half a pixel since world coordinate
// origin is in pixel centre while display is at pixel edge.
//
vtkRenderer* createRenderer( int width, int height )
{
    vtkRenderWindow* renderWindow = vtkRenderWindow::New();
    renderWindow->SetSize( width, height );

    vtkRenderer* renderer = vtkRenderer::New();
    renderWindow->AddRenderer( renderer );

    vtkCamera* camera = renderer->GetActiveCamera();

    double xFocal = ( width - 1 ) / 2.0;
    double yFocal = ( height - 1 ) / 2.0;

    camera->SetViewUp( 0, 1, 0 );
    camera->SetFocalPoint( xFocal, yFocal, 0 );
    camera->SetPosition( xFocal, yFocal, 2 );
    camera->SetClippingRange( 1, 3 );

    camera->ParallelProjectionOn();
    camera->SetParallelScale( height / 2.0 );

    return renderer;
}

int main( int ac, char* av[] )
{
    vtkRenderer* renderer = createRenderer( 5, 5 );
    convertWorldToDisplay1( renderer, 1, 0 );
    convertWorldToDisplay2( renderer, 1, 0 );

    return 0;
}


-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
URL: <http://public.kitware.com/pipermail/vtk-developers/attachments/20070803/7c7a01e5/attachment.sig>


More information about the vtk-developers mailing list