diff --git a/plotjuggler_app/CMakeLists.txt b/plotjuggler_app/CMakeLists.txt index a6243454d..cd4ac32f1 100644 --- a/plotjuggler_app/CMakeLists.txt +++ b/plotjuggler_app/CMakeLists.txt @@ -35,6 +35,7 @@ QT5_WRAP_UI ( UI_SRC transforms/outlier_removal.ui transforms/integral_transform.ui transforms/scale_transform.ui + transforms/samples_count.ui cheatsheet/cheatsheet_dialog.ui ) @@ -86,6 +87,7 @@ SET( PLOtJUGGLER_SRC transforms/outlier_removal.cpp transforms/integral_transform.cpp transforms/absolute_transform.cpp + transforms/samples_count.cpp transforms/first_derivative.cpp transforms/scale_transform.cpp @@ -103,7 +105,7 @@ add_executable(plotjuggler ${PLOtJUGGLER_SRC} ${RES_SRC} ${UI_SRC} - ${BACKWARD_ENABLE}) + ${BACKWARD_ENABLE} ) if (NOT WIN32) add_backward(plotjuggler) diff --git a/plotjuggler_app/main.cpp b/plotjuggler_app/main.cpp index 0e2ecfabc..b12959d2e 100644 --- a/plotjuggler_app/main.cpp +++ b/plotjuggler_app/main.cpp @@ -24,6 +24,7 @@ #include "PlotJuggler/transform_function.h" #include "transforms/first_derivative.h" +#include "transforms/samples_count.h" #include "transforms/scale_transform.h" #include "transforms/moving_average_filter.h" #include "transforms/moving_variance.h" @@ -245,6 +246,7 @@ int main(int argc, char* argv[]) TransformFactory::registerTransform(); TransformFactory::registerTransform(); TransformFactory::registerTransform(); + TransformFactory::registerTransform(); //--------------------------- QCommandLineParser parser; diff --git a/plotjuggler_app/transforms/samples_count.cpp b/plotjuggler_app/transforms/samples_count.cpp new file mode 100644 index 000000000..969960e00 --- /dev/null +++ b/plotjuggler_app/transforms/samples_count.cpp @@ -0,0 +1,72 @@ +#include "samples_count.h" +#include "ui_samples_count.h" + +#include + +SamplesCountFilter::SamplesCountFilter() + : ui(new Ui::SamplesCount) + , _widget(new QWidget()) +{ + ui->setupUi(_widget); + + connect(ui->spinBoxMilliseconds, + qOverload(&QSpinBox::valueChanged), this, + [=](int) { emit parametersChanged(); }); +} + +SamplesCountFilter::~SamplesCountFilter() +{ + delete ui; + delete _widget; +} + +QWidget* SamplesCountFilter::optionsWidget() +{ + return _widget; +} + +bool SamplesCountFilter::xmlSaveState(QDomDocument& doc, + QDomElement& parent_element) const +{ + QDomElement widget_el = doc.createElement("options"); + widget_el.setAttribute("milliseconds", ui->spinBoxMilliseconds->value()); + parent_element.appendChild(widget_el); + return true; +} + +bool SamplesCountFilter::xmlLoadState(const QDomElement& parent_element) +{ + QDomElement widget_el = parent_element.firstChildElement("options"); + if(widget_el.isNull()) + { + return false; + } + int ms = widget_el.attribute("milliseconds", "1000").toInt(); + ui->spinBoxMilliseconds->setValue(ms); + return true; +} + +std::optional SamplesCountFilter::calculateNextPoint(size_t index) +{ + if(dataSource()->size() == 0) { + return std::nullopt; + } + const double delta = 0.001 * double(ui->spinBoxMilliseconds->value()); + const auto& point = dataSource()->at(index); + if(index == 0) { + interval_end_ = point.x + delta; + count_ = 0; + } + count_++; + + if(point.x > interval_end_ || index == (dataSource()->size() - 1)) + { + auto out = PJ::PlotData::Point{ interval_end_, double(count_) }; + while(point.x > interval_end_) { + interval_end_ += delta; + } + count_ = 0; + return out; + } + return std::nullopt; +} diff --git a/plotjuggler_app/transforms/samples_count.h b/plotjuggler_app/transforms/samples_count.h new file mode 100644 index 000000000..7e99c4f9b --- /dev/null +++ b/plotjuggler_app/transforms/samples_count.h @@ -0,0 +1,45 @@ +#pragma once + +#include +#include "PlotJuggler/transform_function.h" + +using namespace PJ; + +namespace Ui +{ +class SamplesCount; +} + +class SamplesCountFilter : public TransformFunction_SISO +{ +public: + explicit SamplesCountFilter(); + + ~SamplesCountFilter() override; + + static const char* transformName() + { + return "Samples Counter"; + } + + const char* name() const override + { + return transformName(); + } + + QWidget* optionsWidget() override; + + bool xmlSaveState(QDomDocument& doc, QDomElement& parent_element) const override; + + bool xmlLoadState(const QDomElement& parent_element) override; + +private: + Ui::SamplesCount* ui; + QWidget* _widget; + + int count_ = 0; + double interval_end_ = 0; + + std::optional calculateNextPoint(size_t index) override; +}; + diff --git a/plotjuggler_app/transforms/samples_count.ui b/plotjuggler_app/transforms/samples_count.ui new file mode 100644 index 000000000..b03bb30b7 --- /dev/null +++ b/plotjuggler_app/transforms/samples_count.ui @@ -0,0 +1,87 @@ + + + SamplesCount + + + + 0 + 0 + 400 + 300 + + + + Form + + + + + + Count the number of data points in the given time interval: + + + true + + + + + + + + + Milliseconds: + + + + + + + + 100 + 0 + + + + 1 + + + 999999 + + + 1000 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Qt::Vertical + + + + 20 + 40 + + + + + + + + +