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   
General[Message Deleted]memberavajja17 Oct '08 - 19:02 

GeneralRe: How to View STL file in BINARY formatmemberSharjith23 Oct '08 - 6:34 
First of all the StL format is only vertex and normal data and not curves or surface data. Then what are you planning to write into the iges file? What you can export as iges data is only Point and Triangular face and edge data but that won't smoothen your data. What is the objective in converting stl to iges. Conversion of Iges to Stl can be understood.
 
You may use the code freely in your project. Smile | :)
To read the binary format file of stl data you will have to wite a separate algo.
 
I do have the code I downloaded from the net once upon a time. If you want I will send it... the website doesn't exist now so I can send it to your personal mail.
 
RegardsSmile | :)
N. Sharjith

Questionthanks in advancemembergaryzhg18 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 failurememberVinod_code25 Sep '07 - 0:03 
Hi Sharjit, thanks for such nice tool, I like the concept. I couldn't run the tool but from snapshot it looks great.
I have a question why you are using GLIDE2X.DLL any specific reason?
 
Hi All:
did anybody come across below error while running...?
While running I am getting below error "Genport I/O initialitazion failure" under Windows2000. I guess this error is due to graphics setting.
 
Please let me know if anybody come across such error.
 
Thanks in advance
Vinod
 
.

Generaldimension of stlmembersaisp22 Jul '07 - 21:42 
how to display the dimension of the meshed triangular facets? pls help me
QuestionRe: dimension of stlmemberSharjith23 Jul '07 - 6:51 
What dimension? Coordinates of vertices of each triangle? Or area of each triangle or all dimensions of the entire object? I am not clear, please elaborate.Confused | :confused:
AnswerRe: dimension of stl [modified]-pls i need ur helpmembersaisp24 Jul '07 - 17:28 
sorry for not responding you. actually im having a stl file (diamond model) which i cant import through your code. mine is meshed with polygon. i dont know how to mesh the stl model with polygons and to display the height, weight, length etc?.
 
i have to display the dimension when the model is viewed in front, top, bottom and side. is there any tool available to purchase. pls help me
 

-- modified at 2:27 Thursday 26th July, 2007
QuestionProblem Buildingmemberdspantha29 Jan '07 - 15:54 
Hi,
 
I am running the code in VC++ and obtain the following error:
 
LINK : fatal error LNK1561: entry point must be defined
 
I have no idea how to fix this problem. Any help is much appreciated.
 
Thanks,
 
David
GeneralNOT ABLE TO DISPLAY OTHER STLmembervickys24 Jan '07 - 12:42 
HI ,
 
The software is great and I am finding it useful. I actually want to simulate a mass spectrometer using and want to use your software to display the 3D from .stl files.
 
But I am not able to open other .stl files from your software. It opens fine for the sample files you have given. Please help me as soon as possible.
 
It would also help if you could tell me where is the code to access the co-ordinates in the display.
 
Waiting for your reply,
Thanks,
Vikas
GeneralNOT ABLE TO DISPLAY OTHER STL files!membervickys24 Jan '07 - 12:42 
HI ,
 
The software is great and I am finding it useful. I actually want to simulate a mass spectrometer using and want to use your software to display the 3D from .stl files.
 
But I am not able to open other .stl files from your software. It opens fine for the sample files you have given. Please help me as soon as possible.
 
It would also help if you could tell me where is the code to access the co-ordinates in the display.
 
Waiting for your reply,
Thanks,
Vikas

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