From 6e3ea1900b9b85a25e2ed667689719f2542a287f Mon Sep 17 00:00:00 2001 From: David Allemang Date: Thu, 22 Oct 2020 21:49:06 -0400 Subject: [PATCH] Convert hull to static method; inline all_sg_gens and exclude parameters for future testing. --- vis/include/rendering.hpp | 11 +++++-- vis/include/solver.hpp | 65 +++++++++++---------------------------- vis/src/main.cpp | 14 +++------ 3 files changed, 31 insertions(+), 59 deletions(-) diff --git a/vis/include/rendering.hpp b/vis/include/rendering.hpp index 068db9e..0be3cc2 100644 --- a/vis/include/rendering.hpp +++ b/vis/include/rendering.hpp @@ -45,9 +45,14 @@ public: cgl::Buffer vbo; cgl::VertexArray vao; - template - Slice(const tc::Group &g, T all_sg_gens, const std::vector> &exclude) : group(g) { - auto mesh = merge(hull(g, exclude)); + explicit Slice(const tc::Group &g) : group(g) { + auto gens = generators(group); + auto combos = Combos(gens, 3); + std::vector> exclude = {{0, 1, 2}}; + + auto all_sg_gens = combos; + + auto mesh = Mesh::hull(g, generators(g), all_sg_gens); ibo.put(mesh); vao.ipointer(0, ibo, 4, GL_UNSIGNED_INT); diff --git a/vis/include/solver.hpp b/vis/include/solver.hpp index 94265d9..6eedc24 100644 --- a/vis/include/solver.hpp +++ b/vis/include/solver.hpp @@ -70,29 +70,6 @@ namespace { } } -//template -//auto hull(const tc::Group &group, T all_sg_gens, const std::vector> &exclude) { -// std::vector> parts; -// auto g_gens = generators(group); -// for (const std::vector &sg_gens : all_sg_gens) { -// bool excluded = false; -// for (const auto &test : exclude) { -// if (sg_gens == test) { -// excluded = true; -// break; -// } -// } -// if (excluded) continue; -// -// const auto &base = triangulate(group, sg_gens); -// const auto &tiles = tile(base, group, g_gens, sg_gens); -// for (const auto &tile : tiles) { -// parts.push_back(tile); -// } -// } -// return parts; -//} - template class Mesh { public: @@ -102,7 +79,10 @@ public: Mesh(const tc::Group &g_, std::vector ctx_, size_t cols); - Mesh(const tc::Group &g_, std::vector ctx_); + static Mesh fill(const tc::Group &g, std::vector ctx); + + template + static Mesh hull(const tc::Group &g, std::vector ctx, const SC &sub_ctxs); Mesh recontext(std::vector ctx_); @@ -200,17 +180,16 @@ Mesh::Mesh(const tc::Group &g_, std::vector ctx_, size_t cols) } template -Mesh::Mesh(const tc::Group &g_, std::vector ctx_) - : g(&g_), ctx(std::move(ctx_)) { - if (ctx.size() + 1 != N) // todo make static assert +Mesh Mesh::fill(const tc::Group &g, std::vector ctx) { + if (ctx.size() + 1 != N) throw std::logic_error("ctx size must be one less than N"); - const auto &combos = Combos(ctx, ctx.size() - 1); + const auto &combos = Combos(ctx, (int)ctx.size() - 1); std::vector> meshes; - for (const auto &sctx : combos) { - Mesh base(*g, sctx); + for (const auto &sub_ctx : combos) { + auto base = Mesh::fill(g, sub_ctx); auto parts = base.tile(ctx); parts.erase(parts.begin(), parts.begin() + 1); @@ -221,34 +200,26 @@ Mesh::Mesh(const tc::Group &g_, std::vector ctx_) meshes.push_back(fanned); } - prims = merge(meshes).prims; + return merge(meshes); } template<> -Mesh<1>::Mesh(const tc::Group &g_, std::vector ctx_) : g(&g_), ctx(std::move(ctx_)) { +Mesh<1> Mesh<1>::fill(const tc::Group &g, std::vector ctx) { if (not ctx.empty()) throw std::logic_error("ctx must be empty for a trivial Mesh."); - prims.setZero(1, 1); + return Mesh<1>(g, ctx, 1); } template -auto hull(const tc::Group &g, const std::vector> &exclude) { +template +Mesh Mesh::hull(const tc::Group &g, const std::vector ctx, const SC &sub_ctxs) { std::vector> parts; - auto ctx = generators(g); - auto sub_ctxs = Combos(ctx, N - 1); - for (const auto &sub_ctx : sub_ctxs) { - bool excluded = std::any_of( - exclude.begin(), exclude.end(), - [&](auto e) { return e == sub_ctx; } - ); - if (excluded) continue; - - auto sub_parts = Mesh(g, sub_ctx).tile(ctx); - parts.insert(parts.end(), sub_parts.begin(), sub_parts.end()); + auto face = Mesh::fill(g, sub_ctx).tile(ctx); + parts.insert(parts.end(), face.begin(), face.end()); } - return parts; -} \ No newline at end of file + return merge(parts); +} diff --git a/vis/src/main.cpp b/vis/src/main.cpp index bc0fc4a..052fc1b 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -18,9 +18,9 @@ mat5 wander(float time) { r *= rot<5>(1, 2, time * .13f); r *= rot<5>(0, 1, time * .20f); -// r *= rot<5>(0, 3, time * .17f); -// r *= rot<5>(1, 3, time * .25f); -// r *= rot<5>(2, 3, time * .12f); + r *= rot<5>(0, 3, time * .17f); + r *= rot<5>(1, 3, time * .25f); + r *= rot<5>(2, 3, time * .12f); // r *= rot<5>(1, 4, time * .27f); @@ -66,16 +66,12 @@ public: std::cout << utilInfo(); - std::vector symbol = {5, 3, 2, 2}; + std::vector symbol = {3, 4, 3, 2}; root << .80, .02, .02, .02, .02; auto group = tc::schlafli(symbol); - auto gens = generators(group); - auto combos = Combos(gens, 3); - std::vector> exclude = {{0, 1, 2}}; - - slice = std::make_unique>(group, combos, exclude); + slice = std::make_unique>(group); ren = std::make_unique>(); ubo = std::make_unique>();