Actually use the same node positions internally and externally.
This commit is contained in:
@@ -16,8 +16,8 @@ ActivityAnimation::ActivityAnimation(const vector<pair<DType, pair<size_t, size_
|
|||||||
delta.reserve(bufferLength);
|
delta.reserve(bufferLength);
|
||||||
|
|
||||||
for (auto &entry : interactions) {
|
for (auto &entry : interactions) {
|
||||||
auto *aPos = &aPositions[entry.second.first];
|
auto *aPos = &aPositions[3 * entry.second.first];
|
||||||
auto *bPos = &bPositions[entry.second.second];
|
auto *bPos = &bPositions[3 * entry.second.second];
|
||||||
|
|
||||||
for (auto i : Range(3)) {
|
for (auto i : Range(3)) {
|
||||||
startingPos.emplace_back(aPos[i]);
|
startingPos.emplace_back(aPos[i]);
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ static inline void computeColor(float intensity, float limit, float* destination
|
|||||||
FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering ordering) :
|
FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering ordering) :
|
||||||
LayerVisualisation(layer.numEntries()),
|
LayerVisualisation(layer.numEntries()),
|
||||||
ordering(ordering),
|
ordering(ordering),
|
||||||
faceCount(layer.numEntries() * 4),
|
faceCount(layer.numEntries() * NODE_FACES.size() / 3),
|
||||||
vertexBuffer(new float[faceCount * 3]),
|
vertexBuffer(new float[faceCount * 3]),
|
||||||
colorBuffer(new float[faceCount * 3]),
|
colorBuffer(new float[faceCount * 3]),
|
||||||
indexBuffer(new int[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.size(), 2) << "layer should be flat!" << endl;
|
||||||
CHECK_EQ(shape[0], 1) << "Only single images supported." << endl;
|
CHECK_EQ(shape[0], 1) << "Only single images supported." << endl;
|
||||||
|
|
||||||
|
initializeNodePositions();
|
||||||
|
|
||||||
const auto limit = (int) layer.numEntries();
|
const auto limit = (int) layer.numEntries();
|
||||||
auto data = layer.data();
|
auto data = layer.data();
|
||||||
const auto [minElem, maxElem] = minmax_element(data, data + limit);
|
const auto [minElem, maxElem] = minmax_element(data, data + limit);
|
||||||
@@ -41,28 +43,18 @@ FlatLayerVisualisation::FlatLayerVisualisation(const LayerData &layer, Ordering
|
|||||||
|
|
||||||
int v = 0;
|
int v = 0;
|
||||||
for (int i : Range(limit)) {
|
for (int i : Range(limit)) {
|
||||||
setVertexPositions(i, vertexBuffer.get() + 12 * i);
|
setVertexPositions(i, vertexBuffer.get() + NODE_FACES.size() * i);
|
||||||
const int vertexBase = i * 4;
|
const auto vertexBase = static_cast<int>(i * NODE_FACES.size() / 3);
|
||||||
|
|
||||||
// Define the colors for the vertices
|
// Define the colors for the vertices
|
||||||
for (int c = 0; c < 4; ++c) {
|
for (auto c : Range(NODE_SHAPE.size() / 3)) {
|
||||||
computeColor(data[i], scalingMax, &colorBuffer[12 * i + 3 * c]);
|
computeColor(data[i], scalingMax, &colorBuffer[NODE_FACES.size() * i + 3 * c]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the index set for the faces
|
// Set the face nodes indices
|
||||||
// Simply connect all vertices in ascending order and it works.
|
for (auto faceNode : NODE_FACES) {
|
||||||
indexBuffer[v++] = vertexBase;
|
indexBuffer[v++] = vertexBase + faceNode;
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
assert(v == (int) faceCount * 3);
|
assert(v == (int) faceCount * 3);
|
||||||
}
|
}
|
||||||
@@ -82,42 +74,41 @@ void FlatLayerVisualisation::render()
|
|||||||
|
|
||||||
void FlatLayerVisualisation::setVertexPositions(const int vertexNo, float *destination)
|
void FlatLayerVisualisation::setVertexPositions(const int vertexNo, float *destination)
|
||||||
{
|
{
|
||||||
int j = 0;
|
for (auto i : Range(NODE_SHAPE.size())) {
|
||||||
float zOffset;
|
destination[i] = NODE_SHAPE[i] + nodePositions_[3 * vertexNo + (i % 3)];
|
||||||
float yOffset;
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void FlatLayerVisualisation::initializeNodePositions()
|
||||||
|
{
|
||||||
switch (ordering) {
|
switch (ordering) {
|
||||||
case Ordering::LINE:
|
case Ordering::LINE:
|
||||||
zOffset = -2 * vertexNo;
|
computeNodePositionsLine();
|
||||||
yOffset = 0;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Ordering::SQUARE:
|
case Ordering::SQUARE:
|
||||||
const auto nodes = faceCount / 4;
|
computeNodePositionsSquare();
|
||||||
auto columns = static_cast<int>(numCols(nodes));
|
|
||||||
|
|
||||||
zOffset = -2 * (vertexNo % columns);
|
|
||||||
yOffset = 2 * (vertexNo / columns);
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
nodePositions_[3 * vertexNo] = 0;
|
|
||||||
nodePositions_[3 * vertexNo + 1] = yOffset;
|
void FlatLayerVisualisation::computeNodePositionsSquare()
|
||||||
nodePositions_[3 * vertexNo + 2] = zOffset;
|
{
|
||||||
// TODO: actually compute from this rather than copying to destination.
|
const auto nodes = static_cast<int>(faceCount / 4);
|
||||||
// Side note: should move this out of this function anyway.
|
const auto columns = numCols(nodes);
|
||||||
|
|
||||||
// Create the 4 vertices for the pyramid
|
for (auto i : Range(nodes)) {
|
||||||
destination[j++] = -0.5f;
|
nodePositions_[3 * i + 0] = 0;
|
||||||
destination[j++] = 0 + yOffset;
|
nodePositions_[3 * i + 1] = 2 * (i / columns);
|
||||||
destination[j++] = 0.5f + zOffset;
|
nodePositions_[3 * i + 2] = -2 * (i % columns);
|
||||||
destination[j++] = 0;
|
}
|
||||||
destination[j++] = 0 + yOffset;
|
}
|
||||||
destination[j++] = -0.5f + zOffset;
|
|
||||||
destination[j++] = 0;
|
void FlatLayerVisualisation::computeNodePositionsLine()
|
||||||
destination[j++] = 1 + yOffset;
|
{
|
||||||
destination[j++] = 0 + zOffset;
|
for (auto i : Range(static_cast<int>(faceCount / 4))) {
|
||||||
destination[j++] = 0.5;
|
nodePositions_[3 * i + 0] = 0;
|
||||||
destination[j++] = 0 + yOffset;
|
nodePositions_[3 * i + 1] = 0;
|
||||||
destination[j++] = 0.5f + zOffset;
|
nodePositions_[3 * i + 2] = -2.0f * i;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,6 +26,24 @@ namespace fmri
|
|||||||
std::unique_ptr<float[]> colorBuffer;
|
std::unique_ptr<float[]> colorBuffer;
|
||||||
std::unique_ptr<int[]> indexBuffer;
|
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);
|
void setVertexPositions(int vertexNo, float *destination);
|
||||||
|
|
||||||
|
// Various functions defining the way the nodes will be aligned.
|
||||||
|
void initializeNodePositions();
|
||||||
|
void computeNodePositionsLine();
|
||||||
|
void computeNodePositionsSquare();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user