Subversion Repositories gelsvn

Rev

Rev 567 | 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 TriMesh.h
9
 * @brief Triangle mesh class based on indexed face set data structure.
10
 */
11
 
443 jab 12
#ifndef __GEOMETRY_TRIMESH_H__
13
#define __GEOMETRY_TRIMESH_H__
78 jab 14
 
419 jrf 15
#include <CGLA/Mat4x4f.h>
78 jab 16
#include "IndexedFaceSet.h"
17
#include "Material.h"
18
 
79 jab 19
namespace Geometry
78 jab 20
{
21
 
22
 
89 jab 23
	/** \brief A Triangle Mesh struct. 
24
 
178 bj 25
	    This struct contains three indexed face sets, one for geometry,
26
			textures, and normals. It also contains a vector of materials and a
27
			vector of texture maps.
78 jab 28
 
178 bj 29
			A number of functions are defined allowing for rendering of the triangle
30
			mesh. */
338 jab 31
	class TriMesh 
78 jab 32
	{
338 jab 33
		public:
34
 
78 jab 35
		// ------- DATA -------
36
 
37
		/// Name of model
38
		std::string name;
39
 
40
		/// Indexed face set for the actual geometry
41
		IndexedFaceSet geometry;
42
 
43
		/// Indexed face set for the normals
44
		IndexedFaceSet normals;
45
 
46
		/// Indexed face set for the texture coordinates.
47
		IndexedFaceSet texcoords;
48
 
49
		/// Material indices for all faces
50
		std::vector<int> mat_idx;
51
 
52
		/// Texture indices for all faces
53
		std::vector<int> tex_idx;
54
 
55
		/// Vector of materials
56
		std::vector<Material> materials;
57
 
567 jrf 58
    /// Vector of triangle face areas
59
    std::vector<float> face_areas;
60
 
61
    /// Tabulated cumulative distribution function for sampling triangles according to area
62
    std::vector<float> face_area_cdf;
63
 
64
    /// Total surface area of the triangle mesh
65
    float surface_area;
66
 
78 jab 67
		// -------- FUNCTIONS -----------
68
 
69
		/// Get an axis aligned bounding box for the model.
375 jrf 70
		bool get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
78 jab 71
 
72
		/// Get a bounding sphere for the model.
375 jrf 73
		bool get_bsphere(CGLA::Vec3f& c, float& r) const;
78 jab 74
 
75
		/// Returns true if at least one normal has been defined.
76
		bool has_normals() const 
77
		{
78
			return normals.no_faces()>0;
79
		}
80
 
81
		/// Find a material from its name
82
		int find_material(const std::string&) const;
83
 
84
		/// Compute normals for the mesh. Does not check if there are normals.
85
		void compute_normals();
86
 
567 jrf 87
    /// Compute areas for all faces and total surface area.
88
    void compute_areas();
89
 
419 jrf 90
    /// Apply a transformation matrix to the mesh
91
    void transform(CGLA::Mat4x4f m);
78 jab 92
	};
93
 
94
 
95
}
96
#endif