CurveDataCircularBuffer.cpp
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright (C) 2015 by Ralf Kaestner *
3  * ralf.kaestner@gmail.com *
4  * *
5  * This program is free software; you can redistribute it and/or modify *
6  * it under the terms of the Lesser GNU General Public License as published by*
7  * the Free Software Foundation; either version 3 of the License, or *
8  * (at your option) any later version. *
9  * *
10  * This program is distributed in the hope that it will be useful, *
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13  * Lesser GNU General Public License for more details. *
14  * *
15  * You should have received a copy of the Lesser GNU General Public License *
16  * along with this program. If not, see <http://www.gnu.org/licenses/>. *
17  ******************************************************************************/
18 
20 
21 namespace rqt_multiplot {
22 
23 /*****************************************************************************/
24 /* Constructors and Destructor */
25 /*****************************************************************************/
26 
28  points_(capacity) {
29  xMin_.reserve(capacity);
30  xMax_.reserve(capacity);
31  yMin_.reserve(capacity);
32  yMax_.reserve(capacity);
33 }
34 
36 }
37 
38 /*****************************************************************************/
39 /* Accessors */
40 /*****************************************************************************/
41 
43  return points_.capacity();
44 }
45 
47  return points_.size();
48 }
49 
50 QPointF CurveDataCircularBuffer::getPoint(size_t index) const {
51  const Point& point = points_[index];
52 
53  return QPointF(point.x_, point.y_);
54 }
55 
57  double maxDistance) const {
58  QVector<size_t> indexes;
59 
60  XCoordinateRefMinHeap::ordered_iterator it = std::lower_bound(
61  xMin_.ordered_begin(), xMin_.ordered_end(), x-maxDistance);
62 
63  while (it != xMin_.ordered_end()) {
64  if (fabs(x-it->x_) <= maxDistance) {
65  size_t index = it->index_;
66 
67  if (points_.array_two().second) {
68  index = (index < points_.array_two().second) ?
69  index+points_.array_one().second :
70  index-points_.array_two().second;
71  }
72 
73  indexes.push_back(index);
74  ++it;
75  }
76  else
77  break;
78  }
79 
80  return indexes;
81 }
82 
84  if (!points_.empty()) {
85  QPointF minimum(xMin_.top().x_, yMin_.top());
86  QPointF maximum(xMax_.top(), yMax_.top());
87 
88  return BoundingRectangle(minimum, maximum);
89  }
90 
91 
92  return BoundingRectangle();
93 }
94 
95 /*****************************************************************************/
96 /* Methods */
97 /*****************************************************************************/
98 
99 void CurveDataCircularBuffer::appendPoint(const QPointF& point) {
100  if (points_.full()) {
101  const Point& firstPoint = points_[0];
102 
103  xMin_.erase(firstPoint.xMinHandle_);
104  xMax_.erase(firstPoint.xMaxHandle_);
105  yMin_.erase(firstPoint.yMinHandle_);
106  yMax_.erase(firstPoint.yMaxHandle_);
107  }
108 
109  points_.push_back(point);
110  size_t index = points_.size()-1;
111 
112  if (points_.array_two().second)
113  index = (points_.array_one().first < points_.array_two().first) ?
114  &points_.back()-points_.array_one().first :
115  &points_.back()-points_.array_two().first;
116 
117  points_.back().xMinHandle_ = xMin_.push(XCoordinateRef(point.x(), index));
118  points_.back().xMaxHandle_ = xMax_.push(point.x());
119  points_.back().yMinHandle_ = yMin_.push(point.y());
120  points_.back().yMaxHandle_ = yMax_.push(point.y());
121 }
122 
124  points_.clear();
125 
126  xMin_.clear();
127  xMax_.clear();
128  yMin_.clear();
129  yMax_.clear();
130 }
131 
132 }
QVector< size_t > getPointsInDistance(double x, double maxDistance) const
XCoordinateRefMinHeap::handle_type xMinHandle_


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Wed Jul 10 2019 03:49:44