LCOV - code coverage report
Current view: top level - graphics/GenericPlotter - SimplePlotter.cc (source / functions) Hit Total Coverage
Test: casacpp_coverage.info Lines: 0 545 0.0 %
Date: 2024-12-11 20:54:31 Functions: 0 103 0.0 %

          Line data    Source code
       1             : //# SimplePlotter.cc: Concrete plotting class for common or simple use cases.
       2             : //# Copyright (C) 2008
       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: casa-feedback@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/SimplePlotter.h>
      28             : #include <casacore/casa/BasicMath/Math.h>
      29             : #include <vector>
      30             : 
      31             : using namespace casacore;
      32             : namespace casa {
      33             : 
      34             : ///////////////////////////////
      35             : // SIMPLEPLOTTER DEFINITIONS //
      36             : ///////////////////////////////
      37             : 
      38             : // Constructors/Destructors //
      39             : 
      40           0 : SimplePlotter::SimplePlotter(PlotFactoryPtr factory): m_factory(factory) {
      41           0 :     if(!m_factory.null()) {
      42           0 :         m_plotter = m_factory->plotter();
      43           0 :         m_canvas = m_plotter->canvas();
      44           0 :         m_mouseTools = m_canvas->standardMouseTools();
      45             :         
      46             :         // Set up defaults
      47           0 :         m_line = factory->line("black", PlotLine::SOLID, 1.0);
      48           0 :         m_symbol = factory->symbol(PlotSymbol::DIAMOND);
      49           0 :         m_symbol->setLine(m_line);
      50           0 :         m_symbol->setAreaFill("blue");
      51           0 :         m_areaFill = factory->areaFill("black", PlotAreaFill::MESH3);
      52             :     } else {
      53             :         String error = "SimplePlotter::SimplePlotter(): Invalid plotter "
      54             :                        "implementation.  If you're trying to use qwt, make"
      55             :                        " sure you have the library installed and the "
      56           0 :                        "AIPS_HAS_QWT compiler flag turned on.";
      57           0 :         throw error;
      58           0 :     }
      59           0 : }
      60             : 
      61           0 : SimplePlotter::~SimplePlotter() { }
      62             : 
      63             : 
      64             : // Execution Methods //
      65             : 
      66           0 : int SimplePlotter::execLoop() { return m_factory->execLoop(); }
      67             : 
      68           0 : void SimplePlotter::holdDrawing() { m_canvas->holdDrawing(); }
      69             : 
      70           0 : void SimplePlotter::releaseDrawing() { m_canvas->releaseDrawing(); }
      71             : 
      72             : 
      73             : // Plotter Customization Methods //
      74             : 
      75           0 : void SimplePlotter::setWindowTitle(const String& windowTitle) {
      76           0 :     m_plotter->setWindowTitle(windowTitle);
      77           0 : }
      78             : 
      79           0 : void SimplePlotter::setCanvasTitle(const String& canvasTitle) {
      80           0 :     m_canvas->setTitle(canvasTitle);
      81           0 : }
      82             : 
      83           0 : void SimplePlotter::setAxesLabels(const String& xLabel, const String& yLabel) {
      84           0 :     m_canvas->setAxisLabel(X_BOTTOM, xLabel);
      85           0 :     m_canvas->setAxisLabel(Y_LEFT, yLabel);
      86           0 : }
      87             : 
      88           0 : void SimplePlotter::showCartesianAxes(bool show) {
      89           0 :     m_canvas->showCartesianAxes(show, show);
      90           0 : }
      91             : 
      92           0 : void SimplePlotter::setXAxisRange(double from, double to) {
      93           0 :     m_canvas->setAxisRange(X_BOTTOM, from, to);
      94           0 : }
      95             : 
      96           0 : void SimplePlotter::setYAxisRange(double from, double to) {
      97           0 :     m_canvas->setAxisRange(Y_LEFT, from, to);
      98           0 : }
      99             : 
     100           0 : void SimplePlotter::setAxesAutoRescale(bool on) {
     101           0 :     m_canvas->setAxesAutoRescale(on);
     102           0 : }
     103             : 
     104           0 : void SimplePlotter::rescaleAxes() {
     105           0 :     m_canvas->rescaleAxes();
     106           0 : }
     107             : 
     108             : 
     109             : // Plot/Shape Customization Methods //
     110             : 
     111           0 : void SimplePlotter::showLines(bool showLines) {
     112           0 :     m_line->setStyle(showLines ? PlotLine::SOLID : PlotLine::NOLINE);
     113           0 : }
     114             : 
     115           0 : void SimplePlotter::showSymbols(bool showSymbols) {
     116           0 :     m_symbol->setSymbol(showSymbols ? PlotSymbol::DIAMOND :
     117             :                                       PlotSymbol::NOSYMBOL);
     118           0 : }
     119             : 
     120           0 : void SimplePlotter::setLine(const String& color, PlotLine::Style style,
     121             :         double width) {
     122           0 :     m_line->setColor(color);
     123           0 :     m_line->setStyle(style);
     124           0 :     m_line->setWidth(width);
     125           0 : }
     126             : 
     127           0 : void SimplePlotter::setSymbol(PlotSymbol::Symbol symbol, const String& color,
     128             :         double size, bool outline) {
     129           0 :     m_symbol->setSymbol(symbol);
     130           0 :     m_symbol->setAreaFill(color, PlotAreaFill::FILL);
     131           0 :     m_symbol->setSize(size, size);
     132           0 :     m_symbol->setLine("black", (outline ? PlotLine::SOLID : PlotLine::NOLINE),
     133             :                       1.0);
     134           0 : }
     135             : 
     136           0 : void SimplePlotter::setAreaFill(const String& color,
     137             :         PlotAreaFill::Pattern pattern) {
     138           0 :     m_areaFill->setColor(color);
     139           0 :     m_areaFill->setPattern(pattern);
     140           0 : }
     141             : 
     142             : 
     143             : // Plot Methods //
     144             : 
     145           0 : ScatterPlotPtr SimplePlotter::plotxy(double*& x, double*& y, unsigned int n,
     146             :                                      bool overplot) {
     147           0 :     if(m_factory.null()) return ScatterPlotPtr();
     148           0 :     else return plotxy(m_factory->data(x, y, n), overplot);
     149             : }
     150             : 
     151           0 : ScatterPlotPtr SimplePlotter::plotxy(float*& x, float*& y, unsigned int n,
     152             :                                      bool overplot) {
     153           0 :     if(m_factory.null()) return ScatterPlotPtr();
     154           0 :     else return plotxy(m_factory->data(x, y, n), overplot);
     155             : }
     156             : 
     157           0 : ScatterPlotPtr SimplePlotter::plotxy(int*& x, int*& y, unsigned int n,
     158             :                                      bool overplot) {
     159           0 :     if(m_factory.null()) return ScatterPlotPtr();
     160           0 :     else return plotxy(m_factory->data(x, y, n), overplot);
     161             : }
     162             : 
     163           0 : ScatterPlotPtr SimplePlotter::plotxy(Vector<double>& x, Vector<double>& y,
     164             :                                      bool overplot) {
     165           0 :     if(m_factory.null()) return ScatterPlotPtr();
     166           0 :     else return plotxy(m_factory->data(x, y), overplot);
     167             : }
     168             : 
     169           0 : ScatterPlotPtr SimplePlotter::plotxy(Vector<float>& x, Vector<float>& y,
     170             :                                      bool overplot) {
     171           0 :     if(m_factory.null()) return ScatterPlotPtr();
     172           0 :     else return plotxy(m_factory->data(x, y), overplot);
     173             : }
     174             : 
     175           0 : ScatterPlotPtr SimplePlotter::plotxy(Vector<int>& x, Vector<int>& y,
     176             :                                      bool overplot) {
     177           0 :     if(m_factory.null()) return ScatterPlotPtr();
     178           0 :     else return plotxy(m_factory->data(x, y), overplot);
     179             : }
     180             : 
     181           0 : ScatterPlotPtr SimplePlotter::plotxy(PlotPointDataPtr data, bool overplot) {
     182           0 :     if(m_factory.null() || data.null() || !data->isValid())
     183           0 :         return ScatterPlotPtr();
     184             :     
     185           0 :     ScatterPlotPtr plot = m_factory->scatterPlot(data);
     186           0 :     plot->setLine(m_line);
     187           0 :     plot->setSymbol(m_symbol);    
     188           0 :     m_canvas->plot(plot, overplot);
     189             :     
     190           0 :     return plot;
     191           0 : }
     192             : 
     193           0 : ScatterPlotPtr SimplePlotter::ploty(double*& y, unsigned int n,
     194             :                                     bool overplot) {
     195           0 :     if(m_factory.null()) return ScatterPlotPtr();
     196           0 :     else return ploty(m_factory->data(y, n), overplot);
     197             : }
     198             : 
     199           0 : ScatterPlotPtr SimplePlotter::ploty(float*& y, unsigned int n,
     200             :                                     bool overplot) {
     201           0 :     if(m_factory.null()) return ScatterPlotPtr();
     202           0 :     else return ploty(m_factory->data(y, n), overplot);
     203             : }
     204             : 
     205           0 : ScatterPlotPtr SimplePlotter::ploty(int*& y, unsigned int n,
     206             :                                     bool overplot) {
     207           0 :     if(m_factory.null()) return ScatterPlotPtr();
     208           0 :     else return ploty(m_factory->data(y, n), overplot);
     209             : }
     210             : 
     211           0 : ScatterPlotPtr SimplePlotter::ploty(Vector<double>& y, bool overplot) {
     212           0 :     if(m_factory.null()) return ScatterPlotPtr();
     213           0 :     else return ploty(m_factory->data(y), overplot);
     214             : }
     215             : 
     216           0 : ScatterPlotPtr SimplePlotter::ploty(Vector<float>& y, bool overplot) {
     217           0 :     if(m_factory.null()) return ScatterPlotPtr();
     218           0 :     else return ploty(m_factory->data(y), overplot);
     219             : }
     220             : 
     221           0 : ScatterPlotPtr SimplePlotter::ploty(Vector<int>& y, bool overplot) {
     222           0 :     if(m_factory.null()) return ScatterPlotPtr();
     223           0 :     else return ploty(m_factory->data(y), overplot);
     224             : }
     225             : 
     226           0 : ScatterPlotPtr SimplePlotter::ploty(PlotPointDataPtr data, bool overplot) {
     227           0 :     if(m_factory.null() || data.null() || !data->isValid())
     228           0 :         return ScatterPlotPtr();
     229             :     
     230           0 :     ScatterPlotPtr plot = m_factory->scatterPlot(data);
     231           0 :     plot->setLine(m_line);
     232           0 :     plot->setSymbol(m_symbol);    
     233           0 :     m_canvas->plot(plot, overplot);
     234             :     
     235           0 :     return plot;
     236           0 : }
     237             : 
     238           0 : BarPlotPtr SimplePlotter::barPlot(double*& x, double*& y, unsigned int n,
     239             :                                   bool overplot) {
     240           0 :     if(m_factory.null()) return BarPlotPtr();
     241           0 :     else return barPlot(m_factory->data(x, y, n), overplot);
     242             : }
     243             : 
     244           0 : BarPlotPtr SimplePlotter::barPlot(float*& x, float*& y, unsigned int n,
     245             :                                   bool overplot) {
     246           0 :     if(m_factory.null()) return BarPlotPtr();
     247           0 :     else return barPlot(m_factory->data(x, y, n), overplot);
     248             : }
     249             : 
     250           0 : BarPlotPtr SimplePlotter::barPlot(int*& x, int*& y, unsigned int n,
     251             :                                   bool overplot) {
     252           0 :     if(m_factory.null()) return BarPlotPtr();
     253           0 :     else return barPlot(m_factory->data(x, y, n), overplot);
     254             : }
     255             : 
     256           0 : BarPlotPtr SimplePlotter::barPlot(Vector<double>& x, Vector<double>& y,
     257             :                                   bool overplot) {
     258           0 :     if(m_factory.null()) return BarPlotPtr();
     259           0 :     else return barPlot(m_factory->data(x, y), overplot);
     260             : }
     261             : 
     262           0 : BarPlotPtr SimplePlotter::barPlot(Vector<float>& x, Vector<float>& y,
     263             :                                   bool overplot) {
     264           0 :     if(m_factory.null()) return BarPlotPtr();
     265           0 :     else return barPlot(m_factory->data(x, y), overplot);
     266             : }
     267             : 
     268           0 : BarPlotPtr SimplePlotter::barPlot(Vector<int>& x, Vector<int>& y,
     269             :                                   bool overplot) {
     270           0 :     if(m_factory.null()) return BarPlotPtr();
     271           0 :     else return barPlot(m_factory->data(x, y), overplot);
     272             : }
     273             : 
     274           0 : BarPlotPtr SimplePlotter::barPlot(PlotPointDataPtr data, bool overplot) {
     275           0 :     if(data.null()|| !data->isValid() || m_factory.null()) return BarPlotPtr();
     276             :     
     277           0 :     BarPlotPtr bar = m_factory->barPlot(data);
     278           0 :     bar->setLine(m_line);
     279           0 :     bar->setAreaFill(m_areaFill);
     280           0 :     if(!overplot) m_canvas->clearPlots();
     281           0 :     m_canvas->plot(bar);
     282           0 :     return bar;
     283           0 : }
     284             : 
     285           0 : BarPlotPtr SimplePlotter::histogramPlot(double*& data, unsigned int n,
     286             :         unsigned int bins, bool overplot) {
     287           0 :     if(m_factory.null()) return BarPlotPtr();
     288           0 :     else return barPlot(m_factory->histogramData(data, n, bins), overplot);
     289             : }
     290             : 
     291           0 : BarPlotPtr SimplePlotter::histogramPlot(float*& data, unsigned int n,
     292             :         unsigned int bins, bool overplot) {
     293           0 :     if(m_factory.null()) return BarPlotPtr();
     294           0 :     else return barPlot(m_factory->histogramData(data, n, bins), overplot);
     295             : }
     296             : 
     297           0 : BarPlotPtr SimplePlotter::histogramPlot(int*& data, unsigned int n,
     298             :         unsigned int bins, bool overplot) {
     299           0 :     if(m_factory.null()) return BarPlotPtr();
     300           0 :     else return barPlot(m_factory->histogramData(data, n, bins), overplot);
     301             : }
     302             : 
     303           0 : BarPlotPtr SimplePlotter::histogramPlot(Vector<double>& data,
     304             :         unsigned int bins, bool overplot) {
     305           0 :     if(m_factory.null()) return BarPlotPtr();
     306           0 :     else return barPlot(m_factory->histogramData(data, bins), overplot);
     307             : }
     308             : 
     309           0 : BarPlotPtr SimplePlotter::histogramPlot(Vector<float>& data,
     310             :         unsigned int bins, bool overplot) {
     311           0 :     if(m_factory.null()) return BarPlotPtr();
     312           0 :     else return barPlot(m_factory->histogramData(data, bins), overplot);
     313             : }
     314             : 
     315           0 : BarPlotPtr SimplePlotter::histogramPlot(Vector<int>& data,
     316             :         unsigned int bins, bool overplot) {
     317           0 :     if(m_factory.null()) return BarPlotPtr();
     318           0 :     else return barPlot(m_factory->histogramData(data, bins), overplot);
     319             : }
     320             : 
     321           0 : BarPlotPtr SimplePlotter::histogramPlot(PlotSingleDataPtr data,
     322             :         unsigned int bins, bool overplot) {
     323           0 :     if(m_factory.null()) return BarPlotPtr();
     324           0 :     else return barPlot(m_factory->histogramData(data, bins), overplot);
     325             : }
     326             : 
     327           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<double>& d, bool overplot) {
     328           0 :     if(m_factory.null()) return RasterPlotPtr();
     329           0 :     else return rasterPlot(PlotRasterDataPtr(new PlotRasterMatrixData<double>(
     330           0 :             d)), overplot);
     331             : }
     332             : 
     333           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<float>& d, bool overplot) {
     334           0 :     if(m_factory.null()) return RasterPlotPtr();
     335           0 :     else return rasterPlot(PlotRasterDataPtr(new PlotRasterMatrixData<float>(
     336           0 :             d)), overplot);
     337             : }
     338             : 
     339           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<int>& data, bool overplot) {
     340           0 :     if(m_factory.null()) return RasterPlotPtr();
     341           0 :     else return rasterPlot(PlotRasterDataPtr(new PlotRasterMatrixData<int>(
     342           0 :             data)), overplot);
     343             : }
     344             : 
     345           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<uInt>& data, bool overplot) {
     346           0 :     if(m_factory.null()) return RasterPlotPtr();
     347           0 :     else return rasterPlot(PlotRasterDataPtr(new PlotRasterMatrixData<uInt>(
     348           0 :             data)), overplot);
     349             : }
     350             : 
     351           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<double>& data, double fromX,
     352             :         double toX, double fromY, double toY, bool overplot) {
     353           0 :     if(m_factory.null()) return RasterPlotPtr();
     354             :     
     355           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<double>(data));
     356           0 :     d->setXRange(fromX, toX);
     357           0 :     d->setYRange(fromY, toY);
     358           0 :     return rasterPlot(d, overplot);
     359           0 : }
     360             : 
     361           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<float>& data, double fromX,
     362             :         double toX, double fromY, double toY, bool overplot) {
     363           0 :     if(m_factory.null()) return RasterPlotPtr();
     364             :     
     365           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<float>(data));
     366           0 :     d->setXRange(fromX, toX);
     367           0 :     d->setYRange(fromY, toY);
     368           0 :     return rasterPlot(d, overplot);
     369           0 : }
     370             : 
     371           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<int>& data, double fromX,
     372             :         double toX, double fromY, double toY, bool overplot) {
     373           0 :     if(m_factory.null()) return RasterPlotPtr();
     374             :     
     375           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<int>(data));
     376           0 :     d->setXRange(fromX, toX);
     377           0 :     d->setYRange(fromY, toY);
     378           0 :     return rasterPlot(d, overplot);
     379           0 : }
     380             : 
     381           0 : RasterPlotPtr SimplePlotter::rasterPlot(Matrix<uInt>& data, double fromX,
     382             :         double toX, double fromY, double toY, bool overplot) {
     383           0 :     if(m_factory.null()) return RasterPlotPtr();
     384             :     
     385           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<uInt>(data));
     386           0 :     d->setXRange(fromX, toX);
     387           0 :     d->setYRange(fromY, toY);
     388           0 :     return rasterPlot(d, overplot);
     389           0 : }
     390             : 
     391           0 : RasterPlotPtr SimplePlotter::rasterPlot(PlotRasterDataPtr data, bool overplot){
     392           0 :     if(data.null() || !data->isValid() || m_factory.null())
     393           0 :         return RasterPlotPtr();
     394             :     
     395           0 :     RasterPlotPtr raster = m_factory->rasterPlot(data);
     396           0 :     raster->setLine(m_line);
     397           0 :     m_canvas->plot(raster, overplot);
     398           0 :     return raster;
     399           0 : }
     400             : 
     401           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<double>& d,
     402             :         Vector<double>& contours, bool overplot) {
     403           0 :     if(m_factory.null()) return RasterPlotPtr();
     404             :     
     405           0 :     std::vector<double> v(contours.size());
     406           0 :     for(unsigned int i = 0; i < v.size(); i++)
     407           0 :         v[i] = static_cast<double>(contours[i]);
     408           0 :     return contourPlot(PlotRasterDataPtr(new PlotRasterMatrixData<double>(d)),
     409           0 :                        v, overplot);
     410           0 : }
     411             : 
     412           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<float>& d,
     413             :         Vector<float>& contours, bool overplot) {
     414           0 :     if(m_factory.null()) return RasterPlotPtr();
     415             :     
     416           0 :     std::vector<double> v(contours.size());
     417           0 :     for(unsigned int i = 0; i < v.size(); i++)
     418           0 :         v[i] = static_cast<double>(contours[i]);
     419           0 :     return contourPlot(PlotRasterDataPtr(new PlotRasterMatrixData<float>(d)),
     420           0 :                        v, overplot);
     421           0 : }
     422             : 
     423           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<int>& data,
     424             :         Vector<int>& contours, bool overplot) {
     425           0 :     if(m_factory.null()) return RasterPlotPtr();
     426             :     
     427           0 :     std::vector<double> v(contours.size());
     428           0 :     for(unsigned int i = 0; i < v.size(); i++)
     429           0 :         v[i] = static_cast<double>(contours[i]);
     430           0 :     return contourPlot(PlotRasterDataPtr(new PlotRasterMatrixData<int>(data)),
     431           0 :                        v, overplot);
     432           0 : }
     433             : 
     434           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<uInt>& data,
     435             :         Vector<uInt>& contours, bool overplot) {
     436           0 :     if(m_factory.null()) return RasterPlotPtr();
     437             :     
     438           0 :     std::vector<double> v(contours.size());
     439           0 :     for(unsigned int i = 0; i < v.size(); i++)
     440           0 :         v[i] = static_cast<double>(contours[i]);
     441           0 :     return contourPlot(PlotRasterDataPtr(new PlotRasterMatrixData<uInt>(data)),
     442           0 :                        v, overplot);
     443           0 : }
     444             : 
     445           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<double>& data, double fromX,
     446             :         double toX, double fromY, double toY, Vector<double>& contours,
     447             :         bool overplot) {
     448           0 :     if(m_factory.null()) return RasterPlotPtr();
     449             :     
     450           0 :     std::vector<double> v(contours.size());
     451           0 :     for(unsigned int i = 0; i < v.size(); i++)
     452           0 :         v[i] = static_cast<double>(contours[i]);
     453           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<double>(data));
     454           0 :     d->setXRange(fromX, toX);
     455           0 :     d->setYRange(fromY, toY);
     456           0 :     return contourPlot(d, v, overplot);
     457           0 : }
     458             : 
     459           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<float>& data, double fromX,
     460             :         double toX, double fromY,double toY, Vector<float>& contours,
     461             :         bool overplot) {
     462           0 :     if(m_factory.null()) return RasterPlotPtr();
     463             :     
     464           0 :     std::vector<double> v(contours.size());
     465           0 :     for(unsigned int i = 0; i < v.size(); i++)
     466           0 :         v[i] = static_cast<double>(contours[i]);
     467           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<float>(data));
     468           0 :     d->setXRange(fromX, toX);
     469           0 :     d->setYRange(fromY, toY);
     470           0 :     return contourPlot(d, v, overplot);
     471           0 : }
     472             : 
     473           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<int>& data, double fromX,
     474             :         double toX, double fromY, double toY, Vector<int>& contours,
     475             :         bool overplot) {
     476           0 :     if(m_factory.null()) return RasterPlotPtr();
     477             :     
     478           0 :     std::vector<double> v(contours.size());
     479           0 :     for(unsigned int i = 0; i < v.size(); i++)
     480           0 :         v[i] = static_cast<double>(contours[i]);
     481           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<int>(data));
     482           0 :     d->setXRange(fromX, toX);
     483           0 :     d->setYRange(fromY, toY);
     484           0 :     return contourPlot(d, v, overplot);
     485           0 : }
     486             : 
     487           0 : RasterPlotPtr SimplePlotter::contourPlot(Matrix<uInt>& data, double fromX,
     488             :         double toX, double fromY, double toY, Vector<uInt>& contours,
     489             :         bool overplot) {
     490           0 :     if(m_factory.null()) return RasterPlotPtr();
     491             :     
     492           0 :     std::vector<double> v(contours.size());
     493           0 :     for(unsigned int i = 0; i < v.size(); i++)
     494           0 :         v[i] = static_cast<double>(contours[i]);
     495           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<uInt>(data));
     496           0 :     d->setXRange(fromX, toX);
     497           0 :     d->setYRange(fromY, toY);
     498           0 :     return contourPlot(d, v, overplot);
     499           0 : }
     500             : 
     501           0 : RasterPlotPtr SimplePlotter::contourPlot(PlotRasterDataPtr data,
     502             :         std::vector<double>& contours, bool overplot) {
     503           0 :     if(contours.size() == 0) return rasterPlot(data, overplot);
     504             :     
     505           0 :     if(data.null() || !data->isValid() || m_factory.null())
     506           0 :         return RasterPlotPtr();
     507             :     
     508           0 :     RasterPlotPtr raster = m_factory->rasterPlot(data);
     509           0 :     raster->setLine(m_line);
     510           0 :     raster->setContourLines(contours);
     511           0 :     m_canvas->plot(raster, overplot);
     512           0 :     return raster;
     513           0 : }
     514             : 
     515           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<double>& d,bool overplot){
     516           0 :     if(m_factory.null()) return RasterPlotPtr();
     517           0 :     else return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<double>(
     518           0 :             d)), overplot);
     519             : }
     520             : 
     521           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<float>& d, bool overplot){
     522           0 :     if(m_factory.null()) return RasterPlotPtr();
     523           0 :     else return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<float>(
     524           0 :             d)), overplot);
     525             : }
     526             : 
     527           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<int>& data,bool overplot){
     528           0 :     if(m_factory.null()) return RasterPlotPtr();
     529           0 :     else return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<int>(
     530           0 :             data)), overplot);
     531             : }
     532             : 
     533           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<uInt>& data,
     534             :         bool overplot) {
     535           0 :     if(m_factory.null()) return RasterPlotPtr();
     536           0 :     else return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<uInt>(
     537           0 :             data)), overplot);
     538             : }
     539             : 
     540           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<double>& data,
     541             :         double fromX, double toX, double fromY, double toY, bool overplot) {
     542           0 :     if(m_factory.null()) return RasterPlotPtr();
     543             :     
     544           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<double>(data));
     545           0 :     d->setXRange(fromX, toX);
     546           0 :     d->setYRange(fromY, toY);
     547           0 :     return spectrogram(d, overplot);
     548           0 : }
     549             : 
     550           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<float>& data,double fromX,
     551             :         double toX, double fromY, double toY, bool overplot) {
     552           0 :     if(m_factory.null()) return RasterPlotPtr();
     553             :     
     554           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<float>(data));
     555           0 :     d->setXRange(fromX, toX);
     556           0 :     d->setYRange(fromY, toY);
     557           0 :     return spectrogram(d, overplot);
     558           0 : }
     559             : 
     560           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<int>& data, double fromX,
     561             :         double toX, double fromY, double toY, bool overplot) {
     562           0 :     if(m_factory.null()) return RasterPlotPtr();
     563             :     
     564           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<int>(data));
     565           0 :     d->setXRange(fromX, toX);
     566           0 :     d->setYRange(fromY, toY);
     567           0 :     return spectrogram(d, overplot);
     568           0 : }
     569             : 
     570           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<uInt>& data, double fromX,
     571             :         double toX, double fromY, double toY, bool overplot) {
     572           0 :     if(m_factory.null()) return RasterPlotPtr();
     573             :     
     574           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<uInt>(data));
     575           0 :     d->setXRange(fromX, toX);
     576           0 :     d->setYRange(fromY, toY);
     577           0 :     return spectrogram(d, overplot);
     578           0 : }
     579             : 
     580           0 : RasterPlotPtr SimplePlotter::spectrogram(PlotRasterDataPtr data,
     581             :         bool overplot) {
     582           0 :     if(data.null() || !data->isValid() || m_factory.null())
     583           0 :         return RasterPlotPtr();
     584             :     
     585           0 :     RasterPlotPtr spect = m_factory->spectrogramPlot(data);
     586           0 :     spect->setLine(m_line);
     587           0 :     m_canvas->plot(spect, overplot);
     588           0 :     return spect;
     589           0 : }
     590             : 
     591           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<double>& d,
     592             :         Vector<double>& contours, bool overplot) {
     593           0 :     if(m_factory.null()) return RasterPlotPtr();
     594             :     
     595           0 :     std::vector<double> v(contours.size());
     596           0 :     for(unsigned int i = 0; i < v.size(); i++)
     597           0 :         v[i] = static_cast<double>(contours[i]);
     598           0 :     return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<double>(d)),
     599           0 :                        v, overplot);
     600           0 : }
     601             : 
     602           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<float>& d,
     603             :         Vector<float>& contours, bool overplot) {
     604           0 :     if(m_factory.null()) return RasterPlotPtr();
     605             :     
     606           0 :     std::vector<double> v(contours.size());
     607           0 :     for(unsigned int i = 0; i < v.size(); i++)
     608           0 :         v[i] = static_cast<double>(contours[i]);
     609           0 :     return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<float>(d)),
     610           0 :                        v, overplot);
     611           0 : }
     612             : 
     613           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<int>& data,
     614             :         Vector<int>& contours, bool overplot) {
     615           0 :     if(m_factory.null()) return RasterPlotPtr();
     616             :     
     617           0 :     std::vector<double> v(contours.size());
     618           0 :     for(unsigned int i = 0; i < v.size(); i++)
     619           0 :         v[i] = static_cast<double>(contours[i]);
     620           0 :     return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<int>(data)),
     621           0 :                        v, overplot);
     622           0 : }
     623             : 
     624           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<uInt>& data,
     625             :         Vector<uInt>& contours, bool overplot) {
     626           0 :     if(m_factory.null()) return RasterPlotPtr();
     627             :     
     628           0 :     std::vector<double> v(contours.size());
     629           0 :     for(unsigned int i = 0; i < v.size(); i++)
     630           0 :         v[i] = static_cast<double>(contours[i]);
     631           0 :     return spectrogram(PlotRasterDataPtr(new PlotRasterMatrixData<uInt>(data)),
     632           0 :                        v, overplot);
     633           0 : }
     634             : 
     635           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<double>& da, double fromX,
     636             :         double toX, double fromY, double toY, Vector<double>& contours,
     637             :         bool overplot) {
     638           0 :     if(m_factory.null()) return RasterPlotPtr();
     639             :     
     640           0 :     std::vector<double> v(contours.size());
     641           0 :     for(unsigned int i = 0; i < v.size(); i++)
     642           0 :         v[i] = static_cast<double>(contours[i]);
     643           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<double>(da));
     644           0 :     d->setXRange(fromX, toX);
     645           0 :     d->setYRange(fromY, toY);
     646           0 :     return spectrogram(d, v, overplot);
     647           0 : }
     648             : 
     649           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<float>& data,double fromX,
     650             :         double toX, double fromY,double toY, Vector<float>& contours,
     651             :         bool overplot) {
     652           0 :     if(m_factory.null()) return RasterPlotPtr();
     653             :     
     654           0 :     std::vector<double> v(contours.size());
     655           0 :     for(unsigned int i = 0; i < v.size(); i++)
     656           0 :         v[i] = static_cast<double>(contours[i]);
     657           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<float>(data));
     658           0 :     d->setXRange(fromX, toX);
     659           0 :     d->setYRange(fromY, toY);
     660           0 :     return spectrogram(d, v, overplot);
     661           0 : }
     662             : 
     663           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<int>& data, double fromX,
     664             :         double toX, double fromY, double toY, Vector<int>& contours,
     665             :         bool overplot) {
     666           0 :     if(m_factory.null()) return RasterPlotPtr();
     667             :     
     668           0 :     std::vector<double> v(contours.size());
     669           0 :     for(unsigned int i = 0; i < v.size(); i++)
     670           0 :         v[i] = static_cast<double>(contours[i]);
     671           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<int>(data));
     672           0 :     d->setXRange(fromX, toX);
     673           0 :     d->setYRange(fromY, toY);
     674           0 :     return spectrogram(d, v, overplot);
     675           0 : }
     676             : 
     677           0 : RasterPlotPtr SimplePlotter::spectrogram(Matrix<uInt>& data, double fromX,
     678             :         double toX, double fromY, double toY, Vector<uInt>& contours,
     679             :         bool overplot) {
     680           0 :     if(m_factory.null()) return RasterPlotPtr();
     681             :     
     682           0 :     std::vector<double> v(contours.size());
     683           0 :     for(unsigned int i = 0; i < v.size(); i++)
     684           0 :         v[i] = static_cast<double>(contours[i]);
     685           0 :     PlotRasterDataPtr d(new PlotRasterMatrixData<uInt>(data));
     686           0 :     d->setXRange(fromX, toX);
     687           0 :     d->setYRange(fromY, toY);
     688           0 :     return spectrogram(d, v, overplot);
     689           0 : }
     690             : 
     691           0 : RasterPlotPtr SimplePlotter::spectrogram(PlotRasterDataPtr data,
     692             :         std::vector<double>& contours, bool overplot) {
     693           0 :     if(contours.size() == 0) return spectrogram(data, overplot);
     694             :     
     695           0 :     if(data.null() || !data->isValid() || m_factory.null())
     696           0 :         return RasterPlotPtr();
     697             :     
     698           0 :     RasterPlotPtr spect = m_factory->spectrogramPlot(data);
     699           0 :     spect->setLine(m_line);
     700           0 :     spect->setContourLines(contours);
     701           0 :     m_canvas->plot(spect, overplot);
     702           0 :     return spect;
     703           0 : }
     704             : 
     705           0 : PlotPointPtr SimplePlotter::plotPoint(double x, double y) {
     706           0 :     if(m_factory.null()) return PlotPointPtr();
     707             :     
     708           0 :     PlotPointPtr point = m_factory->point(x, y);
     709           0 :     point->setSymbol(m_symbol);
     710           0 :     m_canvas->plotPoint(point);
     711           0 :     m_accumulatedPoints.push_back(point);
     712             :     
     713           0 :     return point;
     714           0 : }
     715             : 
     716             : 
     717             : // Shapes, Annotations, etc. //
     718             : 
     719           0 : PlotAnnotationPtr SimplePlotter::annotation(double x, double y,
     720             :         const String& text) {
     721           0 :     PlotAnnotationPtr annotation =  m_factory->annotation(text, x, y);
     722           0 :     m_canvas->drawAnnotation(annotation);
     723           0 :     return annotation;
     724           0 : }
     725             : 
     726           0 : PlotShapeRectanglePtr SimplePlotter::rectangle(double left, double top,
     727             :         double right, double bottom) {
     728           0 :     PlotShapeRectanglePtr rect = m_factory->shapeRectangle(left, top,
     729           0 :                                                            right, bottom);
     730           0 :     rect->setLine(m_line);
     731           0 :     rect->setAreaFill(m_areaFill);
     732           0 :     m_canvas->drawShape(rect);
     733           0 :     return rect;
     734           0 : }
     735             : 
     736           0 : PlotShapeEllipsePtr SimplePlotter::ellipse(double centerX, double centerY,
     737             :         double xRadius, double yRadius) {
     738           0 :     PlotShapeEllipsePtr ellipse = m_factory->shapeEllipse(centerX, centerY,
     739           0 :                                                           xRadius, yRadius);
     740           0 :     ellipse->setLine(m_line);
     741           0 :     ellipse->setAreaFill(m_areaFill);
     742           0 :     m_canvas->drawShape(ellipse);
     743           0 :     return ellipse;
     744           0 : }
     745             : 
     746           0 : PlotShapeEllipsePtr SimplePlotter::ellipse(double x, double y, double radius) {
     747           0 :     return ellipse(x, y, radius, radius);
     748             : }
     749             : 
     750           0 : PlotShapeLinePtr SimplePlotter::xLine(double value) {
     751           0 :     PlotShapeLinePtr line = m_factory->shapeLine(value, X_BOTTOM);
     752           0 :     line->setLine(m_line);
     753           0 :     m_canvas->drawShape(line);
     754           0 :     return line;
     755           0 : }
     756             : 
     757           0 : PlotShapeLinePtr SimplePlotter::yLine(double value) {
     758           0 :     PlotShapeLinePtr line = m_factory->shapeLine(value, Y_LEFT);
     759           0 :     line->setLine(m_line);
     760           0 :     m_canvas->drawShape(line);
     761           0 :     return line;
     762           0 : }
     763             : 
     764           0 : PlotShapeArrowPtr SimplePlotter::arrow(double xFrom, double yFrom,
     765             :                                        double xTo, double yTo) {
     766           0 :     PlotShapeArrowPtr arrow = m_factory->shapeArrow(xFrom, yFrom, xTo, yTo);
     767           0 :     arrow->setLine(m_line);
     768           0 :     arrow->setAreaFill(m_areaFill);
     769           0 :     m_canvas->drawShape(arrow);
     770           0 :     return arrow;
     771           0 : }
     772             : 
     773           0 : PlotShapeArrowPtr SimplePlotter::lineSegment(double xFrom, double yFrom,
     774             :                                              double xTo, double yTo) {
     775           0 :     PlotShapeArrowPtr line = m_factory->shapeLineSegment(xFrom, yFrom,
     776           0 :                                                          xTo, yTo);
     777           0 :     line->setLine(m_line);
     778           0 :     m_canvas->drawShape(line);
     779           0 :     return line;
     780           0 : }
     781             : 
     782             : 
     783             : // Clearing Methods //
     784             : 
     785           0 : void SimplePlotter::clear() {
     786           0 :     m_canvas->clearItems();
     787           0 :     m_accumulatedPoints.clear();
     788           0 : }
     789             : 
     790           0 : void SimplePlotter::clearPoints() {
     791           0 :     for(unsigned int i = 0; i < m_accumulatedPoints.size(); i++)
     792           0 :         m_canvas->removePoint(m_accumulatedPoints[i]);
     793           0 :     m_accumulatedPoints.clear();
     794           0 : }
     795             : 
     796             : 
     797             : // Interaction Methods //
     798             : 
     799           0 : void SimplePlotter::showDefaultHandTools(bool show) {
     800           0 :     m_plotter->showDefaultPanel(Plotter::HAND_TOOLS, show);
     801           0 : }
     802             : 
     803           0 : void SimplePlotter::showDefaultExportTools(bool show) {
     804           0 :     m_plotter->showDefaultPanel(Plotter::EXPORT_TOOLS, show);
     805           0 : }
     806             : 
     807           0 : std::vector<PlotRegion> SimplePlotter::allSelectedRegions() {
     808           0 :     return m_mouseTools->selectTool()->getSelectedRects();
     809             : }
     810             : 
     811           0 : void SimplePlotter::clearSelectedRegions() {
     812           0 :     m_mouseTools->selectTool()->clearSelectedRects();
     813           0 : }
     814             : 
     815             : 
     816             : // Export Methods //
     817             : 
     818           0 : String SimplePlotter::fileChooserDialog(const String& title,
     819             :         const String& directory) {
     820           0 :     return m_plotter->fileChooserDialog(title, directory);
     821             : }
     822             : 
     823           0 : bool SimplePlotter::exportPDF(const String& location, bool highQuality,
     824             :         int dpi) {
     825           0 :     PlotExportFormat format(PlotExportFormat::PDF, location);
     826           0 :     if(highQuality) format.resolution = PlotExportFormat::HIGH;
     827           0 :     else format.resolution = PlotExportFormat::SCREEN;
     828           0 :     format.dpi = dpi;
     829           0 :     return exportToFile(format);
     830           0 : }
     831             : 
     832           0 : bool SimplePlotter::exportPS(const String& location, bool highQuality,
     833             :         int dpi) {
     834           0 :     PlotExportFormat format(PlotExportFormat::PS, location);
     835           0 :     if(highQuality) format.resolution = PlotExportFormat::HIGH;
     836           0 :     else format.resolution = PlotExportFormat::SCREEN;
     837           0 :     format.dpi = dpi;
     838           0 :     return exportToFile(format);
     839           0 : }
     840             : 
     841           0 : bool SimplePlotter::exportJPG(const String& location, bool highQuality,
     842             :         int width, int height) {
     843           0 :     PlotExportFormat format(PlotExportFormat::JPG, location);
     844           0 :     if(highQuality) format.resolution = PlotExportFormat::HIGH;
     845           0 :     else format.resolution = PlotExportFormat::SCREEN;
     846           0 :     format.width = width;
     847           0 :     format.height = height;
     848           0 :     return exportToFile(format);
     849           0 : }
     850             : 
     851           0 : bool SimplePlotter::exportPNG(const String& location, bool highQuality,
     852             :         int width, int height) {
     853           0 :     PlotExportFormat format(PlotExportFormat::PNG, location);
     854           0 :     if(highQuality) format.resolution = PlotExportFormat::HIGH;
     855           0 :     else format.resolution = PlotExportFormat::SCREEN;
     856           0 :     format.width = width;
     857           0 :     format.height = height;
     858           0 :     return exportToFile(format);
     859           0 : }
     860             : 
     861           0 : bool SimplePlotter::exportToFile(const PlotExportFormat& format) {
     862           0 :     return m_canvas->exportToFile(format);
     863             : }
     864             : 
     865             : }

Generated by: LCOV version 1.16