From f8e2cf80646dec3244ef788457c64d12e7567b7c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 20 May 2016 18:47:06 -0700 Subject: [PATCH] cleanup vhacd-util logging and variable names --- tools/vhacd-util/src/VHACDUtil.cpp | 89 +++++++++++++-------------- tools/vhacd-util/src/VHACDUtil.h | 2 +- tools/vhacd-util/src/VHACDUtilApp.cpp | 35 +++++------ 3 files changed, 60 insertions(+), 66 deletions(-) diff --git a/tools/vhacd-util/src/VHACDUtil.cpp b/tools/vhacd-util/src/VHACDUtil.cpp index 57ad185f45..b21c2ee01e 100644 --- a/tools/vhacd-util/src/VHACDUtil.cpp +++ b/tools/vhacd-util/src/VHACDUtil.cpp @@ -33,7 +33,7 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, FBXGeometry& result) { if (!fbx.open(QIODevice::ReadOnly)) { return false; } - std::cout << "Reading FBX.....\n"; + qDebug() << "reading FBX file =" << filename << "..."; try { QByteArray fbxContents = fbx.readAll(); FBXGeometry* geom; @@ -182,31 +182,34 @@ AABox getAABoxForMeshPart(const FBXMesh& mesh, const FBXMeshPart &meshPart) { bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, VHACD::IVHACD::Parameters params, FBXGeometry& result, - int startMeshIndex, - int endMeshIndex, + int startPartIndex, + int endPartIndex, float minimumMeshSize, float maximumMeshSize) { + qDebug() << "num meshes =" << geometry.meshes.size(); + // count the mesh-parts - int meshCount = 0; + int numParts = 0; foreach (const FBXMesh& mesh, geometry.meshes) { - meshCount += mesh.parts.size(); + numParts += mesh.parts.size(); } VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD(); - if (startMeshIndex < 0) { - startMeshIndex = 0; + if (startPartIndex < 0) { + startPartIndex = 0; } - if (endMeshIndex < 0) { - endMeshIndex = meshCount; + if (endPartIndex < 0) { + endPartIndex = numParts; } - - std::cout << "Performing V-HACD computation on " << endMeshIndex - startMeshIndex << " meshes ..... " << std::endl; + qDebug() << "num parts of interest =" << (endPartIndex - startPartIndex); result.meshExtents.reset(); result.meshes.append(FBXMesh()); FBXMesh &resultMesh = result.meshes.last(); - int count = 0; + int meshIndex = 0; + int partIndex = 0; + int validPartsFound = 0; foreach (const FBXMesh& mesh, geometry.meshes) { // each mesh has its own transform to move it to model-space @@ -214,51 +217,55 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, foreach (glm::vec3 vertex, mesh.vertices) { vertices.push_back(glm::vec3(mesh.modelTransform * glm::vec4(vertex, 1.0f))); } + auto numVertices = vertices.size(); + + qDebug() << "mesh" << meshIndex << ": " + << " parts =" << mesh.parts.size() << " clusters =" << mesh.clusters.size() + << " vertices =" << numVertices; + ++meshIndex; foreach (const FBXMeshPart &meshPart, mesh.parts) { - - if (count < startMeshIndex || count >= endMeshIndex) { - count ++; + if (partIndex < startPartIndex || partIndex >= endPartIndex) { + ++partIndex; continue; } - qDebug() << "--------------------"; - std::vector triangles; unsigned int triangleCount = getTrianglesInMeshPart(meshPart, triangles); // only process meshes with triangles if (triangles.size() <= 0) { - qDebug() << " Skipping (no triangles)..."; - count++; + qDebug() << " part" << partIndex << ":"; + qDebug() << " skip (zero triangles)"; + ++partIndex; continue; } - auto nPoints = vertices.size(); AABox aaBox = getAABoxForMeshPart(mesh, meshPart); const float largestDimension = aaBox.getLargestDimension(); - qDebug() << "Mesh " << count << " -- " << nPoints << " points, " << triangleCount << " triangles, " - << "size =" << largestDimension; + qDebug() << " part" << partIndex << ": " + << " triangles =" << triangleCount + << " largestDimension =" << largestDimension; if (largestDimension < minimumMeshSize) { - qDebug() << " Skipping (too small)..."; - count++; + qDebug() << " skip (too small)"; + ++partIndex; continue; } if (maximumMeshSize > 0.0f && largestDimension > maximumMeshSize) { - qDebug() << " Skipping (too large)..."; - count++; + qDebug() << " skip (too large)"; + ++partIndex; continue; } // compute approximate convex decomposition - bool res = interfaceVHACD->Compute(&vertices[0].x, 3, (uint)nPoints, &triangles[0], 3, triangleCount, params); - if (!res){ - qDebug() << "V-HACD computation failed for Mesh : " << count; - count++; + bool success = interfaceVHACD->Compute(&vertices[0].x, 3, (uint)numVertices, &triangles[0], 3, triangleCount, params); + if (!success){ + qDebug() << " failed to convexify"; + ++partIndex; continue; } @@ -290,8 +297,8 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, resultMeshPart.triangleIndices.append(index2); } } - - count++; + ++partIndex; + ++validPartsFound; } } @@ -299,12 +306,7 @@ bool vhacd::VHACDUtil::computeVHACD(FBXGeometry& geometry, interfaceVHACD->Clean(); interfaceVHACD->Release(); - if (count > 0){ - return true; - } - else{ - return false; - } + return validPartsFound > 0; } vhacd::VHACDUtil:: ~VHACDUtil(){ @@ -319,16 +321,9 @@ void vhacd::ProgressCallback::Update(const double overallProgress, const char* const operation) { int progress = (int)(overallProgress + 0.5); - if (progress < 10){ - std::cout << "\b\b"; - } - else{ - std::cout << "\b\b\b"; - } - + std::cout << "\b\b\b"; std::cout << progress << "%"; - - if (progress >= 100){ + if (progress >= 100) { std::cout << std::endl; } } diff --git a/tools/vhacd-util/src/VHACDUtil.h b/tools/vhacd-util/src/VHACDUtil.h index 34c2c22e0e..f394301839 100644 --- a/tools/vhacd-util/src/VHACDUtil.h +++ b/tools/vhacd-util/src/VHACDUtil.h @@ -34,7 +34,7 @@ namespace vhacd { bool computeVHACD(FBXGeometry& geometry, VHACD::IVHACD::Parameters params, FBXGeometry& result, - int startMeshIndex, int endMeshIndex, + int startPartIndex, int endPartIndex, float minimumMeshSize, float maximumMeshSize); ~VHACDUtil(); }; diff --git a/tools/vhacd-util/src/VHACDUtilApp.cpp b/tools/vhacd-util/src/VHACDUtilApp.cpp index 2af6bca337..81eb6b399d 100644 --- a/tools/vhacd-util/src/VHACDUtilApp.cpp +++ b/tools/vhacd-util/src/VHACDUtilApp.cpp @@ -301,17 +301,17 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) : Q_UNREACHABLE(); } - - // load the mesh - + // load the mesh FBXGeometry fbx; auto begin = std::chrono::high_resolution_clock::now(); if (!vUtil.loadFBX(inputFilename, fbx)){ - cout << "Error in opening FBX file...."; + qDebug() << "error reading input file" << inputFilename; + return; } auto end = std::chrono::high_resolution_clock::now(); auto loadDuration = std::chrono::duration_cast(end - begin).count(); + qDebug() << "load time =" << (double)loadDuration / 1000000000.00 << "seconds"; if (splitModel) { QVector infileExtensions = {"fbx", "obj"}; @@ -352,38 +352,37 @@ VHACDUtilApp::VHACDUtilApp(int argc, char* argv[]) : params.m_oclAcceleration = true; // true //perform vhacd computation + qDebug() << "running V-HACD algorithm ..."; begin = std::chrono::high_resolution_clock::now(); FBXGeometry result; - if (!vUtil.computeVHACD(fbx, params, result, startMeshIndex, endMeshIndex, - minimumMeshSize, maximumMeshSize)) { - cout << "Compute Failed..."; - } + bool success = vUtil.computeVHACD(fbx, params, result, startMeshIndex, endMeshIndex, minimumMeshSize, maximumMeshSize); + end = std::chrono::high_resolution_clock::now(); auto computeDuration = std::chrono::duration_cast(end - begin).count(); + qDebug() << "run time =" << (double)computeDuration / 1000000000.00 << " seconds"; + + if (!success) { + qDebug() << "failed to convexify model"; + return; + } int totalVertices = 0; int totalTriangles = 0; - int totalMeshParts = 0; foreach (const FBXMesh& mesh, result.meshes) { totalVertices += mesh.vertices.size(); foreach (const FBXMeshPart &meshPart, mesh.parts) { totalTriangles += meshPart.triangleIndices.size() / 3; // each quad was made into two triangles totalTriangles += 2 * meshPart.quadIndices.size() / 4; - totalMeshParts++; } } int totalHulls = result.meshes[0].parts.size(); - cout << endl << "Summary of V-HACD Computation..................." << endl; - cout << "File Path : " << inputFilename.toStdString() << endl; - cout << "Number Of Meshes : " << totalMeshParts << endl; - cout << "Total vertices : " << totalVertices << endl; - cout << "Total Triangles : " << totalTriangles << endl; - cout << "Total Convex Hulls : " << totalHulls << endl; - cout << "Total FBX load time: " << (double)loadDuration / 1000000000.00 << " seconds" << endl; - cout << "V-HACD Compute time: " << (double)computeDuration / 1000000000.00 << " seconds" << endl; + qDebug() << "output file =" << outputFilename; + qDebug() << "vertices =" << totalVertices; + qDebug() << "triangles =" << totalTriangles; + qDebug() << "hulls =" << totalHulls; writeOBJ(outputFilename, result, outputCentimeters); }