Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
478 changes: 418 additions & 60 deletions plotjuggler_base/include/PlotJuggler/plotdatabase.h

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions plotjuggler_base/include/PlotJuggler/string_ref_sso.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,20 @@ class StringRef
return isSSO() ? (SSO_SIZE - _storage.sso.data[SSO_SIZE]) :
_storage.no_sso.size & ~TYPE_BIT;
}

// Equality operator for constant value optimization
bool operator==(const StringRef& other) const
{
if (size() != other.size())
{
return false;
}
if (data() == other.data())
{
return true; // Same pointer, same content
}
return memcmp(data(), other.data(), size()) == 0;
}
};

} // namespace PJ
Expand Down
5 changes: 3 additions & 2 deletions plotjuggler_base/include/PlotJuggler/stringseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ namespace PJ
class StringSeries : public TimeseriesBase<StringRef>
{
public:
using TimeseriesBase<StringRef>::_points;
using TimeseriesBase<StringRef>::_x_data;
using TimeseriesBase<StringRef>::_y_data;

StringSeries(const std::string& name, PlotGroup::Ptr group)
: TimeseriesBase<StringRef>(name, group)
Expand Down Expand Up @@ -66,7 +67,7 @@ class StringSeries : public TimeseriesBase<StringRef>
{
it = _storage.insert(_tmp_str).first;
}
TimeseriesBase<StringRef>::pushBack({ p.x, StringRef(*it) });
TimeseriesBase<StringRef>::pushBack(Point(p.x, StringRef(*it)));
}
}

Expand Down
43 changes: 29 additions & 14 deletions plotjuggler_base/include/PlotJuggler/timeseries.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ class TimeseriesBase : public PlotDataBase<double, Value>
{
protected:
double _max_range_x;
using PlotDataBase<double, Value>::_points;
using PlotDataBase<double, Value>::_x_data;
using PlotDataBase<double, Value>::_y_data;

public:
using Point = typename PlotDataBase<double, Value>::Point;
Expand Down Expand Up @@ -55,7 +56,22 @@ class TimeseriesBase : public PlotDataBase<double, Value>
std::optional<Value> getYfromX(double x) const
{
int index = getIndexFromX(x);
return (index < 0) ? std::nullopt : std::optional(_points[index].y);
if (index < 0)
{
return std::nullopt;
}

// Handle both storage modes like at() method
if (this->_const_y_value.has_value())
{
// Constant mode: return the constant value
return std::optional(*this->_const_y_value);
}
else
{
// Variable mode: return the specific value
return std::optional(this->_y_data[index]);
}
}

void pushBack(const Point& p) override
Expand All @@ -66,11 +82,11 @@ class TimeseriesBase : public PlotDataBase<double, Value>

void pushBack(Point&& p) override
{
bool need_sorting = (!_points.empty() && p.x < this->back().x);
bool need_sorting = (!_x_data.empty() && p.x < _x_data.back());

if (need_sorting)
{
auto it = std::upper_bound(_points.begin(), _points.end(), p,
auto it = std::upper_bound(this->begin(), this->end(), p,
[](const auto& a, const auto& b) { return a.x < b.x; });
PlotDataBase<double, Value>::insert(it, std::move(p));
}
Expand All @@ -84,10 +100,10 @@ class TimeseriesBase : public PlotDataBase<double, Value>
private:
void trimRange()
{
if (_max_range_x < std::numeric_limits<double>::max() && !_points.empty())
if (_max_range_x < std::numeric_limits<double>::max() && !_x_data.empty())
{
auto const back_point_x = _points.back().x;
while (_points.size() > 2 && (back_point_x - _points.front().x) > _max_range_x)
auto const back_point_x = _x_data.back();
while (_x_data.size() > 2 && (back_point_x - _x_data.front()) > _max_range_x)
{
this->popFront();
}
Expand All @@ -105,24 +121,23 @@ class TimeseriesBase : public PlotDataBase<double, Value>
template <typename Value>
inline int TimeseriesBase<Value>::getIndexFromX(double x) const
{
if (_points.size() == 0)
if (_x_data.size() == 0)
{
return -1;
}
auto lower =
std::lower_bound(_points.begin(), _points.end(), Point(x, {}), TimeCompare);
auto index = std::distance(_points.begin(), lower);
auto lower = std::lower_bound(_x_data.begin(), _x_data.end(), x);
auto index = std::distance(_x_data.begin(), lower);

if (index >= _points.size())
if (index >= _x_data.size())
{
return _points.size() - 1;
return _x_data.size() - 1;
}
if (index < 0)
{
return 0;
}

if (index > 0 && (abs(_points[index - 1].x - x) < abs(_points[index].x - x)))
if (index > 0 && (abs(_x_data[index - 1] - x) < abs(_x_data[index] - x)))
{
index = index - 1;
}
Expand Down
3 changes: 1 addition & 2 deletions plotjuggler_base/src/reactive_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ std::pair<double, double> TimeseriesRef::at(unsigned i) const

void TimeseriesRef::set(unsigned index, double x, double y)
{
auto& p = _plot_data->at(index);
p = { x, y };
_plot_data->setPoint(index, { x, y });
}

double TimeseriesRef::atTime(double t) const
Expand Down
2 changes: 1 addition & 1 deletion plotjuggler_base/src/transform_function.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ void TransformFunction_SISO::calculate()

while (index < src_data->size())
{
const auto& in_point = src_data->at(index);
const auto in_point = src_data->at(index);

if (in_point.x >= _last_timestamp)
{
Expand Down
2 changes: 1 addition & 1 deletion plotjuggler_plugins/ParserDataTamer/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
add_library(ParserDataTamer SHARED datatamer_parser.cpp datatamer_parser.h)

target_link_libraries(ParserDataTamer PRIVATE Qt5::Widgets plotjuggler_base
data_tamer_parser fmt::fmt)
data_tamer::parser fmt::fmt)

target_compile_definitions(ParserDataTamer PRIVATE QT_PLUGIN)

Expand Down
2 changes: 1 addition & 1 deletion plotjuggler_plugins/StatePublisherCSV/publisher_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ QString StatePublisherCSV::generateStatisticsCSV(double time_start, double time_

auto current_value = plot.getYfromX(_previous_time);

auto point = plot.at(index);
PJ::PlotData::Point point = plot.at(index);

if (point.x > time_end) // out of range
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ void QuaternionToRollPitchYaw::calculate()

while (index < data_x.size())
{
auto& point_x = data_x.at(index);
auto point_x = data_x.at(index);
double timestamp = point_x.x;
double q_x = point_x.y;
double q_y = data_y.at(index).y;
Expand Down
Loading