[vtkusers] Black Texture, please help me!!

qinghu liao qhliaok at hotmail.com
Tue Mar 18 20:55:40 EST 2003


hi,

I am using the vtk4.2 to build the 3D surface model, which is taken by 3D
Camera.  I can show 3D model without texture, however when I try to map the
texture on it, it is just show the model with black texture. who can tell me
how solve this problem. please help me!    :(

the data is oraganized like this:

1. the polydata file
//----------------------------------------------------------
# vtk DataFile Version 2.0
trunck surface
ASCII
DATASET POLYDATA
POINTS 41179 float
266.951294 -150.814835 119.422646
263.817902 -150.814835 119.183411
263.676270 -146.738419 118.884048

......
......
......

POLYGONS 70230 280920
3 0 1 2
3 0 2 3
3 4 0 3
3 4 3 5
3 7 8 9
......
......
---------------------

2.the texture coordinate file:
//-------------------------------------------------------
41179
0.218967 0.319520
0.215529 0.323332
0.067673 0.519344
0.071111 0.516361
0.068347 0.516001

------
------
------

3. the RGB surface picture(1024x1024) 24bit.

=================================================================
my code is following;
//-------------------
 vtkPolyDataReader  *Reader = vtkPolyDataReader::New();
 vtkPolyDataMapper  *Mapper = vtkPolyDataMapper::New();
 vtkBMPReader *bmpReader = vtkBMPReader::New();
 vtkTexture *texture = vtkTexture::New();

  Actor = vtkActor::New();
  Actor->SetMapper(Mapper);

// read into the texture coordinate
 ifstream f("texture");
 int   NbVertices , i;
 float x,y;

 f >> NbVertices;
 vtkFloatArray *tc = vtkFloatArray::New();
 tc->SetNumberOfComponents(2); //2D texture
 tc->SetNumberOfTuples(NbVertices);
  for( i = 0; i < NbVertices; i++ ){
       f >> x >> y;
      tc->SetTuple2(i,x, y);
 }

// read into the surface picture
bmpReader->SetFileName("skin1.bmp");
texture->SetInput(bmpReader->GetOutput());
Actor->SetTexture(texture);

// read into the 3D model polydata
 this->Reader->SetFileName(lpszPathName);
 vtkPolyData *PolyData = vtkPolyData::New();
 PolyData = this->Reader->GetOutput();
 PolyData->GetPointData()->SetTCoords(tc);
 Mapper->SetInput(PolyData);
 Actor->VisibilityOn();





More information about the vtkusers mailing list