3d Visualization Algorithm For STL File Parser Computer Science Essay

Published:

Initially 3D models are designed using modeling software. Most of the modeling software allows export of STL files. These files have extension .stl. There are two storage formats available for STL are ASCII and Binary. ASCII file is a human readable and can be modified if required. Binary versions of STL are more compact. STL file contains a description of the object's surface in terms of triangles. [1] The vertices of the triangles are listed in counterclockwise, as viewed from outside the surface. A normal vector i.e. a line perpendicular to the triangle also mentioned. STL uses facet-based representation, means it consists of list of facet data. The facets define the surface of a 3-Dimenssional object. Each facet identified by three vertices, corners of the triangle and a unit normal. Three co-ordinates used specify the normal and each vertex. So each facet contains total of 12 numbers. Each STL file represents the single object. It doesn't contain any color information. STL file follows vertex-to-vertex rule, means each triangle share two vertices with each of its adjacent triangles.

Lady using a tablet
Lady using a tablet

Professional

Essay Writers

Lady Using Tablet

Get your grade
or your money back

using our Essay Writing Service!

Essay Writing Service

The block diagram in Figure 1, explains the process carried out in this work. The stl file, which contains description about the object, is given as an input to the program. Parser code stores these details in data structures. Information contained in data structure displayed as object on the screen using OpenGL commands.

Figure 1: Software Architecture

II. STL FILE FORMAT

The file begins with a solid record and ends with endsolid record.[2] Each triangle enclosed within facet and endfacet records. The normal vector part of the facet, specified by normal keyword. The vertices of triangle are delimited by outer loop and endloop. Each vertex specified by the keyword, vertex.

Here is a part of an ASCII STL file, bottle.stl

solid FLIRIS

facet normal 0.9556 -0.9669 0.2363

outer loop

vertex 0.0000 0.8000 0.0000

vertex -0.6758 0.4426 -0.1188

vertex -0.3357 0.4426 -0.1326

endloop

endfacet

facet normal -0.3508 0.3495 -0.8687

outer loop

vertex -0.6758 0.4426 -0.1188

vertex -0.6348 0.6664 -0.1115

vertex -0.3153 0.6664 -0.1244

endloop

endfacet

……………….

end solid

III. PARSER

This Parser is a MFC sample, which parses the inputted STL file i.e., reads triangulated information about CAD model for rendering the object on the screen. Following are the steps carried out for parsing,

Parser begins with checking the extension of the inputted file. If it is .stl then reading continues, else it quits.

Entire contents of file are stored in a character buffer for parsing.

Each STL file represents single object, and each object represented in terms of number of triangles. It is necessary to find number of triangles. Each triangle starts with keyword facet. A function is defined to calculate number of such facets.

Two-dimensional dynamic arrays are used to store co-ordinates information. Four such arrays are defined - one for storing the all facets normal vector details, other three for storing vertices details of all the facets.

norm=new double[nb][4] - all facets normal vector's x, y, z co-ordinates are stored

v1=new double[nb][4] - all triangles first vertex's x, y, z co-ordinates are stored

Same declaration continues for storing 2nd and 3rd vertex of all the triangles. Here 'nb' means number of facets

A function 'OffsetToString' is defined as a pointer to locate the required position in buffer.

OffsetToString("facet normal") - In buffer it points to "facet normal"

Each word accessed from the buffer and stored in the data structure in following manner. Normal vector's x, y, z co-ordinates read from the buffer and stored. Here the array 'norm' stores normal vector of all the triangles.

ReadWord() and copy to norm[i][0]

ReadWord() and copy to norm[i][1]

ReadWord() and copy to norm[i][2]

In same way x, y, z co-ordinates of all the vertices are read from the buffer and stored in v1, v2 and v3. The array v1 contains the first vertex of all the triangles v2 contains the second vertex. of all the triangles and v3 contains third vertex of all the triangles.

Lady using a tablet
Lady using a tablet

Comprehensive

Writing Services

Lady Using Tablet

Plagiarism-free
Always on Time

Marked to Standard

Order Now

IV. RENDERER

Rendering, the process by which computer displays the model on the screen. After storing the facets data in data structure next task for display of the model on the screen. OpenGL tool is used to build the desired model. [6] OpenGL is a software interface to graphics hardware. It consists of various commands to specify the object. Following are the steps carried out for rendering,

Since the Stl file contains only facets information, default color, material and light properties are set by OpenGL commands:

glClearColor(), glLightfv()

Initial settings are done for viewing the geometry of the model on the screen by defining the viewport, field of view angle by the commands:

glViewPort(), gluPerspective()

Stl file's triangulated information present in data structure are inputted to OpenGL commands in following manner,

glBegin(GL_TRIANGLES);

glNormal3d(norm[i][0],norm[i][1],norm[i][2]);

glVertex3d(v1[i][0],v1[i][1],v1[i][2]);

glVertex3d(v2[i][0],v2[i][1],v2[i][2]);

glVertex3d(v3[i][0],v3[i][1],v3[i][2]);

glEnd();

It draws a single triangle. Same thing repeated for all the facets by keeping this code in loop, which displays model on the screen.

There is an option for displaying the object in wireframe mode. The vertices of all the triangles connected by lines forms the wireframe. It clearly shows group of polygons. This can be done by setting the mode of display before drawing the object.

glPolygonMode(GL_FRONT_AND_BACK,GL_LINE)

If the mode is 'GL_POINT' then it displays only the vertices of all the triangles.

Mouse interactions are defined for performing transformation functions like rotation, scaling and translation. The commands performs transformations are:

glRotatef(), glScalef(), glTranslatef()

V. SIGNIFICANCE

The parsing and rendering explained in this paper used for virtual reality visualization system development. The 3D visualization system provides simulation to enable designers to obtain a more realistic feeling. In manufacturing industries the visualization solutions are major tools for rapid prototyping. [5] Rapid prototyping is the method for the creation of components derived from 3D CAD data. It enables engineer to troubleshoot the problems within existing designs and to significantly reduce the risk associated with developing the new designs. It helps the manufacturing industry to reengineer their product development practices in order to bring new, better-quality products to market faster, at a lower cost.

VI. SNAPSHOTS

For testing the capability of a program, bottle.stl file is given as an input. The part of this file is given above in STL file format. The program reads ASCII data and displays the object as an output.

Figure 2: Selecting STL file as a Input

Figure 3: Display of STL Model

VII. CONCLUSION

Stl file format describes the surface geometry of 3-Dimenssional objects in terms of list of facet data. It is complete listing of x, y, z co-ordinates of normal and vertices of all the triangles. Rapid prototyping uses these STL files to build physical 3D models. This software with addition of stereovision display can be used as virtual reality visualization solution in manufacturing industries.