-
Notifications
You must be signed in to change notification settings - Fork 0
/
mesh.h
116 lines (99 loc) · 2.88 KB
/
mesh.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
#ifndef MESH_H
#define MESH_H
#include <GLUT/glut.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtc/type_ptr.hpp>
#include <vector>
#include <iostream>
#include <utility>
#include <list>
#include <boost/unordered_map.hpp>
#include <boost/heap/binomial_heap.hpp>
#define BUFFER_OFFSET(i) (reinterpret_cast<void*>(i))
typedef glm::mat3 mat3 ;
typedef glm::mat4 mat4 ;
typedef glm::vec3 vec3 ;
typedef glm::vec4 vec4 ;
using namespace std;
/********* Data Structures for Winged Edges ***********/
struct vertex_data {
vec3 position;
vec3 normal;
GLfloat padding[2];
};
struct vertex {
vec3 position;
vec3 normal;
GLfloat Q[10];
vertex(float,float,float);
vertex(vertex*);
vertex();
vertex_data data();
};
typedef boost::shared_ptr<vertex> vertexPtr;
struct half_edge;
struct edge_data;
struct edge_compare {
bool operator() (const edge_data* he1, const edge_data* he2) const;
};
struct edge_compare;
typedef boost::heap::binomial_heap<edge_data*, boost::heap::compare<edge_compare> > priorityQueue;
typedef priorityQueue::handle_type edge_handle;
struct edge_data {
vec3 merge_point;
float merge_cost;
half_edge *edge; //the half edges this data represents
edge_handle pq_handle;
void calculate_quad_error(vector<vertex>&);
};
struct half_edge {
int v;
half_edge *prev, *next, *sym; //anti-clockwise ordering
edge_data* data;
int index;
};
struct edge_collapse {
vector<half_edge*> removed;
vector<half_edge*> fromV1;
vector<half_edge*> fromV2;
vector<half_edge*> changedVerts;
vector<int> newVerts;
int V1;
int V2;
int collapseVert;
};
/********* Comprehensive Mesh definition **********/
class Mesh {
GLuint arrayBuffer;
GLuint elementArrayBuffer;
unsigned int numIndices;
vector<edge_collapse> collapse_list;
int level_of_detail;
int max_lod;
public:
vector<half_edge*> edges;
vector<vertex> verts;
boost::unordered_map< pair<int, int>, half_edge* > existing_edges;
priorityQueue pq;
Mesh(vector<vertex>& vertices, vector<vec3>& faces);
~Mesh();
void populate_symmetric_edge(half_edge*, int, int,vector<edge_data*>&);
pair<int, int> get_vertex_key(int,int);
void get_src_edges(vector<half_edge*>&, half_edge*);
void get_dst_edges(vector<half_edge*>&, half_edge*);
void get_neighboring_edges(vector<half_edge*>&, half_edge*);
void collapse_edge();
void remove_fins(half_edge* he, edge_collapse& ec);
void calculate_new_vertex(edge_collapse&, edge_data*, half_edge*, half_edge*);
void update_edge_pointers(half_edge* he, half_edge* hesym);
void update_src_neighbors(half_edge* he, vector<half_edge*>& neighbors, edge_collapse& ec);
void update_dst_neighbors(half_edge* he, vector<half_edge*>& neighbors, edge_collapse& ec);
void remove_degenerate(half_edge* he, edge_collapse&);
void update_buffer();
void draw();
void upLevelOfDetail(const int);
void downLevelOfDetail(const int);
void debug();
};
#endif //MESH_H