Actually use the same node positions internally and externally.

This commit is contained in:
2018-02-15 16:07:13 +01:00
parent ea4b5e486a
commit e4336b6757
3 changed files with 60 additions and 51 deletions

View File

@@ -16,8 +16,8 @@ ActivityAnimation::ActivityAnimation(const vector<pair<DType, pair<size_t, size_
delta.reserve(bufferLength);
for (auto &entry : interactions) {
auto *aPos = &aPositions[entry.second.first];
auto *bPos = &bPositions[entry.second.second];
auto *aPos = &aPositions[3 * entry.second.first];
auto *bPos = &bPositions[3 * entry.second.second];
for (auto i : Range(3)) {
startingPos.emplace_back(aPos[i]);

View File

@@ -24,7 +24,7 @@ static inline void computeColor(float intensity, float limit, float* destination
FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering ordering) :
LayerVisualisation(layer.numEntries()),
ordering(ordering),
faceCount(layer.numEntries() * 4),
faceCount(layer.numEntries() * NODE_FACES.size() / 3),
vertexBuffer(new float[faceCount * 3]),
colorBuffer(new float[faceCount * 3]),
indexBuffer(new int[faceCount * 3])
@@ -33,6 +33,8 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
CHECK_EQ(shape.size(), 2) << "layer should be flat!" << endl;
CHECK_EQ(shape[0], 1) << "Only single images supported." << endl;
initializeNodePositions();
const auto limit = (int) layer.numEntries();
auto data = layer.data();
const auto [minElem, maxElem] = minmax_element(data, data + limit);
@@ -41,28 +43,18 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
int v = 0;
for (int i : Range(limit)) {
setVertexPositions(i, vertexBuffer.get() + 12 * i);
const int vertexBase = i * 4;
setVertexPositions(i, vertexBuffer.get() + NODE_FACES.size() * i);
const auto vertexBase = static_cast<int>(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<int>(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<int>(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<int>(faceCount / 4))) {
nodePositions_[3 * i + 0] = 0;
nodePositions_[3 * i + 1] = 0;
nodePositions_[3 * i + 2] = -2.0f * i;
}
}

View File

@@ -26,6 +26,24 @@ namespace fmri
std::unique_ptr<float[]> colorBuffer;
std::unique_ptr<int[]> indexBuffer;
static constexpr const std::array<float, 12> NODE_SHAPE = {
-0.5f, 0, 0.5f,
0, 0, -0.5f,
0, 1, 0,
0.5f, 0, 0.5f
};
static constexpr const std::array<int, 12> 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();
};
}