From f39341838a9b7aa5a7ec590c12fc2d0f95debd5b Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Mon, 3 Dec 2018 23:34:42 +0100 Subject: [PATCH 01/11] omg this actually works Signed-off-by: Pierre Fenoll --- .dockerignore | 1 + Dockerfile | 17 +++++++++++++++++ README.md | 10 ++++++++++ contained.sh | 16 ++++++++++++++++ 4 files changed, 44 insertions(+) create mode 120000 .dockerignore create mode 100644 Dockerfile create mode 100755 contained.sh diff --git a/.dockerignore b/.dockerignore new file mode 120000 index 0000000..3e4e48b --- /dev/null +++ b/.dockerignore @@ -0,0 +1 @@ +.gitignore \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..809f1b8 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM debian +WORKDIR /app +COPY . $PWD +RUN set -x \ + && apt-get update +RUN set -x \ + && apt-get install -qqy \ + x11-apps \ + libglew-dev libglm-dev libglfw3-dev pkg-config \ + libc++-dev clang cmake +RUN set -x \ + && ./configure \ + && ls -lha \ + && cd build \ + && make -j7 +ENV DISPLAY :0 +CMD xeyes diff --git a/README.md b/README.md index ec4f1b0..90580a8 100644 --- a/README.md +++ b/README.md @@ -39,6 +39,16 @@ The actual file being represented below [is data/BigPictureBG.tga](http://www.do ## Installing +### docker + +Known to work with +* ubuntu 18.10 + docker 18.09.0 + +``` +docker build -t void . +./contained.sh +``` + ### on MacOS 1. Download one of the `osx` files of [the latest release](https://github.com/fenollp/voidstar/releases/latest) diff --git a/contained.sh b/contained.sh new file mode 100755 index 0000000..2cf6562 --- /dev/null +++ b/contained.sh @@ -0,0 +1,16 @@ +#!/bin/bash + +# https://stackoverflow.com/a/25168483/1418165 + +XSOCK=/tmp/.X11-unix +XAUTH=/tmp/.docker.xauth +xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - + +docker run --rm -it \ + -v $XSOCK:$XSOCK \ + -v $XAUTH:$XAUTH \ + -v /dev/input \ + -e XAUTHORITY=$XAUTH \ + void \ + /app/build/voidstar \ + /app/build/voidstar From 3b9c7990c2c16a77473984cd464b4a2df51438ac Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Tue, 4 Dec 2018 00:25:03 +0100 Subject: [PATCH 02/11] this is a pretty big image though Signed-off-by: Pierre Fenoll --- Dockerfile | 8 +++----- contained.sh => docker.sh | 1 - 2 files changed, 3 insertions(+), 6 deletions(-) rename contained.sh => docker.sh (92%) diff --git a/Dockerfile b/Dockerfile index 809f1b8..e24ef63 100644 --- a/Dockerfile +++ b/Dockerfile @@ -2,16 +2,14 @@ FROM debian WORKDIR /app COPY . $PWD RUN set -x \ - && apt-get update -RUN set -x \ - && apt-get install -qqy \ + && apt update \ + && apt install -y \ x11-apps \ libglew-dev libglm-dev libglfw3-dev pkg-config \ libc++-dev clang cmake RUN set -x \ && ./configure \ - && ls -lha \ && cd build \ && make -j7 ENV DISPLAY :0 -CMD xeyes +ENTRYPOINT ["/app/build/voidstar"] diff --git a/contained.sh b/docker.sh similarity index 92% rename from contained.sh rename to docker.sh index 2cf6562..f12fdfd 100755 --- a/contained.sh +++ b/docker.sh @@ -12,5 +12,4 @@ docker run --rm -it \ -v /dev/input \ -e XAUTHORITY=$XAUTH \ void \ - /app/build/voidstar \ /app/build/voidstar From 2cff83a0ce5ec4683b88cccd574879c004a45b8e Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Thu, 20 Dec 2018 01:09:27 +0100 Subject: [PATCH 03/11] docker-dev.sh Signed-off-by: Pierre Fenoll --- Dockerfile.dev | 10 ++++++++++ docker-dev.sh | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) create mode 100644 Dockerfile.dev create mode 100755 docker-dev.sh diff --git a/Dockerfile.dev b/Dockerfile.dev new file mode 100644 index 0000000..eb02c16 --- /dev/null +++ b/Dockerfile.dev @@ -0,0 +1,10 @@ +FROM debian +RUN set -x \ + && apt update \ + && apt install -y \ + x11-apps \ + libglew-dev libglm-dev libglfw3-dev pkg-config \ + libc++-dev clang cmake +ENV DISPLAY :0 +WORKDIR /app +ENTRYPOINT ["/bin/sh", "-c", "set -x && ./configure && cd build && make -j7 && ./voidstar ./voidstar ../data/*"] diff --git a/docker-dev.sh b/docker-dev.sh new file mode 100755 index 0000000..ec7d014 --- /dev/null +++ b/docker-dev.sh @@ -0,0 +1,17 @@ +#!/bin/bash + +#$ docker build -f Dockerfile.dev -t voiddev . + +# https://stackoverflow.com/a/25168483/1418165 + +XSOCK=/tmp/.X11-unix +XAUTH=/tmp/.docker.xauth +xauth nlist :0 | sed -e 's/^..../ffff/' | xauth -f $XAUTH nmerge - + +docker run --rm -it \ + -v $XSOCK:$XSOCK \ + -v $XAUTH:$XAUTH \ + -v /dev/input \ + -v "$PWD":/app \ + -e XAUTHORITY=$XAUTH \ + voiddev From 3fd0c1e99f96d5f07f4dfbd279edfc54a9d20469 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sun, 9 Dec 2018 17:52:44 +0100 Subject: [PATCH 04/11] wip Signed-off-by: Pierre Fenoll --- src/Algo3DCubeContiFrebet.cc | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/Algo3DCubeContiFrebet.cc b/src/Algo3DCubeContiFrebet.cc index 8fcd6ef..9511dd9 100644 --- a/src/Algo3DCubeContiFrebet.cc +++ b/src/Algo3DCubeContiFrebet.cc @@ -1,3 +1,4 @@ +#include #include bool @@ -7,21 +8,22 @@ Algo3DCubeContiFrebet::apply(Floats& vertices, Floats& colors, VertIndices& indi size_t size; const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; + // u8 x = data[0]; + // u8 y = data[1]; for (size_t i = 2; i+3 < size; ++i) { - u8 z = data[i]; - Index id = (y * width + x) * depth + z; - Index idx = 3 * id; + // u8 z = data[i]; + Index id = i;//(y * width + x) * depth + z; + Index idx = id;//3 * id; colors[idx+0] = static_cast(data[i+1]) / 255.0f; colors[idx+1] = static_cast(data[i+2]) / 255.0f; colors[idx+2] = static_cast(data[i+3]) / 255.0f; + std::cout << id << " " << colors[idx] << "\n"; indices.push_back(id); - x = y; - y = z; + // x = y; + // y = z; } return true; From 11b2614af1fef1bfa2d36dfafd253afafd8cfa24 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Thu, 20 Dec 2018 08:13:59 +0100 Subject: [PATCH 05/11] cast explicitly Signed-off-by: Pierre Fenoll --- src/Algo3DCubeContiFrebet.cc | 40 ++++++++++++++++++++++-------------- 1 file changed, 25 insertions(+), 15 deletions(-) diff --git a/src/Algo3DCubeContiFrebet.cc b/src/Algo3DCubeContiFrebet.cc index 9511dd9..173e8f8 100644 --- a/src/Algo3DCubeContiFrebet.cc +++ b/src/Algo3DCubeContiFrebet.cc @@ -8,23 +8,33 @@ Algo3DCubeContiFrebet::apply(Floats& vertices, Floats& colors, VertIndices& indi size_t size; const u8* data = loadDataRange(size); - // u8 x = data[0]; - // u8 y = data[1]; - - for (size_t i = 2; i+3 < size; ++i) { - // u8 z = data[i]; - Index id = i;//(y * width + x) * depth + z; - Index idx = id;//3 * id; - - colors[idx+0] = static_cast(data[i+1]) / 255.0f; - colors[idx+1] = static_cast(data[i+2]) / 255.0f; - colors[idx+2] = static_cast(data[i+3]) / 255.0f; - std::cout << id << " " << colors[idx] << "\n"; - indices.push_back(id); - // x = y; - // y = z; + std::cerr << "#data: " << size << std::endl; + std::cerr << "#colors: " << colors.size() << std::endl; + + typedef struct { + u8 x, y, z, r, g, b; + } void_; + const size_t struct_size = sizeof (void_); + + for (size_t i = 0; i+struct_size < size; ++i) { + auto* casted = (void_*)(data + i); + + auto x = static_cast(casted->x); + auto y = static_cast(casted->y); + auto z = static_cast(casted->z); + + Index id = (y * width + x) * depth + z; + Index idx = 3 * id; + + colors[idx+0] = static_cast(casted->r) / 255.0f; + colors[idx+1] = static_cast(casted->g) / 255.0f; + colors[idx+2] = static_cast(casted->b) / 255.0f; + + indices.push_back(id); } + std::cerr << "#indices: " << indices.size() << std::endl; + return true; } From 9fef901cc2aab2b1d148b3abc288da77e2646040 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sat, 22 Dec 2018 11:23:00 +0100 Subject: [PATCH 06/11] turns out using offset of struct_size (i.e. 6) is less pretty than offset=1 Signed-off-by: Pierre Fenoll --- src/Algo3DCubeContiFrebet.cc | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Algo3DCubeContiFrebet.cc b/src/Algo3DCubeContiFrebet.cc index 173e8f8..e9c9d40 100644 --- a/src/Algo3DCubeContiFrebet.cc +++ b/src/Algo3DCubeContiFrebet.cc @@ -17,19 +17,19 @@ Algo3DCubeContiFrebet::apply(Floats& vertices, Floats& colors, VertIndices& indi } void_; const size_t struct_size = sizeof (void_); - for (size_t i = 0; i+struct_size < size; ++i) { - auto* casted = (void_*)(data + i); + for (size_t i = 0; i+struct_size < size; i += 1) { + auto* cast = (void_*)(data + i); - auto x = static_cast(casted->x); - auto y = static_cast(casted->y); - auto z = static_cast(casted->z); + auto x = static_cast(cast->x); + auto y = static_cast(cast->y); + auto z = static_cast(cast->z); Index id = (y * width + x) * depth + z; Index idx = 3 * id; - colors[idx+0] = static_cast(casted->r) / 255.0f; - colors[idx+1] = static_cast(casted->g) / 255.0f; - colors[idx+2] = static_cast(casted->b) / 255.0f; + colors[idx+0] = static_cast(cast->r) / 255.0f; + colors[idx+1] = static_cast(cast->g) / 255.0f; + colors[idx+2] = static_cast(cast->b) / 255.0f; indices.push_back(id); } From fd841ef6594af87be04ede644f89de80ae732ac9 Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sat, 22 Dec 2018 14:13:51 +0100 Subject: [PATCH 07/11] scene apply DRY Signed-off-by: Pierre Fenoll --- src/Scene2D.cc | 10 +++------- src/Scene3D.cc | 13 +++---------- src/include/Scene2D.hh | 6 ++++++ src/include/Scene3D.hh | 7 +++++++ 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/src/Scene2D.cc b/src/Scene2D.cc index 0833b95..f2b5109 100644 --- a/src/Scene2D.cc +++ b/src/Scene2D.cc @@ -54,10 +54,9 @@ Scene2D::unload() { void Scene2D::reload() { - auto algo = std::static_pointer_cast(algo_); reset_points(); - algo->apply(vertices_, colors_, width_, height_) - || std::cerr << "!apply" << std::endl; + apply(); + glBindVertexArray(vao_); glBindBuffer(GL_ARRAY_BUFFER, colors_id_); glBufferData(GL_ARRAY_BUFFER, Algorithm::vsize(colors_), colors_.data(), GL_STATIC_DRAW); @@ -67,16 +66,13 @@ Scene2D::reload() { void Scene2D::load(std::shared_ptr algorithm) { Scene::load(algorithm); - auto algo = std::static_pointer_cast(algorithm); glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); load_shaders(); - algo->apply(vertices_, colors_, width_, height_) - || std::cerr << "!apply" << std::endl; - load_buffers(); + apply(); } bool diff --git a/src/Scene3D.cc b/src/Scene3D.cc index 2d90cdf..794ae3f 100644 --- a/src/Scene3D.cc +++ b/src/Scene3D.cc @@ -60,12 +60,9 @@ Scene3D::unload() { void Scene3D::reload() { - auto algo = std::static_pointer_cast(algo_); reset_points(); - algo->apply(vertices_, colors_, indices_, width_, height_, depth_) - || std::cerr << "!apply" << std::endl; - std::cout << "#indices: " << Manager::size2str(indices_.size()) << std::endl; - load_buffers(); + apply(); + glBindVertexArray(vao_); glBindBuffer(GL_ARRAY_BUFFER, colors_id_); glBufferData(GL_ARRAY_BUFFER, Algorithm::vsize(colors_), colors_.data(), GL_STATIC_DRAW); @@ -75,7 +72,6 @@ Scene3D::reload() { void Scene3D::load(std::shared_ptr algorithm) { Scene::load(algorithm); - auto algo = std::static_pointer_cast(algorithm); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); @@ -83,10 +79,7 @@ Scene3D::load(std::shared_ptr algorithm) { glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); load_shaders(); - algo->apply(vertices_, colors_, indices_, width_, height_, depth_) - || std::cerr << "!apply" << std::endl; - std::cout << "#indices: " << Manager::size2str(indices_.size()) << std::endl; - load_buffers(); + apply(); // camera_.setPosition(glm::vec3(0, -0.1, 3)); // camera_.lookAt(glm::vec3(0,0,4)); diff --git a/src/include/Scene2D.hh b/src/include/Scene2D.hh index fe4f34b..617097f 100644 --- a/src/include/Scene2D.hh +++ b/src/include/Scene2D.hh @@ -30,6 +30,12 @@ private: vertices_ = Floats(3 * n_points_); colors_ = Floats(3 * n_points_); } + void apply() { + auto algo = std::static_pointer_cast(algo_); + algo->apply(vertices_, colors_, width_, height_) + || std::cerr << "!apply" << std::endl; + load_buffers(); + } protected: GLuint vao_; diff --git a/src/include/Scene3D.hh b/src/include/Scene3D.hh index 995ded3..2c8e20a 100644 --- a/src/include/Scene3D.hh +++ b/src/include/Scene3D.hh @@ -32,6 +32,13 @@ private: colors_ = Floats(3 * n_points_); indices_.clear(); } + void apply() { + auto algo = std::static_pointer_cast(algo_); + algo->apply(vertices_, colors_, indices_, width_, height_, depth_) + || std::cerr << "!apply" << std::endl; + std::cout << "#indices: " << Manager::size2str(indices_.size()) << std::endl; + load_buffers(); + } protected: GLuint vao_; From a79f069288e88d79974693c698e0ba98b26d9aac Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sat, 22 Dec 2018 23:43:55 +0100 Subject: [PATCH 08/11] separate data extraction from transformation and remove unused transforms Signed-off-by: Pierre Fenoll --- CMakeLists.txt | 8 ----- src/Algo3DCubeContiBnW.cc | 26 ---------------- src/Algo3DCubeContiFrebet.cc | 40 ------------------------- src/Algo3DCubeContiRainbow.cc | 26 ---------------- src/Algo3DCubeFull.cc | 16 ---------- src/Algo3DSphereContiBnW.cc | 26 ---------------- src/Algo3DSphereContiFrebet.cc | 32 -------------------- src/Algo3DSphereContiRainbow.cc | 26 ---------------- src/Algo3DSphereFull.cc | 16 ---------- src/Algorithm.cc | 22 ++++---------- src/include/Algo3D.hh | 6 ++-- src/include/Algo3DCube.hh | 14 +++++---- src/include/Algo3DCubeContiBnW.hh | 12 -------- src/include/Algo3DCubeContiFrebet.hh | 12 -------- src/include/Algo3DCubeContiRainbow.hh | 12 -------- src/include/Algo3DCubeFull.hh | 12 -------- src/include/Algo3DCylinder.hh | 20 +++++++++++++ src/include/Algo3DSphere.hh | 14 ++++----- src/include/Algo3DSphereContiBnW.hh | 12 -------- src/include/Algo3DSphereContiFrebet.hh | 12 -------- src/include/Algo3DSphereContiRainbow.hh | 12 -------- src/include/Algo3DSphereFull.hh | 12 -------- src/include/Arguments.hh | 2 +- "src/include/R\316\230\316\246.hh" | 34 +++++++++++++++++++++ src/include/Scene3D.hh | 20 +++++++++++-- src/include/XYZRGB.hh | 33 ++++++++++++++++++++ "src/include/\316\241\316\246Z.hh" | 34 +++++++++++++++++++++ 27 files changed, 163 insertions(+), 348 deletions(-) delete mode 100644 src/Algo3DCubeContiBnW.cc delete mode 100644 src/Algo3DCubeContiFrebet.cc delete mode 100644 src/Algo3DCubeContiRainbow.cc delete mode 100644 src/Algo3DCubeFull.cc delete mode 100644 src/Algo3DSphereContiBnW.cc delete mode 100644 src/Algo3DSphereContiFrebet.cc delete mode 100644 src/Algo3DSphereContiRainbow.cc delete mode 100644 src/Algo3DSphereFull.cc delete mode 100644 src/include/Algo3DCubeContiBnW.hh delete mode 100644 src/include/Algo3DCubeContiFrebet.hh delete mode 100644 src/include/Algo3DCubeContiRainbow.hh delete mode 100644 src/include/Algo3DCubeFull.hh create mode 100644 src/include/Algo3DCylinder.hh delete mode 100644 src/include/Algo3DSphereContiBnW.hh delete mode 100644 src/include/Algo3DSphereContiFrebet.hh delete mode 100644 src/include/Algo3DSphereContiRainbow.hh delete mode 100644 src/include/Algo3DSphereFull.hh create mode 100644 "src/include/R\316\230\316\246.hh" create mode 100644 src/include/XYZRGB.hh create mode 100644 "src/include/\316\241\316\246Z.hh" diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d45069..446a2fd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,14 +77,6 @@ set(SOURCES src/Algo2DEntropy.cc src/Algo2DFourColors.cc src/Algo2DGrayscale.cc - src/Algo3DCubeFull.cc - src/Algo3DCubeContiBnW.cc - src/Algo3DCubeContiRainbow.cc - src/Algo3DCubeContiFrebet.cc - src/Algo3DSphereFull.cc - src/Algo3DSphereContiBnW.cc - src/Algo3DSphereContiRainbow.cc - src/Algo3DSphereContiFrebet.cc src/GlfwManager.cc diff --git a/src/Algo3DCubeContiBnW.cc b/src/Algo3DCubeContiBnW.cc deleted file mode 100644 index f5b6eca..0000000 --- a/src/Algo3DCubeContiBnW.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include - -bool -Algo3DCubeContiBnW::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; - - for (size_t i = 2; i < size; ++i) { - u8 z = data[i]; - Index id = (y * width + x) * depth + z; - Index idx = 3 * id; - colors[idx + 0] = 1.0f; - colors[idx + 1] = 1.0f; - colors[idx + 2] = 1.0f; - indices.push_back(id); - x = y; - y = z; - } - - return true; -} diff --git a/src/Algo3DCubeContiFrebet.cc b/src/Algo3DCubeContiFrebet.cc deleted file mode 100644 index e9c9d40..0000000 --- a/src/Algo3DCubeContiFrebet.cc +++ /dev/null @@ -1,40 +0,0 @@ -#include -#include - -bool -Algo3DCubeContiFrebet::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - - std::cerr << "#data: " << size << std::endl; - std::cerr << "#colors: " << colors.size() << std::endl; - - typedef struct { - u8 x, y, z, r, g, b; - } void_; - const size_t struct_size = sizeof (void_); - - for (size_t i = 0; i+struct_size < size; i += 1) { - auto* cast = (void_*)(data + i); - - auto x = static_cast(cast->x); - auto y = static_cast(cast->y); - auto z = static_cast(cast->z); - - Index id = (y * width + x) * depth + z; - Index idx = 3 * id; - - colors[idx+0] = static_cast(cast->r) / 255.0f; - colors[idx+1] = static_cast(cast->g) / 255.0f; - colors[idx+2] = static_cast(cast->b) / 255.0f; - - indices.push_back(id); - } - - std::cerr << "#indices: " << indices.size() << std::endl; - - return true; -} diff --git a/src/Algo3DCubeContiRainbow.cc b/src/Algo3DCubeContiRainbow.cc deleted file mode 100644 index 53d0ad8..0000000 --- a/src/Algo3DCubeContiRainbow.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include - -bool -Algo3DCubeContiRainbow::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; - - for (size_t i = 2; i < size; ++i) { - u8 z = data[i]; - Index id = (y * width + x) * depth + z; - Index idx = 3 * id; - colors[idx + 0] = static_cast(x) / 255.0f; - colors[idx + 1] = static_cast(y) / 255.0f; - colors[idx + 2] = static_cast(z) / 255.0f; - indices.push_back(id); - x = y; - y = z; - } - - return true; -} diff --git a/src/Algo3DCubeFull.cc b/src/Algo3DCubeFull.cc deleted file mode 100644 index 0a47f83..0000000 --- a/src/Algo3DCubeFull.cc +++ /dev/null @@ -1,16 +0,0 @@ -#include - -bool -Algo3DCubeFull::apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth) { - auto nb_verts = make_vertices(vertices, width, height, depth); - - for (size_t i = 0; i < nb_verts; ++i) { - colors[3 * i + 0] = 1.0f; - colors[3 * i + 1] = 1.0f; - colors[3 * i + 2] = 1.0f; - selected.push_back(i); - } - - return true; -} diff --git a/src/Algo3DSphereContiBnW.cc b/src/Algo3DSphereContiBnW.cc deleted file mode 100644 index ffc3c95..0000000 --- a/src/Algo3DSphereContiBnW.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include - -bool -Algo3DSphereContiBnW::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; - - for (size_t i = 2; i < size; ++i) { - u8 z = data[i]; - Index id = x + y * height + z * depth * height; - Index idx = 3 * id; - colors[idx + 0] = 1.0f; - colors[idx + 1] = 1.0f; - colors[idx + 2] = 1.0f; - indices.push_back(id); - x = y; - y = z; - } - - return true; -} diff --git a/src/Algo3DSphereContiFrebet.cc b/src/Algo3DSphereContiFrebet.cc deleted file mode 100644 index e568d36..0000000 --- a/src/Algo3DSphereContiFrebet.cc +++ /dev/null @@ -1,32 +0,0 @@ -#include - -bool -Algo3DSphereContiFrebet::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; - - for (size_t i = 2; i+3 < size; ++i) { - u8 z = data[i]; - Index id = x + y * height + z * depth * height; - // float r = std::sqrt(std::pow(static_cast(x), 2.0f) + - // std::pow(static_cast(y), 2.0f) + - // std::pow(static_cast(z), 2.0f)); - // float theta = std::acos(static_cast(z) / r); - // float phi = std::atan(static_cast(y) / static_cast(x)); - // size_t id = r + theta * height + phi * depth * height; - Index idx = 3 * id; - colors[idx + 0] = static_cast(data[i+1]) / 255.0f; - colors[idx + 1] = static_cast(data[i+2]) / 255.0f; - colors[idx + 2] = static_cast(data[i+3]) / 255.0f; - indices.push_back(id); - x = y; - y = z; - } - - return true; -} diff --git a/src/Algo3DSphereContiRainbow.cc b/src/Algo3DSphereContiRainbow.cc deleted file mode 100644 index dc64192..0000000 --- a/src/Algo3DSphereContiRainbow.cc +++ /dev/null @@ -1,26 +0,0 @@ -#include - -bool -Algo3DSphereContiRainbow::apply(Floats& vertices, Floats& colors, VertIndices& indices, - size_t width, size_t height, size_t depth) { - make_vertices(vertices, width, height, depth); - - size_t size; - const u8* data = loadDataRange(size); - u8 x = data[0]; - u8 y = data[1]; - - for (size_t i = 2; i < size; ++i) { - u8 z = data[i]; - Index id = x + y * height + z * depth * height; - Index idx = 3 * id; - colors[idx + 0] = static_cast(x) / 255.0f; - colors[idx + 1] = static_cast(y) / 255.0f; - colors[idx + 2] = static_cast(z) / 255.0f; - indices.push_back(id); - x = y; - y = z; - } - - return true; -} diff --git a/src/Algo3DSphereFull.cc b/src/Algo3DSphereFull.cc deleted file mode 100644 index 50dd09f..0000000 --- a/src/Algo3DSphereFull.cc +++ /dev/null @@ -1,16 +0,0 @@ -#include - -bool -Algo3DSphereFull::apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth) { - auto nb_verts = make_vertices(vertices, width, height, depth); - - for (size_t i = 0; i < nb_verts; ++i) { - colors[3 * i + 0] = 1.0f; - colors[3 * i + 1] = 1.0f; - colors[3 * i + 2] = 1.0f; - selected.push_back(i); - } - - return true; -} diff --git a/src/Algorithm.cc b/src/Algorithm.cc index 4419c57..b8aa836 100644 --- a/src/Algorithm.cc +++ b/src/Algorithm.cc @@ -6,14 +6,9 @@ #include #include #include -#include -#include -#include -#include -#include -#include -#include -#include +#include +#include +#include <ΡΦZ.hh> void Algorithm::use(std::shared_ptr loader, std::shared_ptr range) { @@ -57,12 +52,7 @@ const std::map algorithms = { {"entropy", []() { return std::make_shared(); }}, {"4col", []() { return std::make_shared(); }}, {"gray", []() { return std::make_shared(); }}, - {"cube", []() { return std::make_shared(); }}, - {"contibnw", []() { return std::make_shared(); }}, - {"contirb", []() { return std::make_shared(); }}, - {"conti", []() { return std::make_shared(); }}, - {"sphere", []() { return std::make_shared(); }}, - {"sphere_bnw", []() { return std::make_shared(); }}, - {"sphere_rb", []() { return std::make_shared(); }}, - {"sphere_frebet", []() { return std::make_shared(); }}, + {"cube", []() { return std::make_shared(); }}, + {"sphere", []() { return std::make_shared(); }}, + {"cylinder", []() { return std::make_shared<ΡΦZ>(); }}, }; diff --git a/src/include/Algo3D.hh b/src/include/Algo3D.hh index ccc32ea..514bfde 100644 --- a/src/include/Algo3D.hh +++ b/src/include/Algo3D.hh @@ -9,6 +9,8 @@ public: virtual ~Algo3D() {} virtual SceneType sceneType() const { return SCENE_3D; } - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth) = 0; + + virtual size_t value_size() const = 0; + virtual Index cast(const u8* data, Floats& colors, + size_t width, size_t height, size_t depth) const = 0; }; diff --git a/src/include/Algo3DCube.hh b/src/include/Algo3DCube.hh index b40e9e3..7ac2f9e 100644 --- a/src/include/Algo3DCube.hh +++ b/src/include/Algo3DCube.hh @@ -1,17 +1,18 @@ #pragma once +#include + #include class Algo3DCube : public Algo3D { public: virtual ~Algo3DCube() {} - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth) = 0; + static void make_vertices(Floats& vertices, + size_t width, size_t height, size_t depth) { + std::cerr << "drawing " << width << "x" << height << "x" << depth + << " cube" << std::endl; -protected: - size_t - make_vertices(Floats& vertices, size_t width, size_t height, size_t depth) { const float w = static_cast(width) / 2; const float h = static_cast(height) / 2; const float d = static_cast(depth) / 2; @@ -25,6 +26,7 @@ protected: vertices[pos++] = (static_cast(z) - d) / d; } - return vertices.size() / 3; + std::cerr << "drawn cube of " << Manager::size2str(vertices.size() / 3) + << " vertices" << std::endl; } }; diff --git a/src/include/Algo3DCubeContiBnW.hh b/src/include/Algo3DCubeContiBnW.hh deleted file mode 100644 index 37c2489..0000000 --- a/src/include/Algo3DCubeContiBnW.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DCubeContiBnW : public Algo3DCube { -public: - Algo3DCubeContiBnW() {} - virtual ~Algo3DCubeContiBnW() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DCubeContiFrebet.hh b/src/include/Algo3DCubeContiFrebet.hh deleted file mode 100644 index b88daee..0000000 --- a/src/include/Algo3DCubeContiFrebet.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DCubeContiFrebet : public Algo3DCube { -public: - Algo3DCubeContiFrebet() {} - virtual ~Algo3DCubeContiFrebet() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DCubeContiRainbow.hh b/src/include/Algo3DCubeContiRainbow.hh deleted file mode 100644 index e1ae5bf..0000000 --- a/src/include/Algo3DCubeContiRainbow.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DCubeContiRainbow : public Algo3DCube { -public: - Algo3DCubeContiRainbow() {} - virtual ~Algo3DCubeContiRainbow() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DCubeFull.hh b/src/include/Algo3DCubeFull.hh deleted file mode 100644 index 939a6a5..0000000 --- a/src/include/Algo3DCubeFull.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DCubeFull : public Algo3DCube { -public: - Algo3DCubeFull() {} - virtual ~Algo3DCubeFull() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DCylinder.hh b/src/include/Algo3DCylinder.hh new file mode 100644 index 0000000..d2d4ec4 --- /dev/null +++ b/src/include/Algo3DCylinder.hh @@ -0,0 +1,20 @@ +#pragma once + +#include +#include +#include + +#include + +class Algo3DCylinder : public Algo3D { +public: + virtual ~Algo3DCylinder() {} + + static void make_vertices(Floats& vertices, + size_t /*width*/, size_t /*height*/, size_t /*depth*/) { + // TODO + + std::cerr << "drawn cylinder of " << Manager::size2str(vertices.size() / 3) + << " vertices" << std::endl; + } +}; diff --git a/src/include/Algo3DSphere.hh b/src/include/Algo3DSphere.hh index a5ff131..3278699 100644 --- a/src/include/Algo3DSphere.hh +++ b/src/include/Algo3DSphere.hh @@ -1,7 +1,8 @@ #pragma once -#include #include +#include +#include #include @@ -9,12 +10,8 @@ class Algo3DSphere : public Algo3D { public: virtual ~Algo3DSphere() {} - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth) = 0; - -protected: - size_t - make_vertices(Floats& vertices, size_t width, size_t height, size_t depth) { + static void make_vertices(Floats& vertices, + size_t width, size_t height, size_t depth) { const float w = static_cast(width) / 2; const float h = static_cast(height) / 2; const float d = static_cast(depth) / 2; @@ -35,6 +32,7 @@ protected: vertices[pos++] = r * std::cos(theta) / d; } - return vertices.size() / 3; + std::cerr << "drawn sphere of " << Manager::size2str(vertices.size() / 3) + << " vertices" << std::endl; } }; diff --git a/src/include/Algo3DSphereContiBnW.hh b/src/include/Algo3DSphereContiBnW.hh deleted file mode 100644 index 6f30db9..0000000 --- a/src/include/Algo3DSphereContiBnW.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DSphereContiBnW : public Algo3DSphere { -public: - Algo3DSphereContiBnW() {} - virtual ~Algo3DSphereContiBnW() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DSphereContiFrebet.hh b/src/include/Algo3DSphereContiFrebet.hh deleted file mode 100644 index f67d4d1..0000000 --- a/src/include/Algo3DSphereContiFrebet.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DSphereContiFrebet : public Algo3DSphere { -public: - Algo3DSphereContiFrebet() {} - virtual ~Algo3DSphereContiFrebet() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DSphereContiRainbow.hh b/src/include/Algo3DSphereContiRainbow.hh deleted file mode 100644 index 04fb53f..0000000 --- a/src/include/Algo3DSphereContiRainbow.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DSphereContiRainbow : public Algo3DSphere { -public: - Algo3DSphereContiRainbow() {} - virtual ~Algo3DSphereContiRainbow() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Algo3DSphereFull.hh b/src/include/Algo3DSphereFull.hh deleted file mode 100644 index 225e5eb..0000000 --- a/src/include/Algo3DSphereFull.hh +++ /dev/null @@ -1,12 +0,0 @@ -#pragma once - -#include - -class Algo3DSphereFull : public Algo3DSphere { -public: - Algo3DSphereFull() {} - virtual ~Algo3DSphereFull() {} - - virtual bool apply(Floats& vertices, Floats& colors, VertIndices& selected, - size_t width, size_t height, size_t depth); -}; diff --git a/src/include/Arguments.hh b/src/include/Arguments.hh index 30c3d78..5e8698e 100644 --- a/src/include/Arguments.hh +++ b/src/include/Arguments.hh @@ -7,7 +7,7 @@ struct Arguments { Arguments() : name("void*"), - algo("conti"), + algo("cube"), manager("glfw"), width(800), height(600), range_begin(0), range_end(0), diff --git "a/src/include/R\316\230\316\246.hh" "b/src/include/R\316\230\316\246.hh" new file mode 100644 index 0000000..481fba1 --- /dev/null +++ "b/src/include/R\316\230\316\246.hh" @@ -0,0 +1,34 @@ +#pragma once + +#include + +class RΘΦ : public Algo3DSphere { +public: + RΘΦ() {} + virtual ~RΘΦ() {} + + typedef struct { + u8 r, θ, φ, R, G, B; + } value_type; + + virtual size_t value_size() const { return sizeof (value_type); } + + virtual Index cast(const u8* data, Floats& colors, + size_t /*width*/, size_t height, size_t depth) const { + auto* cast = (value_type*)(data); + + auto r = static_cast(cast->r); + auto θ = static_cast(cast->θ); + auto φ = static_cast(cast->φ); + + // TODO: actually use spherical coordinates + Index id = (r * height + θ) * depth + φ; + Index idx = 3 * id; + + colors[idx+0] = static_cast(cast->R) / 255.0f; + colors[idx+1] = static_cast(cast->G) / 255.0f; + colors[idx+2] = static_cast(cast->B) / 255.0f; + + return id; + } +}; diff --git a/src/include/Scene3D.hh b/src/include/Scene3D.hh index 2c8e20a..f83a57b 100644 --- a/src/include/Scene3D.hh +++ b/src/include/Scene3D.hh @@ -4,6 +4,8 @@ #include #include +#include +#include class Scene3D : public Scene { public: @@ -33,10 +35,22 @@ private: indices_.clear(); } void apply() { - auto algo = std::static_pointer_cast(algo_); - algo->apply(vertices_, colors_, indices_, width_, height_, depth_) - || std::cerr << "!apply" << std::endl; + Algo3DCube::make_vertices(vertices_, width_, height_, depth_); + + size_t size; + const u8* data = algo_->loadDataRange(size); + auto algo = std::static_pointer_cast(algo_); + const auto value_size = algo->value_size(); + + for (size_t i = 0; i+value_size < size; ++i) { + std::cout << "i: " << i << std::endl; + auto id = algo->cast(data + i, colors_, width_, height_, depth_); + std::cout << "id:" << id << std::endl; + indices_.push_back(id); + } + std::cout << "#indices: " << Manager::size2str(indices_.size()) << std::endl; + load_buffers(); } diff --git a/src/include/XYZRGB.hh b/src/include/XYZRGB.hh new file mode 100644 index 0000000..9b0cad0 --- /dev/null +++ b/src/include/XYZRGB.hh @@ -0,0 +1,33 @@ +#pragma once + +#include + +class XYZRGB : public Algo3DCube { +public: + XYZRGB() {} + virtual ~XYZRGB() {} + + typedef struct { + u8 x, y, z, R, G, B; + } value_type; + + virtual size_t value_size() const { return sizeof (value_type); } + + virtual Index cast(const u8* data, Floats& colors, + size_t /*width*/, size_t height, size_t depth) const { + auto* cast = (value_type*)(data); + + auto x = static_cast(cast->x); + auto y = static_cast(cast->y); + auto z = static_cast(cast->z); + + Index id = (x * height + y) * depth + z; + Index idx = 3 * id; + + colors[idx+0] = static_cast(cast->R) / 255.0f; + colors[idx+1] = static_cast(cast->G) / 255.0f; + colors[idx+2] = static_cast(cast->B) / 255.0f; + + return id; + } +}; diff --git "a/src/include/\316\241\316\246Z.hh" "b/src/include/\316\241\316\246Z.hh" new file mode 100644 index 0000000..ef7f2f7 --- /dev/null +++ "b/src/include/\316\241\316\246Z.hh" @@ -0,0 +1,34 @@ +#pragma once + +#include + +class ΡΦZ : public Algo3DCylinder { +public: + ΡΦZ() {} + virtual ~ΡΦZ() {} + + typedef struct { + u8 ρ, φ, z, R, G, B; + } value_type; + + virtual size_t value_size() const { return sizeof (value_type); } + + virtual Index cast(const u8* data, Floats& colors, + size_t /*width*/, size_t height, size_t depth) const { + auto* cast = (value_type*)(data); + + auto ρ = static_cast(cast->ρ); + auto φ = static_cast(cast->φ); + auto z = static_cast(cast->z); + + // TODO: actually use cylindrical coordinates + Index id = (ρ * height + φ) * depth + z; + Index idx = 3 * id; + + colors[idx+0] = static_cast(cast->R) / 255.0f; + colors[idx+1] = static_cast(cast->G) / 255.0f; + colors[idx+2] = static_cast(cast->B) / 255.0f; + + return id; + } +}; From 8e6b83c5a842d31ca104b147d8f5aa69a8cfcfab Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sat, 22 Dec 2018 23:55:09 +0100 Subject: [PATCH 09/11] rm some debug code Signed-off-by: Pierre Fenoll --- src/include/Scene3D.hh | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/include/Scene3D.hh b/src/include/Scene3D.hh index f83a57b..886a1be 100644 --- a/src/include/Scene3D.hh +++ b/src/include/Scene3D.hh @@ -43,9 +43,7 @@ private: const auto value_size = algo->value_size(); for (size_t i = 0; i+value_size < size; ++i) { - std::cout << "i: " << i << std::endl; auto id = algo->cast(data + i, colors_, width_, height_, depth_); - std::cout << "id:" << id << std::endl; indices_.push_back(id); } From 426291d1001e4bcf48ea421f4c4eededd37f480b Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sun, 23 Dec 2018 16:20:07 +0100 Subject: [PATCH 10/11] travis use clang 7 Signed-off-by: Pierre Fenoll --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index 01c6532..3751add 100644 --- a/.travis.yml +++ b/.travis.yml @@ -9,8 +9,11 @@ os: dist: trusty addons: + sources: + - llvm-toolchain-trusty-7 # clang-7 apt: packages: + - clang-7 - libglew-dev - libglm-dev - xorg-dev From 54a8e5359df873d6e02bba7712551ab7c790010a Mon Sep 17 00:00:00 2001 From: Pierre Fenoll Date: Sun, 23 Dec 2018 20:48:55 +0100 Subject: [PATCH 11/11] un-specialize Scene3D code Signed-off-by: Pierre Fenoll --- src/Manager.cc | 36 ++++++++++++++++++------------- src/Scene.cc | 36 +++++++------------------------ src/Scene2D.cc | 4 ++-- src/Scene3D.cc | 4 ++-- src/include/Algo2D.hh | 1 - src/include/Algo3D.hh | 3 ++- src/include/Algo3DCube.hh | 4 ++-- src/include/Algo3DCylinder.hh | 4 ++-- src/include/Algo3DSphere.hh | 4 ++-- src/include/Algorithm.hh | 8 ------- src/include/Manager.hh | 1 - src/include/Scene.hh | 40 +++++++++++++++++++++++++++++------ src/include/Scene2D.hh | 5 ++--- src/include/Scene3D.hh | 12 +++++------ 14 files changed, 82 insertions(+), 80 deletions(-) diff --git a/src/Manager.cc b/src/Manager.cc index f8cd85b..62e6af0 100644 --- a/src/Manager.cc +++ b/src/Manager.cc @@ -3,16 +3,6 @@ #include #include -void -Manager::loadScene(std::shared_ptr scene) { - // XXX delete scene prior to creating a new one - if (scene_) { - std::cout << "deleting scene" << std::endl; - } - scene_ = scene; - scene->init(args_); -} - void Manager::loadFile(const std::string& filename) { args_->paths.push_back(filename); @@ -37,13 +27,29 @@ Manager::loadFile(size_t index) { auto range = DataRange::create(args_->range_begin, args_->range_end); if (scene_) { - auto algo = scene_->algorithm(); - algo->use(loader, range); + scene_->algorithm()->use(loader, range); scene_->reload(); - } else { - auto algo = createAlgorithm(args_->algo); + return true; + } + + auto uglyhack_algo = createAlgorithm(args_->algo); + if (auto algo = std::dynamic_pointer_cast(uglyhack_algo)) { + algo->use(loader, range); + if (scene_) { + std::cout << "deleting 3D scene" << std::endl; + } + scene_ = Scene::with_algo(args_, algo); + scene_->init(args_); + return true; + } + + if (auto algo = std::dynamic_pointer_cast(uglyhack_algo)) { algo->use(loader, range); - loadScene(Scene::with_algo(args_, algo)); + if (scene_) { + std::cout << "deleting 2D scene" << std::endl; + } + scene_ = Scene::with_algo(args_, algo); + scene_->init(args_); } return true; } diff --git a/src/Scene.cc b/src/Scene.cc index 2c1dba8..03ede87 100644 --- a/src/Scene.cc +++ b/src/Scene.cc @@ -2,37 +2,17 @@ #include #include -void -Scene::load(std::shared_ptr algo) { - if (type_ != algo->sceneType()) - throw std::runtime_error("Invalid algo for scene"); - if (algo_ && algo_ != algo) - std::cerr << "deleting algo" << std::endl; - algo_ = algo; -} - -void -Scene::unload() { -} - -void -Scene::reload() { +std::shared_ptr +Scene::with_algo(const std::shared_ptr args, const std::shared_ptr algo) { + auto scene = std::make_shared(); + scene->init(args); + scene->load(algo); + return scene; } -#define SCENE(Body) []() -> std::shared_ptr { Body } -using SceneFactoryFunc = std::function()>; -std::map scenes = { - {SCENE_2D, SCENE( return std::make_shared(); )}, - {SCENE_3D, SCENE( return std::make_shared(); )}, -}; - std::shared_ptr -Scene::with_algo(std::shared_ptr args, std::shared_ptr algo) { - auto it = scenes.find(algo->sceneType()); - if (it == scenes.end()) { - throw std::runtime_error("Unknown scene type for algorithm"); - } - auto scene = it->second(); +Scene::with_algo(const std::shared_ptr args, const std::shared_ptr algo) { + auto scene = std::make_shared(); scene->init(args); scene->load(algo); return scene; diff --git a/src/Scene2D.cc b/src/Scene2D.cc index f2b5109..84d001e 100644 --- a/src/Scene2D.cc +++ b/src/Scene2D.cc @@ -64,8 +64,8 @@ Scene2D::reload() { } void -Scene2D::load(std::shared_ptr algorithm) { - Scene::load(algorithm); +Scene2D::load(std::shared_ptr algo) { + Scene::load(algo); glEnable(GL_PROGRAM_POINT_SIZE); glEnable(GL_BLEND); diff --git a/src/Scene3D.cc b/src/Scene3D.cc index 794ae3f..cdea8db 100644 --- a/src/Scene3D.cc +++ b/src/Scene3D.cc @@ -70,8 +70,8 @@ Scene3D::reload() { } void -Scene3D::load(std::shared_ptr algorithm) { - Scene::load(algorithm); +Scene3D::load(std::shared_ptr algo) { + Scene::load(algo); glEnable(GL_DEPTH_TEST); glDepthFunc(GL_LESS); diff --git a/src/include/Algo2D.hh b/src/include/Algo2D.hh index a34b184..b3d84df 100644 --- a/src/include/Algo2D.hh +++ b/src/include/Algo2D.hh @@ -6,7 +6,6 @@ class Algo2D : public Algorithm { public: virtual ~Algo2D() {} - virtual SceneType sceneType() const { return SCENE_2D; } virtual bool apply(Floats& vertices, Floats& colors, size_t width, size_t height) = 0; diff --git a/src/include/Algo3D.hh b/src/include/Algo3D.hh index 514bfde..f9ed77a 100644 --- a/src/include/Algo3D.hh +++ b/src/include/Algo3D.hh @@ -8,7 +8,8 @@ class Algo3D : public Algorithm { public: virtual ~Algo3D() {} - virtual SceneType sceneType() const { return SCENE_3D; } + virtual void make_vertices(Floats& vertices, + size_t width, size_t height, size_t depth) = 0; virtual size_t value_size() const = 0; virtual Index cast(const u8* data, Floats& colors, diff --git a/src/include/Algo3DCube.hh b/src/include/Algo3DCube.hh index 7ac2f9e..94765b8 100644 --- a/src/include/Algo3DCube.hh +++ b/src/include/Algo3DCube.hh @@ -8,8 +8,8 @@ class Algo3DCube : public Algo3D { public: virtual ~Algo3DCube() {} - static void make_vertices(Floats& vertices, - size_t width, size_t height, size_t depth) { + virtual void make_vertices(Floats& vertices, + size_t width, size_t height, size_t depth) { std::cerr << "drawing " << width << "x" << height << "x" << depth << " cube" << std::endl; diff --git a/src/include/Algo3DCylinder.hh b/src/include/Algo3DCylinder.hh index d2d4ec4..bbb51f3 100644 --- a/src/include/Algo3DCylinder.hh +++ b/src/include/Algo3DCylinder.hh @@ -10,8 +10,8 @@ class Algo3DCylinder : public Algo3D { public: virtual ~Algo3DCylinder() {} - static void make_vertices(Floats& vertices, - size_t /*width*/, size_t /*height*/, size_t /*depth*/) { + virtual void make_vertices(Floats& vertices, + size_t /*width*/, size_t /*height*/, size_t /*depth*/) { // TODO std::cerr << "drawn cylinder of " << Manager::size2str(vertices.size() / 3) diff --git a/src/include/Algo3DSphere.hh b/src/include/Algo3DSphere.hh index 3278699..03bd494 100644 --- a/src/include/Algo3DSphere.hh +++ b/src/include/Algo3DSphere.hh @@ -10,8 +10,8 @@ class Algo3DSphere : public Algo3D { public: virtual ~Algo3DSphere() {} - static void make_vertices(Floats& vertices, - size_t width, size_t height, size_t depth) { + virtual void make_vertices(Floats& vertices, + size_t width, size_t height, size_t depth) { const float w = static_cast(width) / 2; const float h = static_cast(height) / 2; const float d = static_cast(depth) / 2; diff --git a/src/include/Algorithm.hh b/src/include/Algorithm.hh index 559a1b0..358d15b 100644 --- a/src/include/Algorithm.hh +++ b/src/include/Algorithm.hh @@ -9,13 +9,6 @@ #include #include -// XXX moved here as a placeholder due to circular dependency #badDesign -enum SceneType { - SCENE_UNDEFINED, - SCENE_2D, - SCENE_3D, -}; - class Algorithm { public: Algorithm(size_t min_size=0, size_t max_size=0) @@ -23,7 +16,6 @@ public: loader_(0), range_(0) {} virtual ~Algorithm() {} - virtual SceneType sceneType() const = 0; virtual void use(std::shared_ptr loader, std::shared_ptr range=NULL); const u8* loadDataRange(const DataRange& range, size_t& size); diff --git a/src/include/Manager.hh b/src/include/Manager.hh index 173a36c..d8590a0 100644 --- a/src/include/Manager.hh +++ b/src/include/Manager.hh @@ -18,7 +18,6 @@ public: {} virtual ~Manager() {} - virtual void loadScene(std::shared_ptr scene); virtual void init() = 0; virtual void run() = 0; diff --git a/src/include/Scene.hh b/src/include/Scene.hh index ccd0b98..7e379b8 100644 --- a/src/include/Scene.hh +++ b/src/include/Scene.hh @@ -13,24 +13,43 @@ #include #include +#include +#include #include #include class Manager; +enum SceneType { + SCENE_UNDEFINED, + SCENE_2D, + SCENE_3D, +}; + class Scene { public: Scene(SceneType type) - : type_(type), algo_(nullptr) + : type_(type) {} virtual ~Scene() {} virtual void init(std::shared_ptr args) = 0; virtual bool update(std::shared_ptr manager, float elapsedTime) = 0; virtual void render() = 0; - virtual void load(std::shared_ptr algo); - virtual void unload(); - virtual void reload(); + + virtual void load(std::shared_ptr algo) { + if (algo2D_ && algo2D_ != algo) + std::cerr << "deleting 2D algo" << std::endl; + algo2D_ = algo; + } + virtual void load(std::shared_ptr algo) { + if (algo3D_ && algo3D_ != algo) + std::cerr << "deleting 3D algo" << std::endl; + algo3D_ = algo; + } + + virtual void unload() {} + virtual void reload() {} virtual void resize(int viewport_width, int viewport_height) { float aspect_ratio = static_cast(viewport_width) / static_cast(viewport_height); @@ -40,11 +59,18 @@ public: } inline SceneType type() const { return type_; } - std::shared_ptr algorithm() const { return algo_; } - static std::shared_ptr with_algo(std::shared_ptr args, std::shared_ptr algo); + std::shared_ptr algorithm() const { + if (algo3D_) + return static_cast>(algo3D_); + return static_cast>(algo2D_); + } + + static std::shared_ptr with_algo(const std::shared_ptr args, const std::shared_ptr algo); + static std::shared_ptr with_algo(const std::shared_ptr args, const std::shared_ptr algo); protected: SceneType type_; - std::shared_ptr algo_; + std::shared_ptr algo2D_; + std::shared_ptr algo3D_; tdogl::Camera camera_; }; diff --git a/src/include/Scene2D.hh b/src/include/Scene2D.hh index 617097f..418522f 100644 --- a/src/include/Scene2D.hh +++ b/src/include/Scene2D.hh @@ -17,7 +17,7 @@ public: virtual ~Scene2D() { unload(); } virtual void init(std::shared_ptr args); - virtual void load(std::shared_ptr algo); + virtual void load(std::shared_ptr algo); virtual void unload(); virtual void reload(); virtual bool update(std::shared_ptr manager, float elapsedTime); @@ -31,8 +31,7 @@ private: colors_ = Floats(3 * n_points_); } void apply() { - auto algo = std::static_pointer_cast(algo_); - algo->apply(vertices_, colors_, width_, height_) + algo2D_->apply(vertices_, colors_, width_, height_) || std::cerr << "!apply" << std::endl; load_buffers(); } diff --git a/src/include/Scene3D.hh b/src/include/Scene3D.hh index 886a1be..3301ad8 100644 --- a/src/include/Scene3D.hh +++ b/src/include/Scene3D.hh @@ -20,7 +20,7 @@ public: virtual ~Scene3D() { unload(); } virtual void init(std::shared_ptr args); - virtual void load(std::shared_ptr algo); + virtual void load(std::shared_ptr algo); virtual void unload(); virtual void reload(); virtual bool update(std::shared_ptr manager, float elapsedTime); @@ -34,16 +34,16 @@ private: colors_ = Floats(3 * n_points_); indices_.clear(); } + void apply() { - Algo3DCube::make_vertices(vertices_, width_, height_, depth_); + algo3D_->make_vertices(vertices_, width_, height_, depth_); size_t size; - const u8* data = algo_->loadDataRange(size); - auto algo = std::static_pointer_cast(algo_); - const auto value_size = algo->value_size(); + const u8* data = algo3D_->loadDataRange(size); + const auto value_size = algo3D_->value_size(); for (size_t i = 0; i+value_size < size; ++i) { - auto id = algo->cast(data + i, colors_, width_, height_, depth_); + auto id = algo3D_->cast(data + i, colors_, width_, height_, depth_); indices_.push_back(id); }