mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
Replace Primitive vector with Eigen matrices.
template<unsigned N> Prims<N> = Eigen::Matrix<unsigned, N, Eigen::Dynamic> Replaces std::vector<Primitive<N>>
This commit is contained in:
@@ -54,7 +54,11 @@ namespace cgl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void put(const std::vector<T> &data, GLenum usage = GL_STATIC_DRAW) {
|
void put(const std::vector<T> &data, GLenum usage = GL_STATIC_DRAW) {
|
||||||
glNamedBufferData(id, sizeof(T) * data.size(), &data[0], usage);
|
put(&data[0], data.size(), usage);
|
||||||
|
}
|
||||||
|
|
||||||
|
void put(const T *data, const size_t &size, GLenum usage = GL_STATIC_DRAW) {
|
||||||
|
glNamedBufferData(id, sizeof(T) * size, data, usage);
|
||||||
}
|
}
|
||||||
|
|
||||||
void bound(GLenum target, const std::function<void()> &action) const {
|
void bound(GLenum target, const std::function<void()> &action) const {
|
||||||
|
|||||||
@@ -7,6 +7,9 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include "combo_iterator.hpp"
|
#include "combo_iterator.hpp"
|
||||||
|
|
||||||
|
template<unsigned N>
|
||||||
|
using Prims = Eigen::Matrix<unsigned, N, Eigen::Dynamic>;
|
||||||
|
|
||||||
template<int N>
|
template<int N>
|
||||||
using vec = Eigen::Matrix<float, N, 1>;
|
using vec = Eigen::Matrix<float, N, 1>;
|
||||||
template<int N>
|
template<int N>
|
||||||
@@ -33,35 +36,3 @@ mat4 ortho(float left, float right, float bottom, float top, float front, float
|
|||||||
0, 0, 0, 1;
|
0, 0, 0, 1;
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* An primitive stage N indices.
|
|
||||||
* @tparam N
|
|
||||||
*/
|
|
||||||
template<unsigned N>
|
|
||||||
struct Primitive {
|
|
||||||
static_assert(N > 0, "Primitives must contain at least one point. Primitive<0> or lower is impossible.");
|
|
||||||
|
|
||||||
std::array<unsigned, N> inds;
|
|
||||||
|
|
||||||
Primitive() = default;
|
|
||||||
|
|
||||||
Primitive(const Primitive<N> &) = default;
|
|
||||||
|
|
||||||
Primitive(const Primitive<N - 1> &sub, unsigned root) {
|
|
||||||
std::copy(sub.inds.begin(), sub.inds.end(), inds.begin());
|
|
||||||
inds[N - 1] = root;
|
|
||||||
}
|
|
||||||
|
|
||||||
explicit Primitive(const std::vector<unsigned> &values) {
|
|
||||||
std::copy(values.begin(), values.begin() + N, inds.begin());
|
|
||||||
}
|
|
||||||
|
|
||||||
~Primitive() = default;
|
|
||||||
|
|
||||||
void apply(const tc::Cosets &table, int gen) {
|
|
||||||
for (auto &ind : inds) {
|
|
||||||
ind = table.get(ind, gen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -38,17 +38,18 @@ private:
|
|||||||
const tc::Group group;
|
const tc::Group group;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
cgl::Buffer<Primitive<N>> ibo;
|
cgl::Buffer<unsigned> ibo;
|
||||||
cgl::Buffer<vec4> vbo;
|
cgl::Buffer<vec4> vbo;
|
||||||
cgl::VertexArray vao;
|
cgl::VertexArray vao;
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
Slice(const tc::Group &g, T all_sg_gens, const std::vector<std::vector<int>> &exclude) : group(g) {
|
Slice(const tc::Group &g, T all_sg_gens, const std::vector<std::vector<int>> &exclude) : group(g) {
|
||||||
ibo.put(merge<N>(hull<N>(g, all_sg_gens, exclude)));
|
const Prims<N> &data = merge<N>(hull<N>(g, all_sg_gens, exclude));
|
||||||
|
ibo.put(data.data(), data.size());
|
||||||
vao.ipointer(0, ibo, 4, GL_UNSIGNED_INT);
|
vao.ipointer(0, ibo, 4, GL_UNSIGNED_INT);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPoints(const vec5 &root, mat5 transform = mat5::Identity()) {
|
void setPoints(const vec5 &root, const mat5 &transform = mat5::Identity()) {
|
||||||
auto cosets = group.solve();
|
auto cosets = group.solve();
|
||||||
auto mirrors = mirror<5>(group);
|
auto mirrors = mirror<5>(group);
|
||||||
|
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ tc::Cosets solve(
|
|||||||
* Apply some context transformation to all primitives of this mesh.
|
* Apply some context transformation to all primitives of this mesh.
|
||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
std::vector<Primitive<N>> apply(std::vector<Primitive<N>> prims, const tc::Cosets &table, int gen) {
|
void apply(const tc::Cosets &table, int gen, Prims<N> &mat) {
|
||||||
for (auto &prim : prims) {
|
auto data = mat.data();
|
||||||
prim.apply(table, gen);
|
for (int i = 0; i < mat.size(); ++i) {
|
||||||
|
data[i] = table.get(data[i], gen);
|
||||||
}
|
}
|
||||||
return prims;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -72,8 +72,8 @@ std::vector<Primitive<N>> apply(std::vector<Primitive<N>> prims, const tc::Coset
|
|||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::vector<Primitive<N>> recontext(
|
Prims<N> recontext(
|
||||||
std::vector<Primitive<N>> prims,
|
Prims<N> prims,
|
||||||
const tc::Group &context,
|
const tc::Group &context,
|
||||||
const std::vector<int> &g_gens,
|
const std::vector<int> &g_gens,
|
||||||
const std::vector<int> &sg_gens
|
const std::vector<int> &sg_gens
|
||||||
@@ -86,11 +86,10 @@ std::vector<Primitive<N>> recontext(
|
|||||||
return table.get(coset, gen);
|
return table.get(coset, gen);
|
||||||
});
|
});
|
||||||
|
|
||||||
std::vector<Primitive<N>> res(prims);
|
Prims<N> res(prims);
|
||||||
for (Primitive<N> &prim : res) {
|
auto data = res.data();
|
||||||
for (auto &ind : prim.inds) {
|
for (int i = 0; i < prims.size(); ++i) {
|
||||||
ind = map[ind];
|
data[i] = map[data[i]];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -100,16 +99,18 @@ std::vector<Primitive<N>> recontext(
|
|||||||
* Union several meshes of the same dimension
|
* Union several meshes of the same dimension
|
||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
std::vector<Primitive<N>> merge(const std::vector<std::vector<Primitive<N>>> &meshes) {
|
Prims<N> merge(const std::vector<Prims<N>> &meshes) {
|
||||||
size_t size = 0;
|
size_t cols = 0;
|
||||||
for (const auto &mesh : meshes) {
|
for (const auto &mesh : meshes) {
|
||||||
size += mesh.size();
|
cols += mesh.cols();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Primitive<N>> res;
|
Prims<N> res(N, cols);
|
||||||
res.reserve(size);
|
|
||||||
for (const auto &mesh : meshes) {
|
size_t offset = 0;
|
||||||
res.insert(res.end(), mesh.begin(), mesh.end());
|
for (const Prims<N> &mesh : meshes) {
|
||||||
|
res.middleCols(offset, mesh.cols()) = mesh;
|
||||||
|
offset += mesh.cols();
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
@@ -117,52 +118,42 @@ std::vector<Primitive<N>> merge(const std::vector<std::vector<Primitive<N>>> &me
|
|||||||
|
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::vector<std::vector<Primitive<N>>> each_tile(
|
std::vector<Prims<N>> tile(
|
||||||
std::vector<Primitive<N>> prims,
|
Prims<N> prims,
|
||||||
const tc::Group &context,
|
const tc::Group &context,
|
||||||
const std::vector<int> &g_gens,
|
const std::vector<int> &g_gens,
|
||||||
const std::vector<int> &sg_gens
|
const std::vector<int> &sg_gens
|
||||||
) {
|
) {
|
||||||
std::vector<Primitive<N>> base = recontext(prims, context, g_gens, sg_gens);
|
Prims<N> base = recontext<N>(prims, context, g_gens, sg_gens);
|
||||||
const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens);
|
const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens);
|
||||||
|
|
||||||
const auto table = solve(context, g_gens, {});
|
const auto table = solve(context, g_gens, {});
|
||||||
const auto path = solve(context, g_gens, sg_gens).path;
|
const auto path = solve(context, g_gens, sg_gens).path;
|
||||||
|
|
||||||
auto _gens = generators(context);
|
std::vector<int> _gens = generators(context);
|
||||||
|
|
||||||
auto res = path.walk<std::vector<Primitive<N>>, int>(base, generators(context), [&](auto from, auto gen) {
|
std::vector<Prims<N>> res = path.walk<Prims<N>, int>(
|
||||||
return apply(from, table, gen);
|
base, _gens,
|
||||||
});
|
[&](Prims<N> from, int gen) {
|
||||||
|
apply<N>(table, gen, from);
|
||||||
|
return from;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N>
|
|
||||||
[[nodiscard]]
|
|
||||||
std::vector<Primitive<N>> tile(
|
|
||||||
std::vector<Primitive<N>> prims,
|
|
||||||
const tc::Group &context,
|
|
||||||
const std::vector<int> &g_gens,
|
|
||||||
const std::vector<int> &sg_gens
|
|
||||||
) {
|
|
||||||
auto res = each_tile<N>(prims, context, g_gens, sg_gens);
|
|
||||||
|
|
||||||
return merge(res);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Produce a mesh of higher dimension by fanning a single point to all primitives in this mesh.
|
* Produce a mesh of higher dimension by fanning a single point to all primitives in this mesh.
|
||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
|
Prims<N + 1> fan(Prims<N> prims, int root) {
|
||||||
std::vector<Primitive<N + 1>> res(prims.size());
|
Prims<N + 1> res(N + 1, prims.cols());
|
||||||
std::transform(prims.begin(), prims.end(), res.begin(),
|
|
||||||
[root](const Primitive<N> &prim) {
|
res.topRows(1) = Prims<1>::Constant(1, prims.cols(), root);
|
||||||
return Primitive<N + 1>(prim, root);
|
res.bottomRows(N) = prims;
|
||||||
}
|
|
||||||
);
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +161,7 @@ std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
|
|||||||
* Produce a mesh of primitives that fill out the volume of the subgroup generated by generators g_gens within the group context
|
* Produce a mesh of primitives that fill out the volume of the subgroup generated by generators g_gens within the group context
|
||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
std::vector<Primitive<N>> triangulate(
|
Prims<N> triangulate(
|
||||||
const tc::Group &context,
|
const tc::Group &context,
|
||||||
const std::vector<int> &g_gens
|
const std::vector<int> &g_gens
|
||||||
) {
|
) {
|
||||||
@@ -179,37 +170,37 @@ std::vector<Primitive<N>> triangulate(
|
|||||||
|
|
||||||
const auto &combos = Combos(g_gens, g_gens.size() - 1);
|
const auto &combos = Combos(g_gens, g_gens.size() - 1);
|
||||||
|
|
||||||
std::vector<std::vector<Primitive<N>>> meshes;
|
std::vector<Prims<N>> meshes;
|
||||||
|
|
||||||
for (const auto &sg_gens : combos) {
|
for (const auto &sg_gens : combos) {
|
||||||
auto base = triangulate<N - 1>(context, sg_gens);
|
auto base = triangulate<N - 1>(context, sg_gens);
|
||||||
auto raised = tile(base, context, g_gens, sg_gens);
|
auto parts = tile<N - 1>(base, context, g_gens, sg_gens);
|
||||||
raised.erase(raised.begin(), raised.begin() + base.size());
|
parts.erase(parts.begin(), parts.begin() + 1);
|
||||||
meshes.push_back(fan(raised, 0));
|
auto raised = merge<N - 1>(parts);
|
||||||
|
auto fanned = fan<N - 1>(raised, 0);
|
||||||
|
meshes.push_back(fanned);
|
||||||
}
|
}
|
||||||
|
|
||||||
return merge(meshes);
|
return merge<N>(meshes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Single-index primitives should not be further triangulated.
|
* Single-index primitives should not be further triangulated.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
std::vector<Primitive<1>> triangulate(
|
Prims<1> triangulate<1>(
|
||||||
const tc::Group &context,
|
const tc::Group &context,
|
||||||
const std::vector<int> &g_gens
|
const std::vector<int> &g_gens
|
||||||
) {
|
) {
|
||||||
if (not g_gens.empty()) // todo make static assert
|
if (not g_gens.empty()) // todo make static assert
|
||||||
throw std::logic_error("g_gens must be empty for a trivial Mesh");
|
throw std::logic_error("g_gens must be empty for a trivial Mesh");
|
||||||
|
|
||||||
std::vector<Primitive<1>> res;
|
return Prims<1>::Zero(1, 1);
|
||||||
res.emplace_back();
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N, class T>
|
template<unsigned N, class T>
|
||||||
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<std::vector<int>> &exclude) {
|
auto hull(const tc::Group &group, T all_sg_gens, const std::vector<std::vector<int>> &exclude) {
|
||||||
std::vector<std::vector<Primitive<N>>> parts;
|
std::vector<Prims<N>> parts;
|
||||||
auto g_gens = generators(group);
|
auto g_gens = generators(group);
|
||||||
for (const std::vector<int> &sg_gens : all_sg_gens) {
|
for (const std::vector<int> &sg_gens : all_sg_gens) {
|
||||||
bool excluded = false;
|
bool excluded = false;
|
||||||
@@ -222,7 +213,7 @@ auto hull(const tc::Group &group, T all_sg_gens, const std::vector<std::vector<i
|
|||||||
if (excluded) continue;
|
if (excluded) continue;
|
||||||
|
|
||||||
const auto &base = triangulate<N>(group, sg_gens);
|
const auto &base = triangulate<N>(group, sg_gens);
|
||||||
const auto &tiles = each_tile(base, group, g_gens, sg_gens);
|
const auto &tiles = tile<N>(base, group, g_gens, sg_gens);
|
||||||
for (const auto &tile : tiles) {
|
for (const auto &tile : tiles) {
|
||||||
parts.push_back(tile);
|
parts.push_back(tile);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,13 +14,16 @@
|
|||||||
|
|
||||||
mat5 wander(float time) {
|
mat5 wander(float time) {
|
||||||
mat5 r = mat5::Identity();
|
mat5 r = mat5::Identity();
|
||||||
r *= rot<5>(0, 2, time * .21f);
|
r *= rot<5>(0, 2, time * .15f);
|
||||||
// r *= rot<5>(1, 4, time * .27f);
|
r *= rot<5>(1, 2, time * .13f);
|
||||||
|
r *= rot<5>(0, 1, time * .20f);
|
||||||
|
|
||||||
r *= rot<5>(0, 3, time * .17f);
|
r *= rot<5>(0, 3, time * .17f);
|
||||||
r *= rot<5>(1, 3, time * .25f);
|
r *= rot<5>(1, 3, time * .25f);
|
||||||
r *= rot<5>(2, 3, time * .12f);
|
r *= rot<5>(2, 3, time * .12f);
|
||||||
|
|
||||||
|
// r *= rot<5>(1, 4, time * .27f);
|
||||||
|
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user