CurveData.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/CurveData.h"
00020 
00021 namespace rqt_multiplot {
00022 
00023 /*****************************************************************************/
00024 /* Constructors and Destructor                                               */
00025 /*****************************************************************************/
00026 
00027 CurveData::CurveData() {
00028 }
00029 
00030 CurveData::~CurveData() {
00031 }
00032 
00033 /*****************************************************************************/
00034 /* Accessors                                                                 */
00035 /*****************************************************************************/
00036 
00037 double CurveData::getValue(size_t index, CurveConfig::Axis axis) const {
00038   if (axis == CurveConfig::X)
00039     return getPoint(index).x();
00040   else if (axis == CurveConfig::Y)
00041     return getPoint(index).y();
00042     
00043   return std::numeric_limits<double>::quiet_NaN();
00044 }
00045 
00046 QVector<size_t> CurveData::getPointsInDistance(double x, double maxDistance)
00047     const {
00048   QVector<size_t> indexes;
00049   
00050   if (!isEmpty()) {
00051     for (size_t index = 0; index < getNumPoints(); ++index) {
00052       double distance = fabs(x-getPoint(index).x());
00053       
00054       if (distance <= maxDistance)
00055         indexes.append(index);
00056     }
00057   }
00058   
00059   return indexes;
00060 }
00061 
00062 QPair<double, double> CurveData::getAxisBounds(CurveConfig::Axis axis) const {
00063   BoundingRectangle bounds = getBounds();
00064   
00065   if (axis == CurveConfig::X)
00066     return QPair<double, double>(bounds.getMinimum().x(),
00067       bounds.getMaximum().x());
00068   else if (axis == CurveConfig::Y)
00069     return QPair<double, double>(bounds.getMinimum().y(),
00070       bounds.getMaximum().y());
00071   
00072   return QPair<double, double>();
00073 }
00074 
00075 bool CurveData::isEmpty() const {
00076   return !getNumPoints();
00077 }
00078 
00079 /*****************************************************************************/
00080 /* Methods                                                                   */
00081 /*****************************************************************************/
00082 
00083 size_t CurveData::size() const {
00084   return getNumPoints();
00085 }
00086 
00087 QPointF CurveData::sample(size_t i) const {
00088   return getPoint(i);
00089 }
00090 
00091 QRectF CurveData::boundingRect() const {
00092   return getBounds().getRectangle();
00093 }
00094 
00095 void CurveData::appendPoint(double x, double y) {
00096   appendPoint(QPointF(x, y));
00097 }
00098 
00099 void CurveData::writeFormatted(QStringList& formattedX, QStringList&
00100     formattedY) const {
00101   formattedX.clear();
00102   formattedY.clear();
00103   
00104   for (size_t index = 0; index < getNumPoints(); ++index) {
00105     QPointF point = getPoint(index);
00106     
00107     formattedX.append(QString::number(point.x(), 'g', 20));
00108     formattedY.append(QString::number(point.y(), 'g', 20));
00109   }
00110 }
00111 
00112 }


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