From 95839dd64e9caec0138efb7f6a308b23bd0da0f3 Mon Sep 17 00:00:00 2001 From: Virendra Singh Date: Fri, 27 Feb 2015 00:27:18 +0530 Subject: [PATCH] untabify the source files --- tools/vhacd/src/VHACDUtil.cpp | 155 ++++++++++++++++----------------- tools/vhacd/src/VHACDUtil.h | 47 +++++----- tools/vhacd/src/main.cpp | 157 +++++++++++++++++----------------- 3 files changed, 180 insertions(+), 179 deletions(-) diff --git a/tools/vhacd/src/VHACDUtil.cpp b/tools/vhacd/src/VHACDUtil.cpp index 95e78b212d..d4ab9d7c8a 100644 --- a/tools/vhacd/src/VHACDUtil.cpp +++ b/tools/vhacd/src/VHACDUtil.cpp @@ -16,104 +16,105 @@ //Read all the meshes from provided FBX file bool vhacd::VHACDUtil::loadFBX(const QString filename, vhacd::LoadFBXResults *results){ - // open the fbx file - QFile fbx(filename); - if (!fbx.open(QIODevice::ReadOnly)) { - return false; - } - std::cout << "Reading FBX.....\n"; + // open the fbx file + QFile fbx(filename); + if (!fbx.open(QIODevice::ReadOnly)) { + return false; + } + std::cout << "Reading FBX.....\n"; - QByteArray fbxContents = fbx.readAll(); - FBXGeometry geometry = readFBX(fbxContents, QVariantHash()); - //results->meshCount = geometry.meshes.count(); - - int count = 0; - foreach(FBXMesh mesh, geometry.meshes) { - //get vertices for each mesh - QVector vertices = mesh.vertices; + QByteArray fbxContents = fbx.readAll(); + FBXGeometry geometry = readFBX(fbxContents, QVariantHash()); + //results->meshCount = geometry.meshes.count(); + + int count = 0; + 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) { - QVector indices = part.triangleIndices; - triangles += indices; - } + //get the triangle indices for each mesh + QVector triangles; + foreach(FBXMeshPart part, mesh.parts) { + QVector indices = part.triangleIndices; + triangles += indices; + } - //only read meshes with triangles - if (triangles.count() <= 0) - continue; - results->perMeshVertices.append(vertices); - results->perMeshTriangleIndices.append(triangles); - count++; - } + //only read meshes with triangles + if (triangles.count() <= 0) + continue; + results->perMeshVertices.append(vertices); + results->perMeshTriangleIndices.append(triangles); + count++; + } - results->meshCount = count; - return true; + results->meshCount = count; + return true; } 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; + 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++){ - - std::vector vertices = meshes->perMeshVertices.at(i).toStdVector(); - std::vector triangles = meshes->perMeshTriangleIndices.at(i).toStdVector(); - int nPoints = (unsigned int)vertices.size(); - int nTriangles = (unsigned int)triangles.size() / 3; - 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){ - std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl; - continue; - } - count++; //For counting number of successfull computations + for (int i = 0; i < meshCount; i++){ + + std::vector vertices = meshes->perMeshVertices.at(i).toStdVector(); + std::vector triangles = meshes->perMeshTriangleIndices.at(i).toStdVector(); + int nPoints = (unsigned int)vertices.size(); + int nTriangles = (unsigned int)triangles.size() / 3; + 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){ + std::cout << "V-HACD computation failed for Mesh : " << i + 1 << std::endl; + continue; + } + count++; //For counting number of successfull computations - //Number of hulls for the mesh - unsigned int nConvexHulls = interfaceVHACD->GetNConvexHulls(); - results->convexHullsCountList.append(nConvexHulls); + //Number of hulls for the mesh + unsigned int nConvexHulls = interfaceVHACD->GetNConvexHulls(); + results->convexHullsCountList.append(nConvexHulls); - //get all the convex hulls for this mesh - QVector convexHulls; - for (unsigned int j = 0; j < nConvexHulls; j++){ - VHACD::IVHACD::ConvexHull hull; - interfaceVHACD->GetConvexHull(j, hull); - convexHulls.append(hull); - } - results->convexHullList.append(convexHulls); - } //end of for loop + //get all the convex hulls for this mesh + QVector convexHulls; + for (unsigned int j = 0; j < nConvexHulls; j++){ + VHACD::IVHACD::ConvexHull hull; + interfaceVHACD->GetConvexHull(j, hull); + convexHulls.append(hull); + } + results->convexHullList.append(convexHulls); + } //end of for loop - results->meshCount = count; + results->meshCount = count; - //release memory - interfaceVHACD->Clean(); - interfaceVHACD->Release(); + //release memory + interfaceVHACD->Clean(); + interfaceVHACD->Release(); - if (count > 0) - return true; - else - return false; + if (count > 0) + return true; + else + return false; } vhacd::VHACDUtil:: ~VHACDUtil(){ - //nothing to be cleaned + //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){ - int progress = (int)(overallProgress + 0.5); +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) - std::cout << "\b\b"; - else - std::cout << "\b\b\b"; - std::cout << progress << "%"; + if (progress < 10) + std::cout << "\b\b"; + else + std::cout << "\b\b\b"; + std::cout << progress << "%"; - if (progress >= 100) - std::cout << std::endl; + if (progress >= 100) + std::cout << std::endl; } diff --git a/tools/vhacd/src/VHACDUtil.h b/tools/vhacd/src/VHACDUtil.h index 036d4ce526..b87ba07ff0 100644 --- a/tools/vhacd/src/VHACDUtil.h +++ b/tools/vhacd/src/VHACDUtil.h @@ -23,32 +23,33 @@ namespace vhacd{ - typedef struct{ - int meshCount; - QVector convexHullsCountList; - QVector> convexHullList; - }ComputeResults; + typedef struct{ + int meshCount; + QVector convexHullsCountList; + QVector> convexHullList; + }ComputeResults; - typedef struct{ - int meshCount; - QVector> perMeshVertices; - QVector> perMeshTriangleIndices; - }LoadFBXResults; + typedef struct{ + int meshCount; + QVector> perMeshVertices; + QVector> perMeshTriangleIndices; + }LoadFBXResults; - class VHACDUtil{ - public: - bool loadFBX(const QString filename, vhacd::LoadFBXResults *results); - bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const; - ~VHACDUtil(); - }; + class VHACDUtil{ + public: + bool loadFBX(const QString filename, vhacd::LoadFBXResults *results); + bool computeVHACD(vhacd::LoadFBXResults *meshes, VHACD::IVHACD::Parameters params, vhacd::ComputeResults *results)const; + ~VHACDUtil(); + }; - class ProgressCallback : public VHACD::IVHACD::IUserCallback{ - public: - ProgressCallback(void); - ~ProgressCallback(); + class ProgressCallback : public VHACD::IVHACD::IUserCallback{ + public: + ProgressCallback(void); + ~ProgressCallback(); - //Couldn't follow coding guideline here due to virtual function declared in IUserCallback - void Update(const double overallProgress, const double stageProgress, const double operationProgress, const char * const stage, const char * const operation); - }; + //Couldn't follow coding guideline here due to virtual function declared in IUserCallback + void Update(const double overallProgress, const double stageProgress, const double operationProgress, + const char * const stage, const char * const operation); + }; } #endif //hifi_VHACDUtil_h \ No newline at end of file diff --git a/tools/vhacd/src/main.cpp b/tools/vhacd/src/main.cpp index 3d7f2d7504..e43f712fa0 100644 --- a/tools/vhacd/src/main.cpp +++ b/tools/vhacd/src/main.cpp @@ -20,93 +20,92 @@ using namespace std; using namespace VHACD; int main(int argc, char * argv[]){ - vector triangles; // array of indexes - vector points; // array of coordinates - vhacd::VHACDUtil vUtil; - vhacd::LoadFBXResults fbx; //mesh data from loaded fbx file - vhacd::ComputeResults results; // results after computing vhacd - VHACD::IVHACD::Parameters params; - vhacd::ProgressCallback pCallBack; - if (argc < 2){ - cout << "please provide a FBX file as argument\n "; - return 1; - } - string filename(argv[1]); - if (filename.empty()){ - cout << "please provide a FBX file as argument\n "; - return 1; - } + vector triangles; // array of indexes + vector points; // array of coordinates + vhacd::VHACDUtil vUtil; + vhacd::LoadFBXResults fbx; //mesh data from loaded fbx file + vhacd::ComputeResults results; // results after computing vhacd + VHACD::IVHACD::Parameters params; + vhacd::ProgressCallback pCallBack; + if (argc < 2){ + cout << "please provide a FBX file as argument\n "; + return 1; + } + string filename(argv[1]); + if (filename.empty()){ + cout << "please provide a FBX file as argument\n "; + return 1; + } - QString fname = QString::fromStdString(filename); + QString fname = QString::fromStdString(filename); - //set parameters for V-HACD - params.m_callback = &pCallBack; //progress callback - params.m_resolution = 50000; - params.m_depth = 10; - params.m_concavity = 0.003; - params.m_alpha = 0.05; // controls the bias toward clipping along symmetry planes - params.m_pca = 1; // enable/disable normalizing the mesh before applying the convex decomposition - params.m_mode = 1; // 0: voxel - based approximate convex decomposition, 1 : tetrahedron - based approximate convex decomposition - params.m_maxNumVerticesPerCH = 128; - params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls + //set parameters for V-HACD + params.m_callback = &pCallBack; //progress callback + params.m_resolution = 50000; + params.m_depth = 10; + params.m_concavity = 0.003; + params.m_alpha = 0.05; // controls the bias toward clipping along symmetry planes + params.m_pca = 1; // enable/disable normalizing the mesh before applying the convex decomposition + params.m_mode = 1; // 0: voxel - based approximate convex decomposition, 1 : tetrahedron - based approximate convex decomposition + params.m_maxNumVerticesPerCH = 128; + params.m_minVolumePerCH = 0.0001; // controls the adaptive sampling of the generated convex - hulls - // load the mesh + // 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(); + 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(); + //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++){ - totalVertices += fbx.perMeshVertices.at(i).count(); - } + int totalVertices = 0; + 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++){ - totalTriangles += fbx.perMeshTriangleIndices.at(i).count(); - } + int totalTriangles = 0; + 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++){ - totalHulls += hullCounts.at(i); - } - cout << endl << "Summary of V-HACD Computation..................." << endl; - cout << "File Path : " << fname.toStdString() << endl; - cout << "Number Of Meshes : " << fbx.meshCount << endl; - cout << "Processed Meshes : " << results.meshCount << 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; - cout << endl << "Summary per convex hull ........................" << endl < chList = results.convexHullList.at(i); - cout << "\t" << "Number Of Hulls : " << chList.count() << endl; + int totalHulls = 0; + QVector hullCounts = results.convexHullsCountList; + for (int i = 0; i < results.meshCount; i++){ + totalHulls += hullCounts.at(i); + } + cout << endl << "Summary of V-HACD Computation..................." << endl; + cout << "File Path : " << fname.toStdString() << endl; + cout << "Number Of Meshes : " << fbx.meshCount << endl; + cout << "Processed Meshes : " << results.meshCount << 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; + 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; + cout << "\t\tNumber Of Triangles : " << chList.at(j).m_nTriangles << endl; + } + } - cout << "\tHUll : " << j + 1 << endl; - cout << "\t\tNumber Of Points : " << chList.at(j).m_nPoints << endl; - cout << "\t\tNumber Of Triangles : " << chList.at(j).m_nTriangles << endl; - } - } - - getchar(); - return 0; + getchar(); + return 0; } \ No newline at end of file