Click here to Skip to main content
15,867,308 members
Articles / Desktop Programming / MFC

StL Data File Viewer

Rate me:
Please Sign up or sign in to vote.
4.87/5 (43 votes)
5 Mar 2003CPOL2 min read 506.8K   14.7K   60   95
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)


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

Comments and Discussions

 
QuestionStl file editing Pin
Bommu n24-Aug-15 22:31
Bommu n24-Aug-15 22:31 
QuestionHow to display on aspx page Pin
HackensackNJ22-Aug-15 8:05
HackensackNJ22-Aug-15 8:05 
Generalvote 5 stars!! Pin
wzlwzl16-Jun-15 5:30
wzlwzl16-Jun-15 5:30 
GeneralRe: vote 5 stars!! Pin
Sharjith16-Jun-15 5:55
professionalSharjith16-Jun-15 5:55 
Questionhelp Pin
sıcak bulut25-Jun-14 9:38
sıcak bulut25-Jun-14 9:38 
AnswerRe: help Pin
Sharjith1-Jul-14 18:49
professionalSharjith1-Jul-14 18:49 
GeneralRe: help Pin
Chidiebere14-Jul-14 16:05
Chidiebere14-Jul-14 16:05 
GeneralRe: help Pin
Sharjith17-Jul-14 6:21
professionalSharjith17-Jul-14 6:21 
Questionplease help me your project in another such as c# Pin
maryamjafary3-Jan-14 21:55
maryamjafary3-Jan-14 21:55 
AnswerRe: please help me your project in another such as c# Pin
Sharjith1-Jul-14 18:48
professionalSharjith1-Jul-14 18:48 
QuestionVS 2010 build fails for me with missing iostream.h Pin
codegrunt2-Jun-12 17:37
codegrunt2-Jun-12 17:37 
AnswerRe: VS 2010 build fails for me with missing iostream.h Pin
Sharjith3-Jun-12 3:51
professionalSharjith3-Jun-12 3:51 
GeneralRe: VS 2010 build fails for me with missing iostream.h Pin
Member 39089022-Oct-12 6:58
Member 39089022-Oct-12 6:58 
QuestionUnable to view the viewer after running the application Pin
sidhu_ind23-May-12 21:47
sidhu_ind23-May-12 21:47 
AnswerRe: Unable to view the viewer after running the application Pin
Sharjith24-May-12 0:37
professionalSharjith24-May-12 0:37 
GeneralRe: Unable to view the viewer after running the application Pin
Member 105096748-Jan-14 6:22
Member 105096748-Jan-14 6:22 
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
ederson.nivel124-Apr-12 9:34 
QuestionSelection window on window 7 machine got distorted. Pin
singh96323-Apr-12 5:00
singh96323-Apr-12 5:00 
Selection window on window 7 machine got distorted.
Questionflash screen appear while resizing window Pin
singh96323-Apr-12 4:54
singh96323-Apr-12 4:54 
QuestionRun-Time Check Failure #2 - Stack around the variable 'str' was corrupted. Pin
waterharbin1-Mar-12 2:33
waterharbin1-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
cjellwood13-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
sangar202023-Sep-10 18:21 

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.