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

StL Data File Viewer

By , 5 Mar 2003
 

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 GNU General Public License (GPLv3)

About the Author

Sharjith
Engineer Tata Technologies Inc
United States United States
Member
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
AnswerRe: Run-Time Check Failure #2 - Stack around the variable 'str' was corrupted.memberSharjith1 Mar '12 - 11:59 
Increase the size of array that reads the input.
RegardsSmile | :)
N. Sharjith

GeneralSTL Viewermembercjellwood13 Feb '11 - 4:02 
MR.Sharjith
 
Can I please hire you to produce a simple CGi code that outputs stl dimensions, volume etc from an uploaded stl file.
 
Chris
GeneralRe: STL ViewermemberSharjith13 Feb '11 - 5:54 
Hi Chris,
 
I am sorry, I didn't get what you mean by CGi. Secondly, you won't be able to get any dimensions of features from the StL model as you get in CAD models. StL models are just triangles so you cannot programatically find dimensions between features like faces, fillets, chamfers etc. Finding volume may be practically possible but relatively very difficult.
RegardsSmile | :)
N. Sharjith

GeneralError [modified]membersangar202023 Sep '10 - 18:21 
MR.Sharjith sir,
 
         Thanks for your immediate response about all previous queries.
Now when i compile your project it is fine. But when i try to open STL file it is just flick but stl file is not showing and also show the debug assertion failed error(read stl click) occur. can you send me some clue or code for how to open stl file in my view. I am using your whole code as it is and try to open stl file.
 
Thanks
Sangaramoorthy A
 

 
-- Modified Friday, September 24, 2010 2:11 AM
GeneralRe: ErrormemberSharjith24 Sep '10 - 7:28 
Can you please send me the debug traces?
RegardsSmile | :)
N. Sharjith

GeneralTell the pathmembersangar202023 Sep '10 - 0:54 
Tell the correct path and also i have .dll and .h extension file the file which folder i can place ...
 
C:\Program Files\Microsoft Visual Studio 9.0\VC
GeneralRe: Tell the pathmemberSharjith23 Sep '10 - 4:42 
Locate the GL folder in your include folder of your compiler installation. If you are using VS2008, it should be probably in the Microsoft SDK folder includes.
 
For me it is:
 
C:\Program Files (x86)\Microsoft SDKs/Windows/v7.0A/Include/GL/
Paste the glut.h file into the above location.
 
C:\Program Files (x86)\Microsoft SDKs/Windows/v7.0A/Lib
Paste the glut32.lib file into the above location.
 
Note: your path may vary as per the installation of SDK versions. Best way is to search for the other OpenGL files like gl.h and glu.h and place glut.h in the same GL folder and then the glut32.lib file in the Lib folder 2 levels above.
 
Hope this helps.
RegardsSmile | :)
N. Sharjith

GeneralFatel errormembersangar202022 Sep '10 - 23:48 
i paste the glut32.dll in system32 folder but the same following   error occur again:
fatal error C1083: Cannot open include file: 'GL/glut.h': No such file or directory    
c:\users\lab-temp\desktop\stlviewer_src\stlviewer\stdafx.h
Questionfollowing message display in .net 2008?membersangar202022 Sep '10 - 18:12 
Error     1     fatal error C1083: Cannot open include file: 'GL/glut.h': No such file or directory     c:\users\lab-temp\desktop\stlviewer_src\stlviewer\stdafx.h     26     StLViewer
AnswerRe: following message display in .net 2008?memberSharjith22 Sep '10 - 18:38 
You need to install the glut library.
 
Find it here:
 
http://www.xmission.com/~nate/glut.html[^]
 
Unzip the binary package and copy the glut32.dll to c:\windows\system32 folder, glut32.lib to the libs folder and glut.h to the include\GL folder of your compiler.
RegardsSmile | :)
N. Sharjith

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

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