Add entities for convolutional layers.

This commit is contained in:
2017-11-27 12:25:56 +01:00
parent 8fb01fb346
commit 3231e078b3
3 changed files with 43 additions and 3 deletions

View File

@@ -88,6 +88,6 @@ void FlatLayerVisualisation::render()
glColorPointer(3, GL_FLOAT, 0, colorBuffer.get());
glDrawElements(GL_TRIANGLES, faceCount * 3, GL_UNSIGNED_INT, indexBuffer.get());
glDisable(GL_VERTEX_ARRAY);
glDisable(GL_COLOR_ARRAY);
glDisableClientState(GL_VERTEX_ARRAY);
glDisableClientState(GL_COLOR_ARRAY);
}

View File

@@ -15,6 +15,10 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer)
width = dimensions[2],
height = dimensions[3];
CHECK_EQ(1, images) << "Only single input image is supported" << endl;
vertexBuffer = std::make_unique<float[]>(channels * 12);
auto dataPtr = layer.data();
for (auto i = 0; i < images; ++i) {
for (auto j = 0; j < channels; ++j) {
@@ -22,6 +26,36 @@ MultiImageVisualisation::MultiImageVisualisation(const fmri::LayerData &layer)
dataPtr += width * height;
}
}
int columns = sqrt(channels);
while (channels % columns) columns++;
int rows = channels / columns;
// Create the quads for the images.
int r = 0, c = 0;
int v = 0;
for (int i = 0; i < channels; ++i) {
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;
}
}
}
MultiImageVisualisation::~MultiImageVisualisation()
@@ -33,5 +67,9 @@ MultiImageVisualisation::~MultiImageVisualisation()
void MultiImageVisualisation::render()
{
// TODO: do something.
glEnableClientState(GL_VERTEX_ARRAY);
glColor3f(1, 1, 1);
glVertexPointer(3, GL_FLOAT, 0, vertexBuffer.get());
glDrawArrays(GL_QUADS, 0, 4 * textureReferences.size());
glDisableClientState(GL_VERTEX_ARRAY);
}

View File

@@ -2,6 +2,7 @@
#include <GL/glew.h>
#include <map>
#include <memory>
#include "LayerVisualisation.hpp"
#include "LayerData.hpp"
@@ -17,5 +18,6 @@ namespace fmri
private:
std::map<std::pair<int, int>, GLuint> textureReferences;
std::unique_ptr<float[]> vertexBuffer;
};
}