From c15c549881c8e6c5aaace851a37142d361b4effd Mon Sep 17 00:00:00 2001 From: Virendra Singh Date: Wed, 25 Feb 2015 07:47:00 +0530 Subject: [PATCH 1/2] Code formatting --- tools/vhacd/src/VHACDUtil.cpp | 29 ++++++++++------------------- tools/vhacd/src/VHACDUtil.h | 3 +-- tools/vhacd/src/main.cpp | 24 ++++++++---------------- 3 files changed, 19 insertions(+), 37 deletions(-) diff --git a/tools/vhacd/src/VHACDUtil.cpp b/tools/vhacd/src/VHACDUtil.cpp index bfcdb74634..dcfd7e447f 100644 --- a/tools/vhacd/src/VHACDUtil.cpp +++ b/tools/vhacd/src/VHACDUtil.cpp @@ -9,13 +9,12 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include +#include #include "VHACDUtil.h" //Read all the meshes from provided FBX file -bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results) -{ +bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results){ // open the fbx file QFile fbx(filename); @@ -29,15 +28,13 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re //results->meshCount = geometry.meshes.count(); int count = 0; - foreach(FBXMesh mesh, geometry.meshes) - { + foreach(FBXMesh mesh, geometry.meshes) { //get vertices for each mesh QVector vertices = mesh.vertices; //get the triangle indices for each mesh QVector triangles; - foreach(FBXMeshPart part, mesh.parts) - { + foreach(FBXMeshPart part, mesh.parts) { QVector indices = part.triangleIndices; triangles += indices; } @@ -54,15 +51,13 @@ bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *re return true; } -bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const -{ +bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const{ VHACD::IVHACD * interfaceVHACD = VHACD::CreateVHACD(); int meshCount = meshes->meshCount; int count = 0; std::cout << "Performing V-HACD computation on " << meshCount <<" meshes ..... " << std::endl; - for (int i = 0; i < meshCount; i++) - { + for (int i = 0; i < meshCount; i++){ std::vector vertices = meshes->perMeshVertices.at(i).toStdVector(); std::vector triangles = meshes->perMeshTriangleIndices.at(i).toStdVector(); @@ -71,8 +66,7 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD std::cout << "Mesh " << i + 1 << " : "; // compute approximate convex decomposition bool res = interfaceVHACD->Compute(&vertices[0].x, 3, nPoints, &triangles[0], 3, nTriangles, params); - if (!res) - { + if (!res){ std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl; continue; } @@ -84,8 +78,7 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD //get all the convex hulls for this mesh QVector convexHulls; - for (unsigned int j = 0; j < nConvexHulls; j++) - { + for (unsigned int j = 0; j < nConvexHulls; j++){ VHACD::IVHACD::ConvexHull hull; interfaceVHACD->GetConvexHull(j, hull); convexHulls.append(hull); @@ -105,14 +98,12 @@ bool vhacd::VHACDUtil::computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD return false; } -vhacd::VHACDUtil:: ~VHACDUtil() -{ +vhacd::VHACDUtil:: ~VHACDUtil(){ //nothing to be cleaned } //ProgressClaback implementation -void vhacd::ProgressCallback::Update(const double overallProgress, const double stageProgress, const double operationProgress, const char * const stage, const char * const operation) -{ +void vhacd::ProgressCallback::Update(const double overallProgress, const double stageProgress, const double operationProgress, const char * const stage, const char * const operation){ int progress = (int)(overallProgress + 0.5); if (progress < 10) diff --git a/tools/vhacd/src/VHACDUtil.h b/tools/vhacd/src/VHACDUtil.h index a9df5d7f2a..aaabcdf904 100644 --- a/tools/vhacd/src/VHACDUtil.h +++ b/tools/vhacd/src/VHACDUtil.h @@ -42,8 +42,7 @@ namespace vhacd{ ~VHACDUtil(); }; - class ProgressCallback : public VHACD::IVHACD::IUserCallback - { + class ProgressCallback : public VHACD::IVHACD::IUserCallback{ public: ProgressCallback(void); ~ProgressCallback(); diff --git a/tools/vhacd/src/main.cpp b/tools/vhacd/src/main.cpp index 55a152c179..a80a57bb3e 100644 --- a/tools/vhacd/src/main.cpp +++ b/tools/vhacd/src/main.cpp @@ -19,8 +19,7 @@ using namespace std; using namespace VHACD; -int main(int argc, char * argv[]) -{ +int main(int argc, char * argv[]){ vector triangles; // array of indexes vector points; // array of coordinates vhacd::VHACDUtil vUtil; @@ -44,34 +43,29 @@ int main(int argc, char * argv[]) params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls // load the mesh - if (!vUtil.loadFBX(fname, &fbx)) - { + if (!vUtil.loadFBX(fname, &fbx)){ cout << "Error in opening FBX file...."; return 1; } - if (!vUtil.computeVHACD(&fbx, params, &results)) - { + if (!vUtil.computeVHACD(&fbx, params, &results)){ cout << "Compute Failed..."; return 1; } int totalVertices = 0; - for (int i = 0; i < fbx.meshCount; i++) - { + for (int i = 0; i < fbx.meshCount; i++){ totalVertices += fbx.perMeshVertices.at(i).count(); } int totalTriangles = 0; - for (int i = 0; i < fbx.meshCount; i++) - { + for (int i = 0; i < fbx.meshCount; i++){ totalTriangles += fbx.perMeshTriangleIndices.at(i).count(); } int totalHulls = 0; QVector hullCounts = results.convexHullsCountList; - for (int i = 0; i < results.meshCount; i++) - { + for (int i = 0; i < results.meshCount; i++){ totalHulls += hullCounts.at(i); } cout << endl << "Summary of V-HACD Computation..................." << endl; @@ -82,14 +76,12 @@ int main(int argc, char * argv[]) cout << "Total Triangles : " << totalTriangles << endl; cout << "Total Convex Hulls : " << totalHulls << endl; cout << endl << "Summary per convex hull ........................" << endl < chList = results.convexHullList.at(i); cout << "\t" << "Number Of Hulls : " << chList.count() << endl; - for (int j = 0; j < results.convexHullList.at(i).count(); j++) - { + for (int j = 0; j < results.convexHullList.at(i).count(); j++){ cout << "\tHUll : " << j + 1 << endl; cout << "\t\tNumber Of Points : " << chList.at(j).m_nPoints << endl; From 9a153a6506cb6a70da655176daaf58a36261b595 Mon Sep 17 00:00:00 2001 From: Virendra Singh Date: Wed, 25 Feb 2015 08:36:58 +0530 Subject: [PATCH 2/2] Time measurement Used c++11 chrono class to measure elapsed time. --- tools/vhacd/src/VHACDUtil.h | 2 +- tools/vhacd/src/main.cpp | 19 +++++++++++++++++-- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/tools/vhacd/src/VHACDUtil.h b/tools/vhacd/src/VHACDUtil.h index aaabcdf904..036d4ce526 100644 --- a/tools/vhacd/src/VHACDUtil.h +++ b/tools/vhacd/src/VHACDUtil.h @@ -16,7 +16,7 @@ #include #include #include - +#include //c++11 feature #include #include #include diff --git a/tools/vhacd/src/main.cpp b/tools/vhacd/src/main.cpp index a80a57bb3e..31866a7cfc 100644 --- a/tools/vhacd/src/main.cpp +++ b/tools/vhacd/src/main.cpp @@ -27,9 +27,14 @@ int main(int argc, char * argv[]){ vhacd::ComputeResults results; // results after computing vhacd VHACD::IVHACD::Parameters params; vhacd::ProgressCallback pCallBack; - - QString fname = "F:/models/ship/Sample_Ship.fbx"; + string filename(argv[1]); + if (filename.empty()){ + cout << "please provide a FBX file as argument\n "; + return 1; + } + + QString fname = QString::fromStdString(filename); //set parameters for V-HACD params.m_callback = &pCallBack; //progress callback @@ -43,15 +48,23 @@ int main(int argc, char * argv[]){ params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls // load the mesh + + auto begin = std::chrono::high_resolution_clock::now(); if (!vUtil.loadFBX(fname, &fbx)){ cout << "Error in opening FBX file...."; return 1; } + auto end = std::chrono::high_resolution_clock::now(); + auto loadDuration = std::chrono::duration_cast(end - begin).count(); + //perform vhacd computation + begin = std::chrono::high_resolution_clock::now(); if (!vUtil.computeVHACD(&fbx, params, &results)){ cout << "Compute Failed..."; return 1; } + end = std::chrono::high_resolution_clock::now(); + auto computeDuration = std::chrono::duration_cast(end - begin).count(); int totalVertices = 0; for (int i = 0; i < fbx.meshCount; i++){ @@ -75,6 +88,8 @@ int main(int argc, char * argv[]){ 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; cout << endl << "Summary per convex hull ........................" << endl <