Click here to Skip to main content
Click here to Skip to main content

StL Data File Viewer

, 5 Mar 2003 GPL3
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 GNU General Public License (GPLv3)


About the Author

Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions

GeneralRe: how to convert CL data file to G codes/machine language Pinmemberdixitava9-Feb-09 20:06 
GeneralRe: how to convert CL data file to G codes/machine language Pinmemberdixitava11-Feb-09 19:07 
GeneralRe: for which controller Pinmemberdixitava11-Feb-09 19:09 
QuestionHow can I contact you? Pinmemberjemmyell12-Dec-08 8:13 
AnswerRe: How can I contact you? PinmemberSharjith15-Dec-08 5:47 
General[Message Deleted] Pinmemberavajja17-Oct-08 20:02 
GeneralRe: How to View STL file in BINARY format PinmemberSharjith23-Oct-08 7:34 
Questionthanks in advance Pinmembergaryzhg19-Jul-08 0:44 
QuestionGenport I/O initialitazion failure PinmemberVinod_code25-Sep-07 1:03 
Generaldimension of stl Pinmembersaisp22-Jul-07 22:42 
how to display the dimension of the meshed triangular facets? pls help me
QuestionRe: dimension of stl PinmemberSharjith23-Jul-07 7:51 
AnswerRe: dimension of stl [modified]-pls i need ur help Pinmembersaisp24-Jul-07 18:28 
QuestionProblem Building Pinmemberdspantha29-Jan-07 16:54 
GeneralNOT ABLE TO DISPLAY OTHER STL Pinmembervickys24-Jan-07 13:42 
GeneralNOT ABLE TO DISPLAY OTHER STL files! Pinmembervickys24-Jan-07 13:42 
AnswerRe: NOT ABLE TO DISPLAY OTHER STL files! Pinmembertulip.sun7-Feb-07 23:45 
Questiontrouble building Pinmembermea3616-Jan-07 8:31 
QuestionI am very interested in the topological relation of triangles [modified] Pinmemberhyzhujc4-Dec-06 21:38 
AnswerRe: I am very interested in the topological relation of triangles PinmemberSharjith18-Dec-06 5:15 
GeneralNC & RP code Pinmemberharshalmsrsas20-Nov-06 0:14 
AnswerRe: NC & RP code PinmemberSharjith18-Dec-06 5:07 
GeneralI want to use OpenGL with STL From Robotic 6 axis Pinmemberaluntum15-Feb-06 10:25 
QuestionI can't load other stl file Pinmemberqinhongxian19-Dec-05 7:24 
GeneralSlow and Selection should disabled out of the stl object Pinmemberlua8-Jun-05 2:03 
GeneralRe: Slow and Selection should disabled out of the stl object Pinmemberhero3blade24-Sep-05 17:09 
GeneralCould not complie a code PinmemberTejas_qp1-Mar-05 9:00 
GeneralRe: Could not complie a code PinmemberSharjith3-Mar-05 22:22 
GeneralRe: Could not complie a code Pinmember1vs18-Apr-05 20:44 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pinmemberwerter15-Jun-04 22:53 
GeneralOT: Starting Point Pinsusslj993234-Aug-03 17:48 
GeneralRe: OT: Starting Point Pinmemberjcdemo17-Mar-05 21:50 
GeneralCan't not #include <GL/glut.h> PinmemberICE_WIZARD24-Jul-03 8:25 
GeneralRe: Can't not #include <GL/glut.h> PinmemberJonathan de Halleux24-Jul-03 8:35 
GeneralSTL viewer does not display Pinmemberreddnedk23-Jun-03 7:18 
GeneralRe: STL viewer does not display PinmemberSharjith26-Jun-03 6:14 
GeneralRe: STL viewer does not display PinsussAnonymous2-Jul-03 20:09 
Generalview Pinmembermcalves@coc.ufrj.br8-May-03 21:05 
QuestionHow does GL_SELECT mode work in MFC? Pinmemberkillerdoll18-Mar-03 6:33 
AnswerRe: How does GL_SELECT mode work in MFC? PinmemberSharjith28-Mar-03 3:01 
General0xC0000005: Access Violation. PinsussSorry I donnot know why I cannot fill in right con7-Mar-03 14:33 
GeneralRe: 0xC0000005: Access Violation. PinmemberSharjith7-Mar-03 20:48 
GeneralRe: 0xC0000005: Access Violation. PinmemberMy name is Iain Scott. Does it matter that there a25-Jun-06 2:12 
NewsRe: 0xC0000005: Access Violation. PinmemberSharjith28-Jun-06 23:00 

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

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

| Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.150414.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid