Click here to Skip to main content
11,704,768 members (58,419 online)
Click here to Skip to main content

StL Data File Viewer

, 5 Mar 2003 CPOL 249.2K 9.2K 49
Rate this:
Please Sign up or sign in to vote.
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)

Share

About the Author

Sharjith
Engineer Tata Technologies Ltd
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

 
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
memberSharjith1-Apr-10 7:17 
GeneralUnable to open other stl file Pin
Member 460375414-Feb-10 20:12
memberMember 460375414-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
memberSharjith9-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 
AnswerRe: how to convert CL data file to G codes/machine language Pin
Sharjith9-Feb-09 2:29
memberSharjith9-Feb-09 2:29 
GeneralRe: how to convert CL data file to G codes/machine language Pin
dixitava9-Feb-09 19:06
memberdixitava9-Feb-09 19:06 
GeneralRe: how to convert CL data file to G codes/machine language Pin
dixitava11-Feb-09 18:07
memberdixitava11-Feb-09 18:07 
GeneralRe: for which controller Pin
dixitava11-Feb-09 18:09
memberdixitava11-Feb-09 18:09 
QuestionHow can I contact you? Pin
jemmyell12-Dec-08 7:13
memberjemmyell12-Dec-08 7:13 
AnswerRe: How can I contact you? Pin
Sharjith15-Dec-08 4:47
memberSharjith15-Dec-08 4:47 
General[Message Deleted] Pin
avajja17-Oct-08 19:02
memberavajja17-Oct-08 19:02 
GeneralRe: How to View STL file in BINARY format Pin
Sharjith23-Oct-08 6:34
memberSharjith23-Oct-08 6:34 
Questionthanks in advance Pin
garyzhg18-Jul-08 23:44
membergaryzhg18-Jul-08 23:44 
Dear sir ,

I am learning nor of your systems called STL Viewer ,but I am just a newbie about VC++ and opengl .so it's a little hard for me to read the program clearly . and I hope you can add more description to the program or some informationso that I can understand it easyier . If you could mail it to me I will really appreciate it .
By the way , I am working in the Reverse Engineering business .Now I am studying how to cover the holes existing in the STL files . so I wonder if you can give me some programs or system related to it .
Thank you in advance . I am looking forward to your reply !
QuestionGenport I/O initialitazion failure Pin
Vinod_code25-Sep-07 0:03
memberVinod_code25-Sep-07 0:03 
Generaldimension of stl Pin
saisp22-Jul-07 21:42
membersaisp22-Jul-07 21:42 
QuestionRe: dimension of stl Pin
Sharjith23-Jul-07 6:51
memberSharjith23-Jul-07 6:51 
AnswerRe: dimension of stl [modified]-pls i need ur help Pin
saisp24-Jul-07 17:28
membersaisp24-Jul-07 17:28 
QuestionProblem Building Pin
dspantha29-Jan-07 15:54
memberdspantha29-Jan-07 15:54 
GeneralNOT ABLE TO DISPLAY OTHER STL Pin
vickys24-Jan-07 12:42
membervickys24-Jan-07 12:42 
GeneralNOT ABLE TO DISPLAY OTHER STL files! Pin
vickys24-Jan-07 12:42
membervickys24-Jan-07 12:42 
AnswerRe: NOT ABLE TO DISPLAY OTHER STL files! Pin
tulip.sun7-Feb-07 22:45
membertulip.sun7-Feb-07 22:45 
Questiontrouble building Pin
mea3616-Jan-07 7:31
membermea3616-Jan-07 7:31 
QuestionI am very interested in the topological relation of triangles [modified] Pin
hyzhujc4-Dec-06 20:38
memberhyzhujc4-Dec-06 20:38 
AnswerRe: I am very interested in the topological relation of triangles Pin
Sharjith18-Dec-06 4:15
memberSharjith18-Dec-06 4:15 
GeneralNC & RP code Pin
harshalmsrsas19-Nov-06 23:14
memberharshalmsrsas19-Nov-06 23:14 
AnswerRe: NC & RP code Pin
Sharjith18-Dec-06 4:07
memberSharjith18-Dec-06 4:07 
GeneralI want to use OpenGL with STL From Robotic 6 axis Pin
aluntum15-Feb-06 9:25
memberaluntum15-Feb-06 9:25 
QuestionI can't load other stl file Pin
qinhongxian19-Dec-05 6:24
memberqinhongxian19-Dec-05 6:24 
GeneralSlow and Selection should disabled out of the stl object Pin
lua8-Jun-05 1:03
memberlua8-Jun-05 1:03 
GeneralRe: Slow and Selection should disabled out of the stl object Pin
hero3blade24-Sep-05 16:09
memberhero3blade24-Sep-05 16:09 
GeneralCould not complie a code Pin
Tejas_qp1-Mar-05 8:00
memberTejas_qp1-Mar-05 8:00 
GeneralRe: Could not complie a code Pin
Sharjith3-Mar-05 21:22
memberSharjith3-Mar-05 21:22 
GeneralRe: Could not complie a code Pin
1vs18-Apr-05 19:44
member1vs18-Apr-05 19:44 
QuestionHow to run 2 different(or same) OpenGL objects in one DialogBox? Pin
werter15-Jun-04 21:53
memberwerter15-Jun-04 21:53 
GeneralOT: Starting Point Pin
lj993234-Aug-03 16:48
susslj993234-Aug-03 16:48 
GeneralRe: OT: Starting Point Pin
jcdemo17-Mar-05 20:50
memberjcdemo17-Mar-05 20:50 
GeneralCan't not #include <GL/glut.h> Pin
ICE_WIZARD24-Jul-03 7:25
memberICE_WIZARD24-Jul-03 7:25 
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 
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 

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