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:

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.

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<standardlibrary.h> 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.