Subversion Repositories gelsvn

Rev

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

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