Subversion Repositories gelsvn

Rev

Rev 64 | Rev 443 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
61 jab 1
/**********************************************************************
2
 
3
polygonizer.h
4
 
5
This is Jules Bloomenthal's implicit surface polygonizer from GRAPHICS 
6
GEMS IV. Bloomenthal's polygonizer is still used and the present code
7
is simply the original code morphed into C++.
8
 
9
J. Andreas Bærentzen 2003.
10
 
11
**********************************************************************/
12
 
13
#ifndef POLYGONIZER_H
14
#define POLYGONIZER_H
15
 
16
#include <vector>
17
 
64 jab 18
namespace Geometry
61 jab 19
{
20
 
21
	enum ToTetraHedralize
22
		{
23
			TET = 0,  // use tetrahedral decomposition 
24
			NOTET = 1  // no tetrahedral decomposition  */
25
		};
26
 
89 jab 27
	/** \brief Implicit function.
28
 
29
	The implicit function class represents the implicit function we wish 
61 jab 30
			to polygonize. Derive a class from this one and implement your 
31
			implicit primitive in the eval function. Eval takes x,y,z coordinates and
32
			returns a value. We assume that the surface is the zero level set 
33
			and that the negative values are outside. This an arbitrary choice
34
			which does not make the code less general. */
35
	class ImplicitFunction
36
		{
37
		public:
38
			virtual float eval(float,float,float) = 0;
39
		};
40
 
41
	struct POINT { float x, y, z;	};
42
 
43
	typedef POINT VERTEX;
44
	typedef POINT NORMAL;
45
 
46
	/** TRIANGLE struct contains the indices of the vertices comprising 
47
			the triangle */
48
	struct TRIANGLE
49
	{
50
		int v0,v1,v2;
51
	};
52
 
89 jab 53
	/** \brief Polygonizer is the class used to perform polygonization.*/
61 jab 54
	class Polygonizer
55
		{
56
			std::vector<NORMAL> gnormals;  
57
			std::vector<VERTEX> gvertices;  
58
			std::vector<TRIANGLE> gtriangles;
59
 
60
			ImplicitFunction* func;
61
			float size;
62
			int bounds;
63
 
64
			bool use_tetra;
65
			bool use_normals;
66
 
67
		public:	
68
 
69
			/** Constructor of Polygonizer. The first argument is the 
70
					ImplicitFunction that we wish to polygonize. The second
71
					argument is the size of the polygonizing cell. 
72
					The third arg. is the limit to how far away we will
73
					look for components of the implicit surface. 
74
					the fourth argument indicates whether the polygonizing cell
75
					is a tetrahedron (true) or cube (false). The final argument
76
					indicates whether normals should be computed.
77
			*/
78
			Polygonizer(ImplicitFunction* _func, float _size, int _bounds,
79
									bool _use_tetra=false,
80
									bool _use_normals=false):
81
				func(_func), size(_size), bounds(_bounds),
82
				use_tetra(_use_tetra),
83
				use_normals(_use_normals) {}
84
 
85
			/** March erases the triangles gathered so far and builds a new 
86
					polygonization.  The  x,y,z 
87
					arguments indicate a point near the surface. */
88
			void march(float x, float y, float z);
89
 
90
			/** Return number of triangles generated after the polygonization.
91
					Call this function only when march has been called. */
92
			int no_triangles() const
93
				{
94
					return gtriangles.size();
95
				}
96
 
97
			/** Return number of vertices generated after the polygonization.
98
					Call this function only when march has been called. */
99
			int no_vertices() const
100
				{
101
					return gvertices.size();
102
				}
103
 
104
			/** Return number of normals generated after the polygonization.
105
					Of course the result of calling this function is the same as
106
					no_vertices.
107
					Call this function only when march has been called. */
108
			int no_normals() const
109
				{
110
					return gnormals.size();
111
				}
112
 
113
			/// Return triangle with index i. 
114
				TRIANGLE& get_triangle(int i) 
115
					{
116
						return gtriangles[i];
117
					}
118
 
119
				/// Return vertex with index i. 
120
					VERTEX& get_vertex(int i) 
121
						{
122
							return gvertices[i];
123
						}
124
 
125
 
126
					/// Return normal with index i. 
127
						NORMAL& get_normal(int i) 
128
							{
129
								return gnormals[i];
130
							}
131
 
132
 
133
		};
134
}
135
 
136
#endif