Subversion Repositories gelsvn

Rev

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