[vtkusers] create vtkTexture w/ RGB

John Shalf jshalf at lbl.gov
Thu Jun 21 21:40:25 EDT 2001


Hi Randy,
with older (version 3.1 vtk) I use the following code
snippet.  I haven't tested with 3.2.  This is setting RGBA
rather than just RGB.  I use this for slice vis because
texture mapping deals with banded colormaps better than
colorizing the vertices.  The OpenGL vertex interpolation
creates lots of artifacts....

  vtkScalars* tmapscalars =
vtkScalars::New(VTK_UNSIGNED_CHAR,4);
  tmapscalars->SetNumberOfScalars(256*256); 
  vtkUnsignedCharArray *colorData = 
	(vtkUnsignedCharArray *)tmapscalars->GetData();
  unsigned char *colors = colorData->GetPointer(0);
  for(int index=0,j=0;j<256;j++) {
    for(int i=0;i<256;i++) {
      for(int n=0;n<3;n++,index++)
	colors[index]=cmap[index%(256*4)];
      colors[index++]=j; // fade transparency using Alpha
channel
    }
  }
  tmap->GetPointData()->SetScalars(tmapscalars);
  tmapscalars->Delete();
  vtkTexture *atext = vtkTexture::New();
  // atext->SetInput(pnm->GetOutput());
  atext->SetInput(tmap);
  atext->InterpolateOn();
	// and then the rest of the stuff to apply the texture to a
plane
  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);


-john

Randy Heiland wrote:
> 
> How do I create/update a vtkTexture by manually inserting RGB (0-255) values?
> 
> --Randy
> 
> _______________________________________________
> 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://public.kitware.com/mailman/listinfo/vtkusers




More information about the vtkusers mailing list