From a84e4e80a2e3bc24c7b6c87b6c1e1684fedafb09 Mon Sep 17 00:00:00 2001 From: Bert Peters Date: Fri, 9 Feb 2018 11:55:48 +0100 Subject: [PATCH] Clean up on layer visualisations. --- src/DummyLayerVisualisation.hpp | 16 ++++++++++++++ src/LayerInfo.cpp | 3 ++- src/LayerInfo.hpp | 1 + src/camera.cpp | 5 +++-- src/camera.hpp | 2 +- src/main.cpp | 38 +++++++++++++++++++++------------ 6 files changed, 47 insertions(+), 18 deletions(-) create mode 100644 src/DummyLayerVisualisation.hpp diff --git a/src/DummyLayerVisualisation.hpp b/src/DummyLayerVisualisation.hpp new file mode 100644 index 0000000..943f601 --- /dev/null +++ b/src/DummyLayerVisualisation.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "LayerVisualisation.hpp" + +namespace fmri +{ + /** + * Visualisation that does not actually do anything. + */ + class DummyLayerVisualisation : public LayerVisualisation + { + public: + void render() override + {}; + }; +} diff --git a/src/LayerInfo.cpp b/src/LayerInfo.cpp index 411e3a4..47d14c3 100644 --- a/src/LayerInfo.cpp +++ b/src/LayerInfo.cpp @@ -14,6 +14,8 @@ LayerInfo::Type LayerInfo::typeByName(string_view name) return Type::ReLU; } else if (name == "Pooling") { return Type::Pooling; + } else if (name == "InnerProduct") { + return Type::InnerProduct; } else { LOG(INFO) << "Received unknown layer type: " << name << endl; return Type::Other; @@ -24,7 +26,6 @@ LayerInfo::LayerInfo(string_view name, string_view type, const vector>> ¶meters) : parameters_(parameters), type_(typeByName(type)), name_(name) { - } const std::string &LayerInfo::name() const diff --git a/src/LayerInfo.hpp b/src/LayerInfo.hpp index 24d4787..9692b4b 100644 --- a/src/LayerInfo.hpp +++ b/src/LayerInfo.hpp @@ -17,6 +17,7 @@ namespace fmri ReLU, Pooling, Output, + InnerProduct, Other }; diff --git a/src/camera.cpp b/src/camera.cpp index 09bd9fc..513bf08 100644 --- a/src/camera.cpp +++ b/src/camera.cpp @@ -1,4 +1,4 @@ -#include +#include #include #include #include @@ -60,7 +60,8 @@ static void handleKeys(unsigned char key, int, int) case 'q': // Utility quit function. - exit(0); + glutLeaveMainLoop(); + break; case 'h': camera.reset(); diff --git a/src/camera.hpp b/src/camera.hpp index 936f27d..fc7a75d 100644 --- a/src/camera.hpp +++ b/src/camera.hpp @@ -16,6 +16,6 @@ namespace fmri static Camera& instance(); private: - Camera() = default; + Camera() noexcept = default; }; } diff --git a/src/main.cpp b/src/main.cpp index 9d7981a..1b70b29 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,8 @@ #include "FlatLayerVisualisation.hpp" #include "MultiImageVisualisation.hpp" #include "Range.hpp" +#include "ActivityAnimation.hpp" +#include "DummyLayerVisualisation.hpp" using namespace std; using namespace fmri; @@ -25,6 +27,7 @@ struct vector> data; vector>::iterator currentData; vector> layerVisualisations; + vector> animations; } rendererData; static void loadSimulationData(const Options &options) @@ -84,6 +87,8 @@ static void render() glPopMatrix(); glTranslatef(-10, 0, 0); } + + glPopMatrix(); glutSwapBuffers(); @@ -98,24 +103,15 @@ static void renderLayerName(const LayerData &data) glTranslatef(0, 0, -10); } +static LayerVisualisation *getVisualisationForLayer(const LayerData &layer); + static void updateVisualisers() { rendererData.layerVisualisations.clear(); + rendererData.animations.clear(); - for (auto &layer : *rendererData.currentData) { - LayerVisualisation* visualisation = nullptr; - switch (layer.shape().size()) { - case 2: - visualisation = new FlatLayerVisualisation(layer, FlatLayerVisualisation::Ordering::SQUARE); - break; - - case 4: - visualisation = new MultiImageVisualisation(layer); - break; - - default: - abort(); - } + for (LayerData &layer : *rendererData.currentData) { + LayerVisualisation* visualisation = getVisualisationForLayer(layer); rendererData.layerVisualisations.emplace_back(visualisation); } @@ -123,6 +119,20 @@ static void updateVisualisers() glutPostRedisplay(); } +LayerVisualisation *getVisualisationForLayer(const LayerData &layer) +{ + switch (layer.shape().size()) { + case 2: + return new FlatLayerVisualisation(layer, FlatLayerVisualisation::Ordering::SQUARE); + + case 4: + return new MultiImageVisualisation(layer); + + default: + return new DummyLayerVisualisation(); + } +} + static void specialKeyFunc(int key, int, int) { switch (key) {