CurveDataCircularBuffer.h
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner                                        *
00003  * ralf.kaestner@gmail.com                                                    *
00004  *                                                                            *
00005  * This program is free software; you can redistribute it and/or modify       *
00006  * it under the terms of the Lesser GNU General Public License as published by*
00007  * the Free Software Foundation; either version 3 of the License, or          *
00008  * (at your option) any later version.                                        *
00009  *                                                                            *
00010  * This program is distributed in the hope that it will be useful,            *
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of             *
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the               *
00013  * Lesser GNU General Public License for more details.                        *
00014  *                                                                            *
00015  * You should have received a copy of the Lesser GNU General Public License   *
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.       *
00017  ******************************************************************************/
00018 
00019 #ifndef RQT_MULTIPLOT_CURVE_DATA_CIRCULAR_BUFFER_H
00020 #define RQT_MULTIPLOT_CURVE_DATA_CIRCULAR_BUFFER_H
00021 
00022 #include <boost/circular_buffer.hpp>
00023 #include <boost/heap/d_ary_heap.hpp>
00024 
00025 #include <rqt_multiplot/CurveData.h>
00026 
00027 namespace rqt_multiplot {
00028   class CurveDataCircularBuffer :
00029     public CurveData {
00030   public:
00031     CurveDataCircularBuffer(size_t capacity = 0);
00032     ~CurveDataCircularBuffer();
00033 
00034     size_t getCapacity() const;
00035     size_t getNumPoints() const;
00036     QPointF getPoint(size_t index) const;
00037     QVector<size_t> getPointsInDistance(double x, double maxDistance)
00038       const;
00039     BoundingRectangle getBounds() const;
00040     
00041     void appendPoint(const QPointF& point);
00042     void clearPoints();
00043   
00044   private:
00045     class Point;
00046     
00047     class XCoordinateRef {
00048     public:
00049       inline XCoordinateRef(double x = 0.0, size_t index = 0) :
00050         x_(x),
00051         index_(index) {
00052       };
00053 
00054       inline XCoordinateRef(const XCoordinateRef& src) :
00055         x_(src.x_),
00056         index_(src.index_) {
00057       };
00058       
00059       inline bool operator==(const XCoordinateRef& reference) const {
00060         return (x_ == reference.x_);
00061       };
00062       
00063       inline bool operator>(const XCoordinateRef& reference) const {
00064         return (x_ > reference.x_);
00065       };
00066       
00067       inline bool operator<(const XCoordinateRef& reference) const {
00068         return (x_ < reference.x_);
00069       };
00070       
00071       double x_;
00072       size_t index_;
00073     };
00074     
00075     typedef boost::circular_buffer<Point> Points;    
00076     typedef boost::heap::d_ary_heap<XCoordinateRef, boost::
00077       heap::arity<2>, boost::heap::mutable_<true>, boost::
00078       heap::compare<std::greater<XCoordinateRef> > >
00079       XCoordinateRefMinHeap;
00080     typedef boost::heap::d_ary_heap<double, boost::heap::arity<2>, 
00081       boost::heap::mutable_<true>, boost::heap::compare<std::
00082       greater<double> > > CoordinateMinHeap;
00083     typedef boost::heap::d_ary_heap<double, boost::heap::arity<2>, 
00084       boost::heap::mutable_<true>, boost::heap::compare<std::
00085       less<double> > > CoordinateMaxHeap;
00086     
00087     class Point {
00088     public:
00089       inline Point(const QPointF& point = QPointF(0.0, 0.0)) :
00090         x_(point.x()),
00091         y_(point.y()) {
00092       };
00093       
00094       double x_;
00095       double y_;
00096       
00097       XCoordinateRefMinHeap::handle_type xMinHandle_;
00098       CoordinateMaxHeap::handle_type xMaxHandle_;
00099       CoordinateMinHeap::handle_type yMinHandle_;
00100       CoordinateMaxHeap::handle_type yMaxHandle_;
00101     };
00102       
00103     Points points_;
00104     
00105     XCoordinateRefMinHeap xMin_;
00106     CoordinateMaxHeap xMax_;
00107     CoordinateMinHeap yMin_;
00108     CoordinateMaxHeap yMax_;
00109   };
00110 };
00111 
00112 #endif


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Thu Jun 6 2019 21:49:10