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
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?
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

GeneralDuplicated points removalmemberM.Siyamalan3-May-10 18:56 
Hi,
In a STL file, there are many duplicated points. How can I remove them?
In order to remove duplicated points we need to search the entire point list. I think you are using linked list to store the points.In that case the searching time will be high. I tried using KD tree but still the time needed to load the stl file is high. "Meshlab" quickly loading stl meshs and removing duplicate points. How can I efficiently load a STL mesh?
GeneralRe: Duplicated points removalmemberSharjith3-May-10 19:40 
Removing duplicate elements in a list can be done by using the standard template library algorithms like using the unique method of the std::list class. For that you may also have to provide equality operator for the Point class for comparison. But once you remove the duplicates the individual triangle's self-contained vertex information would be lost. To keep account of that, you must store indexes to reference the vertex of each triangle, as each unique point will be vertex to more than one triangle. This will no longer be a simple data structure but a complicated topological data structure with vertex nodes and neighbouring triangle information etc. If you need to do any processing on the StL data, it is worth doing all this. However, the application shown here just builds the visualization data structure for the StL model.
RegardsSmile | :)
N. Sharjith

QuestionHow to calculate angle between trianglesmembernsivabalan202031-Mar-10 20:50 
Hi Friends!!
my name is siva.i have few doubts.
 
1. HOW TO CALCULATE INTERIOR ANGLE OF A TRIANGLE? (I Have x,y,z coordinate points as vertices)

2. HOW TO CALCULATE ANGLE BETWEEN UNIT NORMALS OF TWO ADJUSTANT TRIANGLE? (I Have known normal value for each triangle)
 
3. HOW TO CALCULATE ANGLE BETWEEN UNIT NORMALS OF TWO ADJUSTANT TRIANGULAR FACETS? (I Have known normal value for each triangle in a surface)
 

Please if anybody knows regarding these question..
mail me.. atleast refer website links which having solved answer...
 
SIVABALAN
 
vigisiva@gmail.com
india.
AnswerRe: How to calculate angle between trianglesmemberSharjith1-Apr-10 7:17 
1 HOW TO CALCULATE INTERIOR ANGLE OF A TRIANGLE? (I Have x,y,z coordinate points as vertices)
http://mathworld.wolfram.com/Triangle.html[^]
 
2. HOW TO CALCULATE ANGLE BETWEEN UNIT NORMALS OF TWO ADJUSTANT TRIANGLE? (I Have known normal value for each triangle)
 
Angle between any two vectors can be found by calculating the dot product and dividing it by the product of magnitudes of both vectors and then calculating the inverse cosine of the resulting value.
 
double CVector3D::Angle(const CVector3D& Other) const
{
	double theta, a, b, dot;
	CVector3D tempV = Other;
	if(!this->IsNull() && !tempV.IsNull())
	{
		dot = this->Dot(Other);
		a = this->Magnitude();
		b = tempV.Magnitude();
		theta = acos(dot/(a*b));
		return theta;
	}
	else
		return 0;
}
 
3. HOW TO CALCULATE ANGLE BETWEEN UNIT NORMALS OF TWO ADJUSTANT TRIANGULAR FACETS? (I Have known normal value for each triangle in a surface)
 
Looks like question 2 repeated
 

Hope this helps.
RegardsSmile | :)
N. Sharjith

GeneralUnable to open other stl filememberMember 460375414-Feb-10 20:12 
Hi Sirjith sir ji
I saw your application it is very good. But when i compile your project it is fine. But when i try to open STL file it is just flick and second document open but stl file is not showing. 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.
i,e, i am unable to open second stl file.
Thanks
Osho
GeneralStereolithography file (STL) editmembernsivabalan202030-Nov-09 19:25 
My Name is SIVABALAN
im doing M.E degree
i have few doubts on STL file:
can any one please answer
 
1.HOW TO EDIT THE STL FILE ?
 
2.WHICH SOFTWARES WILL DO EDITING OF STL FILES?
 
3.IS IT POSSIBLE TO EDIT ACII & BINARY CODING OF STL FILE ? i.e FACET XYZ CORDINATES VALUES.
 
4.HOW TO DO TRIANGULATION AND RE-TRIANGULATION?
 

my emailid:vigisiva@gmail.com
mobile:09791399265
Tamilnadu
GeneralWat knowledge should i must have to handle this taskmemberDevelopmentNoob21-Apr-09 17:58 
I'm new in VC++ 2008.
i got a CAD file which is already convert into STL file.
how do i display it as a 3D image in MFC..
Wat knowledge should i must have to handle this task?
GeneralIs there component out there that can recognize the demension of stl and iges filesmemberMember 14020139-Apr-09 5:56 
Hi,
 
I'm currently working on a web project that analyze stl and iges file's demension (x, y, z). Anyone in here know if there is a component (.net, java) out there that can do this. Please help.
AnswerRe: Is there component out there that can recognize the demension of stl and iges filesmemberSharjith9-Apr-09 7:21 
How do you want the dimension? If the stl is of a surface how can you get the dimension? You can at the most calculate the bounding box by sorting vertices and finding the min-max extents in x, y and z directions.
 
RegardsSmile | :)
N. Sharjith

Questionhow to convert CL data file to G codes/machine languagememberdixitava8-Feb-09 23:37 
dear sir,
i am doing my post graduation in Computer integrated manufacturing.
 
as a project work i m developing module which should convert CL data
 
file into machine code language.pl can you help me out how shoud i proceed.
 
i hope you will fulfil my querry.
 
thanking you
 
dixitava
AnswerRe: how to convert CL data file to G codes/machine languagememberSharjith9-Feb-09 2:29 
Hopefully, if you can give me more details about the CL data, which CAM has generated, binary/ascii? for which controller? etc.
 
Mail me the details, probably can work out. Smile | :)
 
RegardsSmile | :)
N. Sharjith

GeneralRe: how to convert CL data file to G codes/machine languagememberdixitava9-Feb-09 19:06 
thanku sir for immiediet response,
 
i will do it earliest and will send you the file.
 
thanku so much.
 
dixitava
GeneralRe: how to convert CL data file to G codes/machine languagememberdixitava11-Feb-09 18:07 
Dear sir,
I am getting that CL data file in ascii format.
now a days as i said,making module for cam software,is Collabcad.
its open source software,right now only for two dimensional i m getting that CL data file,how can i convert it into 3d view?
I can work out that collabcad software to make 2d drawing and NC command it can reciev to generate 2d simulattion environment which ultimately; gives me CLdata for 2d.
pl guide me how to go further.
GeneralRe: for which controllermemberdixitava11-Feb-09 18:09 
about controller,
i have to make it for multi controllers,but right now want to stick to fanuc alone.
as i make this system running for fanuc,then it can be implemented to others also.
QuestionHow can I contact you?memberjemmyell12-Dec-08 7:13 
I am very interested in what you have done with OpenGL. How can I contact you to discuss a possible project?
 
-James
AnswerRe: How can I contact you?memberSharjith15-Dec-08 4:47 
You can mail me to sharjith@gmail.com
 
RegardsSmile | :)
N. Sharjith

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
AnswerRe: NOT ABLE TO DISPLAY OTHER STL files!membertulip.sun7-Feb-07 22:45 
Maybe,this software just support ASCII files,you should change the binary files to ASCII files.
Questiontrouble buildingmembermea3616-Jan-07 7:31 
Is anyone else having trouble building the code? I'm getting a bunch of errors and they are all over my head. Does anyone still check this and will be able to help me?
 
-Me

QuestionI am very interested in the topological relation of triangles [modified]memberhyzhujc4-Dec-06 20:38 
Hello,at first thank you for your good viewer .I am a student and I am very interested in the topological relationship of triangles.Now,I can select one point of the triangles model,but I can't find its neighbor points.So we should rebuild topological structures .Would you have some good idea?
 
I am looking forward to good news .My e-mail:hyzhujc@163.com
 
-- modified at 2:50 Tuesday 5th December, 2006
 

-- modified at 2:54 Tuesday 5th December, 2006
 
I have a dream...

AnswerRe: I am very interested in the topological relation of trianglesmemberSharjith18-Dec-06 4:15 
hi,
basically, in this application the triangles are read and directly displayed as opengl elements. for making use of topology, the triangles have to be stored in a topological data structure where the list of triangle nodes are to be stored with indexes and then edges and faces have to be constructed with the topological relations maintained. in the present case, if you notice, there is duplication of nodes of triangles sharing the same vertices, whereas when you use topology, the duplication has to be eliminated thus maintaining the rule of topology.
 
regds
n. sharjithSmile | :)

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

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