diff options
author | Samuel Fadel <samuelfadel@gmail.com> | 2016-02-10 13:03:22 -0200 |
---|---|---|
committer | Samuel Fadel <samuelfadel@gmail.com> | 2016-02-10 13:03:22 -0200 |
commit | 0e232a1db450d08a662be16279607730b049eb4d (patch) | |
tree | fe361b81cf1144db4222db4cc46f1ac21abd071d | |
parent | ed0db5c8d8ed12fa02eab5e529db60d92d78d8b2 (diff) |
Fixed issue #20; also removed some unused #include.
-rw-r--r-- | manipulationhandler.cpp | 18 | ||||
-rw-r--r-- | manipulationhandler.h | 3 | ||||
-rw-r--r-- | projectionobserver.cpp | 37 | ||||
-rw-r--r-- | projectionobserver.h | 7 |
4 files changed, 38 insertions, 27 deletions
diff --git a/manipulationhandler.cpp b/manipulationhandler.cpp index 707d4c7..5bd916a 100644 --- a/manipulationhandler.cpp +++ b/manipulationhandler.cpp @@ -1,10 +1,6 @@ #include "manipulationhandler.h" #include <algorithm> -#include <iostream> -#include <numeric> - -#include <QDebug> #include "mp.h" #include "numericrange.h" @@ -13,8 +9,12 @@ ManipulationHandler::ManipulationHandler(const arma::mat &X, const arma::uvec &cpIndices) : m_X(X) , m_Y(X.n_rows, 2) + , m_firstY(X.n_rows, 2) + , m_prevY(X.n_rows, 2) , m_cpIndices(cpIndices) , m_rpIndices(X.n_rows - cpIndices.n_elem) + , m_hasFirst(false) + , m_hasPrev(false) , m_technique(TECHNIQUE_LAMP) { NumericRange<arma::uword> range(0, m_X.n_rows); @@ -32,7 +32,10 @@ void ManipulationHandler::setTechnique(ManipulationHandler::Technique technique) void ManipulationHandler::setCP(const arma::mat &Ys) { - m_prevY = m_Y; + if (m_hasFirst) { + m_prevY = m_Y; + m_hasPrev = true; + } switch (m_technique) { case TECHNIQUE_PLMP: @@ -52,7 +55,8 @@ void ManipulationHandler::setCP(const arma::mat &Ys) break; } - if (m_firstY.n_rows != m_Y.n_rows) { + if (!m_hasFirst) { + m_hasFirst = true; m_firstY = m_Y; } @@ -63,7 +67,7 @@ void ManipulationHandler::setCP(const arma::mat &Ys) void ManipulationHandler::setRewind(double t) { - if (m_prevY.n_rows != m_Y.n_rows) { + if (!m_hasPrev) { return; } diff --git a/manipulationhandler.h b/manipulationhandler.h index e099da8..f900ec8 100644 --- a/manipulationhandler.h +++ b/manipulationhandler.h @@ -33,8 +33,9 @@ public slots: void setRewind(double t); private: - arma::mat m_X, m_Y, m_prevY, m_firstY; + arma::mat m_X, m_Y, m_firstY, m_prevY; arma::uvec m_cpIndices, m_rpIndices; + bool m_hasFirst, m_hasPrev; Technique m_technique; }; diff --git a/projectionobserver.cpp b/projectionobserver.cpp index bcdda57..cefac03 100644 --- a/projectionobserver.cpp +++ b/projectionobserver.cpp @@ -2,7 +2,6 @@ #include <algorithm> #include <cmath> -#include <numeric> #include "mp.h" #include "numericrange.h" @@ -15,9 +14,13 @@ ProjectionObserver::ProjectionObserver(const arma::mat &X, , m_rpIndices(X.n_rows - cpIndices.n_elem) , m_cpSelectionEmpty(true) , m_rpSelectionEmpty(true) + , m_values(X.n_rows) + , m_prevValues(X.n_rows) + , m_firstValues(X.n_rows) + , m_hasFirst(false) + , m_hasPrev(false) { m_distX = mp::dist(m_X); - m_values.set_size(m_X.n_rows); NumericRange<arma::uword> range(0, m_X.n_rows); std::set_symmetric_difference(range.cbegin(), range.cend(), @@ -49,19 +52,24 @@ void ProjectionObserver::computeAlphas() void ProjectionObserver::setMap(const arma::mat &Y) { // update previous map - m_prevY = m_Y; - m_prevDistY = m_distY; - m_prevValues = m_values; + if (m_hasFirst) { + m_hasPrev = true; + + m_prevY = m_Y; + m_prevDistY = m_distY; + m_prevValues = m_values; + } m_Y = Y; m_distY = mp::dist(Y); mp::aggregatedError(m_distX, m_distY, m_values); - // method called for the first time; set original Y - if (m_origY.n_elem != m_Y.n_elem) { - m_origY = m_Y; - m_origDistY = m_distY; - m_origValues = m_values; + if (!m_hasFirst) { + m_hasFirst = true; + + m_firstY = m_Y; + m_firstDistY = m_distY; + m_firstValues = m_values; } if (m_cpSelectionEmpty && m_rpSelectionEmpty) { @@ -153,8 +161,8 @@ bool ProjectionObserver::emitValuesChanged() const } return false; case OBSERVER_DIFF_ORIGINAL: - if (m_origValues.n_elem == m_values.n_elem) { - arma::vec diff = m_values - m_origValues; + if (m_firstValues.n_elem == m_values.n_elem) { + arma::vec diff = m_values - m_firstValues; emit rpValuesChanged(diff(m_rpIndices)); emit valuesChanged(diff); return true; @@ -167,14 +175,11 @@ bool ProjectionObserver::emitValuesChanged() const void ProjectionObserver::setRewind(double t) { - if (m_prevValues.n_elem != m_values.n_elem - || !m_cpSelectionEmpty - || !m_rpSelectionEmpty) { + if (!m_hasPrev) { return; } arma::vec values = m_values * t + m_prevValues * (1.0 - t); - emit cpValuesRewound(values(m_cpIndices)); emit rpValuesRewound(values(m_rpIndices)); emit valuesRewound(values); diff --git a/projectionobserver.h b/projectionobserver.h index db68c73..6d8b0f9 100644 --- a/projectionobserver.h +++ b/projectionobserver.h @@ -34,8 +34,8 @@ private: bool emitValuesChanged() const; int m_type; - arma::mat m_X, m_Y, m_origY, m_prevY; - arma::mat m_distX, m_distY, m_origDistY, m_prevDistY; + arma::mat m_X, m_Y, m_firstY, m_prevY; + arma::mat m_distX, m_distY, m_firstDistY, m_prevDistY; arma::uvec m_cpIndices, m_rpIndices; bool m_cpSelectionEmpty, m_rpSelectionEmpty; @@ -46,7 +46,8 @@ private: arma::mat m_alphas, m_influences; // TODO: one per implemented measure - arma::vec m_values, m_prevValues, m_origValues; + arma::vec m_values, m_firstValues, m_prevValues; + bool m_hasFirst, m_hasPrev; }; #endif // PROJECTIONOBSERVER_H |