Commit b21bdb93 by Philipp Adolf

Use pointer to vertex buffer in Triangle

Fixes #5
parent 4e5f6931
...@@ -155,11 +155,11 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) { ...@@ -155,11 +155,11 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
QVector<Triangle> triangles; QVector<Triangle> triangles;
for (int i = 0; i < ib.length(); i+=3) { for (int i = 0; i < ib.length(); i+=3) {
triangles.push_back(Triangle(vb, ib[i], ib[i+1], ib[i+2])); triangles.push_back(Triangle(&vb, ib[i], ib[i+1], ib[i+2]));
} }
QVector<Triangle> triangles_regular; QVector<Triangle> triangles_regular;
for (int i = 0; i < ib_regular.length(); i+=3) { for (int i = 0; i < ib_regular.length(); i+=3) {
triangles.push_back(Triangle(vb, ib_regular[i], ib_regular[i+1], ib_regular[i+2])); triangles.push_back(Triangle(&vb, ib_regular[i], ib_regular[i+1], ib_regular[i+2]));
} }
precomputeEdgeTable(tables, triangles, triangles_regular, (unsigned int) vb.length()); precomputeEdgeTable(tables, triangles, triangles_regular, (unsigned int) vb.length());
...@@ -458,14 +458,14 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -458,14 +458,14 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
} }
} }
Triangle t367(vb,i3,i6,i7); Triangle t367(&vb,i3,i6,i7);
for (int j = i+3; j < ib_combined.length()-2; j += 3){ for (int j = i+3; j < ib_combined.length()-2; j += 3){
unsigned int j0 = ib_combined[j]; unsigned int j0 = ib_combined[j];
unsigned int j1 = ib_combined[j+1]; unsigned int j1 = ib_combined[j+1];
unsigned int j2 = ib_combined[j+2]; unsigned int j2 = ib_combined[j+2];
Triangle tj(vb,j0,j1,j2); Triangle tj(&vb,j0,j1,j2);
if (t367.hasSharedEdge(tj)){ if (t367.hasSharedEdge(tj)){
QVector<Triangle> neighbors = adj.value(tj,QVector<Triangle>()); QVector<Triangle> neighbors = adj.value(tj,QVector<Triangle>());
...@@ -488,7 +488,7 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_ ...@@ -488,7 +488,7 @@ QVector<unsigned int> Subdivision::getPatchIndexBuffer(QVector<unsigned int> ib_
i3 = ib_regular[i]; i3 = ib_regular[i];
i6 = ib_regular[i+1]; i6 = ib_regular[i+1];
i7 = ib_regular[i+2]; i7 = ib_regular[i+2];
Triangle ti(vb,i3,i6,i7); Triangle ti(&vb,i3,i6,i7);
bool found0, found1, found5, found8, found9, found11; bool found0, found1, found5, found8, found9, found11;
QVector<Triangle> neighbors = adj.value(ti,QVector<Triangle>()); QVector<Triangle> neighbors = adj.value(ti,QVector<Triangle>());
for (int j = 0; j < neighbors.length(); j++){ for (int j = 0; j < neighbors.length(); j++){
......
...@@ -13,7 +13,7 @@ Triangle::Triangle(const Triangle &other) { ...@@ -13,7 +13,7 @@ Triangle::Triangle(const Triangle &other) {
this->w_ = other.w_; this->w_ = other.w_;
} }
Triangle::Triangle(const QVector<Vertex> &vertex_buffer, unsigned int u, unsigned int v, unsigned int w) { Triangle::Triangle(const QVector<Vertex> *vertex_buffer, unsigned int u, unsigned int v, unsigned int w) {
this->vertex_buffer_ = vertex_buffer; this->vertex_buffer_ = vertex_buffer;
this->u_ = u; this->u_ = u;
this->v_ = v; this->v_ = v;
...@@ -21,15 +21,15 @@ Triangle::Triangle(const QVector<Vertex> &vertex_buffer, unsigned int u, unsigne ...@@ -21,15 +21,15 @@ Triangle::Triangle(const QVector<Vertex> &vertex_buffer, unsigned int u, unsigne
} }
Vertex Triangle::u() const { Vertex Triangle::u() const {
return vertex_buffer_[u_]; return (*vertex_buffer_)[u_];
} }
Vertex Triangle::v() const { Vertex Triangle::v() const {
return vertex_buffer_[v_]; return (*vertex_buffer_)[v_];
} }
Vertex Triangle::w() const { Vertex Triangle::w() const {
return vertex_buffer_[w_]; return (*vertex_buffer_)[w_];
} }
unsigned int Triangle::u_idx() const { unsigned int Triangle::u_idx() const {
......
...@@ -23,7 +23,7 @@ class Triangle { ...@@ -23,7 +23,7 @@ class Triangle {
Triangle(); Triangle();
Triangle(const Triangle &other); Triangle(const Triangle &other);
Triangle(const QVector<Vertex> &vertex_buffer, unsigned int u, unsigned int v, unsigned int w); Triangle(const QVector<Vertex> *vertex_buffer, unsigned int u, unsigned int v, unsigned int w);
Vertex u() const; Vertex u() const;
Vertex v() const; Vertex v() const;
...@@ -48,7 +48,7 @@ class Triangle { ...@@ -48,7 +48,7 @@ class Triangle {
bool next_clockwise(Edge first, Edge next) const; bool next_clockwise(Edge first, Edge next) const;
private: private:
QVector<Vertex> vertex_buffer_; const QVector<Vertex> *vertex_buffer_;
unsigned int u_; unsigned int u_;
unsigned int v_; unsigned int v_;
unsigned int w_; unsigned int w_;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment