[vtkusers] Texture a vtk-file

Franz Th. Langer eplanung at t-online.de
Thu Apr 4 07:15:05 EST 2002


Hi,

I want to to Texture the file test.vtk in C++, but the programm works as

if there is no Texture at all!
what's wrong?

I am using the following code.
...
//read vtk-file
    this->Reader->SetFileName("Test.vtk");
    vtkPolyData* poly=vtkPolyData::New();
//establish structure
     poly=this->Reader->GetPolyDataOutput();

//texture bitmap
 vtkBMPReader* imageIn=vtkBMPReader::New();
     imageIn->SetFileName ("g:\\vtkdata\\beach.bmp");
 vtkTexture *atext = vtkTexture::New();
    atext->SetInput(imageIn->GetOutput());
    atext->InterpolateOn();
     imageIn->Delete();

//get number of points
 long n=poly->GetNumberOfPoints();

//create min,max coors
 float bds[6];
 poly->ComputeBounds();
 poly->GetBounds(bds);

 vtkPoints*points=vtkPoints::New();
 points=poly->GetPoints();

//create texture coordinates
    vtkTCoords* tcoor=vtkTCoords::New();
         tcoor->SetNumberOfComponents(2);
         tcoor->SetNumberOfTCoords(n);

 float xmin=bds[0], xmax=bds[1];
 float ymin=bds[2], ymax=bds[3];
 float zmin=bds[4], zmax=bds[5];
 float dx=xmax-xmin, dy=ymax-ymin, dz=zmax-zmin;
    float v[3];
 for(long i=0; i<n; i++)
 {
  points->GetPoint(i,v);
  v[0]=(v[0]-xmin)/dx;//between 0 and 1
  v[1]=(v[1]-ymin)/dy;//between 0 and 1
  v[2]=(v[2]-zmin)/dz;//between 0 and 1
  tcoor->SetTCoord(i,v);
 }

 poly->GetPointData()->SetTCoords(tcoor);
 tcoor->Delete();
//end texture coors

    this->Mapper->SetInput(poly);
   this->Actor->SetTexture(atext);
 atext->Delete();

    this->Actor->VisibilityOn();

....
when I put the Textureinformation  in the Test.vtk file everything is
ok!

Thanks for any help!
Franz








More information about the vtkusers mailing list