[vtkusers] 2d actors, vtkImageActor and multiple rendering layers

Anja Ende anja.ende at googlemail.com
Sat Oct 14 06:55:07 EDT 2006


Hi again,

As per my previous problem of mixing 2d and 3d actors in the same scene, I
thought it might be a graphics card problem. So, I managed to get another
windows machine (I was using Linux before) but I still see the same
problem.... the 2d actor only gets displayed when I do a pick operation on
the 3d actor.... This is completely bizarre and after several days I have
come with no explanation for that. I have stepped through the renderer code
multiple times during debug, but see nothing that could offer some kind of
explanation.

I really wish someone here would take a look at this very trivial code and
see if they could point something out. I tried to convert everything in my
code to 3d actors but that presents another set of complications,
unfortunately.

I am attaching the code again. I really request someone to please help me.
It will not take too much of your time. The code is really small and
functional.

#include "vtkImageData.h"
#include "vtkImageActor.h"
#include "vtkActor2D.h"
#include "vtkRenderWindow.h"
#include "vtkRenderer.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkImageMapper.h"
#include "vtkPNGReader.h"
#include "vtkImageChangeInformation.h"

int main ()
{
    // Read the image
    vtkPNGReader * cursorImage = vtkPNGReader::New();
    // Please replace with your own path
    cursorImage->SetFileName("C:\\crosshair.png");
    cursorImage->Update();
    // Shift center to image data oigin
    vtkImageChangeInformation * imageChange =
vtkImageChangeInformation::New();
    imageChange->SetInput(cursorImage->GetOutput());
    imageChange->CenterImageOn();

      // create actor2d
    vtkImageMapper * mapper = vtkImageMapper::New();
    mapper->SetInput(imageChange->GetOutput());
    mapper->SetColorWindow(256.0);
    mapper->SetColorLevel(128.0);
    vtkActor2D * actor2d = vtkActor2D::New();
    actor2d->SetMapper(mapper);
    actor2d->SetPosition(120.0, 100.0);

    // create actor 3d
    vtkImageActor * actor3d = vtkImageActor::New();
    actor3d->SetInput(imageChange->GetOutput());

    // following lines creates our 2 layers of renderers
    vtkRenderer *ren1 = vtkRenderer::New(); // 2d actor
    ren1->AddViewProp(actor2d);
    ren1->SetLayer(0); // bottom layer

    vtkRenderer *ren2 = vtkRenderer::New();
    ren2->AddViewProp(actor3d); // 3d actor
    ren2->SetLayer(1); // top layer

    vtkRenderWindow *renWin = vtkRenderWindow::New();
    renWin->SetNumberOfLayers(2); // we have 2 layers of renderers in our
window
    renWin->AddRenderer(ren1);
    renWin->AddRenderer(ren2);

    vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New(); //
an interactor
    iren->SetRenderWindow(renWin);
    renWin->Render();
    iren->Start();

    // We will not bother with deletions...program is ending anyways...
    return 0;
}

The crosshair.png image can be downloaded from here...

http://pligame.sourceforge.net/images/crosshair.png


Cheers,

Anja
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061014/05c60419/attachment.htm>


More information about the vtkusers mailing list