AW: [vtkusers] How to show semi-transparent image?

Simon DROUIN sdrouin at bic.mni.mcgill.ca
Thu Jan 15 07:56:07 EST 2004


Hi Chunyan,

I have had a quick look at the code of vtkOpenGlImageActor. It seems to be
doing what I've been doing for a while: put the image as a texture on a
polygon. It just seem to me that the interface of vtkImageActor is not
complete. To get more freedom in displaying 2D images, you could manually
create a plane and put a your image on it as a texture map. With this
method, you need to reshape your image to make sure width and length are
powers of 2 ( needed by OpenGl for texture mapping and done
automatically by vtkImageActor ). Here is some code for one 640x480 image
(the vtkImageData is called imageData ):

    //------------------------------------------------------------------
    // create plane on which texture will be mapped
    //
    vtkPlaneSource * plane = vtkPlaneSource::New();
    plane->SetXResolution(1);
    plane->SetYResolution(1);
    plane->SetOrigin(-0.5,-0.5,0);
    plane->SetPoint1(319.5,-0.5,0);
    plane->SetPoint2(-0.5,239.5,0);

    //----------------------------------------------------------------
    // generate texture coordinates by mapping points to plane
    //
    vtkTextureMapToPlane * plane2 = vtkTextureMapToPlane::New();
    plane2->SetOrigin(-0.5,-0.5,0);
    plane2->SetPoint1(511.5,-0.5,0);
    plane2->SetPoint2(-0.5,255.5,0);
    plane2->SetInput( plane->GetOutput() );

    //----------------------------------------------------------------
    //map vtkDataSet and derived classes to graphics primitives.
    //
    vtkDataSetMapper * mapper = vtkDataSetMapper::New();
    mapper->SetInput( plane2->GetOutput() );

    //----------------------------------------------------------------
    //handles properties associated with a texture map.
    //
    vtkTexture * atext = vtkTexture::New();
    atext->SetInput( imageData );
    atext->SetQualityTo32Bit();
    atext->InterpolateOn();
    atext->RepeatOff();

    //----------------------------------------------------------------
    //represents an object (geometry & properties) in a rendered scene.
    //
    vtkActor * actor = vtkActor::New();
    actor->SetMapper(mapper);
    actor->SetTexture(atext);

    //----------------------------------------------------------------
    // Create rendering stuff
    vtkRenderer * ren1 = vtkRenderer::New();
    ren1->AddActor( actor );

You can add a second actor for a second image. You can also get the
properties of the actor and set a transparency. If someone has time, it
might be usefull to build a vtkImageActor2 like this.

Simon


On Thu, 15 Jan 2004, jiang wrote:

> Hi Simon,
> The two images can be rendered correctly. The pipeline should be:
> vtkImageData->vtkImageActor---->vtkRenderer
>                                            |->vtkRenderWindow
> vtkImageData->vtkImageActor---->vtkRenderer
>
> combine with vtkRenderer->SetLayer and
> vtkRenderWindow->SetNumberOfLayers(2).
>
> Cheers,
>
> Chunyan
>
>
> -----Ursprungliche Nachricht-----
> Von: Simon DROUIN [mailto:sdrouin at bic.mni.mcgill.ca]
> Gesendet: Dienstag, 13. Januar 2004 14:21
> An: jiang
> Cc: VTK
> Betreff: Re: [vtkusers] How to show semi-transparent image?
>
>
> jiang wrote:
>
> >Hi vtk-users,
> >I have already shown one image in vtk pipeline:
> >vtkImageData->vtkImageActor->vtkRenderer
> >Now I want to show one other image in this pipeline. The second image
> should
> >be semi-transparent, and cover on the first image. How can I realize it?
> >
> >Thank you very much!
> >
> >
> >Chunyan
> >
> >_______________________________________________
> >This is the private VTK discussion list.
> >Please keep messages on-topic. Check the FAQ at:
> <http://public.kitware.com/cgi-bin/vtkfaq>
> >Follow this link to subscribe/unsubscribe:
> >http://www.vtk.org/mailman/listinfo/vtkusers
> >
> >
>
> new pipeline:
>
> vtkImageData->vtkImageActor---->vtkRenderer
>                             |
> vtkImageData->vtkImageActor--
>
>
> On the second actor, do that:
>
> actor->GetProperty()->SetOpacity
> <cid:part1.04030609.04000504 at bic.mni.mcgill.ca>( 0.5 )
>
>
> Simon Drouin
>
> _______________________________________________
> This is the private VTK discussion list.
> Please keep messages on-topic. Check the FAQ at: <http://public.kitware.com/cgi-bin/vtkfaq>
> Follow this link to subscribe/unsubscribe:
> http://www.vtk.org/mailman/listinfo/vtkusers
>




More information about the vtkusers mailing list