Subversion Repositories gelsvn

Rev

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

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