From 53ef632bdc25e41672e89ab03761847370bc9087 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Sun, 18 Feb 2018 18:25:43 +0100 Subject: [PATCH] Actually implement node positions for image-like-layers. --- src/MultiImageVisualisation.cpp | 48 +++++++++++++-------------------- src/MultiImageVisualisation.hpp | 6 +++++ 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/MultiImageVisualisation.cpp b/src/MultiImageVisualisation.cpp index 26345d3..db60689 100644 --- a/src/MultiImageVisualisation.cpp +++ b/src/MultiImageVisualisation.cpp @@ -18,40 +18,28 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer) CHECK_EQ(1, images) << "Only single input image is supported" << endl; - int columns = numCols(channels); - - // Create the quads for the images. - int r = 0, c = 0; - int v = 0; - - vertexBuffer = std::make_unique(channels * 12); - textureReferences.resize(channels); - + nodePositions_.resize(channels * 3); auto dataPtr = layer.data(); - + const int columns = numCols(channels); + textureReferences.resize(channels); for (auto i : Range(channels)) { textureReferences[i] = loadTexture(dataPtr, width, height); - vertexBuffer[v++] = 0; - vertexBuffer[v++] = 0 + 3 * r; - vertexBuffer[v++] = 0 - 3 * c; - - vertexBuffer[v++] = 0; - vertexBuffer[v++] = 2 + 3 * r; - vertexBuffer[v++] = 0 - 3 * c; - - vertexBuffer[v++] = 0; - vertexBuffer[v++] = 2 + 3 * r; - vertexBuffer[v++] = 2 - 3 * c; - - vertexBuffer[v++] = 0; - vertexBuffer[v++] = 0 + 3 * r; - vertexBuffer[v++] = 2 - 3 * c; - - if (++c >= columns) { - c = 0; - ++r; - } dataPtr += width * height; + + nodePositions_[3 * i + 0] = 0; + nodePositions_[3 * i + 1] = 3 * (i / columns); + nodePositions_[3 * i + 2] = -3 * (i % columns); + } + + vertexBuffer = std::make_unique(channels * BASE_VERTICES.size()); + + auto v = 0; + + for (auto i : Range(channels)) { + const auto& nodePos = &nodePositions_[3 * i]; + for (auto j : Range(BASE_VERTICES.size())) { + vertexBuffer[v++] = nodePos[j % 3] + BASE_VERTICES[j]; + } } } diff --git a/src/MultiImageVisualisation.hpp b/src/MultiImageVisualisation.hpp index 29de5ca..70eb7d1 100644 --- a/src/MultiImageVisualisation.hpp +++ b/src/MultiImageVisualisation.hpp @@ -17,6 +17,12 @@ namespace fmri void render() override; private: + constexpr const static std::array BASE_VERTICES = { + 0, -1, -1, + 0, 1, -1, + 0, 1, 1, + 0, -1, 1, + }; std::vector textureReferences; std::unique_ptr vertexBuffer; };