Subversion Repositories gelsvn

Rev

Rev 409 | Rev 595 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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