OPT: Remove not-working parity logic for culling

This commit is contained in:
David Allemang
2023-01-26 16:19:36 -05:00
parent 6ef6fbf4ac
commit 486977f444

View File

@@ -28,15 +28,10 @@ struct Primitive {
~Primitive() = default; ~Primitive() = default;
inline void flip() {
if (N > 1) std::swap(inds[0], inds[1]);
}
void apply(const tc::Cosets<> &table, int gen) { void apply(const tc::Cosets<> &table, int gen) {
for (auto &ind: inds) { for (auto &ind: inds) {
ind = table.get(ind, gen); ind = table.get(ind, gen);
} }
flip();
} }
}; };
@@ -51,15 +46,15 @@ std::vector<size_t> generators(const tc::Group<> &context) {
/** /**
* Determine which of g_gens are the correct names for sg_gens within the current context * Determine which of g_gens are the correct names for sg_gens within the current context
*
* Produces the indexes of sg_gens within g_gens; sorted.
*/ */
std::vector<size_t> recontext_gens( std::vector<size_t> recontext_gens(
const tc::Group<> &context, const tc::Group<> &context,
std::vector<size_t> g_gens, const std::vector<size_t> &g_gens,
std::vector<size_t> sg_gens) { const std::vector<size_t> &sg_gens) {
std::sort(g_gens.begin(), g_gens.end()); size_t inv_gen_map[context.rank()];
int inv_gen_map[context.rank()];
for (size_t i = 0; i < g_gens.size(); i++) { for (size_t i = 0; i < g_gens.size(); i++) {
inv_gen_map[g_gens[i]] = i; inv_gen_map[g_gens[i]] = i;
} }
@@ -69,45 +64,10 @@ std::vector<size_t> recontext_gens(
for (const auto gen : sg_gens) { for (const auto gen : sg_gens) {
s_sg_gens.push_back(inv_gen_map[gen]); s_sg_gens.push_back(inv_gen_map[gen]);
} }
std::sort(s_sg_gens.begin(), s_sg_gens.end());
return s_sg_gens; return s_sg_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<size_t> &g_gens,
const std::vector<size_t> &sg_gens
) {
if (g_gens.size() != sg_gens.size() + 1) return 0;
const auto proper_sg_gens = recontext_gens(context, g_gens, sg_gens);
int i = 0;
for (; i < sg_gens.size(); ++i) {
if (proper_sg_gens[i] != i) {
break;
}
}
return i & 1;
}
/**
* 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<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.sub(g_gens).solve(proper_sg_gens);
}
/** /**
* Apply some context transformation to all primitives of this mesh. * Apply some context transformation to all primitives of this mesh.
*/ */
@@ -119,16 +79,6 @@ std::vector<Primitive<N>> apply(std::vector<Primitive<N>> prims, const tc::Coset
return prims; return prims;
} }
/**
* Reverse the orientation of all primitives in this mesh.
*/
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. * 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.
*/ */
@@ -141,26 +91,23 @@ std::vector<Primitive<N>> recontext(
const std::vector<size_t> &sg_gens const std::vector<size_t> &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 = context.sub(g_gens).solve({});
const auto &cosets = solve(context, sg_gens, {}); const auto cosets = context.sub(sg_gens).solve({});
tc::Path<size_t> path(cosets, proper_sg_gens); tc::Path<size_t> path(cosets, proper_sg_gens);
std::vector<size_t> map(path.order()); std::vector<size_t> map(path.order());
path.walk(0, [&table](size_t coset, size_t gen){ path.walk(0, [&table](size_t coset, size_t gen) {
return table.get(coset, gen); return table.get(coset, gen);
}, map.begin()); }, map.begin());
std::vector<Primitive<N>> res(prims); std::vector<Primitive<N>> res(prims);
for (Primitive<N> &prim : res) { 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)
flip(res);
return res; return res;
} }
@@ -194,10 +141,11 @@ std::vector<std::vector<Primitive<N>>> each_tile(
std::vector<Primitive<N>> base = recontext(prims, 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 = context.sub(g_gens).solve({});
tc::Path path(solve(context, g_gens, sg_gens));
auto _gens = generators(context); const tc::Cosets<> &cosets = context.sub(g_gens).solve(proper_sg_gens);
tc::Path path(cosets);
std::vector<std::vector<Primitive<N>>> res(path.order()); std::vector<std::vector<Primitive<N>>> res(path.order());
path.walk(base, [&](auto from, auto to) { path.walk(base, [&](auto from, auto to) {
@@ -227,10 +175,12 @@ template<unsigned N>
[[nodiscard]] [[nodiscard]]
std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, size_t root) { std::vector<Primitive<N + 1>> fan(std::vector<Primitive<N>> prims, size_t 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(
[root](const Primitive<N> &prim) { prims.begin(), prims.end(),
return Primitive<N + 1>(prim, root); res.begin(),
} [root](const Primitive<N> &prim) {
return Primitive<N + 1>(prim, root);
}
); );
return res; return res;
} }
@@ -243,14 +193,15 @@ std::vector<Primitive<N>> triangulate(
const tc::Group<> &context, const tc::Group<> &context,
const std::vector<size_t> &g_gens const std::vector<size_t> &g_gens
) { ) {
if (g_gens.size() + 1 != N) // todo make static assert if (g_gens.size() + 1 != N) {
throw std::logic_error("g_gens size must be one less than N"); throw std::logic_error("g_gens size must be one less than N");
}
const auto &combos = Combos(g_gens, g_gens.size() - 1); const auto &combos = Combos<size_t>(g_gens, g_gens.size() - 1U);
std::vector<std::vector<Primitive<N>>> meshes; std::vector<std::vector<Primitive<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 raised = tile(base, context, g_gens, sg_gens);
raised.erase(raised.begin(), raised.begin() + base.size()); raised.erase(raised.begin(), raised.begin() + base.size());
@@ -260,16 +211,15 @@ std::vector<Primitive<N>> triangulate(
return merge(meshes); return merge(meshes);
} }
/** // Single-index primitives should not be further triangulated.
* Single-index primitives should not be further triangulated.
*/
template<> template<>
std::vector<Primitive<1>> triangulate( std::vector<Primitive<1>> triangulate(
const tc::Group<> &context, const tc::Group<> &,
const std::vector<size_t> &g_gens const std::vector<size_t> &g_gens
) { ) {
if (not g_gens.empty()) // todo make static assert if (not g_gens.empty()) {
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; std::vector<Primitive<1>> res;
res.emplace_back(); res.emplace_back();
@@ -279,7 +229,9 @@ std::vector<Primitive<1>> triangulate(
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<size_t>> &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; std::vector<std::vector<Primitive<N>>> parts;
auto g_gens = generators(group); auto g_gens = generators(group);
for (std::vector<size_t> sg_gens: all_sg_gens) { for (std::vector<size_t> sg_gens: all_sg_gens) {
bool excluded = false; bool excluded = false;
for (const auto &test: exclude) { for (const auto &test: exclude) {