Subversion Repositories gelsvn

Rev

Rev 601 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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