[vtk-developers] per-face tcoords problem (vtkOBJReader, vtkVRMLImporter)

Tim Hutton T.Hutton at eastman.ucl.ac.uk
Tue Jul 8 07:02:26 EDT 2003


Hello VTK developers,

The issue of per-face texture coordinates has cropped-up for me again. Both 
the OBJ and VRML formats support this but vtkOBJReader and vtkVRMLImporter 
do not, and in fact cause eventual access violations if you try to use them 
to read certain files.

I have a workaround (below) and was wondering if anybody has any experience 
with this, or any tips on how I can change vtkOBJReader and vtkVRMLImporter 
to cope with this situation?

File contains:

A: vertices  (eg. 2728 3D points)
B: polys  (eg. 5342 int-triplets, indexed into A)
C: tcoords  (eg. 3078 2D points)
D: tcoord polys  (eg. 5342 int-triplets, indexed into C)

Always, n(D)==n(B) since these correspond.

My workaround is to construct a new points structure, E and do this: 
(pseudo-code)

E->SetNumberOfPoints( n(C) );

for( i=0; i<n(D); i++ ) {
   for( j=0; j<3; j++ ) {
     E[ D[i][j] ] = A[ B[i][j] ]; // copy point from A into E
   }
}

the final polydata has:

poly->SetPoints(E);
poly->SetPolys(D);
poly->GetPointData()->SetTCoords(C);

One drawback of this method is that by duplicating vertices we have split 
the mesh, which means normals cannot correctly be computed. (If you merge 
the mesh before computing the normals then the texture no longer maps 
correctly.)

An added complication is when some polys do not have any tcoords at all, 
leaving n(D)!=n(B). But this is even trickier, since VTK cannot cope with 
partially-textured surfaces I think. Maybe these polys could be added to a 
separate vtkPolyData.

I'm loathe to make changes until I'm sure what the right thing to do is, so 
I'm looking for guidance! Is there a way to get VTK to use per-face tcoords 
"naturally"?

Thanks,

Tim.

---------------------------------------------------------------------------
Tim Hutton,                        http://www.eastman.ucl.ac.uk/~dmi/MINORI
Research Fellow & PhD student,                   T.Hutton at eastman.ucl.ac.uk
MINORI Project, Biomedical Informatics Unit,
Eastman Dental Institute, UCL,                   Tel: [+44] (0)20 7915 2344
256 Gray's Inn Road, London WC1X 8LD, UK         Fax: on request
---------------------------------------------------------------------------
This email represents the views of the sender alone and must not be 
construed as representing the views of the Eastman Dental Institute. It may 
contain confidential information and may be protected by law as a legally 
privileged document and copyright work. Its content should not be disclosed 
and it should not be given or copied to anyone other than the person(s) 
named or referenced above. If you have received this email in error, please 
contact the sender.





More information about the vtk-developers mailing list