Subversion Repositories gelsvn

Rev

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

Rev 667 Rev 677
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
#include <string.h>
-
 
19
 
18
 
20
namespace Geometry
19
namespace Geometry
21
{
20
{
22
  /** \brief A Triangle Mesh struct. 
21
  /** \brief A Triangle Mesh struct. 
23

22
 
24
      This struct contains three indexed face sets, one for geometry,
23
      This struct contains three indexed face sets, one for geometry,
25
      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
26
      vector of texture maps.
25
      vector of texture maps.
27

26
 
28
      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
29
      mesh. */
28
      mesh. */
30
  class TriMesh 
29
  class TriMesh 
31
  {
30
  {
32
  public:
31
  public:
33
		
32
		
34
    // ------- DATA -------
33
    // ------- DATA -------
35
 
34
 
36
    /// Name of model
35
    /// Name of model
37
    std::string name;
36
    std::string name;
38
		
37
		
39
    /// Indexed face set for the actual geometry
38
    /// Indexed face set for the actual geometry
40
    IndexedFaceSet geometry;
39
    IndexedFaceSet geometry;
41
 
40
 
42
    /// Indexed face set for the normals
41
    /// Indexed face set for the normals
43
    IndexedFaceSet normals;
42
    IndexedFaceSet normals;
44
 
43
 
45
    /// Indexed face set for the texture coordinates.
44
    /// Indexed face set for the texture coordinates.
46
    IndexedFaceSet texcoords;
45
    IndexedFaceSet texcoords;
47
 
46
 
48
    /// Material indices for all faces
47
    /// Material indices for all faces
49
    std::vector<int> mat_idx;
48
    std::vector<int> mat_idx;
50
 
49
 
51
    /// Texture indices for all faces
50
    /// Texture indices for all faces
52
    std::vector<int> tex_idx;
51
    std::vector<int> tex_idx;
53
 
52
 
54
    /// Vector of materials
53
    /// Vector of materials
55
    std::vector<Material> materials;
54
    std::vector<Material> materials;
56
 
55
 
57
    /// Vector of triangle face areas
56
    /// Vector of triangle face areas
58
    std::vector<float> face_areas;
57
    std::vector<float> face_areas;
59
 
58
 
60
    /// Tabulated cumulative distribution function for sampling triangles according to area
59
    /// Tabulated cumulative distribution function for sampling triangles according to area
61
    std::vector<float> face_area_cdf;
60
    std::vector<float> face_area_cdf;
62
 
61
 
63
    /// Total surface area of the triangle mesh
62
    /// Total surface area of the triangle mesh
64
    float surface_area;
63
    float surface_area;
65
 
64
 
66
    // -------- FUNCTIONS -----------
65
    // -------- FUNCTIONS -----------
67
 
66
 
68
    /// Get an axis aligned bounding box for the model.
67
    /// Get an axis aligned bounding box for the model.
69
    bool get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
68
    bool get_bbox(CGLA::Vec3f& p0, CGLA::Vec3f& p7) const;
70
 
69
 
71
    /// Get a bounding sphere for the model.
70
    /// Get a bounding sphere for the model.
72
    bool get_bsphere(CGLA::Vec3f& c, float& r) const;
71
    bool get_bsphere(CGLA::Vec3f& c, float& r) const;
73
 
72
 
74
    /// Returns true if at least one normal has been defined.
73
    /// Returns true if at least one normal has been defined.
75
    bool has_normals() const { return normals.no_faces() > 0; }
74
    bool has_normals() const { return normals.no_faces() > 0; }
76
 
75
 
77
    /// Find a material from its name
76
    /// Find a material from its name
78
    int find_material(const std::string&) const;
77
    int find_material(const std::string&) const;
79
 
78
 
80
    /// 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.
81
    void compute_normals();
80
    void compute_normals();
82
 
81
 
83
    /// Compute areas for all faces and total surface area.
82
    /// Compute areas for all faces and total surface area.
84
    void compute_areas();
83
    void compute_areas();
85
 
84
 
86
    /// Apply a transformation matrix to the mesh
85
    /// Apply a transformation matrix to the mesh
87
    void transform(const CGLA::Mat4x4f& m);
86
    void transform(const CGLA::Mat4x4f& m);
88
 
87
 
89
    /// Apply a transformation matrix to the texture coordinates
88
    /// Apply a transformation matrix to the texture coordinates
90
    void tex_transform(const CGLA::Mat4x4f& m);
89
    void tex_transform(const CGLA::Mat4x4f& m);
91
 
90
 
92
    /// Apply a transformation matrix to the texture coordinates associated with a particular material
91
    /// Apply a transformation matrix to the texture coordinates associated with a particular material
93
    void tex_transform(const CGLA::Mat4x4f& m, const std::string& material);
92
    void tex_transform(const CGLA::Mat4x4f& m, const std::string& material);
94
  };
93
  };
95
}
94
}
96
#endif
95
#endif