Textures corrupting my 2DActors

Robert Stein rstein at ncsa.uiuc.edu
Thu Apr 6 17:33:05 EDT 2000


Well here's kind of a strange one for you...

Let's say that I've got a plane with a texture applied to it... this is a
regular 3D actor... and I want to be able to pan rotate zoom etc... with
it...  Next I want to have some sort of Heads up display... so I'll create
some polydata and stick it into a vtkPolyData2DMapper and then give it to a
vtkActor2D with the right screen coordinates...

Here's the problem... when I do this, my 2D Actor wether it be a polygon or
lines or whatever, seems to pick up the last texture to be applied to a
totatlly separate actor in the 3D scene... I'm very puzzled by this and
wonder if it's a vtk bug, or something I'm doing wrong...

I've boiled it down to a simple test case here, and I've included the c++
code to run it... just give the program a *.ppm file on the command line
and it will texture the plane (and the 2D triangle) with it...  If someone
could help me out here that would be great...


Thanks, 

Rob Stein

-------------- next part --------------
// vtk includes
#include "vtkRenderer.h"
#include "vtkRenderWindow.h"
#include "vtkRenderWindowInteractor.h"
#include "vtkPNMReader.h"
#include "vtkTexture.h"
#include "vtkPlaneSource.h"
#include "vtkPolyDataMapper.h"
#include "vtkPolyDataMapper2D.h"
#include "vtkActor2D.h"
#include "vtkActor.h"

vtkRenderer* ren1;
vtkRenderWindow* renWin;

void user(void* d){
 // load the texture map
  vtkPNMReader *pnm = vtkPNMReader::New();
    pnm->SetFileName("test.ppm");
  vtkTexture *atext = vtkTexture::New();
    atext->SetInput(pnm->GetOutput());
    atext->InterpolateOn();

  vtkPlaneSource *plane = vtkPlaneSource::New();
  vtkPolyDataMapper *planeMapper = vtkPolyDataMapper::New();
    planeMapper->SetInput(plane->GetOutput());
  vtkActor *planeActor = vtkActor::New();
    planeActor->SetMapper(planeMapper);
    planeActor->SetTexture(atext);

  ren1->AddActor(planeActor);
  renWin->Render();
}

void main (int argc, char *argv[]) {
  if(argc<2){
    fprintf(stderr, "Usage %s: <filename.ppm>\n", argv[0]);
    exit(0);
  }
    
  renWin = vtkRenderWindow::New();
  ren1 = vtkRenderer::New();
  vtkRenderWindowInteractor *iren = vtkRenderWindowInteractor::New();
  renWin->AddRenderer(ren1);
  iren->SetRenderWindow(renWin);
  //iren->SetUserMethod(user, NULL);

  // load the texture map
  vtkPNMReader *pnm = vtkPNMReader::New();
    pnm->SetFileName(argv[1]);
  vtkTexture *atext = vtkTexture::New();
    atext->SetInput(pnm->GetOutput());
    atext->InterpolateOn();

  vtkPlaneSource *plane = vtkPlaneSource::New();
  vtkPolyDataMapper *planeMapper = vtkPolyDataMapper::New();
    planeMapper->SetInput(plane->GetOutput());
  vtkActor *planeActor = vtkActor::New();
    planeActor->SetMapper(planeMapper);
    planeActor->SetTexture(atext);

  ren1->AddActor(planeActor);
  ren1->SetBackground(0.2,0.3,0.4);
  renWin->SetSize(300,300);

  vtkPolyData* camera = vtkPolyData::New();
  vtkCellArray* cells = vtkCellArray::New();
  vtkPoints* points = vtkPoints::New();
  int pts[3] = { 0, 1, 2 };
  points->InsertPoint(0, -20, -20, 0);
  points->InsertPoint(1, 20, -20, 0);
  points->InsertPoint(2, 0, 20, 0);
  cells->InsertNextCell(3, pts);
  camera->SetPoints(points);
  camera->SetPolys(cells);
  
  vtkPolyDataMapper2D* cameraMapper = vtkPolyDataMapper2D::New();
  cameraMapper->SetInput(camera);
  vtkActor2D* cameraActor = vtkActor2D::New();
  cameraActor->SetMapper(cameraMapper);
  cameraActor->SetPosition(100, 100);
  ren1->AddActor(cameraActor);
  
  renWin->Render();
  iren->Start(); // start rendering
}
-------------- next part --------------

Robert J. Stein
National Center For Supercomputing Applications
405 N. Matthews, Urbana, IL
(217) 244-7584
rstein at ncsa.uiuc.edu


More information about the vtkusers mailing list