mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
COMP: Replace toddcox-faster by reimplemented toddcox
This commit is contained in:
@@ -32,8 +32,8 @@ struct Primitive {
|
||||
if (N > 1) std::swap(inds[0], inds[1]);
|
||||
}
|
||||
|
||||
void apply(const tc::Cosets &table, int gen) {
|
||||
for (auto &ind : inds) {
|
||||
void apply(const tc::Cosets<> &table, int gen) {
|
||||
for (auto &ind: inds) {
|
||||
ind = table.get(ind, gen);
|
||||
}
|
||||
flip();
|
||||
@@ -43,8 +43,8 @@ struct Primitive {
|
||||
/**
|
||||
* Produce a list of all generators for the group context. The range [0..group.ngens).
|
||||
*/
|
||||
std::vector<int> generators(const tc::Group &context) {
|
||||
std::vector<int> g_gens(context.ngens);
|
||||
std::vector<size_t> generators(const tc::Group<> &context) {
|
||||
std::vector<size_t> g_gens(context.rank());
|
||||
std::iota(g_gens.begin(), g_gens.end(), 0);
|
||||
return g_gens;
|
||||
}
|
||||
@@ -52,19 +52,19 @@ std::vector<int> generators(const tc::Group &context) {
|
||||
/**
|
||||
* Determine which of g_gens are the correct names for sg_gens within the current context
|
||||
*/
|
||||
std::vector<int> recontext_gens(
|
||||
const tc::Group &context,
|
||||
std::vector<int> g_gens,
|
||||
std::vector<int> sg_gens) {
|
||||
std::vector<size_t> recontext_gens(
|
||||
const tc::Group<> &context,
|
||||
std::vector<size_t> g_gens,
|
||||
std::vector<size_t> sg_gens) {
|
||||
|
||||
std::sort(g_gens.begin(), g_gens.end());
|
||||
|
||||
int inv_gen_map[context.ngens];
|
||||
int inv_gen_map[context.rank()];
|
||||
for (size_t i = 0; i < g_gens.size(); i++) {
|
||||
inv_gen_map[g_gens[i]] = i;
|
||||
}
|
||||
|
||||
std::vector<int> s_sg_gens;
|
||||
std::vector<size_t> s_sg_gens;
|
||||
s_sg_gens.reserve(sg_gens.size());
|
||||
for (const auto gen : sg_gens) {
|
||||
s_sg_gens.push_back(inv_gen_map[gen]);
|
||||
@@ -78,9 +78,9 @@ std::vector<int> recontext_gens(
|
||||
* Determine whether the orientation of the group sg_gens is reversed from the group g_gens within group context
|
||||
*/
|
||||
int get_parity(
|
||||
const tc::Group &context,
|
||||
const std::vector<int> &g_gens,
|
||||
const std::vector<int> &sg_gens
|
||||
const tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens,
|
||||
const std::vector<size_t> &sg_gens
|
||||
) {
|
||||
if (g_gens.size() != sg_gens.size() + 1) return 0;
|
||||
|
||||
@@ -99,21 +99,21 @@ int get_parity(
|
||||
/**
|
||||
* Solve the cosets generated by sg_gens within the subgroup generated by g_gens of the group context
|
||||
*/
|
||||
tc::Cosets solve(
|
||||
const tc::Group &context,
|
||||
const std::vector<int> &g_gens,
|
||||
const std::vector<int> &sg_gens
|
||||
tc::Cosets<> solve(
|
||||
const tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens,
|
||||
const std::vector<size_t> &sg_gens
|
||||
) {
|
||||
const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens);
|
||||
return context.subgroup(g_gens).solve(proper_sg_gens);
|
||||
return context.sub(g_gens).solve(proper_sg_gens);
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply some context transformation to all primitives of this mesh.
|
||||
*/
|
||||
template<unsigned N>
|
||||
std::vector<Primitive<N>> apply(std::vector<Primitive<N>> prims, const tc::Cosets &table, int gen) {
|
||||
for (auto &prim : prims) {
|
||||
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;
|
||||
@@ -136,17 +136,20 @@ 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 tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens,
|
||||
const std::vector<size_t> &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, sg_gens, {}).path;
|
||||
const auto &cosets = solve(context, sg_gens, {});
|
||||
|
||||
auto map = path.template walk<int, int>(0, proper_sg_gens, [table](int coset, int gen) {
|
||||
tc::Path<size_t> path(cosets, proper_sg_gens);
|
||||
|
||||
std::vector<size_t> map(path.order());
|
||||
path.walk(0, [&table](size_t coset, size_t gen){
|
||||
return table.get(coset, gen);
|
||||
});
|
||||
}, map.begin());
|
||||
|
||||
std::vector<Primitive<N>> res(prims);
|
||||
for (Primitive<N> &prim : res) {
|
||||
@@ -184,21 +187,22 @@ template<unsigned N>
|
||||
[[nodiscard]]
|
||||
std::vector<std::vector<Primitive<N>>> each_tile(
|
||||
std::vector<Primitive<N>> prims,
|
||||
const tc::Group &context,
|
||||
const std::vector<int> &g_gens,
|
||||
const std::vector<int> &sg_gens
|
||||
const tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens,
|
||||
const std::vector<size_t> &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;
|
||||
tc::Path path(solve(context, g_gens, sg_gens));
|
||||
|
||||
auto _gens = generators(context);
|
||||
|
||||
auto res = path.walk<std::vector<Primitive<N>>, int>(base, generators(context), [&](auto from, auto gen) {
|
||||
return apply(from, table, gen);
|
||||
});
|
||||
std::vector<std::vector<Primitive<N>>> res(path.order());
|
||||
path.walk(base, [&](auto from, auto to) {
|
||||
return apply(from, table, to);
|
||||
}, res.begin());
|
||||
|
||||
return res;
|
||||
}
|
||||
@@ -207,9 +211,9 @@ 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 tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens,
|
||||
const std::vector<size_t> &sg_gens
|
||||
) {
|
||||
auto res = each_tile<N>(prims, context, g_gens, sg_gens);
|
||||
|
||||
@@ -221,12 +225,12 @@ std::vector<Primitive<N>> tile(
|
||||
*/
|
||||
template<unsigned N>
|
||||
[[nodiscard]]
|
||||
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
|
||||
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, size_t 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);
|
||||
}
|
||||
[root](const Primitive<N> &prim) {
|
||||
return Primitive<N + 1>(prim, root);
|
||||
}
|
||||
);
|
||||
return res;
|
||||
}
|
||||
@@ -236,8 +240,8 @@ std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, int root) {
|
||||
*/
|
||||
template<unsigned N>
|
||||
std::vector<Primitive<N>> triangulate(
|
||||
const tc::Group &context,
|
||||
const std::vector<int> &g_gens
|
||||
const tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens
|
||||
) {
|
||||
if (g_gens.size() + 1 != N) // todo make static assert
|
||||
throw std::logic_error("g_gens size must be one less than N");
|
||||
@@ -261,8 +265,8 @@ std::vector<Primitive<N>> triangulate(
|
||||
*/
|
||||
template<>
|
||||
std::vector<Primitive<1>> triangulate(
|
||||
const tc::Group &context,
|
||||
const std::vector<int> &g_gens
|
||||
const tc::Group<> &context,
|
||||
const std::vector<size_t> &g_gens
|
||||
) {
|
||||
if (not g_gens.empty()) // todo make static assert
|
||||
throw std::logic_error("g_gens must be empty for a trivial Mesh");
|
||||
@@ -273,12 +277,12 @@ std::vector<Primitive<1>> triangulate(
|
||||
}
|
||||
|
||||
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<size_t>> &exclude) {
|
||||
std::vector<std::vector<Primitive<N>>> parts;
|
||||
auto g_gens = generators(group);
|
||||
for (const std::vector<int> &sg_gens : all_sg_gens) {
|
||||
for (std::vector<size_t> sg_gens: all_sg_gens) {
|
||||
bool excluded = false;
|
||||
for (const auto &test : exclude) {
|
||||
for (const auto &test: exclude) {
|
||||
if (sg_gens == test) {
|
||||
excluded = true;
|
||||
break;
|
||||
|
||||
@@ -94,10 +94,10 @@ float dot(const V &a, const V &b) {
|
||||
}
|
||||
|
||||
template<unsigned N>
|
||||
std::vector<vec<N>> mirror(const tc::Group &group) {
|
||||
std::vector<vec<N>> mirror(const tc::Group<> &group) {
|
||||
std::vector<std::vector<float>> mirrors;
|
||||
|
||||
for (int p = 0; p < group.ngens; ++p) {
|
||||
for (int p = 0; p < group.rank(); ++p) {
|
||||
std::vector<float> vp;
|
||||
for (int m = 0; m < p; ++m) {
|
||||
auto &vq = mirrors[m];
|
||||
|
||||
Reference in New Issue
Block a user