mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
ENH: Format solver
This commit is contained in:
@@ -13,7 +13,9 @@
|
|||||||
/**
|
/**
|
||||||
* Produce a list of all generators for the group context. The range [0..group.rank()).
|
* Produce a list of all generators for the group context. The range [0..group.rank()).
|
||||||
*/
|
*/
|
||||||
std::vector<size_t> generators(const tc::Group &context) {
|
std::vector<size_t> _generators(
|
||||||
|
const tc::Group &context
|
||||||
|
) {
|
||||||
std::vector<size_t> g_gens(context.rank());
|
std::vector<size_t> g_gens(context.rank());
|
||||||
std::iota(g_gens.begin(), g_gens.end(), 0);
|
std::iota(g_gens.begin(), g_gens.end(), 0);
|
||||||
return g_gens;
|
return g_gens;
|
||||||
@@ -24,7 +26,12 @@ std::vector<size_t> generators(const tc::Group &context) {
|
|||||||
*
|
*
|
||||||
* For example if g_gens contains {a, b, c, d} and sg_gens contains {b, d, a} then the result is {1, 3, 0}
|
* For example if g_gens contains {a, b, c, d} and sg_gens contains {b, d, a} then the result is {1, 3, 0}
|
||||||
*/
|
*/
|
||||||
std::vector<size_t> recontext_gens(std::vector<size_t> g_gens, std::vector<size_t> sg_gens) {
|
std::vector<size_t> _recontext_gens(
|
||||||
|
std::vector<size_t> g_gens,
|
||||||
|
std::vector<size_t> sg_gens
|
||||||
|
) {
|
||||||
|
auto orig = sg_gens;
|
||||||
|
|
||||||
for (size_t &gen: sg_gens) {
|
for (size_t &gen: sg_gens) {
|
||||||
gen = std::distance(
|
gen = std::distance(
|
||||||
g_gens.begin(),
|
g_gens.begin(),
|
||||||
@@ -39,9 +46,13 @@ std::vector<size_t> recontext_gens(std::vector<size_t> g_gens, std::vector<size_
|
|||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Indices<N> recontext(Indices<N> prims, const tc::Group &context, const std::vector<size_t> &g_gens,
|
Indices<N> recontext(
|
||||||
const std::vector<size_t> &sg_gens) {
|
Indices<N> prims,
|
||||||
const auto proper_sg_gens = recontext_gens(g_gens, 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(g_gens, sg_gens);
|
||||||
const auto table = context.sub(g_gens).solve({});
|
const auto table = context.sub(g_gens).solve({});
|
||||||
const auto cosets = context.sub(sg_gens).solve({});
|
const auto cosets = context.sub(sg_gens).solve({});
|
||||||
|
|
||||||
@@ -65,7 +76,9 @@ Indices<N> recontext(Indices<N> prims, const tc::Group &context, const std::vect
|
|||||||
* Union several meshes of the same dimension
|
* Union several meshes of the same dimension
|
||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
Indices<N> merge(const std::vector<Indices<N>> &meshes) {
|
Indices<N> merge(
|
||||||
|
const std::vector<Indices<N>> &meshes
|
||||||
|
) {
|
||||||
size_t cols = 0;
|
size_t cols = 0;
|
||||||
for (const auto &mesh: meshes) {
|
for (const auto &mesh: meshes) {
|
||||||
cols += mesh.cols();
|
cols += mesh.cols();
|
||||||
@@ -84,10 +97,14 @@ Indices<N> merge(const std::vector<Indices<N>> &meshes) {
|
|||||||
|
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
std::vector<Indices<N>> tile(Indices<N> prims, const tc::Group &context, const std::vector<size_t> &g_gens,
|
std::vector<Indices<N>> tile(
|
||||||
const std::vector<size_t> &sg_gens) {
|
Indices<N> prims,
|
||||||
|
const tc::Group &context,
|
||||||
|
const std::vector<size_t> &g_gens,
|
||||||
|
const std::vector<size_t> &sg_gens
|
||||||
|
) {
|
||||||
Indices<N> base = recontext<N>(prims, context, g_gens, sg_gens);
|
Indices<N> base = recontext<N>(prims, context, g_gens, sg_gens);
|
||||||
const auto proper_sg_gens = recontext_gens(g_gens, sg_gens);
|
const auto proper_sg_gens = _recontext_gens(g_gens, sg_gens);
|
||||||
|
|
||||||
const auto &table = context.sub(g_gens).solve({});
|
const auto &table = context.sub(g_gens).solve({});
|
||||||
const auto &cosets = context.sub(g_gens).solve(proper_sg_gens);
|
const auto &cosets = context.sub(g_gens).solve(proper_sg_gens);
|
||||||
@@ -111,7 +128,10 @@ std::vector<Indices<N>> tile(Indices<N> prims, const tc::Group &context, const s
|
|||||||
*/
|
*/
|
||||||
template<unsigned N>
|
template<unsigned N>
|
||||||
[[nodiscard]]
|
[[nodiscard]]
|
||||||
Indices<N + 1> fan(Indices<N> prims, int root) {
|
Indices<N + 1> fan(
|
||||||
|
Indices<N> prims,
|
||||||
|
int root
|
||||||
|
) {
|
||||||
Indices<N + 1> res(N + 1, prims.cols());
|
Indices<N + 1> res(N + 1, prims.cols());
|
||||||
|
|
||||||
res.topRows(1) = Indices<1>::Constant(1, prims.cols(), root);
|
res.topRows(1) = Indices<1>::Constant(1, prims.cols(), root);
|
||||||
@@ -124,7 +144,10 @@ Indices<N + 1> fan(Indices<N> prims, int root) {
|
|||||||
* 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>
|
||||||
Indices<N> triangulate(const tc::Group &context, const std::vector<size_t> &g_gens) {
|
Indices<N> triangulate(
|
||||||
|
const tc::Group &context,
|
||||||
|
const std::vector<size_t> &g_gens
|
||||||
|
) {
|
||||||
if (g_gens.size() + 1 != N) // todo make static assert
|
if (g_gens.size() + 1 != N) // todo make static assert
|
||||||
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");
|
||||||
|
|
||||||
@@ -148,7 +171,10 @@ Indices<N> triangulate(const tc::Group &context, const std::vector<size_t> &g_ge
|
|||||||
* Single-index primitives should not be further triangulated.
|
* Single-index primitives should not be further triangulated.
|
||||||
*/
|
*/
|
||||||
template<>
|
template<>
|
||||||
Indices<1> triangulate<1>(const tc::Group &context, const std::vector<size_t> &g_gens) {
|
Indices<1> triangulate<1>(
|
||||||
|
const tc::Group &context,
|
||||||
|
const std::vector<size_t> &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");
|
||||||
|
|
||||||
@@ -156,9 +182,13 @@ Indices<1> triangulate<1>(const tc::Group &context, const std::vector<size_t> &g
|
|||||||
}
|
}
|
||||||
|
|
||||||
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<Indices<N>> parts;
|
std::vector<Indices<N>> parts;
|
||||||
auto g_gens = generators(group);
|
auto g_gens = _generators(group);
|
||||||
for (const std::vector<size_t> &sg_gens: all_sg_gens) {
|
for (const 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) {
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ namespace vis {
|
|||||||
vec3 color;
|
vec3 color;
|
||||||
|
|
||||||
std::vector<std::vector<size_t>> exclude {{0, 1, 2}};
|
std::vector<std::vector<size_t>> exclude {{0, 1, 2}};
|
||||||
std::vector<std::vector<size_t>> include = combinations(generators(group), 3);
|
std::vector<std::vector<size_t>> include = combinations(_generators(group), 3);
|
||||||
};
|
};
|
||||||
|
|
||||||
struct VBOs {
|
struct VBOs {
|
||||||
|
|||||||
Reference in New Issue
Block a user