Subversion Repositories gelsvn

Rev

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

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