mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
Add wireframe hypercube
This commit is contained in:
@@ -13,8 +13,12 @@ namespace ml {
|
||||
using PointsType = Eigen::MatrixXf;
|
||||
using CellsType = Eigen::MatrixXi;
|
||||
|
||||
[[nodiscard]] virtual Eigen::Index dim() const = 0;
|
||||
|
||||
[[nodiscard]] virtual PointsType points() const = 0;
|
||||
|
||||
[[nodiscard]] virtual Eigen::Index rank() const = 0;
|
||||
|
||||
[[nodiscard]] virtual CellsType cells() const = 0;
|
||||
};
|
||||
|
||||
@@ -31,6 +35,10 @@ namespace ml {
|
||||
DynamicMesh(PointsType points, CellsType cells)
|
||||
: _points(std::move(points)), _cells(std::move(cells)) {}
|
||||
|
||||
Eigen::Index dim() const override {
|
||||
return _points.rows();
|
||||
}
|
||||
|
||||
[[nodiscard]] PointsType &points() {
|
||||
return _points;
|
||||
}
|
||||
@@ -39,6 +47,10 @@ namespace ml {
|
||||
return _points;
|
||||
}
|
||||
|
||||
Eigen::Index rank() const override {
|
||||
return _points.rows();
|
||||
}
|
||||
|
||||
[[nodiscard]] CellsType &cells() {
|
||||
return _cells;
|
||||
}
|
||||
@@ -55,6 +67,10 @@ namespace ml {
|
||||
explicit CubeMesh(PointsType::Scalar radius = 0.5)
|
||||
: radius(radius) {}
|
||||
|
||||
Eigen::Index dim() const override {
|
||||
return 3;
|
||||
}
|
||||
|
||||
[[nodiscard]] PointsType points() const override {
|
||||
PointsType out(3, 8);
|
||||
out.transpose() <<
|
||||
@@ -69,6 +85,10 @@ namespace ml {
|
||||
return out;
|
||||
}
|
||||
|
||||
Eigen::Index rank() const override {
|
||||
return 3;
|
||||
}
|
||||
|
||||
CellsType cells() const override {
|
||||
CellsType out(3, 12);
|
||||
out.transpose() <<
|
||||
@@ -83,4 +103,54 @@ namespace ml {
|
||||
return out;
|
||||
}
|
||||
};
|
||||
|
||||
class WireCubeMesh : public MeshBase {
|
||||
PointsType::Scalar radius;
|
||||
long _dim;
|
||||
long _npoints;
|
||||
long _nlines;
|
||||
|
||||
public:
|
||||
explicit WireCubeMesh(long dim = 3, PointsType::Scalar radius = 0.5)
|
||||
: _dim(dim), radius(radius) {
|
||||
_npoints = 1 << _dim;
|
||||
_nlines = _dim * (_npoints >> 1);
|
||||
}
|
||||
|
||||
Eigen::Index dim() const override {
|
||||
return _dim;
|
||||
}
|
||||
|
||||
[[nodiscard]] PointsType points() const override {
|
||||
PointsType out(_dim, _npoints);
|
||||
out.fill(radius);
|
||||
for (int i = 0; i < out.cols(); ++i) {
|
||||
for (int j = 0; j < _dim; ++j) {
|
||||
if ((i >> j) & 1) {
|
||||
out(j, i) *= -1;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
Eigen::Index rank() const override {
|
||||
return 2;
|
||||
}
|
||||
|
||||
[[nodiscard]] CellsType cells() const override {
|
||||
CellsType out(2, _nlines);
|
||||
int k = 0;
|
||||
for (int i = 0; i < _npoints; ++i) {
|
||||
for (int j = 0; j < _dim; ++j) {
|
||||
if ((i >> j) & 1) {
|
||||
out(0, k) = i;
|
||||
out(1, k) = i ^ (1 << j);
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
return out;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user