From e4336b6757e55d465ba09beb10dd8d96ca965a94 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Thu, 15 Feb 2018 16:07:13 +0100 Subject: [PATCH] Actually use the same node positions internally and externally. --- src/ActivityAnimation.cpp | 4 +- src/FlatLayerVisualisation.cpp | 89 +++++++++++++++------------------- src/FlatLayerVisualisation.hpp | 18 +++++++ 3 files changed, 60 insertions(+), 51 deletions(-) diff --git a/src/ActivityAnimation.cpp b/src/ActivityAnimation.cpp index 51de794..5825b15 100644 --- a/src/ActivityAnimation.cpp +++ b/src/ActivityAnimation.cpp @@ -16,8 +16,8 @@ ActivityAnimation::ActivityAnimation(const vector(i * NODE_FACES.size() / 3); // Define the colors for the vertices - for (int c = 0; c < 4; ++c) { - computeColor(data[i], scalingMax, &colorBuffer[12 * i + 3 * c]); + for (auto c : Range(NODE_SHAPE.size() / 3)) { + computeColor(data[i], scalingMax, &colorBuffer[NODE_FACES.size() * i + 3 * c]); } - // Create the index set for the faces - // Simply connect all vertices in ascending order and it works. - indexBuffer[v++] = vertexBase; - indexBuffer[v++] = vertexBase + 1; - indexBuffer[v++] = vertexBase + 2; - indexBuffer[v++] = vertexBase; - indexBuffer[v++] = vertexBase + 1; - indexBuffer[v++] = vertexBase + 3; - indexBuffer[v++] = vertexBase; - indexBuffer[v++] = vertexBase + 2; - indexBuffer[v++] = vertexBase + 3; - indexBuffer[v++] = vertexBase + 1; - indexBuffer[v++] = vertexBase + 2; - indexBuffer[v++] = vertexBase + 3; + // Set the face nodes indices + for (auto faceNode : NODE_FACES) { + indexBuffer[v++] = vertexBase + faceNode; + } } assert(v == (int) faceCount * 3); } @@ -82,42 +74,41 @@ void FlatLayerVisualisation::render() void FlatLayerVisualisation::setVertexPositions(const int vertexNo, float *destination) { - int j = 0; - float zOffset; - float yOffset; + for (auto i : Range(NODE_SHAPE.size())) { + destination[i] = NODE_SHAPE[i] + nodePositions_[3 * vertexNo + (i % 3)]; + } +} +void FlatLayerVisualisation::initializeNodePositions() +{ switch (ordering) { case Ordering::LINE: - zOffset = -2 * vertexNo; - yOffset = 0; + computeNodePositionsLine(); break; case Ordering::SQUARE: - const auto nodes = faceCount / 4; - auto columns = static_cast(numCols(nodes)); - - zOffset = -2 * (vertexNo % columns); - yOffset = 2 * (vertexNo / columns); + computeNodePositionsSquare(); break; } - - nodePositions_[3 * vertexNo] = 0; - nodePositions_[3 * vertexNo + 1] = yOffset; - nodePositions_[3 * vertexNo + 2] = zOffset; - // TODO: actually compute from this rather than copying to destination. - // Side note: should move this out of this function anyway. - - // Create the 4 vertices for the pyramid - destination[j++] = -0.5f; - destination[j++] = 0 + yOffset; - destination[j++] = 0.5f + zOffset; - destination[j++] = 0; - destination[j++] = 0 + yOffset; - destination[j++] = -0.5f + zOffset; - destination[j++] = 0; - destination[j++] = 1 + yOffset; - destination[j++] = 0 + zOffset; - destination[j++] = 0.5; - destination[j++] = 0 + yOffset; - destination[j++] = 0.5f + zOffset; +} + +void FlatLayerVisualisation::computeNodePositionsSquare() +{ + const auto nodes = static_cast(faceCount / 4); + const auto columns = numCols(nodes); + + for (auto i : Range(nodes)) { + nodePositions_[3 * i + 0] = 0; + nodePositions_[3 * i + 1] = 2 * (i / columns); + nodePositions_[3 * i + 2] = -2 * (i % columns); + } +} + +void FlatLayerVisualisation::computeNodePositionsLine() +{ + for (auto i : Range(static_cast(faceCount / 4))) { + nodePositions_[3 * i + 0] = 0; + nodePositions_[3 * i + 1] = 0; + nodePositions_[3 * i + 2] = -2.0f * i; + } } diff --git a/src/FlatLayerVisualisation.hpp b/src/FlatLayerVisualisation.hpp index 4a6da11..7090851 100644 --- a/src/FlatLayerVisualisation.hpp +++ b/src/FlatLayerVisualisation.hpp @@ -26,6 +26,24 @@ namespace fmri std::unique_ptr colorBuffer; std::unique_ptr indexBuffer; + static constexpr const std::array NODE_SHAPE = { + -0.5f, 0, 0.5f, + 0, 0, -0.5f, + 0, 1, 0, + 0.5f, 0, 0.5f + }; + static constexpr const std::array NODE_FACES = { + 0, 1, 2, + 0, 1, 3, + 0, 2, 3, + 1, 2, 3 + }; + void setVertexPositions(int vertexNo, float *destination); + + // Various functions defining the way the nodes will be aligned. + void initializeNodePositions(); + void computeNodePositionsLine(); + void computeNodePositionsSquare(); }; }