diff --git a/src/meshgenerator.cpp b/src/meshgenerator.cpp index ca5925ae..ac35d565 100644 --- a/src/meshgenerator.cpp +++ b/src/meshgenerator.cpp @@ -45,7 +45,7 @@ void MeshGenerator::addPreviewRequirement() void MeshGenerator::addPartPreviewRequirement(const QString &partId) { - qDebug() << "addPartPreviewRequirement:" << partId; + //qDebug() << "addPartPreviewRequirement:" << partId; m_requirePartPreviewMap.insert(partId); if (m_partPreviewRenderMap.find(partId) == m_partPreviewRenderMap.end()) { ModelOfflineRender *render = new ModelOfflineRender; @@ -104,13 +104,13 @@ void MeshGenerator::process() float originZ = valueOfKeyInMapOrEmpty(m_snapshot->canvas, "originZ").toFloat(); bool originSettled = false; if (originX > 0 && originY > 0 && originZ > 0) { - qDebug() << "Use settled origin: " << originX << originY << originZ << " calculated:" << mainProfileMiddleX << mainProfileMiddleY << sideProfileMiddleX; + //qDebug() << "Use settled origin: " << originX << originY << originZ << " calculated:" << mainProfileMiddleX << mainProfileMiddleY << sideProfileMiddleX; mainProfileMiddleX = originX; mainProfileMiddleY = originY; sideProfileMiddleX = originZ; originSettled = true; } else { - qDebug() << "No settled origin, calculated:" << mainProfileMiddleX << mainProfileMiddleY << sideProfileMiddleX; + //qDebug() << "No settled origin, calculated:" << mainProfileMiddleX << mainProfileMiddleY << sideProfileMiddleX; } for (const auto &partIdIt: m_snapshot->partIdList) { @@ -131,7 +131,7 @@ void MeshGenerator::process() QString partId = valueOfKeyInMapOrEmpty(edgeIt.second, "partId"); QString fromNodeId = valueOfKeyInMapOrEmpty(edgeIt.second, "from"); QString toNodeId = valueOfKeyInMapOrEmpty(edgeIt.second, "to"); - qDebug() << "Processing edge " << fromNodeId << "<=>" << toNodeId; + //qDebug() << "Processing edge " << fromNodeId << "<=>" << toNodeId; const auto fromIt = m_snapshot->nodes.find(fromNodeId); const auto toIt = m_snapshot->nodes.find(toNodeId); if (fromIt == m_snapshot->nodes.end() || toIt == m_snapshot->nodes.end()) @@ -149,11 +149,11 @@ void MeshGenerator::process() float y = (valueOfKeyInMapOrEmpty(fromIt->second, "y").toFloat() - mainProfileMiddleY) / longHeight; float z = (valueOfKeyInMapOrEmpty(fromIt->second, "z").toFloat() - sideProfileMiddleX) / longHeight; bmeshFromNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, radius); - qDebug() << "bmeshId[" << bmeshId << "] add node[" << bmeshFromNodeId << "]" << radius << x << y << z; + //qDebug() << "bmeshId[" << bmeshId << "] add node[" << bmeshFromNodeId << "]" << radius << x << y << z; bmeshNodeMap[fromNodeId] = bmeshFromNodeId; } else { bmeshFromNodeId = bmeshFromIt->second; - qDebug() << "bmeshId[" << bmeshId << "] use existed node[" << bmeshFromNodeId << "]"; + //qDebug() << "bmeshId[" << bmeshId << "] use existed node[" << bmeshFromNodeId << "]"; } int bmeshToNodeId = 0; @@ -164,11 +164,11 @@ void MeshGenerator::process() float y = (valueOfKeyInMapOrEmpty(toIt->second, "y").toFloat() - mainProfileMiddleY) / longHeight; float z = (valueOfKeyInMapOrEmpty(toIt->second, "z").toFloat() - sideProfileMiddleX) / longHeight; bmeshToNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, radius); - qDebug() << "bmeshId[" << bmeshId << "] add node[" << bmeshToNodeId << "]" << radius << x << y << z; + //qDebug() << "bmeshId[" << bmeshId << "] add node[" << bmeshToNodeId << "]" << radius << x << y << z; bmeshNodeMap[toNodeId] = bmeshToNodeId; } else { bmeshToNodeId = bmeshToIt->second; - qDebug() << "bmeshId[" << bmeshId << "] use existed node[" << bmeshToNodeId << "]"; + //qDebug() << "bmeshId[" << bmeshId << "] use existed node[" << bmeshToNodeId << "]"; } meshlite_bmesh_add_edge(meshliteContext, bmeshId, bmeshFromNodeId, bmeshToNodeId); @@ -188,7 +188,7 @@ void MeshGenerator::process() float y = (valueOfKeyInMapOrEmpty(nodeIt.second, "y").toFloat() - mainProfileMiddleY) / longHeight; float z = (valueOfKeyInMapOrEmpty(nodeIt.second, "z").toFloat() - sideProfileMiddleX) / longHeight; int bmeshNodeId = meshlite_bmesh_add_node(meshliteContext, bmeshId, x, y, z, radius); - qDebug() << "bmeshId[" << bmeshId << "] add lonely node[" << bmeshNodeId << "]" << radius << x << y << z; + //qDebug() << "bmeshId[" << bmeshId << "] add lonely node[" << bmeshNodeId << "]" << radius << x << y << z; bmeshNodeMap[nodeIt.first] = bmeshNodeId; } @@ -259,8 +259,8 @@ void MeshGenerator::process() } else { mergedMeshId = subdivMeshIds[0]; } - if (mergedMeshId > 0) - mergedMeshId = meshlite_combine_coplanar_faces(meshliteContext, mergedMeshId); + //if (mergedMeshId > 0) + // mergedMeshId = meshlite_combine_coplanar_faces(meshliteContext, mergedMeshId); if (mergedMeshId > 0) { int errorCount = 0; int subdivedMeshId = subdivMesh(meshliteContext, mergedMeshId, &errorCount); @@ -283,8 +283,8 @@ void MeshGenerator::process() mergedMeshId = unionMeshs(meshliteContext, meshIds, &errorCount); if (errorCount) broken = true; - else if (mergedMeshId > 0) - mergedMeshId = meshlite_combine_coplanar_faces(meshliteContext, mergedMeshId); + //else if (mergedMeshId > 0) + // mergedMeshId = meshlite_combine_coplanar_faces(meshliteContext, mergedMeshId); } else if (meshIds.size() > 0) { mergedMeshId = meshIds[0]; } diff --git a/src/meshutil.cpp b/src/meshutil.cpp index 69a807d2..18f74cc5 100644 --- a/src/meshutil.cpp +++ b/src/meshutil.cpp @@ -1,3 +1,4 @@ +#include #include "meshutil.h" #include "meshlite.h" @@ -12,6 +13,7 @@ // https://github.com/CGAL/cgal/issues/2875 // https://doc.cgal.org/latest/Polygon_mesh_processing/Polygon_mesh_processing_2hausdorff_distance_remeshing_example_8cpp-example.html#a3 // https://github.com/CGAL/cgal/blob/master/Subdivision_method_3/examples/Subdivision_method_3/CatmullClark_subdivision.cpp +// https://doc.cgal.org/latest/Polygon_mesh_processing/index.html#title25 #include #include #include @@ -146,18 +148,22 @@ int unionMeshs(void *meshliteContext, const std::vector &meshIds, int *erro std::vector externalMeshs; for (size_t i = 0; i < meshIds.size(); i++) { int triangledMeshId = meshlite_triangulate(meshliteContext, meshIds[i]); - if (meshlite_is_triangulated_manifold(meshliteContext, triangledMeshId)) - externalMeshs.push_back(makeCgalMeshFromMeshlite(meshliteContext, triangledMeshId)); + if (!meshlite_is_triangulated_manifold(meshliteContext, triangledMeshId)) + qDebug() << "Mesh is not manifold after triangulated:" << triangledMeshId; + externalMeshs.push_back(makeCgalMeshFromMeshlite(meshliteContext, triangledMeshId)); } if (externalMeshs.size() > 0) { ExactMesh *mergedExternalMesh = externalMeshs[0]; for (size_t i = 1; i < externalMeshs.size(); i++) { - if (!mergedExternalMesh) + if (!mergedExternalMesh) { + qDebug() << "Last union failed, break with remains unprocessed:" << (externalMeshs.size() - i); break; + } ExactMesh *unionedExternalMesh = NULL; try { unionedExternalMesh = unionCgalMeshs(mergedExternalMesh, externalMeshs[i]); } catch (...) { + qDebug() << "unionCgalMeshs throw exception"; if (errorCount) (*errorCount)++; } @@ -165,10 +171,21 @@ int unionMeshs(void *meshliteContext, const std::vector &meshIds, int *erro if (unionedExternalMesh) { delete mergedExternalMesh; mergedExternalMesh = unionedExternalMesh; + } else { + if (errorCount) + (*errorCount)++; + qDebug() << "unionCgalMeshs failed"; } } if (mergedExternalMesh) { int mergedMeshId = makeMeshliteMeshFromCgal(meshliteContext, mergedExternalMesh); + if (mergedMeshId) + mergedMeshId = fixMeshHoles(meshliteContext, mergedMeshId); + else { + if (errorCount) + (*errorCount)++; + qDebug() << "makeMeshliteMeshFromCgal failed"; + } delete mergedExternalMesh; return mergedMeshId; } @@ -206,8 +223,15 @@ int subdivMesh(void *meshliteContext, int meshId, int *errorCount) } if (simpleMesh) delete simpleMesh; + if (subdiviedMeshId) + subdiviedMeshId = fixMeshHoles(meshliteContext, subdiviedMeshId); return subdiviedMeshId; #endif } return meshlite_subdivide(meshliteContext, meshId); } + +int fixMeshHoles(void *meshliteContext, int meshId) +{ + return meshlite_fix_hole(meshliteContext, meshId); +} diff --git a/src/meshutil.h b/src/meshutil.h index b8b207c7..bcb4145d 100644 --- a/src/meshutil.h +++ b/src/meshutil.h @@ -5,5 +5,6 @@ int mergeMeshs(void *meshliteContext, const std::vector &meshIds); int unionMeshs(void *meshliteContext, const std::vector &meshIds, int *errorCount=0); int subdivMesh(void *meshliteContext, int meshId, int *errorCount=0); +int fixMeshHoles(void *meshliteContext, int meshId); #endif diff --git a/src/modelofflinerender.cpp b/src/modelofflinerender.cpp index 385186df..ff3ef06b 100644 --- a/src/modelofflinerender.cpp +++ b/src/modelofflinerender.cpp @@ -104,8 +104,6 @@ QImage ModelOfflineRender::toImage(const QSize &size) m_context->functions()->glFlush(); image = renderFbo->toImage(); - - qDebug() << "Generated image size:" << image.size(); renderFbo->bindDefault(); delete renderFbo; diff --git a/src/skeletonsnapshot.cpp b/src/skeletonsnapshot.cpp index ac7cd675..f476c2f8 100644 --- a/src/skeletonsnapshot.cpp +++ b/src/skeletonsnapshot.cpp @@ -50,9 +50,9 @@ void SkeletonSnapshot::resolveBoundingBox(QRectF *mainProfile, QRectF *sideProfi } *mainProfile = QRectF(QPointF(left, top), QPointF(right, bottom)); *sideProfile = QRectF(QPointF(zLeft, top), QPointF(zRight, bottom)); - qDebug() << "resolveBoundingBox left:" << left << "top:" << top << "right:" << right << "bottom:" << bottom << " zLeft:" << zLeft << "zRight:" << zRight; - qDebug() << "mainHeight:" << mainProfile->height() << "mainWidth:" << mainProfile->width(); - qDebug() << "sideHeight:" << sideProfile->height() << "sideWidth:" << sideProfile->width(); + //qDebug() << "resolveBoundingBox left:" << left << "top:" << top << "right:" << right << "bottom:" << bottom << " zLeft:" << zLeft << "zRight:" << zRight; + //qDebug() << "mainHeight:" << mainProfile->height() << "mainWidth:" << mainProfile->width(); + //qDebug() << "sideHeight:" << sideProfile->height() << "sideWidth:" << sideProfile->width(); } diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll old mode 100755 new mode 100644 index 293050b6..d9078df0 Binary files a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll and b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll differ diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll.lib b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll.lib old mode 100755 new mode 100644 index 93f58b64..89490bac Binary files a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll.lib and b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.dll.lib differ diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.h b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.h old mode 100755 new mode 100644 index 13dc7e04..99b3cfd7 --- a/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.h +++ b/thirdparty/meshlite/meshlite_unstable_vc14_x64/meshlite.h @@ -44,6 +44,7 @@ int meshlite_combine_coplanar_faces(void *context, int mesh_id); int meshlite_trim(void *context, int mesh_id, int normalize); int meshlite_mirror_in_x(void *context, int mesh_id, float center_x); int meshlite_mirror_in_z(void *context, int mesh_id, float center_z); +int meshlite_fix_hole(void *context, int mesh_id); #ifdef __cplusplus } diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll old mode 100755 new mode 100644 index ac58c9e3..36119e92 Binary files a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll and b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll differ diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll.lib b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll.lib old mode 100755 new mode 100644 index 1ebab955..311f314b Binary files a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll.lib and b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.dll.lib differ diff --git a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.h b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.h old mode 100755 new mode 100644 index 13dc7e04..99b3cfd7 --- a/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.h +++ b/thirdparty/meshlite/meshlite_unstable_vc14_x86/meshlite.h @@ -44,6 +44,7 @@ int meshlite_combine_coplanar_faces(void *context, int mesh_id); int meshlite_trim(void *context, int mesh_id, int normalize); int meshlite_mirror_in_x(void *context, int mesh_id, float center_x); int meshlite_mirror_in_z(void *context, int mesh_id, float center_z); +int meshlite_fix_hole(void *context, int mesh_id); #ifdef __cplusplus }