Commit b4a91fe7 by Philipp Adolf

Merge branch '9-findregular-ist-langsam' into 'patchRender'

Resolve "findRegular ist langsam" Closes #9 See merge request !8
parents 0fb2b6dd d029fb25
...@@ -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();
QMap<Triangle, Triangle::Neighbors> neighbors;
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;
}
}
findRegular(current_mesh->buffers[0]->indices_irregular, current_mesh->buffers[0]->vertices, regular, irregular); QVector<Triangle> regular;
findRegular(current_mesh->buffers[0]->indices_regular, current_mesh->buffers[0]->vertices, regular, irregular); QVector<Triangle> irregular;
findRegular(all_triangles, neighbors, regular, irregular);
QVector<unsigned int> patches = getPatchIndexBuffer(regular, irregular,current_mesh->buffers[0]->vertices);//TODO is this the corret vertex buffer? 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.
*/
void Subdivision::findRegular(QVector<unsigned int> index_buffer, QVector<Vertex> vertex_buffer, QVector<unsigned int> &regular, QVector<unsigned int> &irregular) {
QTime totalTimer;
totalTimer.start();
qCDebug(log_timing)<<"Find Regular started";
for (int i = 0; i < index_buffer.length()-2; i += 3){
Vertex vx = vertex_buffer[index_buffer[i]];
Vertex vy = vertex_buffer[index_buffer[i+1]];
Vertex vz = vertex_buffer[index_buffer[i+2]];
int countx = 0;
int county = 0;
int countz = 0;
for (int j = 0; j < index_buffer.length(); j++){
if (j != i && j != i+1 && j != i+2){
if (vx.samePos(vertex_buffer[index_buffer[j]])){
countx++;
} }
if (vy.samePos(vertex_buffer[index_buffer[j]])){ return count == 6 && *current_neighbor.triangle == triangle;
county++; }
}
if (vz.samePos(vertex_buffer[index_buffer[j]])){ void Subdivision::findRegular(QVector<Triangle> triangles, QMap<Triangle, Triangle::Neighbors> neighbors, QVector<Triangle> &regular, QVector<Triangle> &irregular) {
countz++; QTime timer;
timer.start();
qCDebug(log_timing) << "findRegular started";
QVectorIterator<Triangle> it(triangles);
while (it.hasNext()) {
Triangle triangle = it.next();
Triangle::Neighbors ns = neighbors.value(triangle);
bool is_regular = true;
if (!isVertexRegular(triangle, ns.uv, neighbors)) {
is_regular = false;
} }
if (is_regular && !isVertexRegular(triangle, ns.vw, neighbors)) {
is_regular = false;
} }
if (is_regular && !isVertexRegular(triangle, ns.wu, neighbors)) {
is_regular = false;
} }
if (countx == 5 && county == 5 && countz == 5){
regular.push_back(index_buffer[i]); if (is_regular) {
regular.push_back(index_buffer[i+1]); regular.push_back(triangle);
regular.push_back(index_buffer[i+2]);
} 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);
......
...@@ -192,6 +192,17 @@ void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Trian ...@@ -192,6 +192,17 @@ void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Trian
} }
} }
void trianglesToIB(const QVector<Triangle> &triangles, QVector<unsigned int> &ib) {
ib.reserve(ib.length() + triangles.length() * 3);
QVectorIterator<Triangle> it(triangles);
while (it.hasNext()) {
Triangle triangle = it.next();
ib.push_back(triangle.u_idx());
ib.push_back(triangle.v_idx());
ib.push_back(triangle.w_idx());
}
}
Triangle::Neighbor Triangle::Neighbors::get_neighbor(Triangle::Edge::Name name) const { Triangle::Neighbor Triangle::Neighbors::get_neighbor(Triangle::Edge::Name name) const {
switch (name) { switch (name) {
case Triangle::Edge::Name::uv: case Triangle::Edge::Name::uv:
......
...@@ -73,6 +73,7 @@ class Triangle { ...@@ -73,6 +73,7 @@ class Triangle {
Triangle::Edge::Name rotate_edge_name(Triangle::Edge::Name edge); Triangle::Edge::Name rotate_edge_name(Triangle::Edge::Name edge);
void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Triangle> &triangles); void ibToTriangles(QVector<Vertex> *vb, QVector<unsigned int> &ib, QVector<Triangle> &triangles);
void trianglesToIB(const QVector<Triangle> &triangles, QVector<unsigned int> &ib);
QDebug operator<<(QDebug d, const Triangle &triangle); QDebug operator<<(QDebug d, const Triangle &triangle);
......
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