mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 12:02:47 -05:00
new solver - point generation
This commit is contained in:
22
vis/src/combotest.cpp
Normal file
22
vis/src/combotest.cpp
Normal file
@@ -0,0 +1,22 @@
|
||||
#include <combo.hpp>
|
||||
|
||||
#include <iostream>
|
||||
|
||||
std::ostream &operator<<(std::ostream &o, const std::vector<int> &data) {
|
||||
o << "[ ";
|
||||
for (const auto &el: data) {
|
||||
o << el << " ";
|
||||
}
|
||||
o << "]";
|
||||
return o;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::vector<int> data{1, 2, 3, 4, 5};
|
||||
|
||||
for (const auto &combo: combinations(data, 3)) {
|
||||
std::cout << combo << std::endl;
|
||||
}
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
@@ -1,80 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#ifndef NDEBUG
|
||||
|
||||
void GLAPIENTRY log_gl_debug_callback(
|
||||
GLenum source,
|
||||
GLenum type,
|
||||
GLuint id,
|
||||
GLenum severity,
|
||||
GLsizei length,
|
||||
const GLchar *message,
|
||||
const void *userParam
|
||||
) {
|
||||
std::string s_source;
|
||||
switch (type) {
|
||||
case GL_DEBUG_SOURCE_API:
|
||||
s_source = "API:";
|
||||
case GL_DEBUG_SOURCE_WINDOW_SYSTEM:
|
||||
s_source = "WINDOW:";
|
||||
case GL_DEBUG_SOURCE_SHADER_COMPILER:
|
||||
s_source = "SHADER:";
|
||||
case GL_DEBUG_SOURCE_THIRD_PARTY:
|
||||
s_source = "3P:";
|
||||
case GL_DEBUG_SOURCE_APPLICATION:
|
||||
s_source = "APP:";
|
||||
default:
|
||||
s_source = "";
|
||||
}
|
||||
|
||||
std::string s_type;
|
||||
switch (type) {
|
||||
case GL_DEBUG_TYPE_ERROR:
|
||||
s_type = "ERROR:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_DEPRECATED_BEHAVIOR:
|
||||
s_type = "DEPRECATED:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_UNDEFINED_BEHAVIOR:
|
||||
s_type = "UNDEFINED:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PORTABILITY:
|
||||
s_type = "PORTABILITY:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PERFORMANCE:
|
||||
s_type = "PERFORMANCE:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_MARKER:
|
||||
s_type = "MARKER:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_PUSH_GROUP:
|
||||
s_type = "PUSH_GROUP:";
|
||||
break;
|
||||
case GL_DEBUG_TYPE_POP_GROUP:
|
||||
s_type = "POP_GROUP:";
|
||||
break;
|
||||
default:
|
||||
s_type = "";
|
||||
break;
|
||||
}
|
||||
|
||||
std::string s_severity;
|
||||
switch (severity) {
|
||||
case GL_DEBUG_SEVERITY_HIGH:
|
||||
s_severity = "HIGH:";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_MEDIUM:
|
||||
s_severity = "MED:";
|
||||
break;
|
||||
case GL_DEBUG_SEVERITY_LOW:
|
||||
s_severity = "LOW:";
|
||||
break;
|
||||
default:
|
||||
s_severity = "INFO:";
|
||||
break;
|
||||
}
|
||||
|
||||
fmt::print(stderr, "GL:{}{}{} {}", s_source, s_type, s_severity, message);
|
||||
}
|
||||
|
||||
#endif
|
||||
74
vis/src/geometrytest.cpp
Normal file
74
vis/src/geometrytest.cpp
Normal file
@@ -0,0 +1,74 @@
|
||||
#include <tc/groups.hpp>
|
||||
#include <geo/geometry.hpp>
|
||||
#include <geo/solver.hpp>
|
||||
#include <geo/mirror.hpp>
|
||||
|
||||
#include <ml/meshlib.hpp>
|
||||
#include <ml/meshlib_json.hpp>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
template<int N>
|
||||
using ProjectiveNf = Eigen::Transform<float, N, Eigen::Projective>;
|
||||
|
||||
template<int N>
|
||||
using VectorNf = Eigen::Vector<float, N>;
|
||||
|
||||
template<int N>
|
||||
Eigen::Matrix<float, N, Eigen::Dynamic> make_points(
|
||||
const tc::Group &group,
|
||||
const Eigen::Vector<float, N> &root
|
||||
) {
|
||||
// todo clean up mirror / plane_intersections / barycentric
|
||||
// ideally barycentric will work in rotors, so that stellations etc. will be possible
|
||||
auto mirrors = mirror<N>(group);
|
||||
auto corners = plane_intersections(mirrors);
|
||||
auto start = barycentric(corners, root);
|
||||
|
||||
auto cosets = group.solve();
|
||||
|
||||
auto verts = cosets.path.walk<VectorNf<N>, VectorNf<N>>(start, mirrors, reflect<vec4>);
|
||||
|
||||
Eigen::Matrix<float, N, Eigen::Dynamic> points(root.size(), verts.size());
|
||||
std::copy(verts.begin(), verts.end(), points.colwise().begin());
|
||||
|
||||
return points;
|
||||
}
|
||||
|
||||
template<int N>
|
||||
Eigen::Matrix<unsigned, N, Eigen::Dynamic> make_cells(
|
||||
const tc::Group &group,
|
||||
const std::vector<std::vector<int>> &exclude = {}
|
||||
) {
|
||||
auto gens = generators(group);
|
||||
auto combos = combinations(gens, N - 1);
|
||||
|
||||
// todo clean up merge(hull(...))
|
||||
Eigen::Matrix<unsigned, N, Eigen::Dynamic> cells = merge<N>(hull<N>(group, combos, exclude));
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::vector<int> symbol = {5, 3, 3};
|
||||
auto group = tc::schlafli(symbol);
|
||||
|
||||
vec4 root{0.80, 0.02, 0.02, 0.02};
|
||||
|
||||
auto points = make_points(group, root);
|
||||
auto cells = make_cells<3>(group, {{0, 1}});
|
||||
|
||||
ml::Mesh mesh(points, cells);
|
||||
|
||||
// auto transform = ProjectiveNf<vec4::RowsAtCompileTime>::Identity();
|
||||
// transform.translation() << 0, 0.5, 0, 0;
|
||||
// points = (transform * points.colwise().homogeneous()).colwise().hnormalized();
|
||||
|
||||
std::cout << points.rows() << " " << points.cols() << std::endl;
|
||||
std::cout << cells.rows() << " " << cells.cols() << std::endl;
|
||||
|
||||
ml::write(mesh, std::ofstream("dodeca.pak", std::ios::out | std::ios::binary));
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
212
vis/src/main.cpp
212
vis/src/main.cpp
@@ -3,28 +3,193 @@
|
||||
#include <imgui.h>
|
||||
#include <backends/imgui_impl_glfw.h>
|
||||
#include <backends/imgui_impl_opengl3.h>
|
||||
|
||||
#include <fmt/core.h>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
|
||||
#include "debug.hpp"
|
||||
#include <fmt/core.h>
|
||||
#include <fmt/ranges.h>
|
||||
|
||||
int run(GLFWwindow *window, ImGuiContext *ctx) {
|
||||
glClearColor(0.1, 0.1, 0.9, 1.0);
|
||||
#include <gl/debug.hpp>
|
||||
#include <gl/buffer.hpp>
|
||||
#include <gl/shader.hpp>
|
||||
#include <gl/vertexarray.hpp>
|
||||
|
||||
#include <tc/groups.hpp>
|
||||
#include <tc/core.hpp>
|
||||
|
||||
#include <geo/mirror.hpp>
|
||||
|
||||
struct State {
|
||||
Eigen::Vector4f bg{0.169f, 0.169f, 0.169f, 1.00f};
|
||||
Eigen::Vector4f fg{0.71f, 0.53f, 0.94f, 1.00f};
|
||||
Eigen::Vector4f wf{0.95f, 0.95f, 0.95f, 1.00f};
|
||||
|
||||
Eigen::Vector4f R{1.00f, 0.00f, 0.00f, 1.00f};
|
||||
Eigen::Vector4f G{0.00f, 1.00f, 0.00f, 1.00f};
|
||||
Eigen::Vector4f B{0.00f, 0.00f, 1.00f, 1.00f};
|
||||
Eigen::Vector4f Y{1.20f, 1.20f, 0.00f, 1.00f};
|
||||
|
||||
Eigen::Matrix4f rot = Eigen::Matrix4f::Identity();
|
||||
|
||||
bool color_axes = false;
|
||||
};
|
||||
|
||||
Eigen::Matrix4f rotor(int u, int v, float rad) {
|
||||
Eigen::Matrix4f res = Eigen::Matrix4f::Identity();
|
||||
res(u, u) = res(v, v) = cosf(rad);
|
||||
res(u, v) = res(v, u) = sinf(rad);
|
||||
res(u, v) *= -1;
|
||||
return res;
|
||||
}
|
||||
|
||||
template<typename T_>
|
||||
T_ mix(const T_ &a, const T_ &b, const typename T_::Scalar &x) {
|
||||
return a * (1 - x) + b * x;
|
||||
}
|
||||
|
||||
void show_overlay(State &state) {
|
||||
static std::string gl_vendor = (const char *) glGetString(GL_VENDOR);
|
||||
static std::string gl_renderer = (const char *) glGetString(GL_RENDERER);
|
||||
static std::string gl_version = (const char *) glGetString(GL_VERSION);
|
||||
static std::string glsl_version = (const char *) glGetString(GL_SHADING_LANGUAGE_VERSION);
|
||||
|
||||
ImGuiWindowFlags window_flags =
|
||||
ImGuiWindowFlags_AlwaysAutoResize |
|
||||
ImGuiWindowFlags_NoSavedSettings |
|
||||
ImGuiWindowFlags_NoFocusOnAppearing |
|
||||
ImGuiWindowFlags_NoNav |
|
||||
ImGuiWindowFlags_NoBringToFrontOnFocus |
|
||||
ImGuiWindowFlags_NoMove;
|
||||
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
const auto PAD = style.DisplaySafeAreaPadding;
|
||||
auto window_pos = PAD;
|
||||
|
||||
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowBgAlpha(0.35f * style.Alpha);
|
||||
ImGui::SetNextWindowCollapsed(true, ImGuiCond_Appearing);
|
||||
ImGui::Begin("Graphics Information", nullptr, window_flags);
|
||||
ImGui::Text("GL Vendor | %s", gl_vendor.c_str());
|
||||
ImGui::Text("GL Renderer | %s", gl_renderer.c_str());
|
||||
ImGui::Text("GL Version | %s", gl_version.c_str());
|
||||
ImGui::Text("GLSL Version | %s", glsl_version.c_str());
|
||||
|
||||
auto v2 = ImGui::GetWindowSize();
|
||||
window_pos.y += v2.y + PAD.y;
|
||||
ImGui::End();
|
||||
|
||||
ImGui::SetNextWindowPos(window_pos, ImGuiCond_Always);
|
||||
ImGui::SetNextWindowBgAlpha(0.35f * style.Alpha);
|
||||
ImGui::Begin("Controls", nullptr, window_flags);
|
||||
|
||||
ImGuiIO &io = ImGui::GetIO();
|
||||
ImGui::Text("FPS | %.2f", io.Framerate);
|
||||
|
||||
ImGui::Separator();
|
||||
|
||||
ImGui::ColorEdit3("Background", state.bg.data(), ImGuiColorEditFlags_Float);
|
||||
ImGui::ColorEdit3("Foreground", state.fg.data(), ImGuiColorEditFlags_Float);
|
||||
ImGui::ColorEdit3("Wireframe", state.wf.data(), ImGuiColorEditFlags_Float);
|
||||
|
||||
ImGui::Checkbox("Show RGBY axis colors", &state.color_axes);
|
||||
|
||||
if (io.MouseDown[0] && !io.WantCaptureMouse) {
|
||||
Eigen::Matrix4f rot = Eigen::Matrix4f::Identity();
|
||||
Eigen::Vector2f del{io.MouseDelta.x, io.MouseDelta.y};
|
||||
del /= 200.0f;
|
||||
|
||||
if (io.KeyShift) {
|
||||
del /= 5.0f;
|
||||
}
|
||||
|
||||
if (io.KeyCtrl) {
|
||||
Eigen::Matrix4f rx = rotor(0, 3, -del.x());
|
||||
Eigen::Matrix4f ry = rotor(1, 3, del.y());
|
||||
rot = rx * ry;
|
||||
} else {
|
||||
Eigen::Matrix4f rx = rotor(0, 2, -del.x());
|
||||
Eigen::Matrix4f ry = rotor(1, 2, del.y());
|
||||
rot = rx * ry;
|
||||
}
|
||||
|
||||
state.rot = rot * state.rot;
|
||||
}
|
||||
|
||||
ImGui::End();
|
||||
}
|
||||
|
||||
void set_style() {
|
||||
ImGui::StyleColorsDark();
|
||||
|
||||
ImGuiStyle &style = ImGui::GetStyle();
|
||||
style.WindowRounding = 4;
|
||||
style.FrameRounding = 2;
|
||||
style.DisplaySafeAreaPadding.x = 10;
|
||||
style.DisplaySafeAreaPadding.y = 10;
|
||||
}
|
||||
|
||||
int run(GLFWwindow *window, ImGuiContext *context) {
|
||||
State state;
|
||||
|
||||
// Buffer<GLuint> ind_buf;
|
||||
Buffer<Eigen::Vector4f> vert_buf;
|
||||
|
||||
VertexArray<Eigen::Vector4f> vao(vert_buf);
|
||||
// glVertexArrayElementBuffer(vao, ind_buf);
|
||||
|
||||
tc::Group group = tc::coxeter("3 4 3");
|
||||
|
||||
auto cosets = solve(group, {}, 1000000);
|
||||
vec4 coords {1, 1, 1, 1};
|
||||
|
||||
auto mirrors = mirror<4>(group);
|
||||
|
||||
auto corners = plane_intersections(mirrors);
|
||||
auto start = barycentric(corners, coords);
|
||||
start.normalize();
|
||||
|
||||
auto points = cosets.path.walk<vec4, vec4>(start, mirrors, reflect<vec4>);
|
||||
|
||||
vert_buf.upload(points);
|
||||
|
||||
VertexShader vs(std::ifstream("res/shaders/main.vert.glsl"));
|
||||
FragmentShader fs(std::ifstream("res/shaders/main.frag.glsl"));
|
||||
|
||||
Program pgm(vs, fs);
|
||||
|
||||
glEnable(GL_DEPTH_TEST);
|
||||
glPointSize(2);
|
||||
|
||||
Eigen::Projective3f proj;
|
||||
|
||||
while (!glfwWindowShouldClose(window)) {
|
||||
glfwPollEvents();
|
||||
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
ImGui_ImplGlfw_NewFrame();
|
||||
ImGui::NewFrame();
|
||||
ImGui::Begin("Hello There!", nullptr, ImGuiWindowFlags_None);
|
||||
ImGui::Text("General Kenobi.");
|
||||
ImGui::End();
|
||||
show_overlay(state);
|
||||
ImGui::Render();
|
||||
|
||||
int display_w, display_h;
|
||||
glfwGetFramebufferSize(window, &display_w, &display_h);
|
||||
glViewport(0, 0, display_w, display_h);
|
||||
glClearColor(state.bg[0], state.bg[1], state.bg[2], state.bg[3]);
|
||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||
|
||||
auto aspect = (float) display_h / (float) display_w;
|
||||
proj = Eigen::AlignedScaling3f(aspect, 1.0, -0.6);
|
||||
|
||||
glUseProgram(pgm);
|
||||
glBindVertexArray(vao);
|
||||
glUniform4fv(0, 1, state.fg.data());
|
||||
glUniform1f(1, (GLfloat) glfwGetTime());
|
||||
glUniformMatrix4fv(2, 1, false, proj.data());
|
||||
glUniformMatrix4fv(3, 1, false, state.rot.data());
|
||||
glDrawArrays(GL_POINTS, 0, points.size());
|
||||
glBindVertexArray(0);
|
||||
glUseProgram(0);
|
||||
|
||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||
glfwSwapBuffers(window);
|
||||
}
|
||||
@@ -34,21 +199,16 @@ int run(GLFWwindow *window, ImGuiContext *ctx) {
|
||||
|
||||
int main() {
|
||||
if (!glfwInit()) {
|
||||
fmt::print(stderr, "GLFW : Failed Initialization\n");
|
||||
std::cerr << "GLFW:Failed initialization" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 4);
|
||||
glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 6);
|
||||
glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_CORE_PROFILE);
|
||||
GLFWwindow *window = glfwCreateWindow(
|
||||
1280, 720,
|
||||
"Cosets Visualization",
|
||||
nullptr, nullptr
|
||||
);
|
||||
|
||||
auto *window = glfwCreateWindow(1280, 720, "Cosets Visualization", nullptr, nullptr);
|
||||
if (!window) {
|
||||
fmt::print("GLFW : Failed to create window.\n");
|
||||
std::cerr << "GLFW:Failed to create window" << std::endl;
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
@@ -67,17 +227,19 @@ int main() {
|
||||
#endif
|
||||
|
||||
IMGUI_CHECKVERSION();
|
||||
ImGuiContext *ctx = ImGui::CreateContext();
|
||||
auto *context = ImGui::CreateContext();
|
||||
ImGui_ImplGlfw_InitForOpenGL(window, true);
|
||||
ImGui_ImplOpenGL3_Init("#version 130");
|
||||
|
||||
int code = EXIT_SUCCESS;
|
||||
set_style();
|
||||
|
||||
int exit_code = EXIT_SUCCESS;
|
||||
|
||||
try {
|
||||
code = run(window, ctx);
|
||||
} catch (const std::exception &ex) {
|
||||
fmt::print(stderr, "{}\n", ex.what());
|
||||
code = EXIT_FAILURE;
|
||||
exit_code = run(window, context);
|
||||
} catch (const std::exception &e) {
|
||||
std::cerr << e.what() << std::endl;
|
||||
exit_code = EXIT_FAILURE;
|
||||
}
|
||||
|
||||
ImGui_ImplOpenGL3_Shutdown();
|
||||
@@ -87,5 +249,5 @@ int main() {
|
||||
glfwDestroyWindow(window);
|
||||
glfwTerminate();
|
||||
|
||||
return code;
|
||||
return exit_code;
|
||||
}
|
||||
|
||||
45
vis/src/serialtest.cpp
Normal file
45
vis/src/serialtest.cpp
Normal file
@@ -0,0 +1,45 @@
|
||||
#include <Eigen/Eigen>
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
#include <ml/meshlib.hpp>
|
||||
#include <ml/meshlib_json.hpp>
|
||||
|
||||
auto make_circle(float radius, size_t npoints = 32) {
|
||||
Eigen::Array<float, 1, Eigen::Dynamic> theta(1, npoints);
|
||||
for (int i = 0; i < theta.size(); ++i) {
|
||||
theta(i) = (float) M_PI * 2.0f * (float) i / (float) npoints;
|
||||
}
|
||||
|
||||
Eigen::Array<float, 3, Eigen::Dynamic> points(3, npoints);
|
||||
points.row(0) = theta.sin();
|
||||
points.row(1) = theta.cos();
|
||||
points.row(2).setZero();
|
||||
|
||||
Eigen::Array<unsigned int, 1, Eigen::Dynamic> idx(1, npoints - 1);
|
||||
for (int i = 0; i < idx.size(); ++i) {
|
||||
idx(i) = i;
|
||||
}
|
||||
|
||||
Eigen::Array<unsigned int, 3, Eigen::Dynamic> cells(3, npoints - 1);
|
||||
cells.row(0) = 0;
|
||||
cells.row(1) = idx;
|
||||
cells.row(2) = idx + 1;
|
||||
|
||||
return ml::Mesh(points, cells);
|
||||
}
|
||||
|
||||
int main() {
|
||||
std::string path = "circle.pak";
|
||||
|
||||
auto omesh = make_circle(1.0f);
|
||||
using MT = decltype(omesh);
|
||||
|
||||
ml::write(omesh, std::ofstream(path, std::ios::out | std::ios::binary));
|
||||
|
||||
auto imesh = ml::read<MT>(std::ifstream(path, std::ios::in | std::ios::binary));
|
||||
|
||||
std::cout << imesh.points << std::endl;
|
||||
std::cout << imesh.cells << std::endl;
|
||||
}
|
||||
Reference in New Issue
Block a user