mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
remove old "Mesh" class
This commit is contained in:
@@ -108,33 +108,22 @@ tc::Cosets solve(
|
|||||||
return context.subgroup(g_gens).solve(proper_sg_gens);
|
return context.subgroup(g_gens).solve(proper_sg_gens);
|
||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N>
|
|
||||||
struct Mesh {
|
|
||||||
std::vector<Primitive<N>> prims;
|
|
||||||
|
|
||||||
Mesh() : prims() {}
|
|
||||||
|
|
||||||
Mesh(const Mesh<N> &) = default;
|
|
||||||
|
|
||||||
explicit Mesh(std::vector<Primitive<N>> &prims) : prims(prims) {}
|
|
||||||
|
|
||||||
[[nodiscard]] size_t size() const {
|
|
||||||
return prims.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Apply some context transformation to all primitives of this mesh.
|
* Apply some context transformation to all primitives of this mesh.
|
||||||
*/
|
*/
|
||||||
void apply(const tc::Cosets &table, int gen) {
|
template<unsigned N>
|
||||||
|
std::vector<Primitive<N>> apply(std::vector<Primitive<N>> prims, const tc::Cosets &table, int gen) {
|
||||||
for (auto &prim : prims) {
|
for (auto &prim : prims) {
|
||||||
prim.apply(table, gen);
|
prim.apply(table, gen);
|
||||||
}
|
}
|
||||||
|
return prims;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Reverse the orientation of all primitives in this mesh.
|
* Reverse the orientation of all primitives in this mesh.
|
||||||
*/
|
*/
|
||||||
void flip() {
|
template<unsigned N>
|
||||||
|
void flip(std::vector<Primitive<N>> prims) {
|
||||||
for (auto &prim : prims) {
|
for (auto &prim : prims) {
|
||||||
prim.flip();
|
prim.flip();
|
||||||
}
|
}
|
||||||
@@ -143,12 +132,14 @@ struct Mesh {
|
|||||||
/**
|
/**
|
||||||
* Convert the indexes of this mesh to those of a different context, using g_gens to build the parent context and sg_gens to build this context.
|
* Convert the indexes of this mesh to those of a different context, using g_gens to build the parent context and sg_gens to build this context.
|
||||||
*/
|
*/
|
||||||
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mesh<N> recontext(
|
std::vector<Primitive<N>> recontext(
|
||||||
|
std::vector<Primitive<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
|
||||||
) const {
|
) {
|
||||||
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, sg_gens, {}).path;
|
const auto path = solve(context, sg_gens, {}).path;
|
||||||
@@ -157,78 +148,81 @@ struct Mesh {
|
|||||||
return table.get(coset, gen);
|
return table.get(coset, gen);
|
||||||
});
|
});
|
||||||
|
|
||||||
Mesh<N> res = *this;
|
std::vector<Primitive<N>> res(prims);
|
||||||
for (Primitive<N> &prim : res.prims) {
|
for (Primitive<N> &prim : res) {
|
||||||
for (auto &ind : prim.inds) {
|
for (auto &ind : prim.inds) {
|
||||||
ind = map[ind];
|
ind = map[ind];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (get_parity(context, g_gens, sg_gens) == 1)
|
if (get_parity(context, g_gens, sg_gens) == 1)
|
||||||
res.flip();
|
flip(res);
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Union several meshes of the same dimension
|
||||||
|
*/
|
||||||
|
template<unsigned N>
|
||||||
|
std::vector<Primitive<N>> merge(const std::vector<std::vector<Primitive<N>>> &meshes) {
|
||||||
|
size_t size = 0;
|
||||||
|
for (const auto &mesh : meshes) {
|
||||||
|
size += mesh.size();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<Primitive<N>> res;
|
||||||
|
res.reserve(size);
|
||||||
|
for (const auto &mesh : meshes) {
|
||||||
|
res.insert(res.end(), mesh.begin(), mesh.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mesh<N> tile(
|
std::vector<Primitive<N>> tile(
|
||||||
|
std::vector<Primitive<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
|
||||||
) const {
|
) {
|
||||||
Mesh<N> base = recontext(context, g_gens, sg_gens);
|
std::vector<Primitive<N>> base = recontext(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;
|
||||||
|
|
||||||
const auto all = path.template walk<Mesh<N>, int>(base, gens(context), [table](Mesh<N> from, int gen) {
|
auto _gens = gens(context);
|
||||||
from.apply(table, gen);
|
|
||||||
return from;
|
auto res = path.walk<std::vector<Primitive<N>>, int>(base, gens(context), [&](auto from, auto gen) {
|
||||||
|
return apply(from, table, gen);
|
||||||
});
|
});
|
||||||
|
|
||||||
return merge(all);
|
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>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Mesh<N + 1> fan(int root) const {
|
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
|
||||||
std::vector<Primitive<N + 1>> res(prims.size());
|
std::vector<Primitive<N + 1>> res(prims.size());
|
||||||
std::transform(prims.begin(), prims.end(), res.begin(),
|
std::transform(prims.begin(), prims.end(), res.begin(),
|
||||||
[root](const Primitive<N> &prim) {
|
[root](const Primitive<N> &prim) {
|
||||||
return Primitive<N + 1>(prim, root);
|
return Primitive<N + 1>(prim, root);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
return Mesh<N + 1>(res);
|
return res;
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Union several meshes of the same dimension
|
|
||||||
*/
|
|
||||||
template<unsigned N>
|
|
||||||
Mesh<N> merge(const std::vector<Mesh<N>> &meshes) {
|
|
||||||
size_t size = 0;
|
|
||||||
for (const auto &mesh : meshes) {
|
|
||||||
size += mesh.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<Primitive<N>> prims;
|
|
||||||
prims.reserve(size);
|
|
||||||
for (const auto &mesh : meshes) {
|
|
||||||
prims.insert(prims.end(), mesh.prims.begin(), mesh.prims.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
return Mesh(prims);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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>
|
||||||
Mesh<N> triangulate(
|
std::vector<Primitive<N>> triangulate(
|
||||||
const tc::Group &context,
|
const tc::Group &context,
|
||||||
const std::vector<int> &g_gens
|
const std::vector<int> &g_gens
|
||||||
) {
|
) {
|
||||||
@@ -237,13 +231,13 @@ Mesh<N> triangulate(
|
|||||||
|
|
||||||
const auto &combos = Combos(g_gens, g_gens.size() - 1);
|
const auto &combos = Combos(g_gens, g_gens.size() - 1);
|
||||||
|
|
||||||
std::vector<Mesh<N>> meshes;
|
std::vector<std::vector<Primitive<N>>> meshes;
|
||||||
|
|
||||||
for (const auto &sg_gens : combos) {
|
for (const auto &sg_gens : combos) {
|
||||||
Mesh<N - 1> base = triangulate<N - 1>(context, sg_gens);
|
auto base = triangulate<N - 1>(context, sg_gens);
|
||||||
Mesh<N - 1> raised = base.tile(context, g_gens, sg_gens);
|
auto raised = tile(base, context, g_gens, sg_gens);
|
||||||
raised.prims.erase(raised.prims.begin(), raised.prims.begin() + base.size());
|
raised.erase(raised.begin(), raised.begin() + base.size());
|
||||||
Mesh<N> fan = raised.fan(0);
|
meshes.push_back(fan(raised, 0));
|
||||||
meshes.push_back(fan);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return merge(meshes);
|
return merge(meshes);
|
||||||
@@ -253,14 +247,14 @@ Mesh<N> triangulate(
|
|||||||
* Single-index primitives should not be further triangulated.
|
* Single-index primitives should not be further triangulated.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
Mesh<1> triangulate<1>(
|
std::vector<Primitive<1>> triangulate(
|
||||||
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");
|
||||||
|
|
||||||
Mesh<1> res;
|
std::vector<Primitive<1>> res;
|
||||||
res.prims.emplace_back();
|
res.emplace_back();
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -85,12 +85,12 @@ Matrices build(GLFWwindow *window, float st) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
std::vector<Mesh<N>> poly_parts(const tc::Group &group) {
|
std::vector<std::vector<Primitive<N>>> poly_parts(const tc::Group &group) {
|
||||||
std::vector<Mesh<N>> parts;
|
std::vector<std::vector<Primitive<N>>> parts;
|
||||||
auto g_gens = gens(group);
|
auto g_gens = gens(group);
|
||||||
for (const auto &sg_gens : Combos(g_gens, N - 1)) {
|
for (const auto &sg_gens : Combos(g_gens, N - 1)) {
|
||||||
parts.push_back(
|
parts.push_back(
|
||||||
triangulate<N>(group, sg_gens).tile(group, g_gens, sg_gens)
|
tile(triangulate<N>(group, sg_gens), group, g_gens, sg_gens)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return parts;
|
return parts;
|
||||||
@@ -171,10 +171,10 @@ void run(GLFWwindow *window) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Drawable<2, float> wires(GL_LINES);
|
Drawable<2, float> wires(GL_LINES);
|
||||||
wires.ibo.put(wire_data.prims);
|
wires.ibo.put(wire_data);
|
||||||
|
|
||||||
Drawable<4, glm::vec3> slices(GL_POINTS);
|
Drawable<4, glm::vec3> slices(GL_POINTS);
|
||||||
slices.ibo.put(slice_data.prims);
|
slices.ibo.put(slice_data);
|
||||||
slices.vbo.put(slice_colors);
|
slices.vbo.put(slice_colors);
|
||||||
slices.vao.ipointer(0, slices.ibo, 4, GL_UNSIGNED_INT);
|
slices.vao.ipointer(0, slices.ibo, 4, GL_UNSIGNED_INT);
|
||||||
slices.vao.pointer(1, slices.vbo, 3, GL_FLOAT);
|
slices.vao.pointer(1, slices.vbo, 3, GL_FLOAT);
|
||||||
|
|||||||
Reference in New Issue
Block a user