simple Mesh class
This commit is contained in:
@@ -20,9 +20,12 @@ struct Mults {
|
||||
|
||||
[[nodiscard]] std::vector<int> relation(int a, int b) const;
|
||||
|
||||
[[nodiscard]] std::vector<std::vector<int>> relations(const std::vector<int>& gens) const;
|
||||
[[nodiscard]] std::vector<std::vector<int>> relations(const std::vector<int> &gens) const;
|
||||
|
||||
[[nodiscard]] std::vector<std::vector<int>> irelations(const Table *table, const std::vector<int> &gens) const;
|
||||
|
||||
[[nodiscard]] Table *solve(const std::vector<int> &subgens) const;
|
||||
[[nodiscard]] Table *solve(const std::vector<int> &gens, const std::vector<int> &subgens) const;
|
||||
};
|
||||
|
||||
struct Table {
|
||||
@@ -79,11 +82,11 @@ struct IRow {
|
||||
[[nodiscard]] bool learn(Table *table);
|
||||
};
|
||||
|
||||
Table *solve(const std::vector<int> &gens, const std::vector<int> &subgens, const Mults &mults);
|
||||
|
||||
Table *solve(const std::vector<int> &subgens, const Mults &mults);
|
||||
|
||||
Table *solve_elems(const Mults &mults);
|
||||
//Table *solve(const std::vector<int> &gens, const std::vector<int> &subgens, const Mults &mults);
|
||||
//
|
||||
//Table *solve(const std::vector<int> &subgens, const Mults &mults);
|
||||
//
|
||||
//Table *solve_elems(const Mults &mults);
|
||||
|
||||
Mults schlafli(const std::vector<int> &symbol);
|
||||
|
||||
|
||||
@@ -17,3 +17,27 @@ std::vector<glm::vec4> vertices(const Table *t_vert, const glm::vec4 ident);
|
||||
std::vector<int> edges(const Table *t_vert);
|
||||
|
||||
std::vector<int> faces(const Table *t_vert);
|
||||
|
||||
|
||||
struct Buffer {
|
||||
const GLuint name;
|
||||
const unsigned size;
|
||||
const float gen_time;
|
||||
};
|
||||
|
||||
struct Mesh {
|
||||
const Mults mults;
|
||||
const Table *t_vert;
|
||||
|
||||
Buffer vert;
|
||||
Buffer edge;
|
||||
Buffer face;
|
||||
|
||||
Mesh(Mults mults, const Table *t_vert, Buffer vert, Buffer edge, Buffer face);
|
||||
|
||||
~Mesh();
|
||||
};
|
||||
|
||||
Mesh *mesh(const Mults &mults, glm::vec4 ident);
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, Buffer b);
|
||||
|
||||
@@ -16,14 +16,7 @@ class CosetsWindow : public Window {
|
||||
GLint program;
|
||||
GLuint vert_vao, edge_vao, face_vao;
|
||||
|
||||
GLuint verts_buf;
|
||||
std::vector<glm::vec4> vert_data;
|
||||
|
||||
GLuint edges_buf;
|
||||
std::vector<int> edge_data;
|
||||
|
||||
GLuint faces_buf;
|
||||
std::vector<int> face_data;
|
||||
Mesh *figure;
|
||||
|
||||
GLint u_proj, u_view, u_color;
|
||||
|
||||
@@ -52,93 +45,35 @@ public:
|
||||
u_view = glGetUniformLocation(program, "view");
|
||||
u_color = glGetUniformLocation(program, "color");
|
||||
|
||||
const Mults &mults = schlafli({3, 4, 3});
|
||||
const Mults &mults = schlafli({5, 3, 2});
|
||||
// const glm::vec4 ident = center(mults);
|
||||
const glm::vec4 ident = identity(mults, {10, .1, .1, .5});
|
||||
const glm::vec4 ident = identity(mults, {2, .1, .1, 3});
|
||||
std::cout << "Dimension: " << mults.num_gens << std::endl;
|
||||
|
||||
std::cout << "Generation times: " << std::endl;
|
||||
|
||||
auto gen_start = std::chrono::high_resolution_clock::now();
|
||||
|
||||
const Table *t_vert = solve_elems(mults);
|
||||
auto gen_solve = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> solve_time = gen_solve - gen_start;
|
||||
std::cout
|
||||
<< "Table: "
|
||||
<< std::setw(5) << std::setprecision(3) << solve_time.count()
|
||||
<< std::endl;
|
||||
|
||||
|
||||
vert_data = vertices(t_vert, ident);
|
||||
auto gen_vert = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> vert_time = gen_vert - gen_solve;
|
||||
std::cout
|
||||
<< "Vertices: "
|
||||
<< std::setw(5) << std::setprecision(3) << vert_time.count()
|
||||
<< " (" << vert_data.size() << ")"
|
||||
<< std::endl;
|
||||
|
||||
edge_data = edges(t_vert);
|
||||
auto gen_edge = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> edge_time = gen_edge - gen_vert;
|
||||
std::cout
|
||||
<< " Edges: "
|
||||
<< std::setw(5) << std::setprecision(3) << edge_time.count()
|
||||
<< " (" << edge_data.size() / 2 << ")"
|
||||
<< std::endl;
|
||||
|
||||
face_data = faces(t_vert);
|
||||
auto gen_face = std::chrono::high_resolution_clock::now();
|
||||
std::chrono::duration<double> face_time = gen_face - gen_edge;
|
||||
std::cout
|
||||
<< " Faces: "
|
||||
<< std::setw(5) << std::setprecision(3) << face_time.count()
|
||||
<< " (" << face_data.size() / 3 << ")"
|
||||
<< std::endl;
|
||||
|
||||
std::chrono::duration<double> full_time = gen_face - gen_start;
|
||||
std::cout
|
||||
<< " Total: "
|
||||
<< std::setw(5) << std::setprecision(3) << full_time.count()
|
||||
<< std::endl;
|
||||
|
||||
delete t_vert;
|
||||
|
||||
glGenBuffers(1, &verts_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, verts_buf);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4) * vert_data.size(), &vert_data[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &edges_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, edges_buf);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * edge_data.size(), &edge_data[0], GL_STATIC_DRAW);
|
||||
|
||||
glGenBuffers(1, &faces_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, faces_buf);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * face_data.size(), &face_data[0], GL_STATIC_DRAW);
|
||||
figure = mesh(mults, ident);
|
||||
|
||||
glGenVertexArrays(1, &vert_vao);
|
||||
glBindVertexArray(vert_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, verts_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, figure->vert.name);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
|
||||
glGenVertexArrays(1, &edge_vao);
|
||||
glBindVertexArray(edge_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, verts_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, figure->vert.name);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, edges_buf);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, figure->edge.name);
|
||||
|
||||
glGenVertexArrays(1, &face_vao);
|
||||
glBindVertexArray(face_vao);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, verts_buf);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, figure->vert.name);
|
||||
glEnableVertexAttribArray(0);
|
||||
glVertexAttribPointer(0, 4, GL_FLOAT, false, 0, nullptr);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, faces_buf);
|
||||
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, figure->face.name);
|
||||
|
||||
glBindVertexArray(0);
|
||||
}
|
||||
@@ -188,20 +123,20 @@ public:
|
||||
|
||||
glBindVertexArray(vert_vao);
|
||||
glUniform4f(u_color, 1, 0, 0, 1);
|
||||
glDrawArrays(GL_POINTS, 0, vert_data.size());
|
||||
glDrawArrays(GL_POINTS, 0, figure->vert.size);
|
||||
|
||||
glBindVertexArray(edge_vao);
|
||||
glUniform4f(u_color, 1, 0, 0, 1);
|
||||
glDrawElements(GL_LINES, edge_data.size(), GL_UNSIGNED_INT, 0);
|
||||
glDrawElements(GL_LINES, figure->edge.size, GL_UNSIGNED_INT, 0);
|
||||
|
||||
glBindVertexArray(face_vao);
|
||||
glCullFace(GL_NONE);
|
||||
glUniform4f(u_color, 1, 1, 1, 1);
|
||||
// glDrawElements(GL_TRIANGLES, face_data.size(), GL_UNSIGNED_INT, 0);
|
||||
// glDrawElements(GL_TRIANGLES, figure->face.size, GL_UNSIGNED_INT, 0);
|
||||
|
||||
// glCullFace(GL_FRONT);
|
||||
// glUniform4f(u_color, .3, .3, 1, 1);
|
||||
// glDrawElements(GL_TRIANGLES, face_data.size(), GL_UNSIGNED_INT, 0);
|
||||
// glDrawElements(GL_TRIANGLES, figure->face.size, GL_UNSIGNED_INT, 0);
|
||||
|
||||
swapbuffers();
|
||||
}
|
||||
|
||||
@@ -57,7 +57,7 @@ Table::Table(const std::vector<int> &gens, const Mults mults) : gens(gens), mult
|
||||
add_row();
|
||||
|
||||
gen_inds = std::vector<int>(gens[gens.size() - 1] + 1, -1);
|
||||
for (int i = 0; i <(int) gens.size(); i++) {
|
||||
for (int i = 0; i < (int) gens.size(); i++) {
|
||||
gen_inds[gens[i]] = i;
|
||||
}
|
||||
}
|
||||
@@ -73,7 +73,7 @@ int Table::gen_index(int gen) const {
|
||||
|
||||
std::vector<int> Table::gen_index_each(std::vector<int> rel) const {
|
||||
std::vector<int> res(rel.size(), 0);
|
||||
for (int i = 0; i < (int)rel.size(); ++i) {
|
||||
for (int i = 0; i < (int) rel.size(); ++i) {
|
||||
res[i] = gen_index(rel[i]);
|
||||
}
|
||||
return res;
|
||||
@@ -223,9 +223,9 @@ bool IRow::learn(Table *table) {
|
||||
return false;
|
||||
}
|
||||
|
||||
Table *solve(const std::vector<int> &gens, const std::vector<int> &subgens, const Mults &mults) {
|
||||
auto *table = new Table(gens, mults);
|
||||
const auto irels = mults.irelations(table, gens);
|
||||
Table *Mults::solve(const std::vector<int> &gens, const std::vector<int> &subgens) const {
|
||||
auto *table = new Table(gens, *this);
|
||||
const auto irels = irelations(table, gens);
|
||||
|
||||
for (int gen : subgens)
|
||||
table->set(0, gen, 0);
|
||||
@@ -260,12 +260,8 @@ Table *solve(const std::vector<int> &gens, const std::vector<int> &subgens, cons
|
||||
return table;
|
||||
}
|
||||
|
||||
Table *solve(const std::vector<int> &subgens, const Mults &mults) {
|
||||
return solve(all_gens(mults.num_gens), subgens, mults);
|
||||
}
|
||||
|
||||
Table *solve_elems(const Mults &mults) {
|
||||
return solve({}, mults);
|
||||
Table *Mults::solve(const std::vector<int> &subgens) const {
|
||||
return this->solve(all_gens(num_gens), subgens);
|
||||
}
|
||||
|
||||
Mults schlafli(const std::vector<int> &symbol) {
|
||||
|
||||
@@ -1,3 +1,7 @@
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <utility>
|
||||
#include <chrono>
|
||||
#include "mesh.hpp"
|
||||
|
||||
glm::vec4 identity(const std::vector<glm::vec4> &normals, const std::vector<float> &coords) {
|
||||
@@ -25,6 +29,42 @@ glm::vec4 center(const Mults &mults) {
|
||||
return glm::normalize(identity);
|
||||
}
|
||||
|
||||
Mesh::Mesh(Mults mults, const Table *t_vert, Buffer vert, Buffer edge, Buffer face)
|
||||
: mults(std::move(mults)), t_vert(t_vert), vert(vert), edge(edge), face(face) {
|
||||
}
|
||||
|
||||
Mesh::~Mesh() {
|
||||
delete t_vert;
|
||||
|
||||
glDeleteBuffers(1, &vert.name);
|
||||
glDeleteBuffers(1, &edge.name);
|
||||
glDeleteBuffers(1, &face.name);
|
||||
}
|
||||
|
||||
Mesh *mesh(const Mults &mults, glm::vec4 ident) {
|
||||
GLuint buffers[3];
|
||||
glGenBuffers(3, buffers);
|
||||
|
||||
Table *t_vert = mults.solve({});
|
||||
|
||||
auto vert_data = vertices(t_vert, ident);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[0]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(glm::vec4) * vert_data.size(), &vert_data[0], GL_STATIC_DRAW);
|
||||
Buffer vert{buffers[0], vert_data.size()};
|
||||
|
||||
auto edge_data = edges(t_vert);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[1]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * edge_data.size(), &edge_data[0], GL_STATIC_DRAW);
|
||||
Buffer edge{buffers[1], edge_data.size()};
|
||||
|
||||
auto face_data = faces(t_vert);
|
||||
glBindBuffer(GL_ARRAY_BUFFER, buffers[2]);
|
||||
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * face_data.size(), &face_data[0], GL_STATIC_DRAW);
|
||||
Buffer face{buffers[2], face_data.size()};
|
||||
|
||||
return new Mesh(mults, t_vert, vert, edge, face);
|
||||
}
|
||||
|
||||
std::vector<glm::vec4>
|
||||
vertices(const Table *t_vert, const glm::vec4 ident) {
|
||||
const std::vector<glm::vec4> normals = mirror(t_vert->mults);
|
||||
@@ -49,11 +89,11 @@ std::vector<int> edges(const Table *t_vert) {
|
||||
const std::vector<int> &gens = t_vert->gens;
|
||||
|
||||
for (const auto &subgens : combinations(N, 1)) {
|
||||
Table *t_edge = solve(subgens, {}, mults);
|
||||
Table *t_edge = mults.solve(subgens, {});;
|
||||
|
||||
std::vector<int> edge = t_vert->apply_each(t_edge->words());
|
||||
|
||||
Table *c_edge = solve(gens, subgens, mults);
|
||||
Table *c_edge = mults.solve(gens, subgens);
|
||||
|
||||
for (const auto &coset : c_edge->words()) {
|
||||
for (const auto &e : edge) {
|
||||
@@ -76,14 +116,14 @@ std::vector<int> faces(const Table *t_vert) {
|
||||
|
||||
// for each *kind* of face
|
||||
for (const auto &sg_face : combinations(N, 2)) {
|
||||
Table *cs_face = solve(gens, sg_face, mults);
|
||||
Table *cs_face = mults.solve(gens, sg_face);
|
||||
|
||||
// for each *kind* of edge
|
||||
for (const auto &sg_edge : combinations(sg_face, 1)) {
|
||||
Table *cs_edge = solve(sg_face, sg_edge, mults);
|
||||
Table *cs_edge = mults.solve(sg_face, sg_edge);
|
||||
|
||||
// find the vertices of that edge
|
||||
Table *t_edge = solve(sg_edge, {}, mults);
|
||||
Table *t_edge = mults.solve(sg_edge, {});
|
||||
std::vector<int> edge = t_vert->apply_each(t_edge->words());
|
||||
|
||||
// for each face
|
||||
|
||||
Reference in New Issue
Block a user