Subversion Repositories gelsvn

Rev

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

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