[vtkusers] possible bugs in vtkImageMapper - help!
Glen.Coates at csiro.au
Glen.Coates at csiro.au
Sun Feb 16 22:45:34 EST 2003
Hi,
I've got two problems with the vtkImageMapper class from the 4.1.1
sources.
The first is easily fixed. The default values for ColorWindow and
ColorLevel are 2000 and 1000 respectively, which (correctly) gives a color
shift of 0, however results in a color scale of around 0.125, meaning the
mapped image is 8 times as dark as the original image. These defaults
should be changed to 255 and 127.5 respectively in order to return the
original image. I don't know why the defaults have been set as they
currently are, as no explanation is given in the sources.
The second I am stumped by. With vtkImageMapper::RenderToRectangle
enabled, images are scaled _larger_ when the window drops _below_ a
certain size. For one thing, I can't understand what window size has to
do with the scaling of an image if we're dealing in non-normalized
viewport coordinates. I've done some fiddling, and this applies along
both x & y axes, but let's say we're worried about the x axis:
Let o = x component of image origin (as set by SetPosition())
d = x component of image dimensions (as set by SetPosition2())
w = window width
As soon as w < o+d, the image begins scaling in the opposite direction to
what you'd expect (ie it gets larger when the window is shrinking). I've
attached code that should demonstrate this behaviour (which has only been
tested on Linux, which means that the vtkOpenGLImageMapper could be at
fault). If you resize the window smaller in either direction, you will
see the image stretch out in the _wrong_ direction.
Run the program as ./stretch [jpegfile]. I have attached a small JPEG for
testing.
If anyone's seen this behaviour before and knows of a workaround, please
let me know as this is a major impediment to a project at the moment.
--
Cheers,
Glen
-------------- next part --------------
#include <vtkActor.h>
#include <vtkRenderWindow.h>
#include <vtkRenderer.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkJPEGReader.h>
#include <vtkImageMapper.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();
}
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;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tycho.jpg
Type: image/jpeg
Size: 12221 bytes
Desc:
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20030217/77350279/attachment.jpg>
More information about the vtkusers
mailing list