00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
#ifndef OPENCAL_TRIANGLEMESH_H
00012
#define OPENCAL_TRIANGLEMESH_H
00013
00014
00015
#include <OpenCAL/global.h>
00016
#include <OpenCAL/Texture.h>
00017
using OpenCAL::Utils::Texture;
00018
00019
#include <vector>
00020
using std::vector;
00021
00022
00023
namespace OpenCAL
00024 {
00025
00026
class Vertex;
00027
class Triangle;
00028
namespace Utils {
class Material; }
00029
using Utils::Material;
00030
00031
00035 class OPENCAL_API TriangleMesh
00036 {
00037
protected:
00038
00039
typedef vector<Vertex *> VertexList;
00040
typedef vector<Triangle *> TriangleList;
00041
typedef vector<Material *> MaterialList;
00042
00043
00044
00045 VertexList m_vertices;
00046 TriangleList m_triangles;
00047 MaterialList m_materials;
00048
00049 Texture *m_texture;
00050
00051
bool m_rigid;
00052
bool m_drawNormals;
00053
00054
public:
00055
00056 TriangleMesh(
bool rigid =
false);
00057 TriangleMesh(
const string &filename,
bool rigid =
false);
00058
virtual ~TriangleMesh();
00059
00060
00061
const Texture *getTexture()
const {
return m_texture; }
00062 Texture *getTexture() {
return m_texture; }
00063
bool hasTexture()
const {
return (m_texture != 0); }
00064
bool isRigid()
const {
return m_rigid; }
00065
00066
00067
void setTexture(Texture *texture) { m_texture = texture; }
00068
00069
00070
unsigned int numVertices()
const {
return m_vertices.size(); }
00071
const Vertex *getVertex(
unsigned int i)
const {
return m_vertices[i]; }
00072
Vertex *getVertex(
unsigned int i) {
return m_vertices[i]; }
00073
void reserveVertices(
unsigned int n) { m_vertices.reserve(n); }
00074
Vertex *addVertex(
const Vertex &vertex);
00075
00076
00077
unsigned int numTriangles()
const {
return m_triangles.size(); }
00078
const Triangle *getTriangle(
unsigned int i)
const {
return m_triangles[i]; }
00079
Triangle *getTriangle(
unsigned int i) {
return m_triangles[i]; }
00080
void reserveTriangles(
unsigned int n) { m_triangles.reserve(n); }
00081
Triangle *addTriangle(
const Triangle &triangle);
00082
00083
00084
unsigned int numMaterials()
const {
return m_materials.size(); }
00085
const Material *getMaterial(
unsigned int i)
const {
return m_materials[i]; }
00086
Material *getMaterial(
unsigned int i) {
return m_materials[i]; }
00087
void reserveMaterials(
unsigned int n) { m_materials.reserve(n); }
00088
Material *addMaterial();
00089
Material *addMaterial(
const Material &material);
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
bool getDrawNormals()
const {
return m_drawNormals; }
00100
void setDrawNormals(
bool enabled =
true) { m_drawNormals = enabled; }
00101
void enableDrawNormals() { m_drawNormals =
true; }
00102
void disableDrawNormals() { m_drawNormals =
false; }
00103
void toggleDrawNormals() { m_drawNormals = !m_drawNormals; }
00104
00105
00106
void clear();
00107
void invalidateTriangleNormals();
00108
void calculateVertexNormals();
00109
void loadFromFile(
const string &filename);
00110
00111
00112
00113
00114
00115
00116 };
00117 }
00118
00119
#endif // OPENCAL_TRIANGLEMESH_H