Subversion Repositories gelsvn

Rev

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

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