mirror of
https://github.com/allemangD/toddcox-visualize.git
synced 2025-11-10 20:12:48 -05:00
separate vao for each kind of slice
This commit is contained in:
@@ -4,3 +4,5 @@ target_link_libraries(memo PRIVATE tc vis-util)
|
|||||||
add_executable(geom geomtest.cpp)
|
add_executable(geom geomtest.cpp)
|
||||||
target_link_libraries(geom PRIVATE tc vis-util)
|
target_link_libraries(geom PRIVATE tc vis-util)
|
||||||
|
|
||||||
|
add_executable(sub subtest.cpp)
|
||||||
|
target_link_libraries(sub PRIVATE vis-util)
|
||||||
|
|||||||
24
examples/subtest.cpp
Normal file
24
examples/subtest.cpp
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
#include <combo_iterator.hpp>
|
||||||
|
#include <numeric>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
std::ostream &operator<<(std::ostream &o, const std::vector<T> &v) {
|
||||||
|
for (const auto &e : v) o << e << " ";
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::vector<int> gens(5);
|
||||||
|
std::iota(gens.begin(), gens.end(), 0);
|
||||||
|
|
||||||
|
const Combos<int> &combos = Combos(gens, 2);
|
||||||
|
|
||||||
|
for (const auto &e : combos) {
|
||||||
|
std::cout << e << std::endl;
|
||||||
|
}
|
||||||
|
|
||||||
|
return EXIT_SUCCESS;
|
||||||
|
}
|
||||||
72
vis/include/combo_iterator.hpp
Normal file
72
vis/include/combo_iterator.hpp
Normal file
@@ -0,0 +1,72 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct ComboIterator {
|
||||||
|
const std::vector<T> &vals;
|
||||||
|
const size_t k;
|
||||||
|
size_t n;
|
||||||
|
std::vector<bool> bits;
|
||||||
|
std::vector<T> curr;
|
||||||
|
|
||||||
|
ComboIterator(ComboIterator &) = default;
|
||||||
|
|
||||||
|
ComboIterator(const std::vector<T> &vals, const size_t k, const size_t n)
|
||||||
|
: vals(vals), k(k), n(n), curr(k), bits(vals.size()) {
|
||||||
|
for (size_t i = 0; i < vals.size(); ++i) {
|
||||||
|
bits[i] = i < k;
|
||||||
|
}
|
||||||
|
std::reverse(bits.begin(), bits.end());
|
||||||
|
set_curr();
|
||||||
|
}
|
||||||
|
|
||||||
|
void set_curr() {
|
||||||
|
for (size_t i = 0, j = 0; i < vals.size(); ++i) {
|
||||||
|
if (bits[i]) curr[j++] = vals[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::vector<T> &operator*() const {
|
||||||
|
return curr;
|
||||||
|
}
|
||||||
|
|
||||||
|
void operator++() {
|
||||||
|
std::next_permutation(bits.begin(), bits.end());
|
||||||
|
set_curr();
|
||||||
|
++n;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator!=(const ComboIterator<T> &o) const {
|
||||||
|
return n != o.n;
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] bool operator==(const ComboIterator<T> &o) const {
|
||||||
|
return n == o.n;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
size_t choose(size_t n, size_t k) {
|
||||||
|
if (k == 0) return 1;
|
||||||
|
return n * choose(n - 1, k - 1) / k;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<class T>
|
||||||
|
struct Combos {
|
||||||
|
const std::vector<T> &vals;
|
||||||
|
size_t k;
|
||||||
|
|
||||||
|
Combos(const std::vector<T> &vals, size_t k) : vals(vals), k(k) {
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] ComboIterator<T> begin() const {
|
||||||
|
return ComboIterator(vals, k, 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
[[nodiscard]] ComboIterator<T> end() const {
|
||||||
|
int j = choose(vals.size(), k);
|
||||||
|
return ComboIterator(vals, k, j);
|
||||||
|
}
|
||||||
|
};
|
||||||
@@ -4,6 +4,7 @@
|
|||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#include "combo_iterator.hpp"
|
||||||
|
|
||||||
size_t get_key_from_gens(std::vector<int> &gens) {
|
size_t get_key_from_gens(std::vector<int> &gens) {
|
||||||
size_t key = 0;
|
size_t key = 0;
|
||||||
@@ -229,14 +230,7 @@ struct GeomGen {
|
|||||||
S.vals.push_back(0);
|
S.vals.push_back(0);
|
||||||
return S;
|
return S;
|
||||||
}
|
}
|
||||||
std::vector<int> sg_gens(g_gens.size()-1);
|
for (std::vector<int> sg_gens : Combos(g_gens, g_gens.size() - 1)) {
|
||||||
for (int i = 0; i < g_gens.size(); i++) {
|
|
||||||
int k = 0;
|
|
||||||
for (int j = 0; j < g_gens.size(); j++) {
|
|
||||||
if (j != i) {
|
|
||||||
sg_gens[k++] = g_gens[j];
|
|
||||||
}
|
|
||||||
}
|
|
||||||
auto sub_simps = triangulate(sg_gens);
|
auto sub_simps = triangulate(sg_gens);
|
||||||
int start = sub_simps.size();
|
int start = sub_simps.size();
|
||||||
sub_simps = tile(g_gens, sg_gens, sub_simps);
|
sub_simps = tile(g_gens, sg_gens, sub_simps);
|
||||||
|
|||||||
@@ -139,3 +139,23 @@ GLuint utilCreateShaderProgramFile(GLenum type, const std::vector<std::string> &
|
|||||||
std::transform(files.begin(), files.end(), sources.begin(), utilReadFile);
|
std::transform(files.begin(), files.end(), sources.begin(), utilReadFile);
|
||||||
return utilCreateShaderProgram(type, sources);
|
return utilCreateShaderProgram(type, sources);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::vector<GLuint> utilCreateVertexArrays(int n) {
|
||||||
|
std::vector<GLuint> res(n);
|
||||||
|
glCreateVertexArrays(n, &res[0]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint utilCreateVertexArray() {
|
||||||
|
return utilCreateVertexArrays(1)[0];
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<GLuint> utilCreateBuffers(int n) {
|
||||||
|
std::vector<GLuint> res(n);
|
||||||
|
glCreateBuffers(n, &res[0]);
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
GLuint utilCreateBuffer() {
|
||||||
|
return utilCreateBuffers(1)[0];
|
||||||
|
}
|
||||||
@@ -102,12 +102,35 @@ int main(int argc, char *argv[]) {
|
|||||||
auto mirrors = mirror(group);
|
auto mirrors = mirror(group);
|
||||||
|
|
||||||
auto corners = plane_intersections(mirrors);
|
auto corners = plane_intersections(mirrors);
|
||||||
auto start = barycentric(corners, {1.00f, 0.1f, 0.01f, 0.01f});
|
// auto start = barycentric(corners, {1.0f, 1.0f, 1.0f, 1.0f});
|
||||||
|
auto start = barycentric(corners, {1.00f, 0.2f, 0.1f, 0.05f});
|
||||||
|
// auto start = barycentric(corners, {0.05f, 0.1f, 0.2f, 1.00f});
|
||||||
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
|
auto points = res.path.walk<glm::vec4, glm::vec4>(start, mirrors, reflect);
|
||||||
|
|
||||||
auto g_gens = gg.group_gens();
|
auto g_gens = gg.group_gens();
|
||||||
std::vector<int> sg_gens = {0, 1, 2};
|
|
||||||
const std::vector<int> simps = gg.tile(g_gens, sg_gens, gg.triangulate(sg_gens)).vals;
|
std::vector<GLuint> vaos;
|
||||||
|
std::vector<GLuint> ibos;
|
||||||
|
std::vector<unsigned> counts;
|
||||||
|
|
||||||
|
for (auto sg_gens : Combos(g_gens, 3)) {
|
||||||
|
const std::vector<int> data = gg.tile(g_gens, sg_gens, gg.triangulate(sg_gens)).vals;
|
||||||
|
|
||||||
|
GLuint vao = utilCreateVertexArray();
|
||||||
|
GLuint ibo = utilCreateBuffer();
|
||||||
|
unsigned count = data.size();
|
||||||
|
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, ibo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * count, &data[0], GL_STATIC_DRAW);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
glVertexAttribIPointer(0, 4, GL_INT, 0, nullptr);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
|
|
||||||
|
vaos.push_back(vao);
|
||||||
|
ibos.push_back(ibo);
|
||||||
|
counts.push_back(count);
|
||||||
|
}
|
||||||
//endregion
|
//endregion
|
||||||
|
|
||||||
GLuint vbo;
|
GLuint vbo;
|
||||||
@@ -119,30 +142,11 @@ int main(int argc, char *argv[]) {
|
|||||||
GLuint ubo;
|
GLuint ubo;
|
||||||
glGenBuffers(1, &ubo);
|
glGenBuffers(1, &ubo);
|
||||||
|
|
||||||
GLuint ibo;
|
|
||||||
glGenBuffers(1, &ibo);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, ibo);
|
|
||||||
glBufferData(GL_ARRAY_BUFFER, sizeof(int) * simps.size(), &simps[0], GL_STATIC_DRAW);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
GLuint vao;
|
|
||||||
glGenVertexArrays(1, &vao);
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
|
|
||||||
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, vbo);
|
||||||
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
glBindBufferBase(GL_UNIFORM_BUFFER, 1, ubo);
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, ibo);
|
|
||||||
glEnableVertexAttribArray(0);
|
|
||||||
glVertexAttribIPointer(0, 4, GL_INT, 0, nullptr);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
|
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|
||||||
std::cout << points.size() << " points" << std::endl;
|
|
||||||
std::cout << simps.size() << " simplexes" << std::endl;
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window)) {
|
while (!glfwWindowShouldClose(window)) {
|
||||||
int width, height;
|
int width, height;
|
||||||
glfwGetFramebufferSize(window, &width, &height);
|
glfwGetFramebufferSize(window, &width, &height);
|
||||||
@@ -156,11 +160,18 @@ int main(int argc, char *argv[]) {
|
|||||||
glBufferData(GL_UNIFORM_BUFFER, sizeof(mats), &mats, GL_STATIC_DRAW);
|
glBufferData(GL_UNIFORM_BUFFER, sizeof(mats), &mats, GL_STATIC_DRAW);
|
||||||
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
glBindBuffer(GL_UNIFORM_BUFFER, 0);
|
||||||
|
|
||||||
glBindVertexArray(vao);
|
for (int i = 0; i < vaos.size(); ++i) {
|
||||||
glBindProgramPipeline(pipe);
|
auto c = glm::mix(
|
||||||
|
glm::vec3(.3, .2, .5),
|
||||||
|
glm::vec3(.9, .9, .95),
|
||||||
|
(float) (i + 1) / vaos.size()
|
||||||
|
);
|
||||||
|
|
||||||
glProgramUniform3f(fs, 2, 1.0f, 1.0f, 1.0f);
|
glBindProgramPipeline(pipe);
|
||||||
glDrawArrays(GL_POINTS, 0, simps.size() / 4);
|
glBindVertexArray(vaos[i]);
|
||||||
|
glProgramUniform3f(fs, 2, c.r, c.g, c.b);
|
||||||
|
glDrawArrays(GL_POINTS, 0, counts[i] / 4);
|
||||||
|
}
|
||||||
|
|
||||||
glBindProgramPipeline(0);
|
glBindProgramPipeline(0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
|
|||||||
Reference in New Issue
Block a user