Click here to Skip to main content
13,896,966 members
Click here to Skip to main content
Add your own
alternative version


56 bookmarked
Posted 5 Mar 2003
Licenced CPOL

StL Data File Viewer

, 5 Mar 2003
Rate this:
Please Sign up or sign in to vote.
A simple StereoLithography data file viewer.

Sample Image - StLViewer.jpg


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

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



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.


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


About the Author

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

You may also be interested in...

Comments and Discussions

GeneralMy vote of 5 Pin
Volynsky Alex23-May-12 3:42
professionalVolynsky Alex23-May-12 3:42 
QuestionSlicing Pin
ederson.nivel124-Apr-12 9:34
memberederson.nivel124-Apr-12 9:34 
QuestionSelection window on window 7 machine got distorted. Pin
singh96323-Apr-12 5:00
membersingh96323-Apr-12 5:00 
Questionflash screen appear while resizing window Pin
singh96323-Apr-12 4:54
membersingh96323-Apr-12 4:54 
QuestionRun-Time Check Failure #2 - Stack around the variable 'str' was corrupted. Pin
waterharbin1-Mar-12 2:33
memberwaterharbin1-Mar-12 2:33 
AnswerRe: Run-Time Check Failure #2 - Stack around the variable 'str' was corrupted. Pin
Sharjith1-Mar-12 11:59
professionalSharjith1-Mar-12 11:59 
GeneralSTL Viewer Pin
cjellwood13-Feb-11 4:02
membercjellwood13-Feb-11 4:02 
GeneralRe: STL Viewer Pin
Sharjith13-Feb-11 5:54
professionalSharjith13-Feb-11 5:54 
GeneralError [modified] Pin
sangar202023-Sep-10 18:21
membersangar202023-Sep-10 18:21 
GeneralRe: Error Pin
Sharjith24-Sep-10 7:28
professionalSharjith24-Sep-10 7:28 
GeneralTell the path Pin
sangar202023-Sep-10 0:54
membersangar202023-Sep-10 0:54 
GeneralRe: Tell the path Pin
Sharjith23-Sep-10 4:42
professionalSharjith23-Sep-10 4:42 
GeneralFatel error Pin
sangar202022-Sep-10 23:48
membersangar202022-Sep-10 23:48 
Questionfollowing message display in .net 2008? Pin
sangar202022-Sep-10 18:12
membersangar202022-Sep-10 18:12 
AnswerRe: following message display in .net 2008? Pin
Sharjith22-Sep-10 18:38
professionalSharjith22-Sep-10 18:38 
GeneralDuplicated points removal Pin
M.Siyamalan3-May-10 18:56
memberM.Siyamalan3-May-10 18:56 
GeneralRe: Duplicated points removal Pin
Sharjith3-May-10 19:40
professionalSharjith3-May-10 19:40 
QuestionHow to calculate angle between triangles Pin
nsivabalan202031-Mar-10 20:50
membernsivabalan202031-Mar-10 20:50 
AnswerRe: How to calculate angle between triangles Pin
Sharjith1-Apr-10 7:17
professionalSharjith1-Apr-10 7:17 
GeneralUnable to open other stl file Pin
OSHO58014-Feb-10 20:12
memberOSHO58014-Feb-10 20:12 
GeneralStereolithography file (STL) edit Pin
nsivabalan202030-Nov-09 19:25
membernsivabalan202030-Nov-09 19:25 
GeneralWat knowledge should i must have to handle this task Pin
DevelopmentNoob21-Apr-09 17:58
memberDevelopmentNoob21-Apr-09 17:58 
GeneralIs there component out there that can recognize the demension of stl and iges files Pin
Member 14020139-Apr-09 5:56
memberMember 14020139-Apr-09 5:56 
AnswerRe: Is there component out there that can recognize the demension of stl and iges files Pin
Sharjith9-Apr-09 7:21
professionalSharjith9-Apr-09 7:21 
Questionhow to convert CL data file to G codes/machine language Pin
dixitava8-Feb-09 23:37
memberdixitava8-Feb-09 23:37 

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.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web06 | 2.8.190306.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid