CurveDataVector.cpp
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 #include "rqt_multiplot/CurveDataVector.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 CurveDataVector::CurveDataVector() {
00028 }
00029 
00030 CurveDataVector::~CurveDataVector() {
00031 }
00032 
00033 /*****************************************************************************/
00034 /* Accessors                                                                 */
00035 /*****************************************************************************/
00036 
00037 size_t CurveDataVector::getNumPoints() const {
00038   return points_.count();
00039 }
00040 
00041 QPointF CurveDataVector::getPoint(size_t index) const {
00042   return points_[index];
00043 }
00044 
00045 QVector<size_t> CurveDataVector::getPointsInDistance(double x, double
00046     maxDistance) const {
00047   QVector<size_t> indexes;
00048       
00049   XCoordinateRefSet::const_iterator it = x_.lower_bound(x-maxDistance);
00050   
00051   while (it != x_.end()) {
00052     if (fabs(x-it->x_) <= maxDistance) {
00053       indexes.push_back(it->index_);
00054       ++it;
00055     }
00056     else
00057       break;
00058   }
00059   
00060   return indexes;
00061 }
00062 
00063 BoundingRectangle CurveDataVector::getBounds() const {
00064   return bounds_;
00065 }
00066 
00067 /*****************************************************************************/
00068 /* Methods                                                                   */
00069 /*****************************************************************************/
00070 
00071 void CurveDataVector::appendPoint(const QPointF& point) {
00072   bounds_ += point;
00073   
00074   if (points_.capacity() < points_.count()+1)
00075     points_.reserve(points_.capacity() ? 2*points_.capacity() : 1);
00076     
00077   points_.append(point);
00078   
00079   if (x_.capacity() < x_.size()+1)
00080     x_.reserve(x_.capacity() ? 2*x_.capacity() : 1);
00081     
00082   x_.insert(XCoordinateRef(point.x(), points_.size()-1));
00083 }
00084 
00085 void CurveDataVector::clearPoints() {
00086   points_.clear();
00087   x_.clear();
00088   
00089   bounds_.clear();
00090 }
00091 
00092 }


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