remove old "Mesh" class

This commit is contained in:
2020-03-10 22:45:58 -04:00
parent b03566a519
commit 9120b385c4
2 changed files with 103 additions and 109 deletions

View File

@@ -108,47 +108,38 @@ tc::Cosets solve(
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.
*/
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) {
prim.apply(table, gen);
}
}
return prims;
}
/**
/**
* 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) {
prim.flip();
}
}
}
/**
/**
* 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.
*/
[[nodiscard]]
Mesh<N> recontext(
template<unsigned N>
[[nodiscard]]
std::vector<Primitive<N>> recontext(
std::vector<Primitive<N>> prims,
const tc::Group &context,
const std::vector<int> &g_gens,
const std::vector<int> &sg_gens
) const {
) {
const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens);
const auto table = solve(context, g_gens, {});
const auto path = solve(context, sg_gens, {}).path;
@@ -157,78 +148,81 @@ struct Mesh {
return table.get(coset, gen);
});
Mesh<N> res = *this;
for (Primitive<N> &prim : res.prims) {
std::vector<Primitive<N>> res(prims);
for (Primitive<N> &prim : res) {
for (auto &ind : prim.inds) {
ind = map[ind];
}
}
if (get_parity(context, g_gens, sg_gens) == 1)
res.flip();
flip(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();
}
[[nodiscard]]
Mesh<N> tile(
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]]
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
) 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 table = solve(context, g_gens, {});
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) {
from.apply(table, gen);
return from;
auto _gens = gens(context);
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.
*/
[[nodiscard]]
Mesh<N + 1> fan(int root) const {
template<unsigned N>
[[nodiscard]]
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
std::vector<Primitive<N + 1>> res(prims.size());
std::transform(prims.begin(), prims.end(), res.begin(),
[root](const Primitive<N> &prim) {
return Primitive<N + 1>(prim, root);
}
);
return Mesh<N + 1>(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);
return res;
}
/**
* 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>
Mesh<N> triangulate(
std::vector<Primitive<N>> triangulate(
const tc::Group &context,
const std::vector<int> &g_gens
) {
@@ -237,13 +231,13 @@ Mesh<N> triangulate(
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) {
Mesh<N - 1> base = triangulate<N - 1>(context, sg_gens);
Mesh<N - 1> raised = base.tile(context, g_gens, sg_gens);
raised.prims.erase(raised.prims.begin(), raised.prims.begin() + base.size());
Mesh<N> fan = raised.fan(0);
meshes.push_back(fan);
auto base = triangulate<N - 1>(context, sg_gens);
auto raised = tile(base, context, g_gens, sg_gens);
raised.erase(raised.begin(), raised.begin() + base.size());
meshes.push_back(fan(raised, 0));
}
return merge(meshes);
@@ -253,14 +247,14 @@ Mesh<N> triangulate(
* Single-index primitives should not be further triangulated.
*/
template<>
Mesh<1> triangulate<1>(
std::vector<Primitive<1>> triangulate(
const tc::Group &context,
const std::vector<int> &g_gens
) {
if (not g_gens.empty()) // todo make static assert
throw std::logic_error("g_gens must be empty for a trivial Mesh");
Mesh<1> res;
res.prims.emplace_back();
std::vector<Primitive<1>> res;
res.emplace_back();
return res;
}

View File

@@ -85,12 +85,12 @@ Matrices build(GLFWwindow *window, float st) {
}
template<unsigned N>
std::vector<Mesh<N>> poly_parts(const tc::Group &group) {
std::vector<Mesh<N>> parts;
std::vector<std::vector<Primitive<N>>> poly_parts(const tc::Group &group) {
std::vector<std::vector<Primitive<N>>> parts;
auto g_gens = gens(group);
for (const auto &sg_gens : Combos(g_gens, N - 1)) {
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;
@@ -171,10 +171,10 @@ void run(GLFWwindow *window) {
}
Drawable<2, float> wires(GL_LINES);
wires.ibo.put(wire_data.prims);
wires.ibo.put(wire_data);
Drawable<4, glm::vec3> slices(GL_POINTS);
slices.ibo.put(slice_data.prims);
slices.ibo.put(slice_data);
slices.vbo.put(slice_colors);
slices.vao.ipointer(0, slices.ibo, 4, GL_UNSIGNED_INT);
slices.vao.pointer(1, slices.vbo, 3, GL_FLOAT);