[vtkusers] vtkImageMapper error
John Biddiscombe
jbiddiscombe at skippingmouse.co.uk
Fri Apr 4 19:11:46 EST 2003
Yes. There's a bug in the render to rectangle code.
What's happening is that the render to rectangle is scaling the image
correctly, but unbeknown to it, the image mapper base class has "cropped"
the extents of the visible image before the rectangle scaling is applied.
Hence it gets the scaling wrong and as the screen size drops below the image
size an error is apparent. It doesn't happen when the screen size is bigger
than the image because no cropping occurs.
A fix you can use temporarily is to
mapper->SetRenderToRectangle(1);
mapper->SetUseCustomExtents(1);
int ex[4] = { 0, dims[0]-1, 0, dims[1]-1 };
mapper->SetCustomDisplayExtents(ex);
now we've fixed the extents that are displayed to the limits of the image
and nomatter what happens, the correct pixels are being used, and the
scaling is preserved.
it may take me a while to fix this bug, so perhaps a short term solution is
to alter the docs to tell the user to use custom extents (which is what I
always do and why I've never noticed the bug)
Thanks for pointing it out
JB
----- Original Message -----
From: "Neil Killeen" <Neil.Killeen at atnf.csiro.au>
To: <vtkusers at public.kitware.com>
Sent: Wednesday, April 02, 2003 4:39 AM
Subject: [vtkusers] vtkImageMapper error
> Hello
>
> some time ago, our student posted a message
>
> http://public.kitware.com/pipermail/vtkusers/2003-February/016105.html
>
> requesting help with vtkImageMapper.
>
> He received no reply, and the problem still exists in VTK 4.2
>
> The enclosed test program, stretch.cxx, will generate a Bus Error under
> Solaris. Under Linux, where he was working, the behaviour was
> un-useful (see message above).
>
> Run the program with the provided jpg image as input.
>
> ./stretch tycho.jpg
>
>
> The basic function causing the trouble is
>
> vtkImageMapper::RenderToRectangleOn();
>
> when this function call is commented out, the program runs successfully.
> We assume his usage of the funciton is correct but would be delighted
> to learn otherwise !
>
>
> Would somebody respond please ?
>
> thanks
> Neil Killeen
>
>
>
>
> // stretch.cxx
>
> #include <vtkActor.h>
> #include <vtkRenderWindow.h>
> #include <vtkRenderer.h>
> #include <vtkRenderWindowInteractor.h>
> #include <vtkJPEGReader.h>
> #include <vtkImageMapper.h>
> #include <vtkImageData.h>
> #include <vtkActor2D.h>
>
> #include <iostream>
> #include <math.h>
> using namespace std;
>
> #define WINWIDTH 300
> #define WINHEIGHT 300
>
> int main(int argc, char **argv)
> {
> int dims[3];
>
> vtkJPEGReader *jpeg = vtkJPEGReader::New();{
> jpeg->SetFileName(argv[1]);
> jpeg->Update();
> jpeg->GetOutput()->GetDimensions(dims);
> }
> vtkImageMapper *mapper = vtkImageMapper::New();{
> mapper->SetInput(jpeg->GetOutput());
> mapper->RenderToRectangleOn(); // Trouble maker
> }
>
> vtkActor2D *actor = vtkActor2D::New();{
> actor->SetMapper(mapper);
> actor->GetPosition2Coordinate()->SetCoordinateSystemToViewport();
> actor->SetPosition(0,0);
> actor->SetPosition2(dims[0],dims[1]);
> }
>
> vtkRenderer *ren = vtkRenderer::New();{
> ren->AddActor(actor);
> }
>
> vtkRenderWindow *win = vtkRenderWindow::New();{
> win->AddRenderer(ren);
> win->SetSize(dims[0],dims[1]);
> }
>
> vtkRenderWindowInteractor *rwi = vtkRenderWindowInteractor::New();{
> rwi->SetRenderWindow(win);
> rwi->Start();
> }
>
> return 0;
> }
>
>
>
>
More information about the vtkusers
mailing list