Commit d029fb25 by Philipp Adolf

Rewrite findRegular to use neighbors map

parent 36f9cdb3
...@@ -89,18 +89,29 @@ void Subdivision::subdivide(Mesh *mesh, int level) { ...@@ -89,18 +89,29 @@ void Subdivision::subdivide(Mesh *mesh, int level) {
Tables tables = precomputeTables(input); Tables tables = precomputeTables(input);
Result result = runShader(input, tables); Result result = runShader(input, tables);
QVector<unsigned int> regular; QVector<Triangle> all_triangles;
QVector<unsigned int> irregular; ibToTriangles(&result.vertex_buffer, tables.index_buffer, all_triangles);
findRegular(tables.index_buffer, result.vertex_buffer, regular, irregular);
QMap<Triangle, Triangle::Neighbors> neighbors;
buildNeighborsMap(result.vertex_buffer, all_triangles, neighbors);
QVector<Triangle> regular;
QVector<Triangle> irregular;
findRegular(all_triangles, neighbors, regular, irregular);
qCDebug(log_subdiv) << "Indices" << tables.index_buffer.length(); qCDebug(log_subdiv) << "Indices" << tables.index_buffer.length();
qCDebug(log_subdiv) << "subdivide: regular" << regular.length(); qCDebug(log_subdiv) << "subdivide: regular" << regular.length();
qCDebug(log_subdiv) << "subdivide: irregular" << irregular.length(); qCDebug(log_subdiv) << "subdivide: irregular" << irregular.length();
QVector<unsigned int> patches = getPatchIndexBuffer(regular, irregular,result.vertex_buffer);//todo is this the correct vb? QVector<unsigned int> regular_ib;
trianglesToIB(regular, regular_ib);
QVector<unsigned int> irregular_ib;
trianglesToIB(irregular, irregular_ib);
QVector<unsigned int> patches = getPatchIndexBuffer(regular_ib, irregular_ib, result.vertex_buffer);
qCDebug(log_subdiv) << "patches" << patches.length(); qCDebug(log_subdiv) << "patches" << patches.length();
current_mesh->update(result.vb_handle, result.vertex_buffer, irregular, patches); current_mesh->update(result.vb_handle, result.vertex_buffer, irregular_ib, patches);
} }
} }
...@@ -545,15 +556,43 @@ void Subdivision::splitRegular(Mesh *mesh) { ...@@ -545,15 +556,43 @@ void Subdivision::splitRegular(Mesh *mesh) {
Mesh::MeshEntry *current_mesh = mesh->getMeshEntry(first_mesh_index); Mesh::MeshEntry *current_mesh = mesh->getMeshEntry(first_mesh_index);
QVector<unsigned int> regular; QVector<Triangle> all_triangles;
QVector<unsigned int> irregular; qDebug() << current_mesh->buffers[0]->indices_irregular.size() << current_mesh->buffers[0]->indices_regular.size();
ibToTriangles(&current_mesh->buffers[0]->vertices, current_mesh->buffers[0]->indices_irregular, all_triangles);
QVector<unsigned int> old_regular_ib = patchIBToTriangleIB(current_mesh->buffers[0]->indices_regular);
ibToTriangles(&current_mesh->buffers[0]->vertices, old_regular_ib, all_triangles);
qDebug() << all_triangles.size();
findRegular(current_mesh->buffers[0]->indices_irregular, current_mesh->buffers[0]->vertices, regular, irregular); QMap<Triangle, Triangle::Neighbors> neighbors;
findRegular(current_mesh->buffers[0]->indices_regular, current_mesh->buffers[0]->vertices, regular, irregular); buildNeighborsMap(current_mesh->buffers[0]->vertices, all_triangles, neighbors);
QVectorIterator<Triangle> i(all_triangles);
while (i.hasNext()) {
Triangle triangle = i.next();
Triangle::Neighbors ns = neighbors.value(triangle);
if (ns.uv.triangle == NULL) {
qDebug() << qSetRealNumberPrecision(10) << "uv" << triangle;
}
if (ns.vw.triangle == NULL) {
qDebug() << qSetRealNumberPrecision(10) << "vw" << triangle;
}
if (ns.wu.triangle == NULL) {
qDebug() << "wu" << triangle;
}
}
QVector<unsigned int> patches = getPatchIndexBuffer(regular, irregular,current_mesh->buffers[0]->vertices);//TODO is this the corret vertex buffer? QVector<Triangle> regular;
QVector<Triangle> irregular;
findRegular(all_triangles, neighbors, regular, irregular);
QVector<unsigned int> regular_ib;
trianglesToIB(regular, regular_ib);
QVector<unsigned int> irregular_ib;
trianglesToIB(irregular, irregular_ib);
QVector<unsigned int> patches = getPatchIndexBuffer(regular_ib, irregular_ib, current_mesh->buffers[0]->vertices);
current_mesh->buffers[0]->indices_regular = patches; current_mesh->buffers[0]->indices_regular = patches;
current_mesh->buffers[0]->indices_irregular = irregular; current_mesh->buffers[0]->indices_irregular = irregular_ib;
current_mesh->buffers[0]->updateIndices(); current_mesh->buffers[0]->updateIndices();
...@@ -759,50 +798,44 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib) ...@@ -759,50 +798,44 @@ QVector<unsigned int> Subdivision::patchIBToTriangleIB(QVector<unsigned int> ib)
return new_ib; return new_ib;
} }
/** bool isVertexRegular(Triangle &triangle, Triangle::Neighbor current_neighbor, QMap<Triangle, Triangle::Neighbors> neighbors) {
* Generates index buffers containing all regular and all irregular triangles in the input index buffer. unsigned int count = 1;
* while (count < 6 && *current_neighbor.triangle != triangle) {
* @param index_buffer Index buffer describing triangles. count++;
* @param vertex_buffer Vertices used by index_buffer. current_neighbor = neighbors.value(*current_neighbor.triangle).get_neighbor(rotate_edge_name(current_neighbor.edge.name));
* @param regular All regular triangles are appended to this index buffer. }
* @param irregular All irregular triangles are appended to this index buffer. return count == 6 && *current_neighbor.triangle == triangle;
*/ }
void Subdivision::findRegular(QVector<unsigned int> index_buffer, QVector<Vertex> vertex_buffer, QVector<unsigned int> &regular, QVector<unsigned int> &irregular) {
QTime totalTimer; void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QVector<Triangle> &regular, QVector<Triangle> &irregular) {
totalTimer.start(); QTime timer;
qCDebug(log_timing)<<"Find Regular started"; timer.start();
for (int i = 0; i < index_buffer.length()-2; i += 3){ qCDebug(log_timing) << "findRegular started";
Vertex vx = vertex_buffer[index_buffer[i]];
Vertex vy = vertex_buffer[index_buffer[i+1]]; QVectorIterator<Triangle> it(triangles);
Vertex vz = vertex_buffer[index_buffer[i+2]]; while (it.hasNext()) {
Triangle triangle = it.next();
int countx = 0; Triangle::Neighbors ns = neighbors.value(triangle);
int county = 0;
int countz = 0; bool is_regular = true;
for (int j = 0; j < index_buffer.length(); j++){ if (!isVertexRegular(triangle, ns.uv, neighbors)) {
if (j != i && j != i+1 && j != i+2){ is_regular = false;
if (vx.samePos(vertex_buffer[index_buffer[j]])){ }
countx++; if (is_regular && !isVertexRegular(triangle, ns.vw, neighbors)) {
} is_regular = false;
if (vy.samePos(vertex_buffer[index_buffer[j]])){
county++;
}
if (vz.samePos(vertex_buffer[index_buffer[j]])){
countz++;
}
}
} }
if (countx == 5 && county == 5 && countz == 5){ if (is_regular && !isVertexRegular(triangle, ns.wu, neighbors)) {
regular.push_back(index_buffer[i]); is_regular = false;
regular.push_back(index_buffer[i+1]); }
regular.push_back(index_buffer[i+2]);
if (is_regular) {
regular.push_back(triangle);
} else { } else {
irregular.push_back(index_buffer[i]); irregular.push_back(triangle);
irregular.push_back(index_buffer[i+1]);
irregular.push_back(index_buffer[i+2]);
} }
} }
qCDebug(log_timing)<<"Find Regular done:"<<formatTimeMeasurement(totalTimer.elapsed());
qCDebug(log_timing) << "findRegular done:" << formatTimeMeasurement(timer.elapsed());
} }
Subdivision::Result Subdivision::runShader(Input input, Tables &tables) { Subdivision::Result Subdivision::runShader(Input input, Tables &tables) {
......
...@@ -62,7 +62,7 @@ private: ...@@ -62,7 +62,7 @@ private:
void precomputeEdgeTable(Subdivision::Tables &tables, QVector<Triangle> &triangles, QMap<Triangle, Triangle::Neighbors> &neighbors, unsigned int offset); 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 precomputeVertexTable(Subdivision::Tables &tables, Input &input, QMap<unsigned int, unsigned int> &modified_vertices);
void updateIndexBuffer(QVector<unsigned int> &index_buffer, QMap<unsigned int, unsigned int> map); void updateIndexBuffer(QVector<unsigned int> &index_buffer, QMap<unsigned int, unsigned int> map);
void findRegular(QVector<unsigned int> index_buffer, QVector<Vertex> vertex_buffer, QVector<unsigned int> &regular, QVector<unsigned int> &irregular); void findRegular(QVector<Triangle> triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QVector<Triangle> &regular, QVector<Triangle> &irregular);
Result runShader(Input input, Tables &tables); Result runShader(Input input, Tables &tables);
void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out); void runCopyShader(GLuint size, GLuint vb_in, GLuint vb_out);
void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle); void runVertexShader(GLuint size, GLuint vb_handle, GLuint vertex_indices_handle, GLuint vertex_offsets_handle, GLuint output_handle, GLuint offset_handle);
......
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