Subversion Repositories gelsvn

Rev

Details | Last modification | View Log | RSS feed

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