Click here to Skip to main content
11,412,578 members (74,855 online)
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

Questionhelp Pin
sıcak bulut at 25-Jun-14 10:38
membersıcak bulut25-Jun-14 10:38 
AnswerRe: help Pin
Sharjith at 1-Jul-14 19:49
professionalSharjith1-Jul-14 19:49 
GeneralRe: help Pin
Chidiebere at 14-Jul-14 17:05
memberChidiebere14-Jul-14 17:05 
GeneralRe: help Pin
Sharjith at 17-Jul-14 7:21
professionalSharjith17-Jul-14 7:21 
Questionplease help me your project in another such as c# Pin
maryamjafaryjebeli at 3-Jan-14 22:55
membermaryamjafaryjebeli3-Jan-14 22:55 
AnswerRe: please help me your project in another such as c# Pin
Sharjith at 1-Jul-14 19:48
professionalSharjith1-Jul-14 19:48 
QuestionVS 2010 build fails for me with missing iostream.h Pin
codegrunt at 2-Jun-12 18:37
membercodegrunt2-Jun-12 18:37 
AnswerRe: VS 2010 build fails for me with missing iostream.h Pin
Sharjith at 3-Jun-12 4:51
memberSharjith3-Jun-12 4:51 
The root cause of the problem is that you are using a latest compiler that has more enforcement of the standards compared to the old compiler. This code should build without any major changes upto VS compilers lower than version 2005. For the code to build on VS2010 you need to replace all #include to #include "standardlibrary" e.g. #include "iostream" instead of iostream.h and #include "cstdlib" instead of stdlib.h. Other than that you also need to change some MFC callback signatures. In the compilers before version 2008 both iostream.h and iostream were available for backward compatibility but from 2008 and up the deprecated headers are no longer supplied. Hope this helps.
RegardsSmile | :)
N. Sharjith

GeneralRe: VS 2010 build fails for me with missing iostream.h Pin
Member 3908902 at 2-Oct-12 7:58
memberMember 39089022-Oct-12 7:58 
QuestionUnable to view the viewer after running the application Pin
sidhu_ind at 23-May-12 22:47
membersidhu_ind23-May-12 22:47 
AnswerRe: Unable to view the viewer after running the application Pin
Sharjith at 24-May-12 1:37
memberSharjith24-May-12 1:37 
GeneralRe: Unable to view the viewer after running the application Pin
Member 10509674 at 8-Jan-14 7:22
memberMember 105096748-Jan-14 7:22 
GeneralMy vote of 5 Pin
Volynsky Alex at 23-May-12 4:42
memberVolynsky Alex23-May-12 4:42 
QuestionSlicing Pin
ederson.nivel1 at 24-Apr-12 10:34
memberederson.nivel124-Apr-12 10:34 
QuestionSelection window on window 7 machine got distorted. Pin
singh963 at 23-Apr-12 6:00
membersingh96323-Apr-12 6:00 
Questionflash screen appear while resizing window Pin
singh963 at 23-Apr-12 5:54
membersingh96323-Apr-12 5:54 
QuestionRun-Time Check Failure #2 - Stack around the variable 'str' was corrupted. Pin
waterharbin at 1-Mar-12 3:33
memberwaterharbin1-Mar-12 3:33 
AnswerRe: Run-Time Check Failure #2 - Stack around the variable 'str' was corrupted. Pin
Sharjith at 1-Mar-12 12:59
memberSharjith1-Mar-12 12:59 
GeneralSTL Viewer Pin
cjellwood at 13-Feb-11 5:02
membercjellwood13-Feb-11 5:02 
GeneralRe: STL Viewer Pin
Sharjith at 13-Feb-11 6:54
memberSharjith13-Feb-11 6:54 
GeneralError [modified] Pin
sangar2020 at 23-Sep-10 19:21
membersangar202023-Sep-10 19:21 
GeneralRe: Error Pin
Sharjith at 24-Sep-10 8:28
memberSharjith24-Sep-10 8:28 
GeneralTell the path Pin
sangar2020 at 23-Sep-10 1:54
membersangar202023-Sep-10 1:54 
GeneralRe: Tell the path Pin
Sharjith at 23-Sep-10 5:42
memberSharjith23-Sep-10 5:42 
GeneralFatel error Pin
sangar2020 at 23-Sep-10 0:48
membersangar202023-Sep-10 0:48 
Questionfollowing message display in .net 2008? Pin
sangar2020 at 22-Sep-10 19:12
membersangar202022-Sep-10 19:12 
AnswerRe: following message display in .net 2008? Pin
Sharjith at 22-Sep-10 19:38
memberSharjith22-Sep-10 19:38 
GeneralDuplicated points removal Pin
M.Siyamalan at 3-May-10 19:56
memberM.Siyamalan3-May-10 19:56 
GeneralRe: Duplicated points removal Pin
Sharjith at 3-May-10 20:40
memberSharjith3-May-10 20:40 
QuestionHow to calculate angle between triangles Pin
nsivabalan2020 at 31-Mar-10 21:50
membernsivabalan202031-Mar-10 21:50 
AnswerRe: How to calculate angle between triangles Pin
Sharjith at 1-Apr-10 8:17
memberSharjith1-Apr-10 8:17 
GeneralUnable to open other stl file Pin
Member 4603754 at 14-Feb-10 21:12
memberMember 460375414-Feb-10 21:12 
GeneralStereolithography file (STL) edit Pin
nsivabalan2020 at 30-Nov-09 20:25
membernsivabalan202030-Nov-09 20:25 
GeneralWat knowledge should i must have to handle this task Pin
DevelopmentNoob at 21-Apr-09 18:58
memberDevelopmentNoob21-Apr-09 18:58 
GeneralIs there component out there that can recognize the demension of stl and iges files Pin
Member 1402013 at 9-Apr-09 6:56
memberMember 14020139-Apr-09 6:56 
AnswerRe: Is there component out there that can recognize the demension of stl and iges files Pin
Sharjith at 9-Apr-09 8:21
memberSharjith9-Apr-09 8:21 
Questionhow to convert CL data file to G codes/machine language Pin
dixitava at 9-Feb-09 0:37
memberdixitava9-Feb-09 0:37 
AnswerRe: how to convert CL data file to G codes/machine language Pin
Sharjith at 9-Feb-09 3:29
memberSharjith9-Feb-09 3:29 
GeneralRe: how to convert CL data file to G codes/machine language Pin
dixitava at 9-Feb-09 20:06
memberdixitava9-Feb-09 20:06 
GeneralRe: how to convert CL data file to G codes/machine language Pin
dixitava at 11-Feb-09 19:07
memberdixitava11-Feb-09 19:07 
GeneralRe: for which controller Pin
dixitava at 11-Feb-09 19:09
memberdixitava11-Feb-09 19:09 
QuestionHow can I contact you? Pin
jemmyell at 12-Dec-08 8:13
memberjemmyell12-Dec-08 8:13 
AnswerRe: How can I contact you? Pin
Sharjith at 15-Dec-08 5:47
memberSharjith15-Dec-08 5:47 
General[Message Deleted] Pin
avajja at 17-Oct-08 20:02
memberavajja17-Oct-08 20:02 
GeneralRe: How to View STL file in BINARY format Pin
Sharjith at 23-Oct-08 7:34
memberSharjith23-Oct-08 7:34 
Questionthanks in advance Pin
garyzhg at 19-Jul-08 0:44
membergaryzhg19-Jul-08 0:44 
QuestionGenport I/O initialitazion failure Pin
Vinod_code at 25-Sep-07 1:03
memberVinod_code25-Sep-07 1:03 
Generaldimension of stl Pin
saisp at 22-Jul-07 22:42
membersaisp22-Jul-07 22:42 
QuestionRe: dimension of stl Pin
Sharjith at 23-Jul-07 7:51
memberSharjith23-Jul-07 7:51 
AnswerRe: dimension of stl [modified]-pls i need ur help Pin
saisp at 24-Jul-07 18:28
membersaisp24-Jul-07 18:28 

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
Web02 | 2.8.150427.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid