Merge newer shaders into memo

# Conflicts:
#	vis/include/geometry.hpp
#	vis/src/main.cpp
This commit is contained in:
Jacob
2020-01-20 18:14:10 -05:00
8 changed files with 120 additions and 10 deletions

3
.idea/misc.xml generated
View File

@@ -12,4 +12,7 @@
<file path="$PROJECT_DIR$/vendor" /> <file path="$PROJECT_DIR$/vendor" />
</libraryRoots> </libraryRoots>
</component> </component>
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
</project> </project>

9
README.md Normal file
View File

@@ -0,0 +1,9 @@
# toddcox-visualize
A new (basic) implementation of the Todd-Coxeter algorithm for Coxeter groups in C++ that beats GAP.
---
Example output with group F4.
![Example render](screen.png)

BIN
screen.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 219 KiB

View File

@@ -11,18 +11,21 @@
class gl_error : public std::domain_error { class gl_error : public std::domain_error {
public: public:
explicit gl_error(const std::string &arg) : domain_error(arg) {} explicit gl_error(const std::string &arg) : domain_error(arg) {}
explicit gl_error(const char *string) : domain_error(string) {} explicit gl_error(const char *string) : domain_error(string) {}
}; };
class shader_error : public gl_error { class shader_error : public gl_error {
public: public:
explicit shader_error(const std::string &arg) : gl_error(arg) {} explicit shader_error(const std::string &arg) : gl_error(arg) {}
explicit shader_error(const char *string) : gl_error(string) {} explicit shader_error(const char *string) : gl_error(string) {}
}; };
class program_error : public gl_error { class program_error : public gl_error {
public: public:
explicit program_error(const std::string &arg) : gl_error(arg) {} explicit program_error(const std::string &arg) : gl_error(arg) {}
explicit program_error(const char *string) : gl_error(string) {} explicit program_error(const char *string) : gl_error(string) {}
}; };

View File

@@ -0,0 +1,25 @@
#version 430
#define SUBS 20
layout(lines) in;
layout(line_strip, max_vertices = SUBS) out;
layout(location=0) uniform mat4 proj;
in vec4 gpos[];
out vec4 vpos;
vec4 stereo(vec4 v) {
return vec4(v.xyz / (1 - v.w), 1);
}
void main() {
for (int i = 0; i < SUBS; i++) {
vpos = mix(gpos[0], gpos[1], i * 1.0f / (SUBS - 1));
vpos = normalize(vpos);
gl_Position = proj * stereo(vpos);
EmitVertex();
}
EndPrimitive();
}

View File

@@ -0,0 +1,12 @@
#version 430
layout(location=1) uniform mat4 view;
layout(location=0) in vec4 pos;
out vec4 gpos;
void main() {
gpos = view * pos;
gl_PointSize = 5;
}

View File

@@ -11,5 +11,5 @@ void main() {
int i = gl_VertexID; int i = gl_VertexID;
vpos = view * pos; vpos = view * pos;
gl_Position = proj * vec4(vpos.xyz / (1 - vpos.w), 1); gl_Position = proj * vec4(vpos.xyz / (1 - vpos.w), 1);
gl_PointSize = 5; gl_PointSize = 5 * smoothstep(-2, 2, gl_Position.z);
} }

View File

@@ -17,6 +17,27 @@ __attribute__((unused)) __declspec(dllexport) int NvOptimusEnablement = 0x000000
} }
#endif #endif
std::vector<int> edge_inds(const tc::Group &group, const tc::Cosets &map, const int gen) {
const tc::SubGroup &eg = group.subgroup({gen});
const tc::Cosets &root = eg.solve({});
size_t N = root.size();
auto edges = root.path.walk<int, int>(0, eg.gen_map, [map](int a, int gen) {
return map.get(a, gen);
});
const tc::Cosets &tile = group.solve({gen});
edges.resize(N * tile.size());
for (size_t i = 0; i < tile.size(); ++i) {
auto act = tile.path.get(i);
for (size_t j = 0; j < N; ++j) {
edges[i * N + j] = map.get(edges[act.from_idx * N + j], act.gen);
}
}
return edges;
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
//region init window //region init window
@@ -47,22 +68,34 @@ int main(int argc, char *argv[]) {
GLuint pgm; GLuint pgm;
try { try {
GLuint vs = utilCompileFiles(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"}); // GLuint vs = utilCompileFiles(GL_VERTEX_SHADER, {"shaders/ortho.vs.glsl"});
GLuint fs = utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"}); // GLuint vs = utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo.vs.glsl"});
// GLuint fs = utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"});
// GLuint fs = utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/w-axis-hue.fs.glsl"});
pgm = utilLinkProgram({vs, fs}); // pgm = utilLinkProgram({vs, fs});
pgm = utilLinkProgram({
utilCompileFiles(GL_VERTEX_SHADER, {"shaders/stereo-proper.vs.glsl"}),
utilCompileFiles(GL_GEOMETRY_SHADER, {"shaders/stereo-proper.gm.glsl"}),
utilCompileFiles(GL_FRAGMENT_SHADER, {"shaders/one-color.fs.glsl"}),
});
} catch (const gl_error &e) { } catch (const gl_error &e) {
std::cerr << e.what() << std::endl; std::cerr << e.what() << std::endl;
glfwTerminate(); glfwTerminate();
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
auto group = tc::group::H(4); auto group = tc::group::F4();
// auto group = tc::group::D(4);
// auto group = tc::group::H(4);
auto res = group.solve(); auto res = group.solve();
auto mirrors = mirror(group); auto mirrors = mirror(group);
auto corners = plane_intersections(mirrors); auto corners = plane_intersections(mirrors);
auto start = barycentric(corners, {1.00, 1.00, 1.00, 1.00}); // auto start = barycentric(corners, {1.00f, 1.00f, 1.00f, 1.00f});
auto start = barycentric(corners, {0.05, 0.05, 1.00, 3.00});
// auto start = barycentric(corners, {0, 0, 0, 1});
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect); auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
GLuint vbo; GLuint vbo;
@@ -73,6 +106,21 @@ int main(int argc, char *argv[]) {
glEnableVertexAttribArray(0); glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr); glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr);
std::vector<int> edge_count;
std::vector<GLuint> edge_ibo;
for (int i = 0; i < group.ngens; ++i) {
const auto data = edge_inds(group, res, i);
edge_count.push_back(data.size());
GLuint ibo;
glGenBuffers(1, &ibo);
glBindBuffer(GL_ARRAY_BUFFER, ibo);
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * data.size(), &data[0], GL_STATIC_DRAW);
edge_ibo.push_back(ibo);
}
glBindBuffer(GL_ARRAY_BUFFER, 0);
while (!glfwWindowShouldClose(window)) { while (!glfwWindowShouldClose(window)) {
int width, height; int width, height;
glfwGetFramebufferSize(window, &width, &height); glfwGetFramebufferSize(window, &width, &height);
@@ -89,10 +137,11 @@ int main(int argc, char *argv[]) {
auto aspect = (float) width / (float) height; auto aspect = (float) width / (float) height;
auto pheight = 1.4f; auto pheight = 1.4f;
auto pwidth = aspect * pheight; auto pwidth = aspect * pheight;
glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -100.0f, 100.0f); glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -2.0f, 2.0f);
// glm::mat4 proj = glm::ortho(-pwidth, pwidth, -pheight, pheight, -100.0f, 100.0f);
glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj)); glUniformMatrix4fv(0, 1, false, glm::value_ptr(proj));
auto t = (float) glfwGetTime() / 5; auto t = (float) glfwGetTime() / 10;
auto view = glm::identity<glm::mat4>(); auto view = glm::identity<glm::mat4>();
view *= utilRotate(0, 1, t * 0.7f); view *= utilRotate(0, 1, t * 0.7f);
view *= utilRotate(0, 2, t * 0.8f); view *= utilRotate(0, 2, t * 0.8f);
@@ -106,6 +155,15 @@ int main(int argc, char *argv[]) {
glUniform3f(2, 1.0f, 1.0f, 1.0f); glUniform3f(2, 1.0f, 1.0f, 1.0f);
glDrawArrays(GL_POINTS, 0, points.size()); glDrawArrays(GL_POINTS, 0, points.size());
glUniform3f(2, 1.0f, 1.0f, 1.0f);
for (int i = 0; i < group.ngens; ++i) {
auto ibo = edge_ibo[i];
auto count = edge_count[i];
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
glDrawElements(GL_LINES, count, GL_UNSIGNED_INT, nullptr);
}
glfwSwapBuffers(window); glfwSwapBuffers(window);
glfwPollEvents(); glfwPollEvents();