Subversion Repositories gelsvn

Rev

Rev 67 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 67 Rev 94
1
#ifndef __IMESH_TRIMESH_H__
1
#ifndef __IMESH_TRIMESH_H__
2
#define __IMESH_TRIMESH_H__
2
#define __IMESH_TRIMESH_H__
3
 
3
 
4
#include <iostream>
4
#include <iostream>
5
#include "AttrVec.h"
5
#include "AttrVec.h"
6
 
6
 
7
namespace IMesh
7
namespace IMesh
8
{
8
{
9
 
9
 
-
 
10
	/** \brief Data for a triangle mesh. Not used directly.
-
 
11
 
10
	/** The TriMeshData class represents the data contents of a TriMesh, and
12
	    The TriMeshData class represents the data contents of a TriMesh, and
11
			it also contains almost all of the functions used to set or get values.
13
			it also contains almost all of the functions used to set or get values.
12
			TriMeshData is never used directly, but TriMesh and TriMeshBuilder 
14
			TriMeshData is never used directly, but TriMesh and TriMeshBuilder 
13
			inherit from this class. */
15
			inherit from this class. */
14
	class TriMeshData
16
	class TriMeshData
15
	{
17
	{
16
	private:
18
	private:
17
		// We do not allow assignment.
19
		// We do not allow assignment.
18
		TriMeshData& operator=(const TriMeshData&);
20
		TriMeshData& operator=(const TriMeshData&);
19
	protected:
21
	protected:
20
	
22
	
21
		// The following attribute handles contain the attribute numbers
23
		// The following attribute handles contain the attribute numbers
22
		// of the default face attributes face normals and face colours.
24
		// of the default face attributes face normals and face colours.
23
		// If these attributes are unused, the integers are -1
25
		// If these attributes are unused, the integers are -1
24
		AttrHandle<CGLA::Vec3f> FA_NORM;
26
		AttrHandle<CGLA::Vec3f> FA_NORM;
25
		AttrHandle<CGLA::Vec4f> FA_COL;
27
		AttrHandle<CGLA::Vec4f> FA_COL;
26
 
28
 
27
		// The following handles contain the attribute numbers of the
29
		// The following handles contain the attribute numbers of the
28
		// default vertex attributes: vertex position, normal, colour, and
30
		// default vertex attributes: vertex position, normal, colour, and
29
		// texture coordinates.
31
		// texture coordinates.
30
		AttrHandle<CGLA::Vec3f> VA_POS;
32
		AttrHandle<CGLA::Vec3f> VA_POS;
31
		AttrHandle<CGLA::Vec3f> VA_NORM; 
33
		AttrHandle<CGLA::Vec3f> VA_NORM; 
32
		AttrHandle<CGLA::Vec4f> VA_COL;
34
		AttrHandle<CGLA::Vec4f> VA_COL;
33
		AttrHandle<CGLA::Vec4f> VA_TEX;
35
		AttrHandle<CGLA::Vec4f> VA_TEX;
34
 
36
 
35
		/// number of faces.
37
		/// number of faces.
36
		int faces_size;
38
		int faces_size;
37
 
39
 
38
		/// vector of face sets.
40
		/// vector of face sets.
39
		std::vector<FaceSet*> face_sets;
41
		std::vector<FaceSet*> face_sets;
40
 
42
 
41
		/// vector of face attribute vectors
43
		/// vector of face attribute vectors
42
		std::vector<AttrVecIf*> face_attr;
44
		std::vector<AttrVecIf*> face_attr;
43
 
45
 
44
		/// Mapping from vertex attribute to face set.
46
		/// Mapping from vertex attribute to face set.
45
		std::vector<int> face_set_mapping;
47
		std::vector<int> face_set_mapping;
46
 
48
 
47
		/// vector of vertex attribute vectors.
49
		/// vector of vertex attribute vectors.
48
		std::vector<AttrVecIf*> vert_attr;
50
		std::vector<AttrVecIf*> vert_attr;
49
 
51
 
50
		/** Construct an empty instance of TriMesh data. This constructor is used
52
		/** Construct an empty instance of TriMesh data. This constructor is used
51
				by the builder when creating a fresh TriMesh. */
53
				by the builder when creating a fresh TriMesh. */
52
		TriMeshData();
54
		TriMeshData();
53
 
55
 
54
		/** Copy constructor. This is called from the TriMesh constructor when
56
		/** Copy constructor. This is called from the TriMesh constructor when
55
				the TriMeshBuilder creates a new TriMesh. */
57
				the TriMeshBuilder creates a new TriMesh. */
56
		TriMeshData(const TriMeshData& tmd);
58
		TriMeshData(const TriMeshData& tmd);
57
		
59
		
58
		/** Resets all variables to the values initialized by the constructor
60
		/** Resets all variables to the values initialized by the constructor
59
				but it does not remove dynamic memory. */
61
				but it does not remove dynamic memory. */
60
		void clear();
62
		void clear();
61
 
63
 
62
		/** Remove all dynamice memory used. */
64
		/** Remove all dynamice memory used. */
63
		void clean_up();
65
		void clean_up();
64
 
66
 
65
	public:
67
	public:
66
 
68
 
67
		//----------------------------------------------------------------------
69
		//----------------------------------------------------------------------
68
		// Functions that find handles
70
		// Functions that find handles
69
		//----------------------------------------------------------------------
71
		//----------------------------------------------------------------------
70
 
72
 
71
		/** Get the handle corresponding to a given vertex attribute vector */
73
		/** Get the handle corresponding to a given vertex attribute vector */
72
		template<class ATTR>
74
		template<class ATTR>
73
		bool get_vattr_handle(const std::string& name, 
75
		bool get_vattr_handle(const std::string& name, 
74
													AttrHandle<ATTR>& handle) const
76
													AttrHandle<ATTR>& handle) const
75
		{
77
		{
76
			for(int i=0;i< vert_attr.size(); ++i)
78
			for(int i=0;i< vert_attr.size(); ++i)
77
				{
79
				{
78
					if (vert_attr[i]->get_name() == name)
80
					if (vert_attr[i]->get_name() == name)
79
						{
81
						{
80
							handle.idx = i;
82
							handle.idx = i;
81
							return true;
83
							return true;
82
						}
84
						}
83
				}
85
				}
84
			return false;
86
			return false;
85
		}
87
		}
86
 
88
 
87
		/** Get the handle corresponding to a given face attribute vector */
89
		/** Get the handle corresponding to a given face attribute vector */
88
		template<class ATTR>
90
		template<class ATTR>
89
		bool get_fattr_handle(const std::string& name, 
91
		bool get_fattr_handle(const std::string& name, 
90
													AttrHandle<ATTR>& handle) const
92
													AttrHandle<ATTR>& handle) const
91
		{
93
		{
92
			for(int i=0;i< face_attr.size(); ++i)
94
			for(int i=0;i< face_attr.size(); ++i)
93
				{
95
				{
94
					if (face_attr[i]->get_name() == name)
96
					if (face_attr[i]->get_name() == name)
95
						{
97
						{
96
							handle.idx = i;
98
							handle.idx = i;
97
							return true;
99
							return true;
98
						}
100
						}
99
				}
101
				}
100
			return false;
102
			return false;
101
		}
103
		}
102
 
104
 
103
				// The following functions return the number of faces, vertices, and attributes.
105
				// The following functions return the number of faces, vertices, and attributes.
104
		
106
		
105
		/// Returns the number of faces
107
		/// Returns the number of faces
106
		int no_faces() const 
108
		int no_faces() const 
107
		{
109
		{
108
			return faces_size;
110
			return faces_size;
109
		}
111
		}
110
 
112
 
111
		/// Return the number of vertex attributes associated with the attribute handles
113
		/// Return the number of vertex attributes associated with the attribute handles
112
		template<class ATTR>
114
		template<class ATTR>
113
		int no_vattrib(const AttrHandle<ATTR>& handle) const 
115
		int no_vattrib(const AttrHandle<ATTR>& handle) const 
114
		{
116
		{
115
			assert(handle.idx>=0);
117
			assert(handle.idx>=0);
116
			return vert_attr[handle.idx]->size();
118
			return vert_attr[handle.idx]->size();
117
		}
119
		}
118
 
120
 
119
		/// Return the number of vertices.
121
		/// Return the number of vertices.
120
		int no_vertices() const 
122
		int no_vertices() const 
121
		{
123
		{
122
			return no_vattrib(VA_POS);
124
			return no_vattrib(VA_POS);
123
		}
125
		}
124
 
126
 
125
		/// Return the number of vertex normals.
127
		/// Return the number of vertex normals.
126
		int no_vnorm() const
128
		int no_vnorm() const
127
		{
129
		{
128
			if(VA_NORM.idx >=0)
130
			if(VA_NORM.idx >=0)
129
				return no_vattrib(VA_NORM);
131
				return no_vattrib(VA_NORM);
130
			return 0;
132
			return 0;
131
		}
133
		}
132
 
134
 
133
		/// Return the number of vertex colours
135
		/// Return the number of vertex colours
134
		int no_vcol() const
136
		int no_vcol() const
135
		{
137
		{
136
			if(VA_COL.idx >=0)
138
			if(VA_COL.idx >=0)
137
				return no_vattrib(VA_COL);
139
				return no_vattrib(VA_COL);
138
			return 0;
140
			return 0;
139
		}
141
		}
140
 
142
 
141
		/// Return the number of vertex texture coords
143
		/// Return the number of vertex texture coords
142
		int no_vtex() const
144
		int no_vtex() const
143
		{
145
		{
144
			if(VA_TEX.idx >=0)
146
			if(VA_TEX.idx >=0)
145
				return no_vattrib(VA_TEX);
147
				return no_vattrib(VA_TEX);
146
			return 0;
148
			return 0;
147
		}
149
		}
148
 
150
 
149
 
151
 
150
 
152
 
151
		//----------------------------------------------------------------------
153
		//----------------------------------------------------------------------
152
		// Set functions
154
		// Set functions
153
		//----------------------------------------------------------------------
155
		//----------------------------------------------------------------------
154
 
156
 
155
		/** Set face. The arguments are the face set, the face index and a Vec3i
157
		/** Set face. The arguments are the face set, the face index and a Vec3i
156
				containing the three indices. */
158
				containing the three indices. */
157
		CGLA::Vec3i& face(int fidx, int face_set=0)
159
		CGLA::Vec3i& face(int fidx, int face_set=0)
158
		{
160
		{
159
			assert(fidx < face_sets[face_set]->size());
161
			assert(fidx < face_sets[face_set]->size());
160
			return (*face_sets[face_set])[fidx];
162
			return (*face_sets[face_set])[fidx];
161
		}
163
		}
162
 
164
 
163
		/** Template function used to set a face attribute. The template argument
165
		/** Template function used to set a face attribute. The template argument
164
				is the attribute type. The arguments are the atttribute number, 
166
				is the attribute type. The arguments are the atttribute number, 
165
				the face index, and the value. */
167
				the face index, and the value. */
166
		template<class ATTR>
168
		template<class ATTR>
167
		ATTR& fattr(AttrHandle<ATTR> handle, int fidx)
169
		ATTR& fattr(AttrHandle<ATTR> handle, int fidx)
168
		{
170
		{
169
			return attr<ATTR>(*face_attr[handle.idx],fidx);
171
			return attr<ATTR>(*face_attr[handle.idx],fidx);
170
		}
172
		}
171
	
173
	
172
		/** Template function used to set a vertex attribute. The template
174
		/** Template function used to set a vertex attribute. The template
173
				argument is the attribute type. The arguments are the attribute
175
				argument is the attribute type. The arguments are the attribute
174
				number, the index of a face, the corresponding corner, and the
176
				number, the index of a face, the corresponding corner, and the
175
				value of the attribute belonging to the thus specified vertex. */
177
				value of the attribute belonging to the thus specified vertex. */
176
		template<class ATTR>
178
		template<class ATTR>
177
		ATTR& vattr(AttrHandle<ATTR> handle, int fidx, int crnr)
179
		ATTR& vattr(AttrHandle<ATTR> handle, int fidx, int crnr)
178
		{
180
		{
179
			int face_set = face_set_mapping[handle.idx];
181
			int face_set = face_set_mapping[handle.idx];
180
			int vidx = (*face_sets[face_set])[fidx][crnr];
182
			int vidx = (*face_sets[face_set])[fidx][crnr];
181
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
183
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
182
		}
184
		}
183
 
185
 
184
		/** Template function used to set a vertex attribute. The template
186
		/** Template function used to set a vertex attribute. The template
185
				argument is the type of the attribute, and the arugments are the
187
				argument is the type of the attribute, and the arugments are the
186
				attribute number,	the vertex index, and the value. */
188
				attribute number,	the vertex index, and the value. */
187
		template<class ATTR>
189
		template<class ATTR>
188
		ATTR& vattr(AttrHandle<ATTR> handle, int vidx)
190
		ATTR& vattr(AttrHandle<ATTR> handle, int vidx)
189
		{
191
		{
190
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
192
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
191
		}
193
		}
192
 
194
 
193
		//----------------------------------------------------------------------
195
		//----------------------------------------------------------------------
194
		// Get functions
196
		// Get functions
195
		//----------------------------------------------------------------------
197
		//----------------------------------------------------------------------
196
 
198
 
197
		/** Get a face. Returns a Vec3i with the face's corner indices.
199
		/** Get a face. Returns a Vec3i with the face's corner indices.
198
				The arguments are the "face set" and the face index. */
200
				The arguments are the "face set" and the face index. */
199
		const CGLA::Vec3i face(int fidx,int face_set=0) const 
201
		const CGLA::Vec3i face(int fidx,int face_set=0) const 
200
		{
202
		{
201
			assert(fidx < face_sets[face_set]->size());
203
			assert(fidx < face_sets[face_set]->size());
202
			return (*face_sets[face_set])[fidx];
204
			return (*face_sets[face_set])[fidx];
203
		}
205
		}
204
 
206
 
205
		/// Template function that gets face attribute.
207
		/// Template function that gets face attribute.
206
		template<class ATTR>
208
		template<class ATTR>
207
		const ATTR& fattr(AttrHandle<ATTR> handle, int fidx) const
209
		const ATTR& fattr(AttrHandle<ATTR> handle, int fidx) const
208
		{
210
		{
209
			return attr<ATTR>(*face_attr[handle.idx],fidx);
211
			return attr<ATTR>(*face_attr[handle.idx],fidx);
210
		}
212
		}
211
	
213
	
212
		/// Template function that gets vertex attribute from face index and corner
214
		/// Template function that gets vertex attribute from face index and corner
213
		template<class ATTR>
215
		template<class ATTR>
214
		const ATTR& vattr(AttrHandle<ATTR> handle, int fidx, int crnr) const
216
		const ATTR& vattr(AttrHandle<ATTR> handle, int fidx, int crnr) const
215
		{
217
		{
216
			int face_set = face_set_mapping[handle.idx];
218
			int face_set = face_set_mapping[handle.idx];
217
			int vidx = (*face_sets[face_set])[fidx][crnr];
219
			int vidx = (*face_sets[face_set])[fidx][crnr];
218
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
220
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
219
		}
221
		}
220
 
222
 
221
		/// Get vertex attribute from vertex index
223
		/// Get vertex attribute from vertex index
222
		template<class ATTR>
224
		template<class ATTR>
223
		const ATTR& vattr(AttrHandle<ATTR> handle, int vidx) const
225
		const ATTR& vattr(AttrHandle<ATTR> handle, int vidx) const
224
		{
226
		{
225
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
227
			return attr<ATTR>(*vert_attr[handle.idx],vidx);
226
		}
228
		}
227
 
229
 
228
		// ----------------------------------------------------------------------
230
		// ----------------------------------------------------------------------
229
		// Utility functions for getting and setting the face normal
231
		// Utility functions for getting and setting the face normal
230
		// ----------------------------------------------------------------------
232
		// ----------------------------------------------------------------------
231
 
233
 
232
		/// Set a face normal
234
		/// Set a face normal
233
		const CGLA::Vec3f& fnorm(int fidx)
235
		const CGLA::Vec3f& fnorm(int fidx)
234
		{
236
		{
235
			return fattr(FA_NORM, fidx);
237
			return fattr(FA_NORM, fidx);
236
		}
238
		}
237
	
239
	
238
		/// Get a face normal
240
		/// Get a face normal
239
		const CGLA::Vec3f& fnorm(int fidx) const
241
		const CGLA::Vec3f& fnorm(int fidx) const
240
		{
242
		{
241
			return fattr(FA_NORM, fidx);
243
			return fattr(FA_NORM, fidx);
242
		}
244
		}
243
 
245
 
244
		// ----------------------------------------------------------------------
246
		// ----------------------------------------------------------------------
245
		// Utility functions for getting and setting the face colour
247
		// Utility functions for getting and setting the face colour
246
		// ----------------------------------------------------------------------
248
		// ----------------------------------------------------------------------
247
 
249
 
248
		/// Set a face colour
250
		/// Set a face colour
249
		CGLA::Vec4f& fcol(int fidx)
251
		CGLA::Vec4f& fcol(int fidx)
250
		{
252
		{
251
			return fattr(FA_COL, fidx);
253
			return fattr(FA_COL, fidx);
252
		}
254
		}
253
	
255
	
254
		/// Get a face colour
256
		/// Get a face colour
255
		const CGLA::Vec4f& fcol(int fidx) const
257
		const CGLA::Vec4f& fcol(int fidx) const
256
		{
258
		{
257
			return fattr(FA_COL, fidx);
259
			return fattr(FA_COL, fidx);
258
		}
260
		}
259
	
261
	
260
		// ----------------------------------------------------------------------
262
		// ----------------------------------------------------------------------
261
		// Utility functions for getting and setting the vertex position
263
		// Utility functions for getting and setting the vertex position
262
		// ----------------------------------------------------------------------
264
		// ----------------------------------------------------------------------
263
	
265
	
264
		/// Set a vertex position using a face index and corner.
266
		/// Set a vertex position using a face index and corner.
265
		CGLA::Vec3f& vpos(int fidx, int crnr)
267
		CGLA::Vec3f& vpos(int fidx, int crnr)
266
		{
268
		{
267
			return vattr(VA_POS, fidx, crnr);
269
			return vattr(VA_POS, fidx, crnr);
268
		}
270
		}
269
 
271
 
270
		/// Set a vertex position using a direct vertex index
272
		/// Set a vertex position using a direct vertex index
271
		CGLA::Vec3f& vpos(int vidx)
273
		CGLA::Vec3f& vpos(int vidx)
272
		{
274
		{
273
			return vattr(VA_POS, vidx);
275
			return vattr(VA_POS, vidx);
274
		}
276
		}
275
 
277
 
276
		/// Get a vertex position using a face index and a corner
278
		/// Get a vertex position using a face index and a corner
277
		const CGLA::Vec3f& vpos(int fidx, int crnr) const
279
		const CGLA::Vec3f& vpos(int fidx, int crnr) const
278
		{
280
		{
279
			return vattr(VA_POS, fidx, crnr);
281
			return vattr(VA_POS, fidx, crnr);
280
		}
282
		}
281
	
283
	
282
		/// Get a vertex position using a direct index
284
		/// Get a vertex position using a direct index
283
		const CGLA::Vec3f& vpos(int vidx) const
285
		const CGLA::Vec3f& vpos(int vidx) const
284
		{
286
		{
285
			return vattr(VA_POS, vidx);
287
			return vattr(VA_POS, vidx);
286
		}
288
		}
287
 
289
 
288
		// ----------------------------------------------------------------------
290
		// ----------------------------------------------------------------------
289
		// Utility functions for getting and setting the vertex normal
291
		// Utility functions for getting and setting the vertex normal
290
		// ----------------------------------------------------------------------
292
		// ----------------------------------------------------------------------
291
	
293
	
292
		/// Set a vertex normal using a face index and corner.
294
		/// Set a vertex normal using a face index and corner.
293
		CGLA::Vec3f& vnorm(int fidx, int crnr)
295
		CGLA::Vec3f& vnorm(int fidx, int crnr)
294
		{
296
		{
295
			return vattr(VA_NORM, fidx, crnr);
297
			return vattr(VA_NORM, fidx, crnr);
296
		}
298
		}
297
 
299
 
298
		/// Set a vertex normal using a direct vertex index
300
		/// Set a vertex normal using a direct vertex index
299
		CGLA::Vec3f& vnorm(int vidx)
301
		CGLA::Vec3f& vnorm(int vidx)
300
		{
302
		{
301
			return vattr(VA_NORM, vidx);
303
			return vattr(VA_NORM, vidx);
302
		}
304
		}
303
 
305
 
304
		/// Get a vertex normal using a face index and a corner
306
		/// Get a vertex normal using a face index and a corner
305
		const CGLA::Vec3f& vnorm(int fidx, int crnr) const 
307
		const CGLA::Vec3f& vnorm(int fidx, int crnr) const 
306
		{
308
		{
307
			return vattr(VA_NORM, fidx, crnr);
309
			return vattr(VA_NORM, fidx, crnr);
308
		}
310
		}
309
	
311
	
310
		/// Get a vertex normal using a direct index
312
		/// Get a vertex normal using a direct index
311
		const CGLA::Vec3f& vnorm(int vidx) const 
313
		const CGLA::Vec3f& vnorm(int vidx) const 
312
		{
314
		{
313
			return vattr(VA_NORM, vidx);
315
			return vattr(VA_NORM, vidx);
314
		}
316
		}
315
 
317
 
316
		// ----------------------------------------------------------------------
318
		// ----------------------------------------------------------------------
317
		// Utility functions for getting and setting the vertex colour
319
		// Utility functions for getting and setting the vertex colour
318
		// ----------------------------------------------------------------------
320
		// ----------------------------------------------------------------------
319
	
321
	
320
		/// Set a vertex colour using a face index and corner.
322
		/// Set a vertex colour using a face index and corner.
321
		CGLA::Vec4f& vcol(int fidx, int crnr)
323
		CGLA::Vec4f& vcol(int fidx, int crnr)
322
		{
324
		{
323
			return vattr(VA_COL, fidx, crnr);
325
			return vattr(VA_COL, fidx, crnr);
324
		}
326
		}
325
 
327
 
326
		/// Set a vertex colour using a direct vertex index
328
		/// Set a vertex colour using a direct vertex index
327
		CGLA::Vec4f& vcol(int vidx)
329
		CGLA::Vec4f& vcol(int vidx)
328
		{
330
		{
329
			return vattr(VA_COL, vidx);
331
			return vattr(VA_COL, vidx);
330
		}
332
		}
331
 
333
 
332
		/// Get a vertex colour using a face index and a corner
334
		/// Get a vertex colour using a face index and a corner
333
		const CGLA::Vec4f& vcol(int fidx, int crnr) const
335
		const CGLA::Vec4f& vcol(int fidx, int crnr) const
334
		{
336
		{
335
			return vattr(VA_COL, fidx, crnr);
337
			return vattr(VA_COL, fidx, crnr);
336
		}
338
		}
337
	
339
	
338
		/// Get a vertex colour using a direct index
340
		/// Get a vertex colour using a direct index
339
		const CGLA::Vec4f& vcol(int vidx) const
341
		const CGLA::Vec4f& vcol(int vidx) const
340
		{
342
		{
341
			return vattr(VA_COL, vidx);
343
			return vattr(VA_COL, vidx);
342
		}
344
		}
343
 
345
 
344
		// ----------------------------------------------------------------------
346
		// ----------------------------------------------------------------------
345
		// Utility functions for getting and setting the vertex tex coord
347
		// Utility functions for getting and setting the vertex tex coord
346
		// ----------------------------------------------------------------------
348
		// ----------------------------------------------------------------------
347
	
349
	
348
		/// Set a vertex texture coord using a face index and corner.
350
		/// Set a vertex texture coord using a face index and corner.
349
		CGLA::Vec4f& vtex(int fidx, int crnr)
351
		CGLA::Vec4f& vtex(int fidx, int crnr)
350
		{
352
		{
351
			return vattr(VA_TEX, fidx, crnr);
353
			return vattr(VA_TEX, fidx, crnr);
352
		}
354
		}
353
 
355
 
354
		/// Set a vertex texture coord using a direct vertex index
356
		/// Set a vertex texture coord using a direct vertex index
355
		CGLA::Vec4f& vtex(int vidx)
357
		CGLA::Vec4f& vtex(int vidx)
356
		{
358
		{
357
			return vattr(VA_TEX, vidx);
359
			return vattr(VA_TEX, vidx);
358
		}
360
		}
359
 
361
 
360
		/// Get a vertex texture coord using a face index and a corner
362
		/// Get a vertex texture coord using a face index and a corner
361
		const CGLA::Vec4f& vtex(int fidx, int crnr) const
363
		const CGLA::Vec4f& vtex(int fidx, int crnr) const
362
		{
364
		{
363
			return vattr(VA_TEX, fidx, crnr);
365
			return vattr(VA_TEX, fidx, crnr);
364
		}
366
		}
365
	
367
	
366
		/// Get a vertex texture coord using a direct index
368
		/// Get a vertex texture coord using a direct index
367
		const CGLA::Vec4f& vtex(int vidx) const
369
		const CGLA::Vec4f& vtex(int vidx) const
368
		{
370
		{
369
			return vattr(VA_TEX, vidx);
371
			return vattr(VA_TEX, vidx);
370
		}
372
		}
371
	};
373
	};
372
 
374
 
373
 
375
 
374
	class TriMeshBuilder;
376
	class TriMeshBuilder;
375
 
377
 
-
 
378
	/** \brief The IMesh triangle mesh class.
-
 
379
 
376
	/** The TriMesh class represents a triangle mesh. It cannot be instantiated
380
	    The TriMesh class represents a triangle mesh. It cannot be instantiated
377
			except by the TriMeshBuilder class. All data and methods are defined
381
			except by the TriMeshBuilder class. All data and methods are defined
378
			in the TriMeshData class from which this class inherits. */
382
			in the TriMeshData class from which this class inherits. */
379
	class TriMesh: public TriMeshData
383
	class TriMesh: public TriMeshData
380
	{
384
	{
381
		friend class TriMeshBuilder;
385
		friend class TriMeshBuilder;
382
	private:
386
	private:
383
		// The following constructors are private and undefined. Hence
387
		// The following constructors are private and undefined. Hence
384
		// they cannot be used.
388
		// they cannot be used.
385
		TriMesh(const TriMesh&);
389
		TriMesh(const TriMesh&);
386
		TriMesh& operator=(const TriMesh&);
390
		TriMesh& operator=(const TriMesh&);
387
		TriMesh();
391
		TriMesh();
388
 
392
 
389
		// The only legal constructor takes a TriMeshData object as argument
393
		// The only legal constructor takes a TriMeshData object as argument
390
		// This constructor can only be called by the TriMeshBuilder since it
394
		// This constructor can only be called by the TriMeshBuilder since it
391
		// us a friend of TriMesh.
395
		// us a friend of TriMesh.
392
 
396
 
393
		/// Construct a TriMesh from an instance of TriMeshData
397
		/// Construct a TriMesh from an instance of TriMeshData
394
		TriMesh(const TriMeshData& tmd): TriMeshData(tmd) {}
398
		TriMesh(const TriMeshData& tmd): TriMeshData(tmd) {}
395
		void *data;
399
		void *data;
396
	public:
400
	public:
397
 
401
 
398
		/// Destructor deletes all attribute vectors. 
402
		/// Destructor deletes all attribute vectors. 
399
		~TriMesh()
403
		~TriMesh()
400
		{
404
		{
401
			clean_up();
405
			clean_up();
402
		}
406
		}
403
 
407
 
404
    void get_bsphere(CGLA::Vec3f& c, float& r) const;
408
    void get_bsphere(CGLA::Vec3f& c, float& r) const;
405
		
409
		
406
    void get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
410
    void get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
407
		
411
		
408
		void set_data(void *data) { 
412
		void set_data(void *data) { 
409
			this->data = data;
413
			this->data = data;
410
		}
414
		}
411
 
415
 
412
		void* get_data() {
416
		void* get_data() {
413
			return data;
417
			return data;
414
		}
418
		}
415
	};
419
	};
416
}
420
}
417
 
421
 
418
#endif
422
#endif
419
 
423