Subversion Repositories gelsvn

Rev

Rev 90 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
78 jab 1
#ifndef __INDEXED_FACE_SET_H__
2
#define __INDEXED_FACE_SET_H__
3
 
4
#pragma warning(disable: 4267 4018)
5
#include <vector>
6
#include "CGLA/Vec3f.h"
7
#include "CGLA/Vec3i.h"
8
 
79 jab 9
namespace Geometry
78 jab 10
{
11
	const CGLA::Vec3i NULL_FACE(-1,-1,-1);
12
 
89 jab 13
	/** \brief This class represents the simplest possible triangle mesh data
14
			structure.
15
 
78 jab 16
			Faces must be triangular, and 3D coordinates are the only values 
17
			associated with the vertices. */
18
	class IndexedFaceSet
19
	{
20
		/// Vertices
21
    std::vector<CGLA::Vec3f> verts;
22
 
23
		/// Vec3is (which must be triangles)
24
    std::vector<CGLA::Vec3i> faces;
25
 
26
	public:
27
 
28
		IndexedFaceSet(): verts(0), faces(0) {}
29
 
30
		// ----------------------------------------
31
		// Functions that operate on faces
32
		// ----------------------------------------
33
 
89 jab 34
		/** Add a face and return the index of the new face. 
35
 
36
		If the optional idx argument is present, the face array is resized so 
37
		that the new index == idx. */
78 jab 38
		int add_face(const CGLA::Vec3i& f, int idx=-1) 
39
		{
40
			if(idx < 0)
41
				idx = faces.size();
42
			faces.resize(idx+1,NULL_FACE);
43
			faces[idx] = f;
44
			return idx;
45
		}
46
 
47
		/// Return the number of faces.
48
		int no_faces() const {return faces.size();}
49
 
89 jab 50
		/** Return the face corresponding to a given index. 
51
 
52
				The NULL_FACE	is returned if the index is out of bounds. */
78 jab 53
		const CGLA::Vec3i& face(int idx) const
54
		{
55
			if(idx<faces.size())
56
				return faces[idx];
57
			return NULL_FACE;
58
		}
59
 
60
		/// Assign f to a face of index idx
61
		CGLA::Vec3i& face_rw(int idx) 
62
		{
63
			return faces[idx];
64
		}
65
 
66
		// ----------------------------------------
67
		// Functions that operate on vertices
68
		// ----------------------------------------
69
 
70
		/// Add a vertex and return the index of the vertex.
71
		int add_vertex(const CGLA::Vec3f& v)
72
		{
73
			int idx= verts.size();
74
			verts.push_back(v);
75
			return idx;
76
		}
77
 
78
		/// Return the number of vertices.
79
		int no_vertices() const {return verts.size();}
80
 
89 jab 81
		/** Return the vertex corresponding to a given index. 
82
 
83
		User is responsible	for bounds checking. */
78 jab 84
		const CGLA::Vec3f& vertex(int idx) const
85
		{
86
			return verts[idx];
87
		}
88
 
89
		/// Assign v to a vertex of index idx
90
		CGLA::Vec3f& vertex_rw(int idx)
91
		{
92
			return verts[idx];
93
		}
94
 
95
	};
96
}
97
 
98
#endif