[vtkusers] Re: Mixing 2d and 3d actors... the problem is in rendering!

Anja Ende anja.ende at googlemail.com
Fri Oct 13 08:14:24 EDT 2006


I am attaching the code here that highlights the problem. It is really
simple. If someone will try it on their machine for me, it would really
help. It might be a hardware problem as well.... I can send the image file,
if someone wants.

Thanks,
Anja

//---------------------------------------------------------------------------------------------------------

#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();

cursorImage->SetFileName("/home/pankaj/development/projects/viewer/bin/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);
    // 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;
}

//---------------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20061013/e9445055/attachment.htm>


More information about the vtkusers mailing list