Subversion Repositories gelsvn

Rev

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

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