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