mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
Simplify mesh class
This commit is contained in:
@@ -6,48 +6,40 @@
|
||||
#include <ml/meshlib.hpp>
|
||||
#include <ml/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;
|
||||
auto make_circle(float radius, size_t npoints = 32) {
|
||||
Eigen::Array<float, 1, Eigen::Dynamic> theta(1, npoints);
|
||||
for (int i = 0; i < theta.size(); ++i) {
|
||||
theta(i) = (float) M_PI * 2.0f * (float) i / (float) npoints;
|
||||
}
|
||||
|
||||
CellsType cells() const override {
|
||||
CellsType t(1, 31);
|
||||
for (int i = 0; i < t.size(); ++i) {
|
||||
t(i) = i;
|
||||
}
|
||||
Eigen::Array<float, 3, Eigen::Dynamic> points(3, npoints);
|
||||
points.row(0) = theta.sin();
|
||||
points.row(1) = theta.cos();
|
||||
points.row(2).setZero();
|
||||
|
||||
CellsType out(3, 31);
|
||||
out.array().row(0) = 0;
|
||||
out.array().row(1) = t.array();
|
||||
out.array().row(2) = t.array() + 1;
|
||||
return out;
|
||||
Eigen::Array<unsigned int, 1, Eigen::Dynamic> idx(1, npoints - 1);
|
||||
for (int i = 0; i < idx.size(); ++i) {
|
||||
idx(i) = i;
|
||||
}
|
||||
};
|
||||
|
||||
Eigen::Array<unsigned int, 3, Eigen::Dynamic> cells(3, npoints - 1);
|
||||
cells.row(0) = 0;
|
||||
cells.row(1) = idx;
|
||||
cells.row(2) = idx + 1;
|
||||
|
||||
return ml::Mesh(points, cells);
|
||||
}
|
||||
|
||||
int main() {
|
||||
auto omesh = Circle(1.0f);
|
||||
std::string path = "circle.pak";
|
||||
|
||||
ml::write(omesh, "circle.pak");
|
||||
auto omesh = make_circle(1.0f);
|
||||
using MT = decltype(omesh);
|
||||
|
||||
auto imesh = ml::read("circle.pak");
|
||||
ml::write(omesh, std::ofstream(path, std::ios::out | std::ios::binary));
|
||||
|
||||
std::cout << "= points ===============" << std::endl;
|
||||
std::cout << imesh.points() << std::endl;
|
||||
std::cout << "= cells ================" << std::endl;
|
||||
std::cout << imesh.cells() << std::endl;
|
||||
auto imesh = ml::read<MT>(std::ifstream(path, std::ios::in | std::ios::binary));
|
||||
|
||||
std::cout << imesh.points << std::endl;
|
||||
std::cout << imesh.cells << std::endl;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user