Click here to Skip to main content
15,860,859 members
Articles / Desktop Programming / MFC

StL Data File Viewer

Rate me:
Please Sign up or sign in to vote.
4.87/5 (43 votes)
5 Mar 2003CPOL2 min read 506.1K   14.7K   60   95
A simple StereoLithography data file viewer.

Sample Image - StLViewer.jpg

Introduction

StereoLithography(StL) is something that is widely used in CAD/CAM, RapidPrototyping etc. The concept is that any surface or solid is exported to StL format by data exchange packages after they are modeled in commercial CAD packages. This data consists of triangulated facets that approximate the surface of the solid. No topological or geometric information is exported. The surface is subdivided into small triangles. The approximation uses chordal deflection for curved surfaces to smoothen the surface. More the smoothening required, more number of smaller triangles are generated by subdivision resulting in larger size of data file. Now, along with triangles, their facet normals are also generated. The data is written both in ASCII and binary formats. The data in ASCII is written like this:

facet normal  0.000000e+000 -1.000000e+000  0.000000e+000
   outer loop
     vertex -1.499999e+002 -1.000000e+002  0.000000e+000
     vertex -1.500000e+002 -1.000000e+002  0.000000e+000
     vertex -1.500000e+002 -1.000000e+002 -5.000000e+001
   endloop
 endfacet

The facet normal tells the three components of the facet normal followed by three vertices of one triangle, enclosed by the statements.

facet normal  0.000000e+000 -1.000000e+000  0.000000e+000

and

endfacet

Thus all the triangles are written one after the other. This data can be then used as input for generating Rapid Prototype models as well as for NC toolpath generation. The Normal data helps to compute tool offsets etc.

Here, for displaying the data in the OpenGL viewer, I have written the code for reading the data and displaying each triangle using glBegin(GL_TRIANGLES) and the normals for lighting. The viewer and geometry coding is same as my earlier project CadSurf. You can read as many StL (ASCII only) files into the viewer zoom, pan, rotate the views, select the objects, change attributes like color and material. The viewer provides object oriented context menus. I.e., when you click the right mouse button in the view with no active selection, you get a context menu for setting the viewer attributes, whereas with StL object selected, you get menu for the object attributes. Some sample StL data is also provided in the Data folder of the project.

Please let me know your comments. Thank you.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Product Manager Mahindra & Mahindra
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions

 
QuestionProblem Building Pin
dspantha29-Jan-07 15:54
dspantha29-Jan-07 15:54 
GeneralNOT ABLE TO DISPLAY OTHER STL Pin
vickys24-Jan-07 12:42
vickys24-Jan-07 12:42 
GeneralNOT ABLE TO DISPLAY OTHER STL files! Pin
vickys24-Jan-07 12:42
vickys24-Jan-07 12:42 
AnswerRe: NOT ABLE TO DISPLAY OTHER STL files! Pin
tulip.sun7-Feb-07 22:45
tulip.sun7-Feb-07 22:45 
Questiontrouble building Pin
mea3616-Jan-07 7:31
mea3616-Jan-07 7:31 
QuestionI am very interested in the topological relation of triangles [modified] Pin
hyzhujc4-Dec-06 20:38
hyzhujc4-Dec-06 20:38 
AnswerRe: I am very interested in the topological relation of triangles Pin
Sharjith18-Dec-06 4:15
professionalSharjith18-Dec-06 4:15 
GeneralNC & RP code Pin
harshalmsrsas19-Nov-06 23:14
harshalmsrsas19-Nov-06 23:14 
Good work Sharjith.
Can you please guide me how extend your work for writing CNC G&M codes or RP codes automatically. Have you done similar kind of work which generates G&M codes / RP codes from STL files..
Please also reply to harshalsawant@yahoo.com

Harshal Sawant
AnswerRe: NC & RP code Pin
Sharjith18-Dec-06 4:07
professionalSharjith18-Dec-06 4:07 
GeneralI want to use OpenGL with STL From Robotic 6 axis Pin
aluntum15-Feb-06 9:25
aluntum15-Feb-06 9:25 
QuestionI can't load other stl file Pin
qinhongxian19-Dec-05 6:24
qinhongxian19-Dec-05 6:24 
GeneralSlow and Selection should disabled out of the stl object Pin
lua8-Jun-05 1:03
lua8-Jun-05 1:03 
GeneralRe: Slow and Selection should disabled out of the stl object Pin
Member 5267224-Sep-05 16:09
Member 5267224-Sep-05 16:09 
GeneralCould not complie a code Pin
Tejas_qp1-Mar-05 8:00
Tejas_qp1-Mar-05 8:00 
GeneralRe: Could not complie a code Pin
Sharjith3-Mar-05 21:22
professionalSharjith3-Mar-05 21:22 
GeneralRe: Could not complie a code Pin
1vs18-Apr-05 19:44
1vs18-Apr-05 19:44 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter15-Jun-04 21:53
werter15-Jun-04 21:53 
GeneralOT: Starting Point Pin
lj993234-Aug-03 16:48
lj993234-Aug-03 16:48 
GeneralRe: OT: Starting Point Pin
jcdemo17-Mar-05 20:50
jcdemo17-Mar-05 20:50 
GeneralCan't not #include <GL/glut.h> Pin
ICE_WIZARD24-Jul-03 7:25
ICE_WIZARD24-Jul-03 7:25 
GeneralRe: Can't not #include <GL/glut.h> Pin
Jonathan de Halleux24-Jul-03 7:35
Jonathan de Halleux24-Jul-03 7:35 
GeneralSTL viewer does not display Pin
reddneck23-Jun-03 6:18
reddneck23-Jun-03 6:18 
GeneralRe: STL viewer does not display Pin
Sharjith26-Jun-03 5:14
professionalSharjith26-Jun-03 5:14 
GeneralRe: STL viewer does not display Pin
Anonymous2-Jul-03 19:09
Anonymous2-Jul-03 19:09 
Generalview Pin
Member 3297728-May-03 20:05
Member 3297728-May-03 20:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.