Subversion Repositories gelsvn

Rev

Rev 64 | Rev 443 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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