SimplePlotter.h

Go to the documentation of this file.
00001 //# SimplePlotter.h: Concrete plotting class for common or simple use cases.
00002 //# Copyright (C) 2008
00003 //# Associated Universities, Inc. Washington DC, USA.
00004 //#
00005 //# This library is free software; you can redistribute it and/or modify it
00006 //# under the terms of the GNU Library General Public License as published by
00007 //# the Free Software Foundation; either version 2 of the License, or (at your
00008 //# option) any later version.
00009 //#
00010 //# This library is distributed in the hope that it will be useful, but WITHOUT
00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00013 //# License for more details.
00014 //#
00015 //# You should have received a copy of the GNU Library General Public License
00016 //# along with this library; if not, write to the Free Software Foundation,
00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00018 //#
00019 //# Correspondence concerning AIPS++ should be addressed as follows:
00020 //#        Internet email: aips2-request@nrao.edu.
00021 //#        Postal address: AIPS++ Project Office
00022 //#                        National Radio Astronomy Observatory
00023 //#                        520 Edgemont Road
00024 //#                        Charlottesville, VA 22903-2475 USA
00025 //#
00026 //# $Id: $
00027 #ifndef SIMPLEPLOTTER_H_
00028 #define SIMPLEPLOTTER_H_
00029 
00030 #include <graphics/GenericPlotter/PlotFactory.h>
00031 
00032 #include <casa/Arrays/Matrix.h>
00033 
00034 namespace casa {
00035 
00036 // SimplePlotter is a concrete class that uses the abstract plotting classes
00037 // to perform common tasks.  SimplePlotter is meant for users who won't need
00038 // any advanced or complicated customization or specialized data types.
00039 class SimplePlotter {
00040 public:
00041     // Constructor that takes a factory to build plotting objects.
00042     SimplePlotter(PlotFactoryPtr factory);
00043     
00044     // Destructor
00045     ~SimplePlotter();
00046     
00047     
00048     // Accessor methods
00049     
00050     // Returns the factory.
00051     PlotFactoryPtr getFactory() { return m_factory; }
00052     
00053     // Returns the Plotter.
00054     PlotterPtr getPlotter() { return m_plotter; }
00055     
00056     // Returns the PlotCanvas.
00057     PlotCanvasPtr getCanvas() { return m_canvas; }
00058     
00059     // Returns the current PlotLine used to draw the plots.
00060     PlotLinePtr getLine() { return m_line; }
00061     
00062     // Returns the current PlotSymbol used for the plots and points.
00063     PlotSymbolPtr getSymbol() { return m_symbol; }
00064     
00065     // Returns the current PlotAreaFill used for shapes, histograms, etc.
00066     PlotAreaFillPtr getAreaFill() { return m_areaFill; }
00067     
00068     
00069     // Execution methods
00070     
00071     // Enters the execution loop and returns the result.
00072     int execLoop();
00073     
00074     // Holds/Releases drawing on the canvas.  Is NOT recursive.
00075     // <group>
00076     void holdDrawing();
00077     void releaseDrawing();
00078     // </group>
00079     
00080     
00081     // Plotter customization
00082     
00083     // Sets the title of the plotting window to the given.
00084     void setWindowTitle(const String& windowTitle);
00085     
00086     // Sets the title of the canvas to the given.
00087     void setCanvasTitle(const String& canvasTitle);
00088     
00089     // Sets the X_BOTTOM and Y_LEFT axes labels to the given.
00090     void setAxesLabels(const String& xLabel, const String& yLabel);
00091     
00092     // Show/hide Cartesian axes.  (See PlotCanvas::showCartesianAxis()).
00093     void showCartesianAxes(bool show = true);
00094     
00095     // Implies setAxesAutoRescale(false)
00096     void setXAxisRange(double from, double to);
00097     
00098     // Implies setAxesAutoRescale(false)
00099     void setYAxisRange(double from, double to);
00100     
00101     // When future items are added to the canvas, automatically rescale
00102     // the axes to show all items.
00103     void setAxesAutoRescale(bool on = true);
00104     
00105     // Automatically rescale the axes to show all items on the canvas.
00106     void rescaleAxes();
00107     
00108     
00109     // Plot customization
00110     
00111     // Turn lines on or off for future plots.
00112     void showLines(bool showLines = true);
00113     
00114     // Turns symbols on or off for future plots and points.
00115     void showSymbols(bool showSymbols = true);
00116     
00117     // Set the line for future plots to the given characteristics.  Color can
00118     // be hexadecimal form ("000000") or name form ("black").
00119     void setLine(const String& color,
00120             PlotLine::Style style = PlotLine::SOLID,  double width = 1.0);
00121     
00122     // Set the symbol for future plots and points to the given characteristics.
00123     void setSymbol(PlotSymbol::Symbol symbol, const String& color = "blue",
00124                    double size = 5, bool outline = true);
00125     
00126     // Set the area fill for future histograms, shapes, etc. to the given
00127     // characteristics.
00128     void setAreaFill(const String& color,
00129                      PlotAreaFill::Pattern pattern = PlotAreaFill::FILL);
00130     
00131     
00132     // Plotting methods
00133     
00134     // IMPORTANT: since the data given to the plotting methods is not copied
00135     // (but rather a reference is used) it is important that the data not
00136     // go out of scope while the plots are being used!
00137     
00138     // Plot the given points, using the current line and symbol.
00139     // <group>
00140     ScatterPlotPtr plotxy(double*& x, double*& y, unsigned int n,
00141                           bool overplot = true);
00142     ScatterPlotPtr plotxy(float*& x, float*& y, unsigned int n,
00143                           bool overplot = true);
00144     ScatterPlotPtr plotxy(int*& x, int*& y, unsigned int n,
00145                           bool overplot = true);
00146     
00147     ScatterPlotPtr plotxy(Vector<double>& x, Vector<double>& y,
00148                           bool overplot = true);
00149     ScatterPlotPtr plotxy(Vector<float>& x, Vector<float>& y,
00150                           bool overplot = true);
00151     ScatterPlotPtr plotxy(Vector<int>& x, Vector<int>& y,
00152                           bool overplot = true);
00153     
00154     ScatterPlotPtr plotxy(PlotPointDataPtr data, bool overplot = true);
00155     
00156     ScatterPlotPtr ploty(double*& y, unsigned int n, bool overplot = true);
00157     ScatterPlotPtr ploty(float*& y, unsigned int n, bool overplot = true);
00158     ScatterPlotPtr ploty(int*& y, unsigned int n, bool overplot = true);
00159     
00160     ScatterPlotPtr ploty(Vector<double>& y, bool overplot = true);
00161     ScatterPlotPtr ploty(Vector<float>& y, bool overplot = true);
00162     ScatterPlotPtr ploty(Vector<int>& y, bool overplot = true);
00163     
00164     ScatterPlotPtr ploty(PlotPointDataPtr data, bool overplot = true);
00165     // </group>
00166     
00167     // Display a bar plot for the given data, using the current line and area
00168     // fill.
00169     // <group>
00170     BarPlotPtr barPlot(double*& x, double*& y, unsigned int n,
00171                        bool overplot = false);
00172     BarPlotPtr barPlot(float*& x, float*& y, unsigned int n,
00173                        bool overplot = false);
00174     BarPlotPtr barPlot(int*& x, int*& y, unsigned int n,
00175                        bool overplot = false);
00176     
00177     BarPlotPtr barPlot(Vector<double>& x, Vector<double>& y,
00178                        bool overplot = false);
00179     BarPlotPtr barPlot(Vector<float>& x, Vector<float>& y,
00180                        bool overplot = false);
00181     BarPlotPtr barPlot(Vector<int>& x, Vector<int>& y,
00182                        bool overplot = false);
00183     
00184     BarPlotPtr barPlot(PlotPointDataPtr data, bool overplot = false);
00185     // </group>
00186     
00187     // Display a histogram for the given data in the given number of bins,
00188     // using the current line and area fill.
00189     // <group>
00190     BarPlotPtr histogramPlot(double*& data, unsigned int n,
00191                              unsigned int numBins, bool overplot= false);
00192     BarPlotPtr histogramPlot(float*& data, unsigned int n,
00193                              unsigned int numBins, bool overplot= false);
00194     BarPlotPtr histogramPlot(int*& data, unsigned int n,
00195                              unsigned int numBins, bool overplot= false);
00196     BarPlotPtr histogramPlot(Vector<double>& data, unsigned int numBins,
00197                              bool overplot = false);
00198     BarPlotPtr histogramPlot(Vector<float>& data, unsigned int numBins,
00199                              bool overplot = false);
00200     BarPlotPtr histogramPlot(Vector<int>& data, unsigned int numBins,
00201                              bool overplot = false);
00202     
00203     BarPlotPtr histogramPlot(PlotSingleDataPtr data, unsigned int numBins,
00204                              bool overplot = false);
00205     // </group>
00206     
00207     // Display a raster or contour plot for the given data, using the current
00208     // line for the contours if applicable.
00209     // <group>
00210     RasterPlotPtr rasterPlot(Matrix<double>& data, bool overplot = false);
00211     RasterPlotPtr rasterPlot(Matrix<float>& data, bool overplot = false);
00212     RasterPlotPtr rasterPlot(Matrix<int>& data, bool overplot = false);
00213     RasterPlotPtr rasterPlot(Matrix<uInt>& data, bool overplot = false);
00214     RasterPlotPtr rasterPlot(Matrix<double>& data, double fromX, double toX,
00215                              double fromY, double toY, bool overplot = false);
00216     RasterPlotPtr rasterPlot(Matrix<float>& data, double fromX, double toX,
00217                              double fromY, double toY, bool overplot = false);
00218     RasterPlotPtr rasterPlot(Matrix<int>& data, double fromX, double toX,
00219                              double fromY, double toY, bool overplot = false);
00220     RasterPlotPtr rasterPlot(Matrix<uInt>& data, double fromX, double toX,
00221                              double fromY, double toY, bool overplot = false);
00222     RasterPlotPtr rasterPlot(PlotRasterDataPtr data, bool overplot = false);
00223     
00224     RasterPlotPtr contourPlot(Matrix<double>& data, Vector<double>& contours,
00225                               bool overplot = false);
00226     RasterPlotPtr contourPlot(Matrix<float>& data, Vector<float>& contours,
00227                               bool overplot = false);
00228     RasterPlotPtr contourPlot(Matrix<int>& data, Vector<int>& contours,
00229                               bool overplot = false);
00230     RasterPlotPtr contourPlot(Matrix<uInt>& data, Vector<uInt>& contours,
00231                               bool overplot = false);
00232     RasterPlotPtr contourPlot(Matrix<double>& data, double fromX, double toX,
00233                               double fromY,double toY,Vector<double>& contours,
00234                               bool overplot = false);
00235     RasterPlotPtr contourPlot(Matrix<float>& data, double fromX, double toX,
00236                               double fromY,double toY, Vector<float>& contours,
00237                               bool overplot = false);
00238     RasterPlotPtr contourPlot(Matrix<int>& data, double fromX, double toX,
00239                               double fromY, double toY, Vector<int>& contours,
00240                               bool overplot = false);
00241     RasterPlotPtr contourPlot(Matrix<uInt>& data, double fromX, double toX,
00242                               double fromY, double toY, Vector<uInt>& contours,
00243                               bool overplot = false);
00244     RasterPlotPtr contourPlot(PlotRasterDataPtr data, vector<double>& contours,
00245                               bool overplot = false);
00246 
00247     RasterPlotPtr spectrogram(Matrix<double>& data, bool overplt = false);
00248     RasterPlotPtr spectrogram(Matrix<float>& data, bool overplot = false);
00249     RasterPlotPtr spectrogram(Matrix<int>& data, bool overplot = false);
00250     RasterPlotPtr spectrogram(Matrix<uInt>& data, bool overplot = false);
00251     RasterPlotPtr spectrogram(Matrix<double>& data, double fromX, double toX,
00252                               double fromY, double toY, bool overplot = false);
00253     RasterPlotPtr spectrogram(Matrix<float>& data, double fromX, double toX,
00254                               double fromY, double toY, bool overplot = false);
00255     RasterPlotPtr spectrogram(Matrix<int>& data, double fromX, double toX,
00256                               double fromY, double toY, bool overplot = false);
00257     RasterPlotPtr spectrogram(Matrix<uInt>& data, double fromX, double toX,
00258                               double fromY, double toY, bool overplot = false);
00259     RasterPlotPtr spectrogram(PlotRasterDataPtr data, bool overplot = false);
00260     
00261     RasterPlotPtr spectrogram(Matrix<double>& d, Vector<double>& contours,
00262                               bool overplot = false);
00263     RasterPlotPtr spectrogram(Matrix<float>& data,Vector<float>& contours,
00264                               bool overplot = false);
00265     RasterPlotPtr spectrogram(Matrix<int>& data, Vector<int>& contours,
00266                               bool overplot = false);
00267     RasterPlotPtr spectrogram(Matrix<uInt>& data, Vector<uInt>& contours,
00268                               bool overplot = false);
00269     RasterPlotPtr spectrogram(Matrix<double>& d, double fromX, double toX,
00270                               double fromY,double toY,Vector<double>& contours,
00271                               bool overplot = false);
00272     RasterPlotPtr spectrogram(Matrix<float>& data,double fromX,double toX,
00273                               double fromY,double toY, Vector<float>& contours,
00274                               bool overplot = false);
00275     RasterPlotPtr spectrogram(Matrix<int>& data, double fromX, double toX,
00276                               double fromY, double toY, Vector<int>& contours,
00277                               bool overplot = false);
00278     RasterPlotPtr spectrogram(Matrix<uInt>& data, double fromX,double toX,
00279                               double fromY, double toY, Vector<uInt>& contours,
00280                               bool overplot = false);
00281     RasterPlotPtr spectrogram(PlotRasterDataPtr data, vector<double>& contours,
00282                               bool overplot = false);
00283     // </group>
00284     
00285     // Plot a point at the given location, using the current symbol.
00286     PlotPointPtr plotPoint(double x, double y);
00287     
00288     
00289     // Shapes, Annotations, etc.
00290     
00291     // Draw an annotation (text) on the canvas at the given point.
00292     PlotAnnotationPtr annotation(double x, double y, const String& text);
00293     
00294     // Draw a rectangle from the given upper left point to the given
00295     // lower right point.
00296     PlotShapeRectanglePtr rectangle(double left, double top,
00297                                     double right, double bottom);
00298     
00299     // Draw an ellipse with the given point as the center and the given
00300     // x and y radii.
00301     // <group>
00302     PlotShapeEllipsePtr ellipse(double centerX, double centerY,
00303                                 double xRadius, double yRadius);
00304     PlotShapeEllipsePtr ellipse(double x, double y, double radius);
00305     // </group>
00306     
00307     // Draw a line at the given x value.
00308     PlotShapeLinePtr xLine(double value);
00309     
00310     // Draw a line at the given y value.
00311     PlotShapeLinePtr yLine(double value);
00312     
00313     // Draw an arrow from the given point to the given point
00314     PlotShapeArrowPtr arrow(double xFrom, double yFrom,
00315                             double xTo, double yTo);
00316     
00317     // Draw a line segment from the given point to the given point
00318     PlotShapeArrowPtr lineSegment(double xFrom, double yFrom,
00319                                   double xTo, double yTo);
00320     
00321     
00322     // Clearing Methods
00323     
00324     // Clear all items currently on the canvas.
00325     void clear();
00326     
00327     // Clear just the points that have been accumulated using plotPoint calls.
00328     void clearPoints();
00329     
00330     
00331     // Interaction Methods
00332     
00333     // Show or hide default "hand tools" panel - i.e., zooming, panning, etc.
00334     // See Plotter::DefaultPanel::HAND_TOOLS.
00335     void showDefaultHandTools(bool show = true);
00336     
00337     // Show or hide default "export tools" panel - i.e., saving to a file.
00338     // See Plotter::DefaultPanel::EXPORT_TOOLS.
00339     void showDefaultExportTools(bool show = true);
00340     
00341     // Returns all selected regions in the canvas' selected region list.  This
00342     // list will contain all user-selected regions since either its
00343     // construction or the last call to clearSelectedRegions().
00344     vector<PlotRegion> allSelectedRegions();
00345     
00346     // Clears the canvas' list of selected regions.
00347     void clearSelectedRegions();
00348     
00349     
00350     // Export Methods
00351     
00352     // Show a file chooser dialog with the given optional window title and
00353     // starting directory.  Returns the absolute filename that the user
00354     // selected, or an empty String if they pushed "Cancel".
00355     String fileChooserDialog(const String& title = "File Chooser",
00356                              const String& directory = "");
00357     
00358     // Exports the plotter to a PDF file at the given location.  If highQuality
00359     // is false, a screenshot-like export is used.  Dots per inch can be set
00360     // using dpi.
00361     bool exportPDF(const String& location, bool highQuality = false,
00362                    int dpi = -1);
00363     
00364     // Exports the plotter to a PS file at the given location.  If highQuality
00365     // is false, a screenshot-like export is used.  Dots per inch can be set
00366     // using dpi.
00367     bool exportPS(const String& location, bool highQuality = false,
00368                   int dpi = -1);
00369     
00370     // Exports the plotter to a JPG file at the given location.  If highQuality
00371     // is false, a screenshot-like export is used.  Width and height of the
00372     // image can be set.
00373     bool exportJPG(const String& location, bool highQuality = false,
00374                    int width = -1, int height = -1);
00375     
00376     // Exports the plotter to a PNG file at the given location.  If highQuality
00377     // is false, a screenshot-like export is used.  Width and height of the
00378     // image can be set.
00379     bool exportPNG(const String& location, bool highQuality = false,
00380                    int width = -1, int height = -1);
00381     
00382     // Exports the plotter using the given format.
00383     bool exportToFile(const PlotExportFormat& format);
00384     
00385 private:
00386     // Factory
00387     PlotFactoryPtr m_factory;
00388     
00389     // Plotter, with single canvas
00390     PlotterPtr m_plotter;
00391     
00392     // Canvas
00393     PlotCanvasPtr m_canvas;
00394     
00395     // Mouse tools
00396     PlotStandardMouseToolGroupPtr m_mouseTools;
00397     
00398     // Points accumulated using plotPoint calls.
00399     vector<PlotPointPtr> m_accumulatedPoints;
00400     
00401     // Line for future plots.
00402     PlotLinePtr m_line;
00403     
00404     // Symbol for future plots and points.
00405     PlotSymbolPtr m_symbol;
00406     
00407     // Area fill for future histograms, shapes, etc.
00408     PlotAreaFillPtr m_areaFill;
00409 };
00410 
00411 typedef CountedPtr<SimplePlotter> SimplePlotterPtr;
00412 
00413 }
00414 
00415 #endif /*SIMPLEPLOTTER_H_*/
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1