diff --git a/vis/include/mirror.hpp b/vis/include/mirror.hpp index aa8b147..89e7aba 100644 --- a/vis/include/mirror.hpp +++ b/vis/include/mirror.hpp @@ -28,44 +28,41 @@ Eigen::Matrix mirror(const tc::Group<> &group) { return res; } -template -vec stereo(const vec &v) { - vec r; - for (int i = 0; i < N; ++i) { - r[i] = v[i] / (1 - v[N]); +struct Stereo { + template + auto operator()(U &&mat) const { + const auto Rows = std::remove_reference::type::RowsAtCompileTime; + return std::forward(mat).template topRows().rowwise() / (1 - mat.template bottomRows<1>()); } - return r; -} +}; -template -vec ortho(const vec &v) { - vec r; - for (int i = 0; i < N; ++i) { - r[i] = v[i]; +struct Ortho { + template + auto operator()(U &&mat) const { + const auto Rows = std::remove_reference::type::RowsAtCompileTime; + return std::forward(mat).template topRows(); } - return r; -} +}; -template -V project(const V &vec, const V &target) { - return vec.dot(target) / target.dot(target) * target; -} +struct Project { + template + auto operator()(U &&point, V &&axis) const { + return point.dot(axis) / axis.dot(axis) * std::forward(axis); + } +}; -template -V reflect(const V &a, const V &axis) { - return a - 2.f * project(a, axis); -} - -template -auto project_(const Point &point, const Axis &axis) { - return axis.dot(point) / axis.dot(axis) * axis; -} +struct Reflect { + template + auto operator()(U &&point, V &&axis) const { + return std::forward(point) - 2 * Project()(point, axis); + } +}; template Mat gram_schmidt(Mat mat) { for (int i = 0; i < mat.cols(); ++i) { for (int j = i + 1; j < mat.cols(); ++j) { - mat.col(j) -= project_(mat.col(j), mat.col(i)); + mat.col(j) -= Project()(mat.col(j), mat.col(i)); } } return mat; diff --git a/vis/src/main.cpp b/vis/src/main.cpp index 799a0f6..43e5b47 100644 --- a/vis/src/main.cpp +++ b/vis/src/main.cpp @@ -43,7 +43,7 @@ struct State { int dimension; }; -Matrices build(GLFWwindow *window, State &state) { +Matrices build(GLFWwindow* window, State &state) { int width, height; glfwGetFramebufferSize(window, &width, &height); @@ -90,13 +90,18 @@ std::vector points(const tc::Group<> &group, const C &coords) { tc::Path path(cosets, mirrors.colwise()); - std::vector higher(path.order()); - path.walk(start, reflect, higher.begin()); + Eigen::Array higher(5, path.order()); + path.walk(start, Reflect(), higher.matrix().colwise().begin()); +// std::vector higher(path.order()); +// path.walk(start, Reflect(), higher.begin()); - std::vector lower(higher.size()); - std::transform(higher.begin(), higher.end(), lower.begin(), stereo<4>); +// Eigen::Array4Xf lower = higher.topRows<4>().rowwise() / (1 - higher.bottomRows<1>()); + Eigen::Array4Xf lower = Stereo()(higher); - return lower; + std::vector vec(lower.cols()); + std::copy(lower.colwise().begin(), lower.colwise().end(), vec.begin()); + + return vec; } template @@ -120,7 +125,7 @@ struct Renderer { void render() const { bound([&]() { - for (const auto &prop : props) { + for (const auto &prop: props) { _draw(prop); } }); @@ -219,7 +224,7 @@ struct DirectRenderer : public Renderer { struct WireframeProp : public Prop<2> { - WireframeProp(vec3 color) : Prop<2>(){ + WireframeProp(vec3 color) : Prop<2>() { this->color = color; } @@ -229,12 +234,12 @@ struct WireframeProp : public Prop<2> { template static WireframeProp build(const tc::Group<> &g, - const C &coords, - bool curve, - bool ortho, - vec3 color, - T all_sg_gens, - const std::vector> &exclude + const C &coords, + bool curve, + bool ortho, + vec3 color, + T all_sg_gens, + const std::vector> &exclude ) { WireframeProp res(color); @@ -245,7 +250,7 @@ struct WireframeProp : public Prop<2> { } }; -void run(const std::string &config_file, GLFWwindow *window) { +void run(const std::string &config_file, GLFWwindow* window) { glEnable(GL_DEPTH_TEST); glEnable(GL_BLEND); @@ -279,13 +284,13 @@ void run(const std::string &config_file, GLFWwindow *window) { state.dimension = scene["dimension"].as(); - for (const auto &group_info : scene["groups"]) { + for (const auto &group_info: scene["groups"]) { auto symbol = group_info["symbol"].as>(); auto group = tc::schlafli(symbol); auto gens = generators(group); if (group_info["slices"].IsDefined()) { - for (const auto &slice_info : group_info["slices"]) { + for (const auto &slice_info: group_info["slices"]) { auto root_arr = slice_info["root"].as>(); auto color_arr = slice_info["color"].as>(); @@ -315,7 +320,7 @@ void run(const std::string &config_file, GLFWwindow *window) { } if (group_info["wires"].IsDefined()) { - for (const auto &wire_info : group_info["wires"]) { + for (const auto &wire_info: group_info["wires"]) { auto root_arr = wire_info["root"].as>(); auto color_arr = wire_info["color"].as>(); @@ -411,7 +416,7 @@ void run(const std::string &config_file, GLFWwindow *window) { } } -int main(int argc, char *argv[]) { +int main(int argc, char* argv[]) { if (!glfwInit()) { std::cerr << "Failed to initialize GLFW" << std::endl; return EXIT_FAILURE;