CurveDataListTimeFrame.cpp
Go to the documentation of this file.
00001 /******************************************************************************
00002  * Copyright (C) 2015 by Ralf Kaestner, Samuel Bachmann                       *
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 #include "rqt_multiplot/CurveDataListTimeFrame.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 CurveDataListTimeFrame::CurveDataListTimeFrame(double length) :
00028   timeFrameLength_(length) {
00029 }
00030 
00031 CurveDataListTimeFrame::~CurveDataListTimeFrame() {
00032 }
00033 
00034 /*****************************************************************************/
00035 /* Accessors                                                                 */
00036 /*****************************************************************************/
00037 
00038 size_t CurveDataListTimeFrame::getNumPoints() const {
00039   return points_.count();
00040 }
00041 
00042 QPointF CurveDataListTimeFrame::getPoint(size_t index) const {
00043   return points_[index];
00044 }
00045 
00046 BoundingRectangle CurveDataListTimeFrame::getBounds() const {
00047   return bounds_;
00048 }
00049 
00050 /*****************************************************************************/
00051 /* Methods                                                                   */
00052 /*****************************************************************************/
00053 
00054 void CurveDataListTimeFrame::appendPoint(const QPointF& point) {
00055   points_.append(point);
00056 
00057   double timeCutoff = point.x() - timeFrameLength_;
00058 
00059 //  QMutableListIterator<QPointF> iterator(points_);
00060 //  while (iterator.hasNext()) {
00061 //    if (iterator.next().x() < timeCutoff)
00062 //      iterator.remove();
00063 //    else
00064 //      break;
00065 //  }
00066 
00067   QList<QPointF>::iterator it = points_.begin();
00068   while (it != points_.end()) {
00069     if ((*it).x() < timeCutoff)
00070       it = points_.erase(it);
00071     else
00072       break;
00073   }
00074 
00075   auto min_max_x = std::minmax_element(points_.begin(), points_.end(),
00076                                        [](const QPointF &a, const QPointF &b) {
00077                                          return a.x() < b.x();
00078                                        });
00079 
00080   auto min_max_y = std::minmax_element(points_.begin(), points_.end(),
00081                                     [](const QPointF &a, const QPointF &b) {
00082                                       return a.y() < b.y();
00083                                     });
00084 
00085   bounds_.setMinimum(QPointF(min_max_x.first->x(), min_max_y.first->y()));
00086   bounds_.setMaximum(QPointF(min_max_x.second->x(), min_max_y.second->y()));
00087 }
00088 
00089 void CurveDataListTimeFrame::clearPoints() {
00090   points_.clear();
00091   bounds_.clear();
00092 }
00093 
00094 }


rqt_multiplot
Author(s): Ralf Kaestner
autogenerated on Tue May 9 2017 02:16:02