Subversion Repositories gelsvn

Rev

Rev 601 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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