Commit 07e28ea6 by Philipp Adolf

temp

parent 2aba8a8a
......@@ -177,13 +177,16 @@ Subdivision::Tables Subdivision::precomputeTables(Input input) {
QVector<Triangle> all_triangles = triangles + triangles_regular;
buildNeighborsMap(vb, all_triangles, neighbors);
QVector<Triangle> extra_old_triangles;
subTimer.restart();
precomputeEdgeTable(tables, triangles, neighbors, (unsigned int) vb.length());
precomputeEdgeTable(tables, triangles, neighbors, (unsigned int) vb.length(), extra_old_triangles);
qCDebug(log_timing) << "precomputeEdgeTable:" << formatTimeMeasurement(subTimer.elapsed());
QVector<Triangle> irregular_and_extra_triangles = triangles + extra_old_triangles;
QMap<unsigned int, unsigned int> modified_vertices;
subTimer.restart();
precomputeVertexTable(tables, input, modified_vertices);
QVector<Triangle> foo = all_triangles + extra_old_triangles;
precomputeVertexTable(tables, vb, foo, neighbors, modified_vertices);
qCDebug(log_timing) << "precomputeVertexTable:" << formatTimeMeasurement(subTimer.elapsed());
subTimer.restart();
......@@ -388,7 +391,7 @@ QVector<Triangle> Subdivision::vertexNeighbors(Triangle &triangle, Triangle::Nei
return ns;
}
void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, unsigned int offset) {
void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, unsigned int offset, QVector<Triangle> extra_old_triangles) {
//compute edge table
//Format: first two entries: edge vertices. last two entries: distant vertices.
......@@ -507,6 +510,7 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
while (extra_it.hasNext()) {
extra_it.next();
Triangle triangle = extra_it.key();
extra_old_triangles.push_back(triangle);
int uv = -1;
int vw = -1;
int wu = -1;
......@@ -603,81 +607,91 @@ void Subdivision::precomputeEdgeTable(Subdivision::Tables &tables, QVector<Trian
}
}
void Subdivision::precomputeVertexTable(Subdivision::Tables &tables, Input &input, QMap<unsigned int, unsigned int> &modified_vertices) {
//compute vertex table
//Format: First entry: original vertex. Other entries: adjacent vertices.
QVector<QVector<unsigned int> > duplicates;//for debugging
QVector<unsigned int> ib_combined = input.index_irregular_buffer + input.index_regular_buffer;
unsigned int offset = 0;
unsigned int output_offset = input.vertex_buffer.size() + tables.edge_indices.size() / 4;
for (int i = 0; i < input.vertex_buffer.length(); i++){
//hat evtl viel redundanz
QVector<Vertex> adj_v;//helfer
tables.vertex_offsets.push_back(offset);
tables.vertex_indices.push_back(i);
modified_vertices.insert(i, output_offset + i);
offset++;
Vertex originalVertex = input.vertex_buffer[i];
QVector<unsigned int> d;
for (int j = 0; j < ib_combined.length(); j++){
//suche verweise auf vertex im indexbuffer
if (input.vertex_buffer[ib_combined[j]].samePos(originalVertex)){
d.push_back(j);
unsigned int i1, i2; //indices for neighbour vertices
switch (j % 3) {
case 0:
i1 = ib_combined[j+1];
i2 = ib_combined[j+2];
break;
case 1:
i1 = ib_combined[j-1];
i2 = ib_combined[j+1];
break;
case 2:
i1 = ib_combined[j-2];
i2 = ib_combined[j-1];
break;
}
Vertex v1,v2; //neighbour vertices;
v1 = input.vertex_buffer[i1];
v2 = input.vertex_buffer[i2];
//check if vertices where already used to influence this vertex
//Note: Can't use contain. Contain uses equal (would have to implement equal, but we're only interested in the position here.
bool found1 = false;
bool found2 = false;
for (int k = 0; k < adj_v.length(); k++){
if (adj_v[k].samePos(v1)) found1 = true;
if (adj_v[k].samePos(v2)) found2 = true;
}
if (!found1){
adj_v.push_back(v1);
tables.vertex_indices.push_back(i1);
offset++;
}
if (!found2){
adj_v.push_back(v2);
tables.vertex_indices.push_back(i2);
offset++;
}
//if one adjacent vertex is referenced by multiple different indices, only its first index will appear in the adjacent_indices list.1
}
void Subdivision::precomputeVertexTable(Tables &tables, QVector<Vertex> &vb, QVector<Triangle> &irregular_triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QMap<unsigned int, unsigned int> &modified_vertices) {
QTime timer;
timer.start();
qCDebug(log_timing) << "precomputeVertexTable started";
unsigned int output_offset = vb.size() + tables.edge_indices.size() / 4;
tables.vertex_offsets.push_back(0);
for (int i = 0; i < irregular_triangles.length(); i++) {
Triangle triangle = irregular_triangles[i];
Triangle::Neighbors ns = neighbors.value(triangle);
unsigned int idx;
QVector<unsigned int> neighbor_indices;
bool removed;
idx = triangle.u_idx();
if (!modified_vertices.contains(idx)) {
tables.vertex_indices.push_back(idx);
modified_vertices.insert(idx, output_offset++);
neighbor_indices = getAllVertexIndices(vb, vertexNeighbors(triangle, ns.uv, neighbors));
removed = removeVertexIndex(vb, neighbor_indices, triangle.u());
assert(removed);
tables.vertex_indices += neighbor_indices;
tables.vertex_offsets.push_back(tables.vertex_indices.length());
}
idx = triangle.v_idx();
if (!modified_vertices.contains(idx)) {
tables.vertex_indices.push_back(idx);
modified_vertices.insert(idx, output_offset++);
neighbor_indices = getAllVertexIndices(vb, vertexNeighbors(triangle, ns.vw, neighbors));
removed = removeVertexIndex(vb, neighbor_indices, triangle.v());
assert(removed);
tables.vertex_indices += neighbor_indices;
tables.vertex_offsets.push_back(tables.vertex_indices.length());
}
idx = triangle.w_idx();
if (!modified_vertices.contains(idx)) {
tables.vertex_indices.push_back(idx);
modified_vertices.insert(idx, output_offset++);
neighbor_indices = getAllVertexIndices(vb, vertexNeighbors(triangle, ns.wu, neighbors));
removed = removeVertexIndex(vb, neighbor_indices, triangle.w());
assert(removed);
tables.vertex_indices += neighbor_indices;
tables.vertex_offsets.push_back(tables.vertex_indices.length());
}
}
qCDebug(log_timing) << "precomputeVertexTable done:" << formatTimeMeasurement(timer.elapsed());
}
bool Subdivision::containsVertexIndex(const QVector<Vertex> &vb, const QVector<unsigned int> &vertices, const Vertex vertex) const {
for (int i = 0; i < vertices.length(); i++) {
if (vertex.samePos(vb[vertices[i]])) {
return true;
}
if (!duplicates.contains(d)) duplicates.push_back(d);
}
return false;
}
tables.vertex_offsets.push_back(offset);
QVector<unsigned int> Subdivision::getAllVertexIndices(const QVector<Vertex> &vb, const QVector<Triangle> &triangles) {
QVector<unsigned int> result;
QVectorIterator<Triangle> i(triangles);
while (i.hasNext()) {
Triangle extra_triangle = i.next();
qCDebug(log_subdiv) << "Done with vertex index table. ";
qCDebug(log_subdiv) << "Duplicates: "<<duplicates.length();
for (int i = 0; i < duplicates.length(); i++){
qCDebug(log_subdiv_trace) << duplicates[i];
if (!containsVertexIndex(vb, result, extra_triangle.u()))
result.push_back(extra_triangle.u_idx());
if (!containsVertexIndex(vb, result, extra_triangle.v()))
result.push_back(extra_triangle.v_idx());
if (!containsVertexIndex(vb, result, extra_triangle.w()))
result.push_back(extra_triangle.w_idx());
}
return result;
}
bool Subdivision::removeVertexIndex(const QVector<Vertex> &vb, QVector<unsigned int> &vertices, const Vertex &vertex) {
QMutableVectorIterator<unsigned int> i(vertices);
while (i.hasNext()) {
if (vertex.samePos(vb[i.next()])) {
i.remove();
return true;
}
}
return false;
}
void Subdivision::updateIndexBuffer(QVector<unsigned int> &index_buffer, QMap<unsigned int, unsigned int> map) {
......
......@@ -62,8 +62,11 @@ private:
Tables precomputeTables(Input input);
void buildNeighborsMap(QVector<Vertex> &vb, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors);
QVector<Triangle> vertexNeighbors(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors);
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, unsigned int offset);
void precomputeVertexTable(Subdivision::Tables &tables, Input &input, QMap<unsigned int, unsigned int> &modified_vertices);
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, unsigned int offset, QVector<Triangle> extra_old_triangles);
void precomputeVertexTable(Tables &tables, QVector<Vertex> &vb, QVector<Triangle> &irregular_triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QMap<unsigned int, unsigned int> &modified_vertices);
bool containsVertexIndex(const QVector<Vertex> &vb, const QVector<unsigned int> &vertices, const Vertex vertex) const;
QVector<unsigned int> getAllVertexIndices(const QVector<Vertex> &vb, const QVector<Triangle> &triangles);
bool removeVertexIndex(const QVector<Vertex> &vb, QVector<unsigned int> &vertices, const Vertex &vertex);
void updateIndexBuffer(QVector<unsigned int> &index_buffer, QMap<unsigned int, unsigned int> map);
void findRegular(QVector<Triangle> triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QVector<Triangle> &regular, QVector<Triangle> &irregular);
Result runShader(Input input, Tables &tables);
......
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