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   
QuestionVS 2010 build fails for me with missing iostream.hmembercodegrunt2 Jun '12 - 17:37 
1>c:\projects\stlviewer\geometry.h(33): fatal error C1083: Cannot open include file: 'iostream.h': No such file or directory
 

Shouldn;t geometry.h #include and not #include ?
 
Of course I tried changing that and got tons of compile problems with istream.
 
Curious how anyone else got this to build in VS 2010??
AnswerRe: VS 2010 build fails for me with missing iostream.hmemberSharjith3 Jun '12 - 3: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.hmemberMember 39089022 Oct '12 - 6:58 
I have replaced the .h files as per this thread, but now I'm getting 261 compilation errors as seen in this link:
https://www.box.com/s/54fdgzgvnu2qpe4yfi8m[^]
 
Can anyone point me in the right direction?
QuestionUnable to view the viewer after running the applicationmembersidhu_ind23 May '12 - 21:47 
Dear Sharjith
 
The tool seems to be very interesting. I have built the application on MS VS2010 and tried to run the same. After running the viewer is seen only for a fraction of second and collapsing. Could you please suggest any possible solution for the same.
sidhu

AnswerRe: Unable to view the viewer after running the applicationmemberSharjith24 May '12 - 0:37 
Does it crash when you load some StL file? If so can you please set a break point at the StLReader methods and see what is happening? I am not sure what is happening. It was built using Visual Studio 6 long back and still works fine if it is built with it.
RegardsSmile | :)
N. Sharjith

GeneralMy vote of 5memberVolynsky Alex23 May '12 - 3:42 
Thanks!!!! Good Job!!!
QuestionSlicingmemberederson.nivel124 Apr '12 - 9:34 
Hi, my name is Ederson, i am from Brazil, is it possible to slice an STL file, i need to do this, i am building an 3d printer with a DLP projection.
QuestionSelection window on window 7 machine got distorted.membersingh96323 Apr '12 - 5:00 
Selection window on window 7 machine got distorted.
Questionflash screen appear while resizing windowmembersingh96323 Apr '12 - 4:54 
While resizing the main window on window 7 the flash screen will come.
QuestionRun-Time Check Failure #2 - Stack around the variable 'str' was corrupted.memberwaterharbin1 Mar '12 - 2:33 
Hi,Sharjith.
I convert your code to VC++ 2008.When I want to open a .stl file.An runtime error occur.The error is in your CStLReader::Read() in your source file "StLReader.cpp". How to fix?

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

Permalink | Advertise | Privacy | Mobile
Web01 | 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