Refactoring for compiling under windows
This commit is contained in:
parent
55def2cfd5
commit
9a7322762a
|
@ -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
|
###Eigen 3 NOTE: Eigen is required on the system the code is ran
|
||||||
find_package(Eigen3 3.3 REQUIRED)
|
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)
|
#link_directories(${CMAKE_CURRENT_LIST_DIR}/boost_graph/libs)
|
||||||
file(GLOB MySourcesFiles ${CMAKE_CURRENT_LIST_DIR}/*.hpp ${CMAKE_CURRENT_LIST_DIR}/*.cpp)
|
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)
|
add_library(${PROJECT_NAME} ${MySourcesFiles} ${vcglib_devel_SOURCE_DIR}/wrap/ply/plylib.cpp)
|
||||||
|
|
|
@ -17,9 +17,9 @@ bool VCGEdgeMesh::save(const string &plyFilename)
|
||||||
{
|
{
|
||||||
std::string filename = plyFilename;
|
std::string filename = plyFilename;
|
||||||
if (filename.empty()) {
|
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))) {
|
} 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");
|
assert(std::filesystem::path(filename).extension().string() == ".ply");
|
||||||
unsigned int mask = 0;
|
unsigned int mask = 0;
|
||||||
|
@ -208,7 +208,7 @@ bool VCGEdgeMesh::load(const string &plyFilename) {
|
||||||
std::cout << "Mesh has " << EN() << " edges." << std::endl;
|
std::cout << "Mesh has " << EN() << " edges." << std::endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
label=std::filesystem::path(plyFilename).stem();
|
label=std::filesystem::path(plyFilename).stem().string();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -123,8 +123,8 @@ public:
|
||||||
if (nodalForce.second[dofIndex] == 0) {
|
if (nodalForce.second[dofIndex] == 0) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
nodalForces.emplace_back(
|
fea::Force f(nodalForce.first, dofIndex, nodalForce.second[dofIndex]);
|
||||||
fea::Force(nodalForce.first, dofIndex, nodalForce.second[dofIndex]));
|
nodalForces.emplace_back(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -48,11 +48,11 @@ void PatternIO::exportPLY(const std::string &patternSetFilePath,
|
||||||
auto tiled = p.createTile(p);
|
auto tiled = p.createTile(p);
|
||||||
p.save(
|
p.save(
|
||||||
std::filesystem::path(outputDirectoryPath)
|
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)
|
tiled.save(std::filesystem::path(outputDirectoryPath)
|
||||||
.append("tiled_" +
|
.append("tiled_" +
|
||||||
std::to_string(patterns[patternIndex].name) +
|
std::to_string(patterns[patternIndex].name) +
|
||||||
".ply"));
|
".ply").string());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -312,7 +312,7 @@ struct Colors
|
||||||
baseTriangle.cP2(0)[0],
|
baseTriangle.cP2(0)[0],
|
||||||
baseTriangle.cP2(0)[1],
|
baseTriangle.cP2(0)[1],
|
||||||
baseTriangle.cP2(0)[2]};
|
baseTriangle.cP2(0)[2]};
|
||||||
baseTriangleFullPattern.save(std::filesystem::path(saveToPath));
|
baseTriangleFullPattern.save(std::filesystem::path(saveToPath).string());
|
||||||
json_optimizationResults[JsonKeys::FullPatternLabel] = baseTriangleFullPattern.getLabel();
|
json_optimizationResults[JsonKeys::FullPatternLabel] = baseTriangleFullPattern.getLabel();
|
||||||
////Save to json file
|
////Save to json file
|
||||||
std::filesystem::path jsonFilePath(
|
std::filesystem::path jsonFilePath(
|
||||||
|
@ -394,7 +394,7 @@ struct Colors
|
||||||
const std::string fullPatternLabel = json_optimizationResults.at(
|
const std::string fullPatternLabel = json_optimizationResults.at(
|
||||||
JsonKeys::FullPatternLabel);
|
JsonKeys::FullPatternLabel);
|
||||||
baseTriangleFullPattern.load(
|
baseTriangleFullPattern.load(
|
||||||
std::filesystem::path(loadFromPath).append(fullPatternLabel + ".ply"));
|
std::filesystem::path(loadFromPath).append(fullPatternLabel + ".ply").string());
|
||||||
|
|
||||||
std::vector<double> baseTriangleVertices = json_optimizationResults.at(
|
std::vector<double> baseTriangleVertices = json_optimizationResults.at(
|
||||||
JsonKeys::baseTriangle);
|
JsonKeys::baseTriangle);
|
||||||
|
|
|
@ -1,8 +1,34 @@
|
||||||
#ifndef SIMULATIONSTRUCTS_HPP
|
#ifndef SIMULATIONSTRUCTS_HPP
|
||||||
#define 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 "simulationmesh.hpp"
|
||||||
#include "nlohmann/json.hpp"
|
#include "nlohmann/json.hpp"
|
||||||
|
#include <string>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
struct SimulationHistory {
|
struct SimulationHistory {
|
||||||
SimulationHistory() {}
|
SimulationHistory() {}
|
||||||
|
@ -211,8 +237,8 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
if (json.contains(jsonLabels.nodalForces)) {
|
if (json.contains(jsonLabels.nodalForces)) {
|
||||||
auto f = std::unordered_map<VertexIndex, std::array<double, 6>>(
|
auto f =
|
||||||
json[jsonLabels.nodalForces]);
|
json[jsonLabels.nodalForces].get<std::unordered_map<VertexIndex, std::array<double, 6>>>();
|
||||||
for (const auto &forces : f) {
|
for (const auto &forces : f) {
|
||||||
nodalExternalForces[forces.first] = Vector6d(forces.second);
|
nodalExternalForces[forces.first] = Vector6d(forces.second);
|
||||||
}
|
}
|
||||||
|
@ -404,31 +430,6 @@ public:
|
||||||
}
|
}
|
||||||
#endif // POLYSCOPE_DEFINED
|
#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
|
struct SimulationResults
|
||||||
{
|
{
|
||||||
/*TODO: remove rotationalDisplacementQuaternion since the last three components of the displacments
|
/*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)
|
void load(const std::filesystem::path &loadFromPath, const std::filesystem::path &loadJobFrom)
|
||||||
{
|
{
|
||||||
//load job
|
//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
|
//Use the first .eigenBin file for loading the displacements
|
||||||
for (auto const &entry : std::filesystem::recursive_directory_iterator(loadFromPath)) {
|
for (auto const &entry : std::filesystem::recursive_directory_iterator(loadFromPath)) {
|
||||||
if (filesystem::is_regular_file(entry) && entry.path().extension() == ".eigenBin") {
|
if (filesystem::is_regular_file(entry) && entry.path().extension() == ".eigenBin") {
|
||||||
|
|
|
@ -345,7 +345,7 @@ bool SimulationMesh::save(const std::string &plyFilename)
|
||||||
{
|
{
|
||||||
std::string filename = plyFilename;
|
std::string filename = plyFilename;
|
||||||
if (filename.empty()) {
|
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;
|
nanoply::NanoPlyWrapper<VCGEdgeMesh>::CustomAttributeDescriptor customAttrib;
|
||||||
customAttrib.GetMeshAttrib(filename);
|
customAttrib.GetMeshAttrib(filename);
|
||||||
|
|
|
@ -5,6 +5,9 @@
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
#include <iterator>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <array>
|
||||||
|
|
||||||
struct Vector6d : public std::array<double, 6> {
|
struct Vector6d : public std::array<double, 6> {
|
||||||
Vector6d() {
|
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::array<double, 6> &arr) : std::array<double, 6>(arr) {}
|
||||||
|
|
||||||
Vector6d(const std::initializer_list<double> &initList) {
|
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 {
|
Vector6d operator*(const double &d) const {
|
||||||
|
@ -88,7 +91,7 @@ struct Vector6d : public std::array<double, 6> {
|
||||||
|
|
||||||
double squaredNorm() const {
|
double squaredNorm() const {
|
||||||
double squaredNorm = 0;
|
double squaredNorm = 0;
|
||||||
std::for_each(begin(), end(),
|
std::for_each(this->begin(), std::end(*this),
|
||||||
[&](const double &v) { squaredNorm += pow(v, 2); });
|
[&](const double &v) { squaredNorm += pow(v, 2); });
|
||||||
return squaredNorm;
|
return squaredNorm;
|
||||||
}
|
}
|
||||||
|
@ -96,7 +99,7 @@ struct Vector6d : public std::array<double, 6> {
|
||||||
double norm() const { return sqrt(squaredNorm()); }
|
double norm() const { return sqrt(squaredNorm()); }
|
||||||
|
|
||||||
bool isFinite() const {
|
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)) {
|
if (!std::isfinite(v)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ bool VCGTriMesh::load(const std::string &filename) {
|
||||||
vcg::tri::UpdateTopology<VCGTriMesh>::VertexFace(*this);
|
vcg::tri::UpdateTopology<VCGTriMesh>::VertexFace(*this);
|
||||||
vcg::tri::UpdateNormal<VCGTriMesh>::PerVertexNormalized(*this);
|
vcg::tri::UpdateNormal<VCGTriMesh>::PerVertexNormalized(*this);
|
||||||
|
|
||||||
label = std::filesystem::path(filename).stem();
|
label = std::filesystem::path(filename).stem().string();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue