Click here to Skip to main content
Click here to Skip to main content
Go to top

StL Data File Viewer

, 5 Mar 2003
Rate this:
Please Sign up or sign in to vote.
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 GNU General Public License (GPLv3)

Share

About the Author

Sharjith
Engineer Tata Technologies Ltd
India India
Sharjith is a Mechanical Engineer with strong passion for Automobiles, Aircrafts and Software development.

Comments and Discussions

 
QuestionHow to calculate angle between triangles Pinmembernsivabalan202031-Mar-10 20:50 
AnswerRe: How to calculate angle between triangles PinmemberSharjith1-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

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140916.1 | Last Updated 6 Mar 2003
Article Copyright 2003 by Sharjith
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid