Subversion Repositories gelsvn

Rev

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

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