Subversion Repositories gelsvn

Rev

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