LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - PlotData.cc (source / functions) Hit Total Coverage
Test: casa_coverage.info Lines: 0 67 0.0 %
Date: 2023-10-25 08:47:59 Functions: 0 17 0.0 %

          Line data    Source code
       1             : //# PlotData.cc: Classes to represent data for plots.
       2             : //# Copyright (C) 2009
       3             : //# Associated Universities, Inc. Washington DC, USA.
       4             : //#
       5             : //# This library is free software; you can redistribute it and/or modify it
       6             : //# under the terms of the GNU Library General Public License as published by
       7             : //# the Free Software Foundation; either version 2 of the License, or (at your
       8             : //# option) any later version.
       9             : //#
      10             : //# This library is distributed in the hope that it will be useful, but WITHOUT
      11             : //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
      12             : //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
      13             : //# License for more details.
      14             : //#
      15             : //# You should have received a copy of the GNU Library General Public License
      16             : //# along with this library; if not, write to the Free Software Foundation,
      17             : //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
      18             : //#
      19             : //# Correspondence concerning AIPS++ should be addressed as follows:
      20             : //#        Internet email: aips2-request@nrao.edu.
      21             : //#        Postal address: AIPS++ Project Office
      22             : //#                        National Radio Astronomy Observatory
      23             : //#                        520 Edgemont Road
      24             : //#                        Charlottesville, VA 22903-2475 USA
      25             : //#
      26             : //# $Id: $
      27             : #include <graphics/GenericPlotter/PlotData.h>
      28             : 
      29             : using namespace casacore;
      30             : namespace casa {
      31             : 
      32             : ///////////////////////////////
      33             : // PLOTPOINTDATA DEFINITIONS //
      34             : ///////////////////////////////
      35             : 
      36           0 : void PlotPointData::xAndYAt(unsigned int index, double& x, double& y) const {
      37           0 :     x = xAt(index);
      38           0 :     y = yAt(index);
      39           0 : }
      40             : 
      41             : 
      42             : ////////////////////////////////////
      43             : // PLOTMASKEDPOINTDATADEFINITIONS //
      44             : ////////////////////////////////////
      45             : 
      46           0 : void PlotMaskedPointData::xyAndMaskAt(unsigned int index, double& x, double& y,
      47             :         bool& mask) const {
      48           0 :     xAndYAt(index, x, y);
      49           0 :     mask = maskedAt(index);
      50           0 : }
      51             : 
      52             : 
      53             : ///////////////////////////////
      54             : // PLOTERRORDATA DEFINITIONS //
      55             : ///////////////////////////////
      56             : 
      57           0 : void PlotErrorData::xyAndErrorsAt(unsigned int index, double& x, double& y,
      58             :         double& xLeftError, double& xRightError, double& yBottomError,
      59             :         double& yTopError) const {
      60           0 :     xAndYAt(index, x, y);
      61           0 :     xLeftError = xLeftErrorAt(index);
      62           0 :     xRightError = xRightErrorAt(index);
      63           0 :     yBottomError = yBottomErrorAt(index);
      64           0 :     yTopError = yTopErrorAt(index);
      65           0 : }
      66             : 
      67             : 
      68             : ///////////////////////////////////////
      69             : // PLOTHISTOGRAMDATAIMPL DEFINITIONS //
      70             : ///////////////////////////////////////
      71             : 
      72           0 : PlotHistogramData::PlotHistogramData(PlotSingleDataPtr data,
      73           0 :         unsigned int numBins) : m_data(data) {
      74           0 :     recalculateBins(numBins);
      75           0 : }
      76             : 
      77           0 : PlotHistogramData::~PlotHistogramData() { }
      78             : 
      79             : 
      80           0 : bool PlotHistogramData::isValid() const {
      81           0 :     return !m_data.null() && m_data->isValid() && m_bins.size() > 0; }
      82             : 
      83           0 : bool PlotHistogramData::willDeleteData() const {
      84           0 :     return !m_data.null() && m_data->willDeleteData(); }
      85             : 
      86           0 : void PlotHistogramData::setDeleteData(bool del) {
      87           0 :     if(!m_data.null()) m_data->setDeleteData(del); }
      88             : 
      89           0 : double PlotHistogramData::xAt(unsigned int i) const {
      90           0 :     return (m_ranges[i].second + m_ranges[i].first) / 2;
      91             : }
      92             : 
      93           0 : double PlotHistogramData::yAt(unsigned int i) const { return m_bins[i]; }
      94             : 
      95           0 : bool PlotHistogramData::minsMaxes(double& xMin, double& xMax, double& yMin,
      96             :         double& yMax) {
      97           0 :     if(m_ranges.size() == 0) return false;
      98           0 :     xMin = m_ranges[0].first; xMax = m_ranges[m_ranges.size() - 1].second;
      99           0 :     yMin = 0;                 yMax = m_max;
     100           0 :     return true;
     101             : }
     102             : 
     103           0 : void PlotHistogramData::recalculateBins(unsigned int numBins) {
     104           0 :     if(numBins == m_bins.size()) return;
     105             :     
     106           0 :     m_bins.resize(0);
     107           0 :     m_ranges.resize(0);
     108           0 :     m_max = 0;
     109           0 :     if(m_data.null() || !m_data->isValid() || m_data->size() == 0 ||
     110           0 :        numBins == 0) return;
     111             :     
     112           0 :     m_bins.resize(numBins, 0);
     113           0 :     m_ranges.resize(numBins);
     114             :     
     115             :     // Find min/max.
     116           0 :     double temp = m_data->at(0);
     117           0 :     double min = temp, max = temp;
     118           0 :     unsigned int size = m_data->size();
     119           0 :     for(unsigned int i = 1; i < size; i++) {
     120           0 :         temp = m_data->at(i);
     121           0 :         if(temp < min) min = temp;
     122           0 :         if(temp > max) max = temp;
     123             :     }
     124             :     
     125             :     // Set ranges.
     126           0 :     m_ranges[0].first = min;
     127           0 :     temp = (max - min) / numBins;
     128           0 :     for(unsigned int i = 0; i < numBins; i++) {
     129           0 :         m_ranges[i].second = min + (temp * (i + 1));
     130           0 :         if(i < numBins - 1) m_ranges[i + 1].first = m_ranges[i].second;
     131             :     }
     132             :     
     133             :     // Find bin counts.
     134           0 :     for(unsigned int i = 0; i < size; i++) {
     135           0 :         temp = m_data->at(i);
     136             :         
     137           0 :         for(unsigned int j = 0; j < numBins; j++) {
     138           0 :             if(temp <= m_ranges[j].second || j == numBins - 1) {
     139           0 :                 m_bins[j]++;
     140           0 :                 break;
     141             :             }
     142             :         }
     143             :     }
     144             :     
     145             :     // Find max bin count.
     146           0 :     m_max = m_bins[0];
     147           0 :     for(unsigned int i = 1; i < numBins; i++)
     148           0 :         if(m_bins[i] > m_max) m_max = m_bins[i];
     149             : }
     150             : 
     151           0 : unsigned int PlotHistogramData::numBins() const { return m_bins.size(); }
     152             : 
     153           0 : prange_t PlotHistogramData::rangeAt(unsigned int i) const {
     154           0 :     return m_ranges[i]; }
     155             : 
     156             : }

Generated by: LCOV version 1.16