diff --git a/CMakeLists.txt b/CMakeLists.txt index 6b5e1b4..c24ff9a 100755 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,10 @@ add_subdirectory(${threed-beam-fea_SOURCE_DIR} ${threed-beam-fea_BINARY_DIR}) ###Eigen 3 NOTE: Eigen is required on the system the code is ran find_package(Eigen3 3.3 REQUIRED) +if(MSVC) + add_compile_definitions(_HAS_STD_BYTE=0) +endif(MSVC) + #link_directories(${CMAKE_CURRENT_LIST_DIR}/boost_graph/libs) file(GLOB MySourcesFiles ${CMAKE_CURRENT_LIST_DIR}/*.hpp ${CMAKE_CURRENT_LIST_DIR}/*.cpp) add_library(${PROJECT_NAME} ${MySourcesFiles} ${vcglib_devel_SOURCE_DIR}/wrap/ply/plylib.cpp) diff --git a/edgemesh.cpp b/edgemesh.cpp index 0fe03e1..a04813c 100755 --- a/edgemesh.cpp +++ b/edgemesh.cpp @@ -17,9 +17,9 @@ bool VCGEdgeMesh::save(const string &plyFilename) { std::string filename = plyFilename; if (filename.empty()) { - filename = std::filesystem::current_path().append(getLabel() + ".ply"); + filename = std::filesystem::current_path().append(getLabel() + ".ply").string(); } else if (std::filesystem::is_directory(std::filesystem::path(plyFilename))) { - filename = std::filesystem::path(plyFilename).append(getLabel() + ".ply"); + filename = std::filesystem::path(plyFilename).append(getLabel() + ".ply").string(); } assert(std::filesystem::path(filename).extension().string() == ".ply"); unsigned int mask = 0; @@ -200,6 +200,7 @@ bool VCGEdgeMesh::load(const string &plyFilename) { getEdges(eigenEdges); getVertices(eigenVertices); vcg::tri::UpdateTopology::VertexEdge(*this); + label = std::filesystem::path(plyFilename).stem().string(); const bool printDebugInfo = false; if (printDebugInfo) { @@ -207,7 +208,7 @@ bool VCGEdgeMesh::load(const string &plyFilename) { std::cout << "Mesh has " << EN() << " edges." << std::endl; } - label = std::filesystem::path(plyFilename).stem().string(); + label=std::filesystem::path(plyFilename).stem().string(); return true; } diff --git a/linearsimulationmodel.hpp b/linearsimulationmodel.hpp index 5086bfb..1ca6621 100644 --- a/linearsimulationmodel.hpp +++ b/linearsimulationmodel.hpp @@ -123,8 +123,8 @@ public: if (nodalForce.second[dofIndex] == 0) { continue; } - nodalForces.emplace_back( - fea::Force(nodalForce.first, dofIndex, nodalForce.second[dofIndex])); + fea::Force f(nodalForce.first, dofIndex, nodalForce.second[dofIndex]); + nodalForces.emplace_back(f); } } diff --git a/patternIO.cpp b/patternIO.cpp index 6cfe8ae..733ef3b 100755 --- a/patternIO.cpp +++ b/patternIO.cpp @@ -48,11 +48,11 @@ void PatternIO::exportPLY(const std::string &patternSetFilePath, auto tiled = p.createTile(p); p.save( std::filesystem::path(outputDirectoryPath) - .append(std::to_string(patterns[patternIndex].name) + ".ply")); + .append(std::to_string(patterns[patternIndex].name) + ".ply").string()); tiled.save(std::filesystem::path(outputDirectoryPath) .append("tiled_" + std::to_string(patterns[patternIndex].name) + - ".ply")); + ".ply").string()); } } diff --git a/reducedmodeloptimizer_structs.hpp b/reducedmodeloptimizer_structs.hpp index 7c3250a..a2666cb 100644 --- a/reducedmodeloptimizer_structs.hpp +++ b/reducedmodeloptimizer_structs.hpp @@ -315,7 +315,7 @@ struct Colors baseTriangle.cP2(0)[0], baseTriangle.cP2(0)[1], baseTriangle.cP2(0)[2]}; - baseTriangleFullPattern.save(std::filesystem::path(saveToPath)); + baseTriangleFullPattern.save(std::filesystem::path(saveToPath).string()); json_optimizationResults[JsonKeys::FullPatternLabel] = baseTriangleFullPattern.getLabel(); ////Save to json file std::filesystem::path jsonFilePath( @@ -397,7 +397,7 @@ struct Colors const std::string fullPatternLabel = json_optimizationResults.at( JsonKeys::FullPatternLabel); baseTriangleFullPattern.load( - std::filesystem::path(loadFromPath).append(fullPatternLabel + ".ply")); + std::filesystem::path(loadFromPath).append(fullPatternLabel + ".ply").string()); std::vector baseTriangleVertices = json_optimizationResults.at( JsonKeys::baseTriangle); diff --git a/simulation_structs.hpp b/simulation_structs.hpp index 9d60766..819915c 100755 --- a/simulation_structs.hpp +++ b/simulation_structs.hpp @@ -1,8 +1,34 @@ #ifndef SIMULATIONSTRUCTS_HPP #define SIMULATIONSTRUCTS_HPP +namespace Eigen { +template +void write_binary(const std::string &filename, const Matrix &matrix) { + std::ofstream out(filename, + std::ios::out | std::ios::binary | std::ios::trunc); + typename Matrix::Index rows = matrix.rows(), cols = matrix.cols(); + out.write((char *)(&rows), sizeof(typename Matrix::Index)); + out.write((char *)(&cols), sizeof(typename Matrix::Index)); + out.write((char *)matrix.data(), + rows * cols * sizeof(typename Matrix::Scalar)); + out.close(); +} +template +void read_binary(const std::string &filename, Matrix &matrix) { + std::ifstream in(filename, std::ios::in | std::ios::binary); + typename Matrix::Index rows = 0, cols = 0; + in.read((char *)(&rows), sizeof(typename Matrix::Index)); + in.read((char *)(&cols), sizeof(typename Matrix::Index)); + matrix.resize(rows, cols); + in.read((char *)matrix.data(), rows * cols * sizeof(typename Matrix::Scalar)); + in.close(); +} +} // namespace Eigen + #include "simulationmesh.hpp" #include "nlohmann/json.hpp" +#include +#include struct SimulationHistory { SimulationHistory() {} @@ -222,8 +248,8 @@ public: } if (json.contains(jsonLabels.nodalForces)) { - auto f = std::unordered_map>( - json[jsonLabels.nodalForces]); + auto f = + json[jsonLabels.nodalForces].get>>(); for (const auto &forces : f) { nodalExternalForces[forces.first] = Vector6d(forces.second); } @@ -418,31 +444,6 @@ public: } #endif // POLYSCOPE_DEFINED }; - -namespace Eigen { -template -void write_binary(const std::string &filename, const Matrix &matrix) { - std::ofstream out(filename, - std::ios::out | std::ios::binary | std::ios::trunc); - typename Matrix::Index rows = matrix.rows(), cols = matrix.cols(); - out.write((char *)(&rows), sizeof(typename Matrix::Index)); - out.write((char *)(&cols), sizeof(typename Matrix::Index)); - out.write((char *)matrix.data(), - rows * cols * sizeof(typename Matrix::Scalar)); - out.close(); -} -template -void read_binary(const std::string &filename, Matrix &matrix) { - std::ifstream in(filename, std::ios::in | std::ios::binary); - typename Matrix::Index rows = 0, cols = 0; - in.read((char *)(&rows), sizeof(typename Matrix::Index)); - in.read((char *)(&cols), sizeof(typename Matrix::Index)); - matrix.resize(rows, cols); - in.read((char *)matrix.data(), rows * cols * sizeof(typename Matrix::Scalar)); - in.close(); -} -} // namespace Eigen - struct SimulationResults { /*TODO: remove rotationalDisplacementQuaternion since the last three components of the displacments @@ -522,7 +523,7 @@ struct SimulationResults void load(const std::filesystem::path &loadFromPath, const std::filesystem::path &loadJobFrom) { //load job - job->load(std::filesystem::path(loadJobFrom).append("SimulationJob.json")); + job->load(std::filesystem::path(loadJobFrom).append("SimulationJob.json").string()); //Use the first .eigenBin file for loading the displacements for (auto const &entry : std::filesystem::recursive_directory_iterator(loadFromPath)) { if (filesystem::is_regular_file(entry) && entry.path().extension() == ".eigenBin") { diff --git a/simulationmesh.cpp b/simulationmesh.cpp index 4892939..c2cf67d 100755 --- a/simulationmesh.cpp +++ b/simulationmesh.cpp @@ -345,7 +345,7 @@ bool SimulationMesh::save(const std::string &plyFilename) { std::string filename = plyFilename; if (filename.empty()) { - filename = std::filesystem::current_path().append(getLabel() + ".ply"); + filename = std::filesystem::current_path().append(getLabel() + ".ply").string(); } nanoply::NanoPlyWrapper::CustomAttributeDescriptor customAttrib; customAttrib.GetMeshAttrib(filename); diff --git a/utilities.hpp b/utilities.hpp index 0289725..d93dac4 100755 --- a/utilities.hpp +++ b/utilities.hpp @@ -5,6 +5,9 @@ #include #include #include +#include +#include +#include struct Vector6d : public std::array { Vector6d() { @@ -27,7 +30,7 @@ struct Vector6d : public std::array { Vector6d(const std::array &arr) : std::array(arr) {} Vector6d(const std::initializer_list &initList) { - std::copy(initList.begin(), initList.end(), this->begin()); + std::copy(initList.begin(), initList.end(), std::begin(*this)); } Vector6d operator*(const double &d) const { @@ -88,7 +91,7 @@ struct Vector6d : public std::array { double squaredNorm() const { double squaredNorm = 0; - std::for_each(begin(), end(), + std::for_each(this->begin(), std::end(*this), [&](const double &v) { squaredNorm += pow(v, 2); }); return squaredNorm; } @@ -96,7 +99,7 @@ struct Vector6d : public std::array { double norm() const { return sqrt(squaredNorm()); } bool isFinite() const { - return std::any_of(begin(), end(), [](const double &v) { + return std::any_of(std::begin(*this), std::end(*this), [](const double &v) { if (!std::isfinite(v)) { return false; } diff --git a/vcgtrimesh.cpp b/vcgtrimesh.cpp index 53de708..c04664a 100755 --- a/vcgtrimesh.cpp +++ b/vcgtrimesh.cpp @@ -27,7 +27,7 @@ bool VCGTriMesh::load(const std::string &filename) { vcg::tri::UpdateTopology::VertexFace(*this); vcg::tri::UpdateNormal::PerVertexNormalized(*this); - label = std::filesystem::path(filename).stem(); + label = std::filesystem::path(filename).stem().string(); return true; }