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];
|
||||
|
||||
@@ -78,17 +78,22 @@ Matrices build(GLFWwindow *window, State &state) {
|
||||
}
|
||||
|
||||
template<class C>
|
||||
std::vector<vec4> points(const tc::Group &group, const C &coords) {
|
||||
std::vector<vec4> points(const tc::Group<> &group, const C &coords) {
|
||||
auto cosets = group.solve();
|
||||
auto mirrors = mirror<5>(group);
|
||||
|
||||
tc::Path<vec5> path(cosets, mirrors);
|
||||
|
||||
auto corners = plane_intersections(mirrors);
|
||||
|
||||
auto start = barycentric(corners, coords);
|
||||
|
||||
const auto &higher = cosets.path.walk<vec5, vec5>(start, mirrors, reflect<vec5>);
|
||||
std::vector<vec5> higher(path.order());
|
||||
path.walk(start, reflect<vec5>, higher.begin());
|
||||
|
||||
std::vector<vec4> lower(higher.size());
|
||||
std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>);
|
||||
|
||||
return lower;
|
||||
}
|
||||
|
||||
@@ -132,11 +137,11 @@ struct SliceProp : public Prop<N> {
|
||||
|
||||
template<class T, class C>
|
||||
static SliceProp<N> build(
|
||||
const tc::Group &g,
|
||||
const tc::Group<> &g,
|
||||
const C &coords,
|
||||
vec3 color,
|
||||
T all_sg_gens,
|
||||
const std::vector<std::vector<int>> &exclude
|
||||
const std::vector<std::vector<size_t>> &exclude
|
||||
) {
|
||||
SliceProp<N> res(color);
|
||||
|
||||
@@ -225,13 +230,13 @@ struct WireframeProp : public Prop<2> {
|
||||
WireframeProp(WireframeProp &&) noexcept = default;
|
||||
|
||||
template<class T, class C>
|
||||
static WireframeProp build(const tc::Group &g,
|
||||
static WireframeProp build(const tc::Group<> &g,
|
||||
const C &coords,
|
||||
bool curve,
|
||||
bool ortho,
|
||||
vec3 color,
|
||||
T all_sg_gens,
|
||||
const std::vector<std::vector<int>> &exclude
|
||||
const std::vector<std::vector<size_t>> &exclude
|
||||
) {
|
||||
WireframeProp res(color);
|
||||
|
||||
@@ -274,10 +279,10 @@ void run(const std::string &config_file, GLFWwindow *window) {
|
||||
State state{};
|
||||
glfwSetWindowUserPointer(window, &state);
|
||||
|
||||
state.dimension = scene["dimension"].as<int>();
|
||||
state.dimension = scene["dimension"].as<size_t>();
|
||||
|
||||
for (const auto &group_info : scene["groups"]) {
|
||||
auto symbol = group_info["symbol"].as<std::vector<int>>();
|
||||
auto symbol = group_info["symbol"].as<std::vector<unsigned int>>();
|
||||
auto group = tc::schlafli(symbol);
|
||||
auto gens = generators(group);
|
||||
|
||||
@@ -285,19 +290,19 @@ void run(const std::string &config_file, GLFWwindow *window) {
|
||||
for (const auto &slice_info : group_info["slices"]) {
|
||||
auto root = slice_info["root"].as<vec5>();
|
||||
auto color = slice_info["color"].as<vec3>();
|
||||
auto exclude = std::vector<std::vector<int>>();
|
||||
auto exclude = std::vector<std::vector<size_t>>();
|
||||
|
||||
if (slice_info["exclude"].IsDefined()) {
|
||||
exclude = slice_info["exclude"].as<std::vector<std::vector<int>>>();
|
||||
exclude = slice_info["exclude"].as<std::vector<std::vector<size_t>>>();
|
||||
}
|
||||
|
||||
if (slice_info["subgroups"].IsDefined()) {
|
||||
auto subgroups = slice_info["subgroups"].as<std::vector<std::vector<int>>>();
|
||||
auto subgroups = slice_info["subgroups"].as<std::vector<std::vector<size_t>>>();
|
||||
sRen.props.push_back(SliceProp<4>::build(
|
||||
group, root, color, subgroups, exclude
|
||||
));
|
||||
} else {
|
||||
auto combos = Combos<int>(gens, 3);
|
||||
auto combos = Combos<size_t>(gens, 3);
|
||||
sRen.props.push_back(SliceProp<4>::build(
|
||||
group, root, color, combos, exclude
|
||||
));
|
||||
@@ -309,16 +314,16 @@ void run(const std::string &config_file, GLFWwindow *window) {
|
||||
for (const auto &wire_info : group_info["wires"]) {
|
||||
auto root = wire_info["root"].as<vec5>();
|
||||
auto color = wire_info["color"].as<vec3>();
|
||||
auto exclude = std::vector<std::vector<int>>();
|
||||
auto exclude = std::vector<std::vector<size_t>>();
|
||||
auto curve = wire_info["curve"].IsDefined() && wire_info["curve"].as<bool>();
|
||||
auto ortho = wire_info["ortho"].IsDefined() && wire_info["ortho"].as<bool>();
|
||||
|
||||
if (wire_info["exclude"].IsDefined()) {
|
||||
exclude = wire_info["exclude"].as<std::vector<std::vector<int>>>();
|
||||
exclude = wire_info["exclude"].as<std::vector<std::vector<size_t>>>();
|
||||
}
|
||||
|
||||
if (wire_info["subgroups"].IsDefined()) {
|
||||
auto subgroups = wire_info["subgroups"].as<std::vector<std::vector<int>>>();
|
||||
auto subgroups = wire_info["subgroups"].as<std::vector<std::vector<size_t>>>();
|
||||
|
||||
if (ortho && curve) {
|
||||
wocRen.props.push_back(WireframeProp::build(
|
||||
@@ -338,7 +343,7 @@ void run(const std::string &config_file, GLFWwindow *window) {
|
||||
));
|
||||
}
|
||||
} else {
|
||||
auto combos = Combos<int>(gens, 1);
|
||||
auto combos = Combos<size_t>(gens, 1);
|
||||
|
||||
if (ortho && curve) {
|
||||
wocRen.props.push_back(WireframeProp::build(
|
||||
|
||||
Reference in New Issue
Block a user