Discussion:
[vtkusers] problem with fitting image into viewport
Thomas Lambertz
2006-05-29 17:52:28 UTC
Permalink
Hi all,

what went wront with the following code ?

renWin->AddRenderer(sliceRenderer[slice]);

vtkCamera *camera = vtkCamera::New();
camera->ParallelProjectionOn();
camera->SetParallelScale(256);
sliceRenderer[slice]->InteractiveOff();
sliceRenderer[slice]->SetActiveCamera(camera);

renWin->Render();

I got the image on the screen - but no scaling whatever value given for
SetParallelScale (the block in the middle can simply be removed without
an effect). Seemes i missed something - but i have no idea what. Any
suggestions ?

Kind regards,
Tom
Thomas Lambertz
2006-05-30 00:45:09 UTC
Permalink
Hi,

it took me some time to realize that not the codesnippet postet below
was is the problem. I tried with the tutuials in vtk/Examples/Tutorials
and when adding
ren1->GetActivecamera()->ParallelProjectionOn();
ren1->GetActivecamera()->SetParallelScale(4);
there, all runs well. So copying some code into my project - and to my
surprise - all is ok WHEN i replace my vtkActor2d with the one from the
tutorial (which is a vtkActor).

[...] (connector is an itkImageToVTKImage Filter)

connector->UpdateLargestPossibleRegion();

vtkRenderer *ren2= vtkRenderer::New();

*1)
vtkImageMapper *testMapper = vtkImageMapper::New();
testMapper->SetInput( connector->GetOutput() );
testMapper->Update();

vtkActor2D *testActor = vtkActor2D::New();
testActor->SetMapper( testMapper);

ren2->AddActor2D( testActor );

ren2->ResetCamera();
ren2->GetActiveCamera()->ParallelProjectionOn();
ren2->GetActiveCamera()->SetParallelScale(10);

renWin->AddRenderer(ren2);

As the displayed image is correct (except the size) i think all before
*1) works well.So still vtkImageMapper and vtkActor2D on the list.
Searching again the web the code here
http://www.imaging.robarts.ca/coders/content/classes/examples/vtkSliceWidget.html
makes me believe that it´s not a general problem between vtkActor2D and
SetParallelScale().
Looks like not being a big problem - but i am just to blind to see the
solution. Can someone help me out of this misery ?

Thx in advance,
Tom
Post by Thomas Lambertz
Hi all,
what went wront with the following code ?
renWin->AddRenderer(sliceRenderer[slice]);
vtkCamera *camera = vtkCamera::New();
camera->ParallelProjectionOn();
camera->SetParallelScale(256);
sliceRenderer[slice]->InteractiveOff();
sliceRenderer[slice]->SetActiveCamera(camera);
renWin->Render();
I got the image on the screen - but no scaling whatever value given
for SetParallelScale (the block in the middle can simply be removed
without an effect). Seemes i missed something - but i have no idea
what. Any suggestions ?
Kind regards,
Tom
Goodwin Lawlor
2006-05-30 13:29:00 UTC
Permalink
Post by Thomas Lambertz
Hi,
it took me some time to realize that not the codesnippet postet below
was is the problem. I tried with the tutuials in vtk/Examples/Tutorials
and when adding
ren1->GetActivecamera()->ParallelProjectionOn();
ren1->GetActivecamera()->SetParallelScale(4);
there, all runs well. So copying some code into my project - and to my
surprise - all is ok WHEN i replace my vtkActor2d with the one from the
tutorial (which is a vtkActor).
[...] (connector is an itkImageToVTKImage Filter)
connector->UpdateLargestPossibleRegion();
vtkRenderer *ren2= vtkRenderer::New();
*1)
vtkImageMapper *testMapper = vtkImageMapper::New();
testMapper->SetInput( connector->GetOutput() );
testMapper->Update();
vtkActor2D *testActor = vtkActor2D::New();
testActor->SetMapper( testMapper);
ren2->AddActor2D( testActor );
ren2->ResetCamera();
ren2->GetActiveCamera()->ParallelProjectionOn();
ren2->GetActiveCamera()->SetParallelScale(10);
renWin->AddRenderer(ren2);
As the displayed image is correct (except the size) i think all before
*1) works well.So still vtkImageMapper and vtkActor2D on the list.
Searching again the web the code here
http://www.imaging.robarts.ca/coders/content/classes/examples/vtkSliceWidget.html
makes me believe that it´s not a general problem between vtkActor2D and
SetParallelScale().
Looks like not being a big problem - but i am just to blind to see the
solution. Can someone help me out of this misery ?
Thx in advance,
Tom
Hi Tom,

Have a look at the tcl code here:
http://www.bioengineering-research.com/vtk/BackgroundImage.tcl

where an image is set as a background in the viewport.

hth

Goodwin
Thomas Lambertz
2006-05-30 15:17:56 UTC
Permalink
Hi Goodwin,

thx for your answer. The link is unfortuantly one of the ones i based my
code on. They used a vtkActor which seemes to work fine.

I am still not sure wether it has to do with vtkActor2D or the
vtkImageMapper i used - or better the way i used them. The bug is
certanly in my code.
Any suggestions ?

Kind regards,
Tom
Post by Goodwin Lawlor
Post by Thomas Lambertz
Hi,
it took me some time to realize that not the codesnippet postet below
was is the problem. I tried with the tutuials in
vtk/Examples/Tutorials and when adding
ren1->GetActivecamera()->ParallelProjectionOn();
ren1->GetActivecamera()->SetParallelScale(4);
there, all runs well. So copying some code into my project - and to
my surprise - all is ok WHEN i replace my vtkActor2d with the one
from the tutorial (which is a vtkActor).
[...] (connector is an itkImageToVTKImage Filter)
connector->UpdateLargestPossibleRegion();
vtkRenderer *ren2= vtkRenderer::New();
*1)
vtkImageMapper *testMapper = vtkImageMapper::New();
testMapper->SetInput( connector->GetOutput() );
testMapper->Update();
vtkActor2D *testActor = vtkActor2D::New();
testActor->SetMapper( testMapper);
ren2->AddActor2D( testActor );
ren2->ResetCamera();
ren2->GetActiveCamera()->ParallelProjectionOn();
ren2->GetActiveCamera()->SetParallelScale(10);
renWin->AddRenderer(ren2);
As the displayed image is correct (except the size) i think all
before *1) works well.So still vtkImageMapper and vtkActor2D on the
list. Searching again the web the code here
http://www.imaging.robarts.ca/coders/content/classes/examples/vtkSliceWidget.html
makes me believe that it´s not a general problem between vtkActor2D
and SetParallelScale().
Looks like not being a big problem - but i am just to blind to see
the solution. Can someone help me out of this misery ?
Thx in advance,
Tom
Hi Tom,
http://www.bioengineering-research.com/vtk/BackgroundImage.tcl
where an image is set as a background in the viewport.
hth
Goodwin
_______________________________________________
This is the private VTK discussion list. Please keep messages
on-topic. Check the FAQ at: http://www.vtk.org/Wiki/VTK_FAQ
http://www.vtk.org/mailman/listinfo/vtkusers
Goodwin Lawlor
2006-05-30 18:06:03 UTC
Permalink
Post by Thomas Lambertz
Hi Goodwin,
thx for your answer. The link is unfortuantly one of the ones i based my
code on. They used a vtkActor which seemes to work fine.
I am still not sure wether it has to do with vtkActor2D or the
vtkImageMapper i used - or better the way i used them. The bug is
certanly in my code.
Any suggestions ?
Kind regards,
Tom
Hi Tom,

You need to set the renWin to the same size as the image...

int dims[3];
connector->GetOutput()->GetDimensions(dims);
renWin->SetSize(dims[0],dims[1]);

the parallel scale should be set to half the y image dimension:

ren2->GetActiveCamera()->SetParallelScale(dims[1]/2);

hth

Goodwin
Goodwin Lawlor
2006-05-30 18:15:34 UTC
Permalink
Post by Goodwin Lawlor
Post by Thomas Lambertz
Hi Goodwin,
thx for your answer. The link is unfortuantly one of the ones i based
my code on. They used a vtkActor which seemes to work fine.
I am still not sure wether it has to do with vtkActor2D or the
vtkImageMapper i used - or better the way i used them. The bug is
certanly in my code.
Any suggestions ?
Kind regards,
Tom
Hi Tom,
You need to set the renWin to the same size as the image...
int dims[3];
connector->GetOutput()->GetDimensions(dims);
renWin->SetSize(dims[0],dims[1]);
ren2->GetActiveCamera()->SetParallelScale(dims[1]/2);
Make that:

ren2->GetActiveCamera()->SetParallelScale(dims[1]/2.0);
Thomas Lambertz
2006-05-30 19:25:52 UTC
Permalink
Post by Goodwin Lawlor
Post by Thomas Lambertz
Hi Goodwin,
thx for your answer. The link is unfortuantly one of the ones i based
my code on. They used a vtkActor which seemes to work fine.
I am still not sure wether it has to do with vtkActor2D or the
vtkImageMapper i used - or better the way i used them. The bug is
certanly in my code.
Any suggestions ?
Kind regards,
Tom
Hi Tom,
You need to set the renWin to the same size as the image...
int dims[3];
connector->GetOutput()->GetDimensions(dims);
renWin->SetSize(dims[0],dims[1]);
ren2->GetActiveCamera()->SetParallelScale(dims[1]/2);
hth
Goodwin
Hi Goodwin,

i thought renWin->SetSize(x,y); sets the dimension of the renderWindow
in display-coordinates. This is exactly what i wanted to avoid. I have a
userdefinded Windowsize and i want to fit my image into that.

After reading more and more in the mailinglistarchive i found out that
my problem seemes to be the use of vtkActor2D as this simply doesnt take
account of camera settings. Someone may correct me if i am wrong.
Post by Goodwin Lawlor
/ here's the bit you need: (app is an image; numCol and numRow are
/>/ the image
/>/ dims)
/>/
/>/ vtkImageActor ia
/>/ ia SetInput [app GetOutput]
/>/ ia InterpolateOff
/>/ vtkRenderer ren1
/>/ ren1 AddActor ia
/>/ ren1 SetBackground 1 1 1
/>/ vtkRenderWindow renWin
/>/ renWin AddRenderer ren1
/>/ renWin SetSize [expr $numCol / 4] [expr $numRow / 4]
/>/ vtkInteractorStyleImage istyle
/>/ vtkRenderWindowInteractor iren
/>/ iren SetRenderWindow renWin
/>/ iren SetInteractorStyle istyle
/>/ [ren1 GetActiveCamera] ParallelProjectionOn
/>/ #fit the image to the render window
/>/ [ren1 GetActiveCamera] SetParallelScale [expr $numRow / 2]
/>/ renWin Render
/>/
/>/
/>/ hth
/>/
/>/ Goodwin

found in http://public.kitware.com/pipermail/vtkusers/2005-May/079949.html seemes to bring me right back on track as it gives me the missing link vtkImageActor.

Thank you very much for your help !

King regards,
Tom
/

Loading...