Subversion Repositories gelsvn

Rev

Rev 443 | Rev 601 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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