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.

Hmm... if you helped with the c# code, you may not be doing the homework for the people asking for it. People have their own strenghts, being able to wrap this code may not be their core strengths but the surely have other strengths like being able to embed this code in an application having other great functionality beyond rendering stl.

Personally, I consider it rude that you assumed you would be doing people's homeworks by providing a c# version of a code you have already provided.

Oh, I am sorry for you if you think I sounded rude. But its not any less rude if someone cannot show up any effort and just bluntly ask for code here. I am indeed not here to do anybody's homework and the way the help has been asked here really sounds like asking for free favour so that they simply copy-paste and complete their project. Sorry, it doesn't work like that. If some one is seeking genuine help, if they are stuck at something after trying hard, they must ask specific questions related to the difficulty. They also must have the courtesy to explain what they tried so far. I am taking the pain to answer your question hoping that people like you and the other asker will understand the real use of CodeProject. This is a place to learn from someone's work and share your work so that others can learn. This is indeed no place to ask someone to write free code for you. Take help from the thousands of tutorials posted here, learn the C# language by putting some efforts and then port the posted code yourself. And thank someone for posting their code here for your use. That will teach you a lot and will be useful for you in the future. I hope I didn't sound rude here. All that I said is for your benefit, take it or leave it, upto you!

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.

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.