Refactoring for compiling under windows

This commit is contained in:
iasonmanolas 2021-05-01 18:44:54 +03:00
parent 55def2cfd5
commit 9a7322762a
9 changed files with 50 additions and 42 deletions

View File

@ -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)

View File

@ -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;
@ -208,7 +208,7 @@ bool VCGEdgeMesh::load(const string &plyFilename) {
std::cout << "Mesh has " << EN() << " edges." << std::endl;
}
label=std::filesystem::path(plyFilename).stem();
label=std::filesystem::path(plyFilename).stem().string();
return true;
}

View File

@ -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);
}
}

View File

@ -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());
}
}

View File

@ -312,7 +312,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(
@ -394,7 +394,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<double> baseTriangleVertices = json_optimizationResults.at(
JsonKeys::baseTriangle);

View File

@ -1,8 +1,34 @@
#ifndef SIMULATIONSTRUCTS_HPP
#define SIMULATIONSTRUCTS_HPP
namespace Eigen {
template <class Matrix>
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 <class Matrix>
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 <string>
#include <vector>
struct SimulationHistory {
SimulationHistory() {}
@ -211,8 +237,8 @@ public:
}
if (json.contains(jsonLabels.nodalForces)) {
auto f = std::unordered_map<VertexIndex, std::array<double, 6>>(
json[jsonLabels.nodalForces]);
auto f =
json[jsonLabels.nodalForces].get<std::unordered_map<VertexIndex, std::array<double, 6>>>();
for (const auto &forces : f) {
nodalExternalForces[forces.first] = Vector6d(forces.second);
}
@ -404,31 +430,6 @@ public:
}
#endif // POLYSCOPE_DEFINED
};
namespace Eigen {
template <class Matrix>
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 <class Matrix>
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
@ -502,7 +503,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") {

View File

@ -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<VCGEdgeMesh>::CustomAttributeDescriptor customAttrib;
customAttrib.GetMeshAttrib(filename);

View File

@ -5,6 +5,9 @@
#include <filesystem>
#include <fstream>
#include <regex>
#include <iterator>
#include <algorithm>
#include <array>
struct Vector6d : public std::array<double, 6> {
Vector6d() {
@ -27,7 +30,7 @@ struct Vector6d : public std::array<double, 6> {
Vector6d(const std::array<double, 6> &arr) : std::array<double, 6>(arr) {}
Vector6d(const std::initializer_list<double> &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, 6> {
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, 6> {
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;
}

View File

@ -27,7 +27,7 @@ bool VCGTriMesh::load(const std::string &filename) {
vcg::tri::UpdateTopology<VCGTriMesh>::VertexFace(*this);
vcg::tri::UpdateNormal<VCGTriMesh>::PerVertexNormalized(*this);
label = std::filesystem::path(filename).stem();
label = std::filesystem::path(filename).stem().string();
return true;
}