From d8fc0fdb92661e2ead7d181c6b0ab0acda2958a1 Mon Sep 17 00:00:00 2001 From: Wannes Rombouts Date: Tue, 10 Jan 2017 16:56:45 +0100 Subject: [PATCH] Remove 2D tab and rename trigram view to ngram. --- CMakeLists.txt | 9 +- include/visualisation/digram.h | 89 ------- include/visualisation/{trigram.h => ngram.h} | 8 +- include/visualisation/panel.h | 9 +- src/ui/hexedittab.cc | 1 + src/ui/main.cc | 3 +- src/ui/veles_mainwindow.cc | 1 + src/visualisation/digram.cc | 225 ------------------ src/visualisation/{trigram.cc => ngram.cc} | 88 +++---- src/visualisation/panel.cc | 33 +-- src/visualisation/shaders/digram/fshader.glsl | 53 ----- src/visualisation/shaders/digram/vshader.glsl | 25 -- .../shaders/{trigram => ngram}/fshader.glsl | 0 .../shaders/{trigram => ngram}/vshader.glsl | 0 src/visualisation/shaders/shaders.qrc | 6 +- 15 files changed, 64 insertions(+), 486 deletions(-) delete mode 100644 include/visualisation/digram.h rename include/visualisation/{trigram.h => ngram.h} (95%) delete mode 100644 src/visualisation/digram.cc rename src/visualisation/{trigram.cc => ngram.cc} (89%) delete mode 100644 src/visualisation/shaders/digram/fshader.glsl delete mode 100644 src/visualisation/shaders/digram/vshader.glsl rename src/visualisation/shaders/{trigram => ngram}/fshader.glsl (100%) rename src/visualisation/shaders/{trigram => ngram}/vshader.glsl (100%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e9d9646..db1baad 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -82,15 +82,13 @@ qt5_add_resources(VISUALISATION_SHADERS ${SRC_DIR}/visualisation/shaders/shaders add_library(veles_visualisation ${INCLUDE_DIR}/visualisation/panel.h ${INCLUDE_DIR}/visualisation/base.h - ${INCLUDE_DIR}/visualisation/digram.h - ${INCLUDE_DIR}/visualisation/trigram.h + ${INCLUDE_DIR}/visualisation/ngram.h ${INCLUDE_DIR}/visualisation/minimap.h ${INCLUDE_DIR}/visualisation/minimap_panel.h ${INCLUDE_DIR}/visualisation/selectrangedialog.h ${SRC_DIR}/visualisation/panel.cc ${SRC_DIR}/visualisation/base.cc - ${SRC_DIR}/visualisation/digram.cc - ${SRC_DIR}/visualisation/trigram.cc + ${SRC_DIR}/visualisation/ngram.cc ${SRC_DIR}/visualisation/minimap.cc ${SRC_DIR}/visualisation/minimap_panel.cc ${SRC_DIR}/visualisation/selectrangedialog.cc @@ -219,13 +217,12 @@ add_executable(main_ui set (GENERATED_MOC_FILES ${CMAKE_SOURCE_DIR}/moc_base.cpp ${CMAKE_SOURCE_DIR}/moc_commands.cpp - ${CMAKE_SOURCE_DIR}/moc_digram.cpp ${CMAKE_SOURCE_DIR}/moc_veles_mainwindow.cpp ${CMAKE_SOURCE_DIR}/moc_hexedittab.cpp ${CMAKE_SOURCE_DIR}/moc_optionsdialog.cpp ${CMAKE_SOURCE_DIR}/moc_hexedit.cpp ${CMAKE_SOURCE_DIR}/moc_searchdialog.cpp - ${CMAKE_SOURCE_DIR}/moc_trigram.cpp) + ${CMAKE_SOURCE_DIR}/moc_ngram.cpp) set_property(DIRECTORY APPEND PROPERTY ADDITIONAL_MAKE_CLEAN_FILES ${GENERATED_MOC_FILES}) diff --git a/include/visualisation/digram.h b/include/visualisation/digram.h deleted file mode 100644 index a8003da..0000000 --- a/include/visualisation/digram.h +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2016 CodiLime - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#ifndef DIGRAM_H -#define DIGRAM_H - -#include "visualisation/digram.h" - -#include - -#include - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "visualisation/base.h" - -namespace veles { -namespace visualisation { - -class DigramWidget : public VisualisationWidget { - Q_OBJECT - - public: - - enum class EVisualisationShape {SQUARE, CIRCLE}; - enum class EVisualisationMode {BIGRAM}; - - explicit DigramWidget(QWidget *parent = 0); - ~DigramWidget(); - - - protected: - void refresh() override; - bool prepareOptionsPanel(QBoxLayout *); - void setShape(EVisualisationShape); - void timerEvent(QTimerEvent *); - - void initializeVisualisationGL() override; - - void resizeGL(int w, int h) override; - void paintGL() override; - - void initShaders(); - void initTextures(); - void initGeometry(); - - private: - - QBasicTimer timer; - QOpenGLShaderProgram program_; - QOpenGLTexture *texture_; - - QOpenGLBuffer square_vertex_; - QOpenGLVertexArrayObject vao_; - float c_sqr, c_cir; - - - EVisualisationShape shape_; - EVisualisationMode mode_; - - QPushButton *square_button_, *circle_button_; - -}; - -} // namespace visualisation -} // namespace veles - -#endif diff --git a/include/visualisation/trigram.h b/include/visualisation/ngram.h similarity index 95% rename from include/visualisation/trigram.h rename to include/visualisation/ngram.h index 7a152d5..3407996 100644 --- a/include/visualisation/trigram.h +++ b/include/visualisation/ngram.h @@ -17,7 +17,7 @@ #ifndef TRIGRAM_H #define TRIGRAM_H -#include "visualisation/trigram.h" +#include "visualisation/ngram.h" #include @@ -39,14 +39,14 @@ namespace veles { namespace visualisation { -class TrigramWidget : public VisualisationWidget { +class NGramWidget : public VisualisationWidget { Q_OBJECT public: enum class EVisualisationShape {CUBE, CYLINDER, SPHERE}; - explicit TrigramWidget(QWidget *parent = 0); - ~TrigramWidget(); + explicit NGramWidget(QWidget *parent = 0); + ~NGramWidget(); bool prepareOptionsPanel(QBoxLayout *layout) override; diff --git a/include/visualisation/panel.h b/include/visualisation/panel.h index 5990dd8..2baff41 100644 --- a/include/visualisation/panel.h +++ b/include/visualisation/panel.h @@ -46,17 +46,16 @@ class VisualisationPanel : public QWidget { private slots: void setSamplingMethod(const QString &name); void setSampleSize(int kilobytes); - void showDigramVisualisation(); - void showTrigramVisualisation(); + void showNGramVisualisation(); void minimapSelectionChanged(size_t start, size_t end); private: enum class ESampler {NO_SAMPLER, UNIFORM_SAMPLER}; - enum class EVisualisation {DIGRAM, EVERYTHING}; + enum class EVisualisation {NGRAM}; static const std::map k_sampler_map; static const ESampler k_default_sampler = ESampler::UNIFORM_SAMPLER; - static const EVisualisation k_default_visualisation = EVisualisation::EVERYTHING; + static const EVisualisation k_default_visualisation = EVisualisation::NGRAM; static const int k_max_sample_size = 128 * 1024; static const int k_minimap_sample_size = 4096; @@ -85,8 +84,6 @@ class VisualisationPanel : public QWidget { QBoxLayout *layout_, *options_layout_; QSplitter *splitter_; QWidget *child_options_wrapper_; - QAction *digram_action_, *trigram_action_, *layered_digram_action_; - QToolBar *visualisation_toolbar_; QLabel *selection_label_; }; diff --git a/src/ui/hexedittab.cc b/src/ui/hexedittab.cc index a41d23e..8c29397 100644 --- a/src/ui/hexedittab.cc +++ b/src/ui/hexedittab.cc @@ -277,6 +277,7 @@ void HexEditTab::showVisualisation() { panel->setWindowTitle(curFilePath); panel->setAttribute(Qt::WA_DeleteOnClose); + qDebug() << "showing."; mainWindow->addTab(panel, dataModel->path().join(" : ") + " - Visualisation"); } diff --git a/src/ui/main.cc b/src/ui/main.cc index abad87a..cc9ce6f 100644 --- a/src/ui/main.cc +++ b/src/ui/main.cc @@ -19,8 +19,7 @@ #include #include "ui/veles_mainwindow.h" -#include "visualisation/digram.h" -#include "visualisation/trigram.h" +#include "visualisation/ngram.h" #include "util/settings/theme.h" #include "util/settings/shortcutmanager.h" diff --git a/src/ui/veles_mainwindow.cc b/src/ui/veles_mainwindow.cc index 52b1f71..2d5db05 100644 --- a/src/ui/veles_mainwindow.cc +++ b/src/ui/veles_mainwindow.cc @@ -617,6 +617,7 @@ void VelesMainWindow::createHexEditTab(QString fileName, new FileBlobModel(fileBlob, {QFileInfo(fileName).fileName()}); HexEditTab *hex = new HexEditTab(this, dataModel); addTab(hex, dataModel->path().join(" : ") + " - Hex"); + QTimer::singleShot(0, hex, SLOT(showVisualisation())); } } // namespace ui diff --git a/src/visualisation/digram.cc b/src/visualisation/digram.cc deleted file mode 100644 index b706025..0000000 --- a/src/visualisation/digram.cc +++ /dev/null @@ -1,225 +0,0 @@ -/* - * Copyright 2016 CodiLime - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#include "visualisation/digram.h" - - -#include -#include -#include - -#include -#include - - - -namespace veles { -namespace visualisation { - -DigramWidget::DigramWidget(QWidget *parent) : - VisualisationWidget(parent), - c_sqr(0), c_cir(0), - shape_(EVisualisationShape::SQUARE), mode_(EVisualisationMode::BIGRAM) {} - -DigramWidget::~DigramWidget() { - makeCurrent(); - delete texture_; - square_vertex_.destroy(); - doneCurrent(); -} - -void DigramWidget::refresh() { - makeCurrent(); - delete texture_; - initTextures(); - doneCurrent(); - update(); -} - -bool DigramWidget::prepareOptionsPanel(QBoxLayout *layout) { - VisualisationWidget::prepareOptionsPanel(layout); - - - QHBoxLayout *shape_box = new QHBoxLayout(); - square_button_ = new QPushButton(); - square_button_->setIcon(getColoredIcon(":/images/cube.png", false)); - square_button_->setIconSize(QSize(32, 32)); - connect(square_button_, &QPushButton::released, - std::bind(&DigramWidget::setShape, this, - EVisualisationShape::SQUARE)); - shape_box->addWidget(square_button_); - - circle_button_ = new QPushButton(); - circle_button_->setIcon(getColoredIcon(":/images/sphere.png")); - circle_button_->setIconSize(QSize(32, 32)); - - connect(circle_button_, &QPushButton::released, - std::bind(&DigramWidget::setShape, this, - EVisualisationShape::CIRCLE)); - shape_box->addWidget(circle_button_); - - - layout->addLayout(shape_box); - - return true; -} - - -void DigramWidget::setShape(EVisualisationShape shape) { - shape_ = shape; -} - - - -void DigramWidget::timerEvent(QTimerEvent *e) { - - // neat trick here to transform towards projections, - // always move towards it, fix later if we went to far. - - if (shape_ == EVisualisationShape::SQUARE) { - c_sqr += 0.01; - } else { - c_sqr -= 0.01; - } - - if (shape_ == EVisualisationShape::CIRCLE) { - c_cir += 0.01; - } else { - c_cir -= 0.01; - } - - if (c_sqr > 1) c_sqr = 1; - if (c_sqr < 0) c_sqr = 0; - if (c_cir > 1) c_cir = 1; - if (c_cir < 0) c_cir = 0; - - // Request an update - // TODO: only if something is changing. - update(); -} - - - -void DigramWidget::initializeVisualisationGL() { - initializeOpenGLFunctions(); - - glClearColor(0, 0, 0, 1); - - initShaders(); - initTextures(); - initGeometry(); -} - -void DigramWidget::initShaders() { - if (!program_.addShaderFromSourceFile(QOpenGLShader::Vertex, - ":/digram/vshader.glsl")) - close(); - - // Compile fragment shader - if (!program_.addShaderFromSourceFile(QOpenGLShader::Fragment, - ":/digram/fshader.glsl")) - close(); - - // Link shader pipeline - if (!program_.link()) close(); - - // Bind shader pipeline for use - if (!program_.bind()) close(); - - timer.start(16, this); -} - -void DigramWidget::initTextures() { - texture_ = new QOpenGLTexture(QOpenGLTexture::Target2D); - texture_->setSize(256, 256); - texture_->setFormat(QOpenGLTexture::RG32F); - texture_->allocateStorage(); - - // effectively arrays of size [256][256][2], represented as single blocks - auto bigtab = new uint64_t[256 * 256 * 2]; - memset(bigtab, 0, 256 * 256 * 2 * sizeof(*bigtab)); - auto ftab = new float[256 * 256 * 2]; - const uint8_t *rowdata = reinterpret_cast(getData()); - - // Build a histogram - for (size_t i = 0; i < getDataSize() - 1; i++) { // FIXME off by one? - size_t index = (rowdata[i] * 256 + rowdata[i + 1]) * 2; - bigtab[index]++; // count hits - bigtab[index + 1] += i; // keeps track of average source position. - } - - // wapiflapi: we can do a cumulative projection here. - // basicaly we sort the histogram and assign color based on rank not value. - // the problem is sortigng is slow, can we fix that? - - // Convert histogram to percentages (realy 0 < floats < 1.0) - for (int i = 0; i < 256; i++) { - for (int j = 0; j < 256; j++) { - size_t index = (i * 256 + j) * 2; - ftab[index] = static_cast(bigtab[index]) / getDataSize(); - ftab[index+1] = - static_cast(bigtab[index+1]) / getDataSize() / getDataSize(); - } - } - - texture_->setData(QOpenGLTexture::RG, QOpenGLTexture::Float32, - reinterpret_cast(ftab)); - texture_->generateMipMaps(); - - texture_->setMinificationFilter(QOpenGLTexture::Nearest); - - texture_->setMagnificationFilter(QOpenGLTexture::Linear); - - texture_->setWrapMode(QOpenGLTexture::ClampToEdge); - - delete[] bigtab; - delete[] ftab; -} - -void DigramWidget::initGeometry() { - square_vertex_.create(); - QVector2D v[] = { - {0, 0}, {0, 1}, {1, 0}, {1, 1}, - }; - square_vertex_.bind(); - square_vertex_.allocate(v, sizeof v); - - vao_.create(); -} - -void DigramWidget::resizeGL(int w, int h) {} - -void DigramWidget::paintGL() { - - glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); - - texture_->bind(); - vao_.bind(); - - program_.setUniformValue("c_sqr", c_sqr); - program_.setUniformValue("c_cir", c_cir); - - square_vertex_.bind(); - int vertexLocation = program_.attributeLocation("a_position"); - program_.enableAttributeArray(vertexLocation); - program_.setAttributeBuffer(vertexLocation, GL_FLOAT, 0, 2, - sizeof(QVector2D)); - glDrawArrays(GL_TRIANGLE_STRIP, 0, 4); - program_.setUniformValue("tx", 0); -} - -} // namespace visualisation -} // namespace veles diff --git a/src/visualisation/trigram.cc b/src/visualisation/ngram.cc similarity index 89% rename from src/visualisation/trigram.cc rename to src/visualisation/ngram.cc index 9c690aa..1bbcb18 100644 --- a/src/visualisation/trigram.cc +++ b/src/visualisation/ngram.cc @@ -14,7 +14,7 @@ * limitations under the License. * */ -#include "visualisation/trigram.h" +#include "visualisation/ngram.h" #include "util/settings/shortcutmanager.h" #include @@ -51,7 +51,7 @@ const int k_brightness_heuristic_max = 66; // decrease this to reduce noise (but you may lose data if you overdo it) const double k_brightness_heuristic_scaling = 2.0; -TrigramWidget::TrigramWidget(QWidget *parent) : +NGramWidget::NGramWidget(QWidget *parent) : VisualisationWidget(parent), c_sph(0), c_cyl(0), c_flat(0), c_layered_x(0), c_layered_z(0), @@ -73,21 +73,21 @@ TrigramWidget::TrigramWidget(QWidget *parent) : -TrigramWidget::~TrigramWidget() { +NGramWidget::~NGramWidget() { makeCurrent(); delete texture; delete databuf; doneCurrent(); } -void TrigramWidget::setBrightness(const int value) { +void NGramWidget::setBrightness(const int value) { brightness_ = value; c_brightness = static_cast(value) * value * value; c_brightness /= getDataSize(); c_brightness = std::min(1.2f, c_brightness); } -void TrigramWidget::refresh() { +void NGramWidget::refresh() { if (use_brightness_heuristic_) { autoSetBrightness(); } @@ -99,7 +99,7 @@ void TrigramWidget::refresh() { doneCurrent(); } -bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { +bool NGramWidget::prepareOptionsPanel(QBoxLayout *layout) { VisualisationWidget::prepareOptionsPanel(layout); QLabel *brightness_label = new QLabel("Brightness: "); @@ -112,21 +112,21 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { brightness_slider_->setMaximum(k_maximum_brightness); brightness_slider_->setValue(brightness_); connect(brightness_slider_, &QSlider::valueChanged, this, - &TrigramWidget::brightnessSliderMoved); + &NGramWidget::brightnessSliderMoved); layout->addWidget(brightness_slider_); use_heuristic_checkbox_ = new QCheckBox( "Automatically adjust brightness"); use_heuristic_checkbox_->setChecked(use_brightness_heuristic_); connect(use_heuristic_checkbox_, &QCheckBox::stateChanged, - this, &TrigramWidget::setUseBrightnessHeuristic); + this, &NGramWidget::setUseBrightnessHeuristic); layout->addWidget(use_heuristic_checkbox_); pause_button_ = new QPushButton(); pause_button_->setIcon(getColoredIcon(":/images/pause.png")); layout->addWidget(pause_button_); connect(pause_button_, &QPushButton::released, - this, &TrigramWidget::playPause); + this, &NGramWidget::playPause); veles::util::settings::shortcutManager ->managedShortcut("playpause", "toggle animation", "Space", pause_button_, &QPushButton::click); @@ -139,7 +139,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { mode_flat_pushbutton_->setIcon(getColoredIcon(":/images/flat.png", false)); mode_flat_pushbutton_->setIconSize(QSize(32, 32)); connect(mode_flat_pushbutton_, &QPushButton::toggled, - this, &TrigramWidget::setFlat); + this, &NGramWidget::setFlat); veles::util::settings::shortcutManager ->managedShortcut("flatmode", "toggle flat mode", "4", mode_flat_pushbutton_, &QPushButton::click); @@ -149,7 +149,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { mode_layered_x_pushbutton_->setIcon(getColoredIcon(":/images/sorted.png")); mode_layered_x_pushbutton_->setIconSize(QSize(32, 32)); connect(mode_layered_x_pushbutton_, &QPushButton::toggled, - this, &TrigramWidget::setLayeredX); + this, &NGramWidget::setLayeredX); veles::util::settings::shortcutManager ->managedShortcut("sorted", "toggle sorted mode", "5", mode_layered_x_pushbutton_, &QPushButton::click); @@ -159,7 +159,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { mode_layered_z_pushbutton_->setIcon(getColoredIcon(":/images/layered.png")); mode_layered_z_pushbutton_->setIconSize(QSize(32, 32)); connect(mode_layered_z_pushbutton_, &QPushButton::toggled, - this, &TrigramWidget::setLayeredZ); + this, &NGramWidget::setLayeredZ); veles::util::settings::shortcutManager ->managedShortcut("layeredmode", "toggle layered mode", "6", mode_layered_z_pushbutton_, &QPushButton::click); @@ -179,7 +179,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { cube_button_->setIcon(getColoredIcon(":/images/cube.png", false)); cube_button_->setIconSize(QSize(32, 32)); connect(cube_button_, &QPushButton::released, - std::bind(&TrigramWidget::setShape, this, + std::bind(&NGramWidget::setShape, this, EVisualisationShape::CUBE)); veles::util::settings::shortcutManager ->managedShortcut("cubeshape", "switch to cube shape", "1", @@ -190,7 +190,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { cylinder_button_->setIcon(getColoredIcon(":/images/cylinder.png", false)); cylinder_button_->setIconSize(QSize(32, 32)); connect(cylinder_button_, &QPushButton::released, - std::bind(&TrigramWidget::setShape, this, + std::bind(&NGramWidget::setShape, this, EVisualisationShape::CYLINDER)); veles::util::settings::shortcutManager ->managedShortcut("cylindershape", "switch to cylinder shape", "2", @@ -201,7 +201,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { sphere_button_->setIcon(getColoredIcon(":/images/sphere.png")); sphere_button_->setIconSize(QSize(32, 32)); connect(sphere_button_, &QPushButton::released, - std::bind(&TrigramWidget::setShape, this, + std::bind(&NGramWidget::setShape, this, EVisualisationShape::SPHERE)); veles::util::settings::shortcutManager ->managedShortcut("sphereshape", "switch to sphere shape", "3", @@ -220,7 +220,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { center_button_ = new QPushButton("center view"); layout->addWidget(center_button_); - connect(center_button_, &QPushButton::released, this, &TrigramWidget::centerView); + connect(center_button_, &QPushButton::released, this, &NGramWidget::centerView); veles::util::settings::shortcutManager ->managedShortcut("centerview", "center view", "0", center_button_, &QPushButton::click); @@ -229,7 +229,7 @@ bool TrigramWidget::prepareOptionsPanel(QBoxLayout *layout) { return true; } -int TrigramWidget::suggestBrightness() { +int NGramWidget::suggestBrightness() { int size = getDataSize(); auto data = reinterpret_cast(getData()); if (size < 100) { @@ -251,7 +251,7 @@ int TrigramWidget::suggestBrightness() { k_brightness_heuristic_max - offset); } -void TrigramWidget::playPause() { +void NGramWidget::playPause() { QPixmap pixmap; if (is_playing_) { pause_button_->setIcon(getColoredIcon(":/images/play.png")); @@ -264,12 +264,12 @@ void TrigramWidget::playPause() { } } -void TrigramWidget::setFlat(bool val) { +void NGramWidget::setFlat(bool val) { mode_layered_z_pushbutton_->setEnabled(!val); mode_flat_ = val; } -void TrigramWidget::setLayeredX(bool val) { +void NGramWidget::setLayeredX(bool val) { qDebug() << QGuiApplication::keyboardModifiers(); if (!QGuiApplication::keyboardModifiers() && val && mode_layered_z_pushbutton_->isChecked()) { @@ -278,7 +278,7 @@ void TrigramWidget::setLayeredX(bool val) { mode_layered_x_ = val; } -void TrigramWidget::setLayeredZ(bool val) { +void NGramWidget::setLayeredZ(bool val) { if (!QGuiApplication::keyboardModifiers() && val && mode_layered_x_pushbutton_->isChecked()) { mode_layered_x_pushbutton_->setChecked(false); @@ -287,25 +287,25 @@ void TrigramWidget::setLayeredZ(bool val) { } -void TrigramWidget::setShape(EVisualisationShape shape) { +void NGramWidget::setShape(EVisualisationShape shape) { shape_ = shape; } -void TrigramWidget::brightnessSliderMoved(int value) { +void NGramWidget::brightnessSliderMoved(int value) { if (value == brightness_) return; use_brightness_heuristic_ = false; use_heuristic_checkbox_->setChecked(false); setBrightness(value); } -void TrigramWidget::setUseBrightnessHeuristic(int state) { +void NGramWidget::setUseBrightnessHeuristic(int state) { use_brightness_heuristic_ = state; if (use_brightness_heuristic_) { autoSetBrightness(); } } -void TrigramWidget::autoSetBrightness() { +void NGramWidget::autoSetBrightness() { auto new_brightness = suggestBrightness(); if (new_brightness == brightness_) return; brightness_ = new_brightness; @@ -315,7 +315,7 @@ void TrigramWidget::autoSetBrightness() { setBrightness(brightness_); } -void TrigramWidget::timerEvent(QTimerEvent *e) { +void NGramWidget::timerEvent(QTimerEvent *e) { // neat trick here to transform towards projections, // always move towards it, fix later if we went to far. @@ -445,7 +445,7 @@ void TrigramWidget::timerEvent(QTimerEvent *e) { update(); } -void TrigramWidget::initializeVisualisationGL() { +void NGramWidget::initializeVisualisationGL() { initializeOpenGLFunctions(); setMouseTracking(true); @@ -461,14 +461,14 @@ void TrigramWidget::initializeVisualisationGL() { setBrightness(brightness_); } -void TrigramWidget::initShaders() { +void NGramWidget::initShaders() { if (!program.addShaderFromSourceFile(QOpenGLShader::Vertex, - ":/trigram/vshader.glsl")) + ":/ngram/vshader.glsl")) close(); // Compile fragment shader if (!program.addShaderFromSourceFile(QOpenGLShader::Fragment, - ":/trigram/fshader.glsl")) + ":/ngram/fshader.glsl")) close(); // Link shader pipeline @@ -477,7 +477,7 @@ void TrigramWidget::initShaders() { timer.start(16, this); } -void TrigramWidget::initTextures() { +void NGramWidget::initTextures() { int size = getDataSize(); const uint8_t *data = reinterpret_cast(getData()); @@ -495,12 +495,12 @@ void TrigramWidget::initTextures() { glTexBuffer(GL_TEXTURE_BUFFER, QOpenGLTexture::R8U, databuf->bufferId()); } -void TrigramWidget::initGeometry() +void NGramWidget::initGeometry() { vao.create(); } -void TrigramWidget::resizeGL(int w, int h) +void NGramWidget::resizeGL(int w, int h) { width = w; height = h; @@ -521,17 +521,17 @@ void TrigramWidget::resizeGL(int w, int h) } -void TrigramWidget::focusInEvent(QFocusEvent *event) +void NGramWidget::focusInEvent(QFocusEvent *event) { qDebug() << "focus in" << event; } -void TrigramWidget::focusOutEvent(QFocusEvent *event) +void NGramWidget::focusOutEvent(QFocusEvent *event) { qDebug() << "focus out" << event; } -void TrigramWidget::keyPressEvent(QKeyEvent *event) +void NGramWidget::keyPressEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Left || event->key() == Qt::Key_A) { @@ -568,7 +568,7 @@ void TrigramWidget::keyPressEvent(QKeyEvent *event) } -void TrigramWidget::keyReleaseEvent(QKeyEvent *event) +void NGramWidget::keyReleaseEvent(QKeyEvent *event) { if (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right || @@ -593,7 +593,7 @@ void TrigramWidget::keyReleaseEvent(QKeyEvent *event) } -void TrigramWidget::centerView() { +void NGramWidget::centerView() { qDebug() << "centering view"; cam_targeting = true; @@ -614,7 +614,7 @@ void TrigramWidget::centerView() { } } -void TrigramWidget::mousePressEvent(QMouseEvent *event) +void NGramWidget::mousePressEvent(QMouseEvent *event) { // Save mouse press position mousePressPosition = QVector2D(event->localPos()); @@ -622,7 +622,7 @@ void TrigramWidget::mousePressEvent(QMouseEvent *event) angularSpeed = 0; } -void TrigramWidget::mouseMoveEvent(QMouseEvent *event) +void NGramWidget::mouseMoveEvent(QMouseEvent *event) { if (!(event->buttons() & Qt::LeftButton)) { @@ -650,7 +650,7 @@ void TrigramWidget::mouseMoveEvent(QMouseEvent *event) } -void TrigramWidget::mouseReleaseEvent(QMouseEvent *event) +void NGramWidget::mouseReleaseEvent(QMouseEvent *event) { // Mouse release position - mouse press position QVector2D diff = QVector2D(event->localPos()) - mousePressPosition; @@ -669,7 +669,7 @@ void TrigramWidget::mouseReleaseEvent(QMouseEvent *event) } - if (is_playing_ ^ bool(event->modifiers() & Qt::ShiftModifier)) { + if (is_playing_ ^ bool(event->modifiers() & Qt::ShiftModifier)) { playPause(); } @@ -680,14 +680,14 @@ void TrigramWidget::mouseReleaseEvent(QMouseEvent *event) } } -void TrigramWidget::wheelEvent(QWheelEvent *event) { +void NGramWidget::wheelEvent(QWheelEvent *event) { float movement = (event->delta() / 8) / 15; float zoom = 2 * movement * qAbs(movement); speed.setZ(speed.z() + zoom); } -void TrigramWidget::paintGL() { +void NGramWidget::paintGL() { glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); diff --git a/src/visualisation/panel.cc b/src/visualisation/panel.cc index 645eea6..ea1db8f 100644 --- a/src/visualisation/panel.cc +++ b/src/visualisation/panel.cc @@ -23,8 +23,7 @@ #include "visualisation/panel.h" #include "util/sampling/fake_sampler.h" #include "util/sampling/uniform_sampler.h" -#include "visualisation/digram.h" -#include "visualisation/trigram.h" +#include "visualisation/ngram.h" namespace veles { namespace visualisation { @@ -108,10 +107,8 @@ util::ISampler* VisualisationPanel::getSampler(ESampler type, VisualisationWidget* VisualisationPanel::getVisualisation(EVisualisation type, QWidget* parent) { switch (type) { - case EVisualisation::DIGRAM: - return new DigramWidget(parent); - case EVisualisation::EVERYTHING: - return new TrigramWidget(parent); + case EVisualisation::NGRAM: + return new NGramWidget(parent); } return nullptr; } @@ -150,12 +147,9 @@ void VisualisationPanel::setSampleSize(int kilobytes) { } } -void VisualisationPanel::showDigramVisualisation() { - setVisualisation(EVisualisation::DIGRAM); -} -void VisualisationPanel::showTrigramVisualisation() { - setVisualisation(EVisualisation::EVERYTHING); +void VisualisationPanel::showNGramVisualisation() { + setVisualisation(EVisualisation::NGRAM); } void VisualisationPanel::minimapSelectionChanged(size_t start, size_t end) { @@ -224,23 +218,6 @@ QBoxLayout* VisualisationPanel::prepareVisualisationOptions() { void VisualisationPanel::initOptionsPanel() { options_layout_ = new QVBoxLayout; - digram_action_ = - new QAction(QIcon(":/images/nginx2d_32.png"), tr("&Digram"), this); - digram_action_->setToolTip("Digram Visualisation"); - connect(digram_action_, SIGNAL(triggered()), this, - SLOT(showDigramVisualisation())); - - trigram_action_ = - new QAction(QIcon(":/images/nginx3d_32.png"), tr("&Trigram"), this); - trigram_action_->setToolTip("Trigram Visualisation"); - connect(trigram_action_, SIGNAL(triggered()), this, - SLOT(showTrigramVisualisation())); - - visualisation_toolbar_ = new QToolBar("Visualisation Type"); - visualisation_toolbar_->addAction(digram_action_); - visualisation_toolbar_->addAction(trigram_action_); - options_layout_->addWidget(visualisation_toolbar_); - QLabel *sampling_label = new QLabel("Sampling method:"); sampling_label->setAlignment(Qt::AlignTop); options_layout_->addWidget(sampling_label); diff --git a/src/visualisation/shaders/digram/fshader.glsl b/src/visualisation/shaders/digram/fshader.glsl deleted file mode 100644 index c8bde16..0000000 --- a/src/visualisation/shaders/digram/fshader.glsl +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2016 CodiLime - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#version 330 -in vec2 v_coord; -layout (location = 0, index = 0) out vec4 o_color; -uniform sampler2D tx; -uniform float c_sqr, c_cir; -const float TAU = 3.1415926535897932384626433832795 * 2; -const float PI = 3.1415926535897932384626433832795; - -void main() { - - vec2 z = v_coord * 2 - vec2(1, 1); - - vec2 cpos = vec2(length(z), (atan(z.y, z.x) + PI) / TAU); - vec2 xpos = v_coord * (1 - c_cir) + cpos * c_cir; - - // YES the transitiion is uglier than for trigrams. - // that's because it's freaking hard to compute the paths - // in this direction. For trigrams we do it the oposite - // way in the vshader. Maybe we should do the same. - // But that would require some refactoring, do that "tomorrow". - - vec4 t = texture(tx, xpos); - - float clr = t.x; - float ch = t.y; - ch /= clr; - clr *= 4096.0; - - if (length(z) > 1) { - // not in circle. - clr = (1 - c_cir) * clr; - } - - // color indicates where the data comes from in the selection. - o_color = vec4(clr * (1.0 - ch), clr/2.0, clr * ch, 0); - -} diff --git a/src/visualisation/shaders/digram/vshader.glsl b/src/visualisation/shaders/digram/vshader.glsl deleted file mode 100644 index c477802..0000000 --- a/src/visualisation/shaders/digram/vshader.glsl +++ /dev/null @@ -1,25 +0,0 @@ -/* - * Copyright 2016 CodiLime - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - */ -#version 330 -in vec2 a_position; -out vec2 v_coord; - -void main() { - vec2 xpos = a_position * vec2(2, 2) - vec2(1, 1); - gl_Position = vec4(xpos, 0, 1); - v_coord = a_position; -} diff --git a/src/visualisation/shaders/trigram/fshader.glsl b/src/visualisation/shaders/ngram/fshader.glsl similarity index 100% rename from src/visualisation/shaders/trigram/fshader.glsl rename to src/visualisation/shaders/ngram/fshader.glsl diff --git a/src/visualisation/shaders/trigram/vshader.glsl b/src/visualisation/shaders/ngram/vshader.glsl similarity index 100% rename from src/visualisation/shaders/trigram/vshader.glsl rename to src/visualisation/shaders/ngram/vshader.glsl diff --git a/src/visualisation/shaders/shaders.qrc b/src/visualisation/shaders/shaders.qrc index ef8d75a..dd92da5 100644 --- a/src/visualisation/shaders/shaders.qrc +++ b/src/visualisation/shaders/shaders.qrc @@ -6,9 +6,7 @@ minimap/lines_fshader.glsl minimap/background_vshader.glsl minimap/background_fshader.glsl - digram/vshader.glsl - digram/fshader.glsl - trigram/vshader.glsl - trigram/fshader.glsl + ngram/vshader.glsl + ngram/fshader.glsl