Serializable mesh with nlohmann_json

Displays a cube generated by meshlib.hpp (serialtest)
This commit is contained in:
David Allemang
2022-02-11 16:12:27 -05:00
committed by David Allemang
parent 10a49a4172
commit 7fff7a375f
6 changed files with 302 additions and 21 deletions

53
src/serialtest.cpp Normal file
View File

@@ -0,0 +1,53 @@
#include <Eigen/Eigen>
#include <fstream>
#include <iostream>
#include "meshlib.hpp"
#include "meshlib_json.hpp"
class Circle : public ml::MeshBase {
public:
PointsType::Scalar radius;
Circle(PointsType::Scalar radius) : radius(radius) {}
PointsType points() const override {
PointsType t(1, 32);
for (int i = 0; i < t.size(); ++i) {
t(i) = 6.28318f * (float) i / 32;
}
PointsType out(3, 32);
out.array().row(0) = t.array().sin();
out.array().row(1) = t.array().cos();
out.array().row(2).setZero();
return out;
}
CellsType cells() const override {
CellsType t(1, 31);
for (int i = 0; i < t.size(); ++i) {
t(i) = i;
}
CellsType out(3, 31);
out.array().row(0) = 0;
out.array().row(1) = t.array();
out.array().row(2) = t.array() + 1;
return out;
}
};
int main() {
auto omesh = Circle(1.0f);
ml::write(omesh, "circle.pak");
auto imesh = ml::read("circle.pak");
std::cout << "= points ===============" << std::endl;
std::cout << imesh.points() << std::endl;
std::cout << "= cells ================" << std::endl;
std::cout << imesh.cells() << std::endl;
}