From 2599d472614f403f8249060272ce288033a919d4 Mon Sep 17 00:00:00 2001 From: iasonmanolas Date: Thu, 4 Feb 2021 14:58:41 +0200 Subject: [PATCH] Refactored code to compile under visual studio. --- beam.hpp | 1 + beamformfinder.cpp | 18 ++++++++++-------- csvfile.hpp | 12 ++++++++++-- edgemesh.cpp | 12 +----------- edgemesh.hpp | 1 - elementalmesh.cpp | 6 ++++++ elementalmesh.hpp | 1 + simulationhistoryplotter.hpp | 2 +- simulationresult.hpp | 11 +++++------ topologyenumerator.cpp | 4 ++-- topologyenumerator.hpp | 2 +- vcgtrimesh.cpp | 4 ++-- 12 files changed, 40 insertions(+), 34 deletions(-) diff --git a/beam.hpp b/beam.hpp index 4cffe70..dc485a4 100644 --- a/beam.hpp +++ b/beam.hpp @@ -3,6 +3,7 @@ #include #include #include +#include struct RectangularBeamDimensions { inline static std::string name{"Rectangular"}; diff --git a/beamformfinder.cpp b/beamformfinder.cpp index 8a530f2..6451d5b 100644 --- a/beamformfinder.cpp +++ b/beamformfinder.cpp @@ -19,7 +19,7 @@ void FormFinder::runUnitTests() { // const size_t spanGridSize = 11; // mesh.createSpanGrid(spanGridSize); beam.loadPly( - std::filesystem::path(groundOfTruthFolder).append("simpleBeam.ply")); + std::filesystem::path(groundOfTruthFolder).append("simpleBeam.ply").string()); std::unordered_map> fixedVertices; fixedVertices[0] = std::unordered_set{0, 1, 2, 3}; fixedVertices[beam.VN() - 1] = std::unordered_set{1, 2}; @@ -50,7 +50,7 @@ void FormFinder::runUnitTests() { simpleBeam_simulationResults.save(); const std::string simpleBeamGroundOfTruthBinaryFilename = std::filesystem::path(groundOfTruthFolder) - .append("SimpleBeam_displacements.eigenBin"); + .append("SimpleBeam_displacements.eigenBin").string(); assert(std::filesystem::exists( std::filesystem::path(simpleBeamGroundOfTruthBinaryFilename))); Eigen::MatrixXd simpleBeam_groundOfTruthDisplacements; @@ -211,7 +211,7 @@ void FormFinder::reset() { history.clear(); constrainedVertices.clear(); rigidSupports.clear(); - pMesh.release(); + pMesh.reset(); plotYValues.clear(); plotHandle.reset(); checkedForMaximumMoment = false; @@ -219,6 +219,7 @@ void FormFinder::reset() { externalMomentsNorm = 0; mSettings.drawingStep = 1; Dt = mSettings.Dtini; + numOfDampings=0; } VectorType FormFinder::computeDisplacementDifferenceDerivative( @@ -793,8 +794,8 @@ void FormFinder::updateResidualForcesOnTheFly( std::vector>(4, {-1, Vector6d()})); // omp_lock_t writelock; // omp_init_lock(&writelock); -#pragma omp parallel for schedule(static) num_threads(8) - for (size_t ei = 0; ei < pMesh->EN(); ei++) { +//#pragma omp parallel for //schedule(static) num_threads(8) + for (int ei = 0; ei < pMesh->EN(); ei++) { const EdgeType &e = pMesh->edge[ei]; const SimulationMesh::VertexType &ev_j = *e.cV(0); const SimulationMesh::VertexType &ev_jplus1 = *e.cV(1); @@ -1790,14 +1791,15 @@ FormFinder::executeSimulation(const std::shared_ptr &pJob, // } // } + pMesh.reset(); pMesh = std::make_unique(*pJob->pMesh); - if (mSettings.beVerbose) { + if (mSettings.beVerbose ) { std::cout << "Executing simulation for mesh with:" << pMesh->VN() << " nodes and " << pMesh->EN() << " elements." << std::endl; } computeRigidSupports(); - if (mSettings.shouldDraw) { + if (mSettings.shouldDraw ) { initPolyscope(); polyscope::registerCurveNetwork( meshPolyscopeLabel, pMesh->getEigenVertices(), pMesh->getEigenEdges()); @@ -1974,7 +1976,7 @@ mesh->currentTotalPotentialEnergykN*/ } else if (std::isnan(pMesh->currentTotalKineticEnergy)) { results.converged = false; - } else if (mSettings.beVerbose) { + } else if (mSettings.beVerbose ) { auto t2 = std::chrono::high_resolution_clock::now(); double simulationDuration = std::chrono::duration_cast(t2 - t1).count(); diff --git a/csvfile.hpp b/csvfile.hpp index a53f575..9bd0511 100644 --- a/csvfile.hpp +++ b/csvfile.hpp @@ -23,8 +23,16 @@ public: : fs_(), is_first_(true), separator_(separator), escape_seq_("\""), special_chars_("\"") { fs_.exceptions(std::ios::failbit | std::ios::badbit); - overwrite ? fs_.open(filename, std::ios::trunc) - : fs_.open(filename, std::ios::app); + if (!std::filesystem::exists(std::filesystem::path("../OptimizationResults") + .append("statistics.csv") + )) { + std::ofstream outfile(std::filesystem::path("../OptimizationResults") + .append("statistics.csv") + .string()); + outfile.close(); +} + overwrite ? fs_.open(filename, std::ios::trunc) + : fs_.open(filename, std::ios::app); } ~csvfile() { diff --git a/edgemesh.cpp b/edgemesh.cpp index c925f70..a32257a 100644 --- a/edgemesh.cpp +++ b/edgemesh.cpp @@ -183,21 +183,11 @@ bool VCGEdgeMesh::loadPly(const std::string plyFilename) { assert(std::filesystem::exists(usedPath)); this->Clear(); const bool useDefaultImporter = false; - if (useDefaultImporter) { - if (!loadUsingDefaultLoader(usedPath)) { - return false; - } - - eigenEdgeNormals.resize(EN(), 3); - for (int i = 0; i < EN(); i++) { - eigenEdgeNormals.row(i) = Eigen::Vector3d(0, 1, 0); - } - } else { if (!loadUsingNanoply(usedPath)) { std::cerr << "Error: Unable to open " + usedPath << std::endl; return false; } - } + getEdges(eigenEdges); getVertices(eigenVertices); vcg::tri::UpdateTopology::VertexEdge(*this); diff --git a/edgemesh.hpp b/edgemesh.hpp index 613deed..e420a4c 100644 --- a/edgemesh.hpp +++ b/edgemesh.hpp @@ -53,7 +53,6 @@ public: Eigen::MatrixX3d getNormals() const; - bool loadUsingDefaultLoader(const std::string &plyFilename); bool hasProperty(const std::vector &v, const std::string &propertyName); diff --git a/elementalmesh.cpp b/elementalmesh.cpp index 0bcd38f..739d268 100644 --- a/elementalmesh.cpp +++ b/elementalmesh.cpp @@ -38,6 +38,12 @@ SimulationMesh::SimulationMesh(VCGEdgeMesh &mesh) { eigenVertices = mesh.getEigenVertices(); } +SimulationMesh::~SimulationMesh() +{ + vcg::tri::Allocator::DeletePerEdgeAttribute(*this, elements); + vcg::tri::Allocator::DeletePerVertexAttribute(*this,nodes); +} + SimulationMesh::SimulationMesh(FlatPattern &pattern) { vcg::tri::MeshAssert::VertexNormalNormalized(pattern); diff --git a/elementalmesh.hpp b/elementalmesh.hpp index cd88e4e..e04c495 100644 --- a/elementalmesh.hpp +++ b/elementalmesh.hpp @@ -23,6 +23,7 @@ private: public: PerEdgeAttributeHandle elements; PerVertexAttributeHandle nodes; + ~SimulationMesh(); SimulationMesh(FlatPattern &pattern); SimulationMesh(ConstVCGEdgeMesh &edgeMesh); SimulationMesh(SimulationMesh &elementalMesh); diff --git a/simulationhistoryplotter.hpp b/simulationhistoryplotter.hpp index fc24434..02ea8e6 100644 --- a/simulationhistoryplotter.hpp +++ b/simulationhistoryplotter.hpp @@ -75,7 +75,7 @@ struct SimulationResultsReporter { createPlots(simulationResult.history, simulationResultPath.string(), graphSuffix); - writeStatistics(simulationResult, simulationResultPath); + writeStatistics(simulationResult, simulationResultPath.string()); } } static void createPlot(const std::string &xLabel, const std::string &yLabel, diff --git a/simulationresult.hpp b/simulationresult.hpp index 8c3d72a..bfe9ceb 100644 --- a/simulationresult.hpp +++ b/simulationresult.hpp @@ -187,16 +187,15 @@ public: if (json.contains(jsonLabel_constrainedVertices)) { constrainedVertices = // auto conV = - std::unordered_map>( - json[jsonLabel_constrainedVertices]); + json[jsonLabel_constrainedVertices].get>>(); std::cout << "Loaded constrained vertices. Number of constrained " "vertices found:" << constrainedVertices.size() << std::endl; } if (json.contains(jsonLabel_nodalForces)) { - auto f = std::unordered_map>( - json[jsonLabel_nodalForces]); + auto f ( + json[jsonLabel_nodalForces].get>>()); for (const auto &forces : f) { nodalExternalForces[forces.first] = Vector6d(forces.second); } @@ -221,7 +220,7 @@ public: std::filesystem::absolute( std::filesystem::canonical( std::filesystem::path(pathFolderDirectory))) - .append(pMesh->getLabel() + ".ply"); + .append(pMesh->getLabel() + ".ply").string(); returnValue = pMesh->savePly(meshFilename); nlohmann::json json; json[jsonLabel_meshFilename] = meshFilename; @@ -238,7 +237,7 @@ public: std::string jsonFilename( std::filesystem::path(pathFolderDirectory) - .append(pMesh->getLabel() + "_simScenario.json")); + .append(pMesh->getLabel() + "_simScenario.json").string()); std::ofstream jsonFile(jsonFilename); jsonFile << json; std::cout << "Saved simulation job as:" << jsonFilename << std::endl; diff --git a/topologyenumerator.cpp b/topologyenumerator.cpp index 04a85ff..01a2d29 100644 --- a/topologyenumerator.cpp +++ b/topologyenumerator.cpp @@ -130,7 +130,7 @@ void TopologyEnumerator::computeValidPatterns( if (debugIsOn) { // Export all valid edges in a ply patternAllValidEdges.savePly( - std::filesystem::path(resultsPath).append("allValidEdges.ply")); + std::filesystem::path(resultsPath).append("allValidEdges.ply").string()); } // statistics.numberOfValidEdges = validEdges.size(); @@ -357,7 +357,7 @@ std::vector TopologyEnumerator::getValidEdges( patternDuplicateEdges, p0, p1); } patternDuplicateEdges.savePly( - std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply")); + std::filesystem::path(duplicateEdgesPath).append("duplicateEdges.ply").string()); } statistics.numberOfDuplicateEdges = duplicateEdges.size(); diff --git a/topologyenumerator.hpp b/topologyenumerator.hpp index 47d8cff..1b3202b 100644 --- a/topologyenumerator.hpp +++ b/topologyenumerator.hpp @@ -156,7 +156,7 @@ private: const size_t &numberOfDesiredEdges) const; std::vector getValidEdges(const std::vector &numberOfNodesPerSlot, - const std::filesystem::__cxx11::path &resultsPath, + const std::filesystem::path &resultsPath, const FlatPatternGeometry &patternGeometryAllEdges, const std::vector &allPossibleEdges); std::unordered_set computeDuplicateEdges(); diff --git a/vcgtrimesh.cpp b/vcgtrimesh.cpp index e68b312..6acbc35 100644 --- a/vcgtrimesh.cpp +++ b/vcgtrimesh.cpp @@ -11,7 +11,7 @@ void VCGTriMesh::loadFromPlyFile(const std::string &filename) { mask |= nanoply::NanoPlyWrapper::IO_EDGEINDEX; mask |= nanoply::NanoPlyWrapper::IO_FACEINDEX; if (nanoply::NanoPlyWrapper::LoadModel( - std::filesystem::absolute(filename).c_str(), *this, mask) != 0) { + std::filesystem::absolute(filename).string().c_str(), *this, mask) != 0) { std::cout << "Could not load tri mesh" << std::endl; } vcg::tri::UpdateTopology::FaceFace(*this); @@ -57,7 +57,7 @@ bool VCGTriMesh::savePly(const std::string plyFilename) { VCGTriMesh::VCGTriMesh() {} VCGTriMesh::VCGTriMesh(const std::string &filename) { - const std::string extension = std::filesystem::path(filename).extension(); + const std::string extension = std::filesystem::path(filename).extension().string(); if (extension == ".ply") { loadFromPlyFile(filename); } else if (extension == ".obj") {