Click here to Skip to main content
13,200,202 members (54,776 online)
Click here to Skip to main content
Add your own
alternative version


54 bookmarked
Posted 5 Mar 2003

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

GeneralRe: Can't not #include <GL/glut.h> Pin
Jonathan de Halleux24-Jul-03 7:35
memberJonathan de Halleux24-Jul-03 7:35 
GeneralSTL viewer does not display Pin
reddnedk23-Jun-03 6:18
memberreddnedk23-Jun-03 6:18 
GeneralRe: STL viewer does not display Pin
Sharjith26-Jun-03 5:14
memberSharjith26-Jun-03 5:14 
GeneralRe: STL viewer does not display Pin
Anonymous2-Jul-03 19:09
sussAnonymous2-Jul-03 19:09 
Gotcha, it worked that way.thanks.

The referenced email address and link failed ... this is a forth generation copy of the original reply...

NOT rapid prototyping as it currently exists ... ( an X-Y plotter with a Z-axis ) Proto-typing in actual machine operation. (machinable surfaces only)
I am still struggling with attempting to actually purchase a "Miniature" 2000 series vertical end mill from SERLINE...check out their site. ( I am lucky to have 2 pennies to rub together after paying the bills every payday)
This mill has a manual 8 axis capability, with rotary table capability, which from what I can tell, can also be added to one of the 8 axis as an additional automated axis... otherwise it only has X, Y, and Z axis control for automation... ( the rotary table also has the capability) I should be able to convert 2 other rotations to automated using rotary tables. A very good friend of mine (Dr. Vern Bunch) has designs ( and is marketing these products) - for controllers and stepper motors that will fit directly on the
Serline Mini Mill already... he will give me 6 of them if I can get the mill for R&D. My plans are to create the software (initially for myself) that will integrate his controllers into a full CNC operation using the aforementioned axis. I AM at a disadvantage though, I am not the greatest with C++ ... which seems to be the only language that the STL format has been ported to ... I am fantastic with all forms of Basic, VB6, Fortran, Machine code, and a multitude of others. . . so I will have a learning curve
unless I can find source modules in VB6 ( or earlier). I understand the slicing problem ... and initially only plan to begin with X and Y axis ... slicing should not be necessary and interpolation for the Z axis will come only after a total debug of the 2D mode. I'm no spring chicken... on computers since the military in the 1960's ... used to be an analyst ... so my math is pretty good, and I have worked with Solid model CAD for more than 15 years. If I can convert the mill to 5 axis control from program, I have
interpolation routines available to achieve toolpath information directly from the coordinates within the STL file ...( the actual tool has to be considered for them to work) this will eliminating slicing by following a calculated toolpath calculated in polar coordinates in free space... I have studied the STL ASCII files and find them to be an over simplification of a DXF / IGES file ... though quite similar in nature. I have done some of these routines from DXF in the past to port the graphics to various CAD systems, so I believe that the STL will also be quite capable if the actual
SHAPE is re-calculated from it by using adjustable "Smoothing" routines ( as are used in IGES translations and in CAD systems. I'm not just spittin in the wind, I am registered at the HAGUE, Holland 5 times for World class inventions. ( Somebody else owns the rights, though ... I don't get any money... just recognition ) I was a control systems engineer for 20 years, and migrated into tooling design and machinery automation design over the years, have an excellent working knowledge of most machine automation. I
have been a professional designer for more than 30 years... and have been programming for almost 40 years... just not the right languages to get jobs any more.
I would like to stay in touch with you if possible ... if I can find a way to finance the mini mill ... I will be working on the program. Thanks for the program ...and tips.
Maybe in the near future I can work with you to expand on it's capabilities
for machine control....especially if everything has to be in "C".

Bill Redd
Unlimited Design
Broomfield, Colorado.
Generalview Pin
mcalves@coc.ufrj.br8-May-03 20:05
membermcalves@coc.ufrj.br8-May-03 20:05 
QuestionHow does GL_SELECT mode work in MFC? Pin
killerdoll18-Mar-03 5:33
memberkillerdoll18-Mar-03 5:33 
AnswerRe: How does GL_SELECT mode work in MFC? Pin
Sharjith28-Mar-03 2:01
memberSharjith28-Mar-03 2:01 
General0xC0000005: Access Violation. Pin
Sorry I donnot know why I cannot fill in right con7-Mar-03 13:33
sussSorry I donnot know why I cannot fill in right con7-Mar-03 13:33 
GeneralRe: 0xC0000005: Access Violation. Pin
Sharjith7-Mar-03 19:48
memberSharjith7-Mar-03 19:48 
GeneralRe: 0xC0000005: Access Violation. Pin
My name is Iain Scott. Does it matter that there a25-Jun-06 1:12
memberMy name is Iain Scott. Does it matter that there a25-Jun-06 1:12 

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 | Terms of Use | Mobile
Web02 | 2.8.171020.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid