[vtkusers] Extract data from STL file to an user-defined array

He Li hli62413 at hotmail.com
Mon Aug 19 15:15:43 EDT 2002


Hi All,

I need to read in a STL file and put the data into an user-defined array of 
triangles. I had difficuties to find the right method to. Please help me on 
this.

The following is a simple example. Please tell me how to extract the 
triangles from the STL file and put them into the triList array. Thank you 
very much!

An user-defined array:

struct triangle {
   float  a[3];      /* a, b and c are three vertices of a triangle */
   float  b[3];
   float  c[3];
}

triangle triList[20];
int      numberOfTriangles;

A STL file represents 12 triangles:
---------------------------------------------------------------------
solid ascii
facet normal 0.0 -1.0 0.0
  outer loop
   vertex 0.0 0.0 0.0
   vertex 3.0 0.0 1.0
   vertex 0.0 0.0 1.0
  endloop
endfacet
facet normal 0.0 -1.0 0.0
  outer loop
   vertex 3.0 0.0 1.0
   vertex 0.0 0.0 0.0
   vertex 3.0 0.0 0.0
  endloop
endfacet
facet normal 0.0 1.0 0.0
  outer loop
   vertex 0.0 2.0 0.0
   vertex 0.0 2.0 1.0
   vertex 3.0 2.0 1.0
  endloop
endfacet
facet normal 0.0 1.0 0.0
  outer loop
   vertex 3.0 2.0 0.0
   vertex 0.0 2.0 0.0
   vertex 3.0 2.0 1.0
  endloop
endfacet
facet normal -1.0 0.0 0.0
  outer loop
   vertex 0.0 0.0 0.0
   vertex 0.0 2.0 1.0
   vertex 0.0 2.0 0.0
  endloop
endfacet
facet normal -1.0 0.0 0.0
  outer loop
   vertex 0.0 0.0 0.0
   vertex 0.0 0.0 1.0
   vertex 0.0 2.0 1.0
  endloop
endfacet
facet normal 1.0 0.0 0.0
  outer loop
   vertex 3.0 0.0 0.0
   vertex 3.0 2.0 0.0
   vertex 3.0 2.0 1.0
  endloop
endfacet
facet normal 1.0 0.0 0.0
  outer loop
   vertex 3.0 0.0 0.0
   vertex 3.0 2.0 1.0
   vertex 3.0 0.0 1.0
  endloop
endfacet
facet normal 0.0 0.0 1.0
  outer loop
   vertex 3.0 0.0 1.0
   vertex 3.0 2.0 1.0
   vertex 0.0 2.0 1.0
  endloop
endfacet
facet normal 0.0 0.0 1.0
  outer loop
   vertex 3.0 0.0 1.0
   vertex 0.0 2.0 1.0
   vertex 0.0 0.0 1.0
  endloop
endfacet
facet normal 0.0 0.0 -1.0
  outer loop
   vertex 3.0 0.0 0.0
   vertex 0.0 2.0 0.0
   vertex 3.0 2.0 0.0
  endloop
endfacet
facet normal 0.0 0.0 -1.0
  outer loop
   vertex 3.0 0.0 0.0
   vertex 0.0 0.0 0.0
   vertex 0.0 2.0 0.0
  endloop
endfacet
endsolid
-------------------------------------------------------------------

Hanna Li





_________________________________________________________________
MSN Photos is the easiest way to share and print your photos: 
http://photos.msn.com/support/worldwide.aspx




More information about the vtkusers mailing list