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