casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
SimplePlotter.h
Go to the documentation of this file.
1 //# SimplePlotter.h: 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: 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 #ifndef SIMPLEPLOTTER_H_
28 #define SIMPLEPLOTTER_H_
29 
31 
32 #include <casa/Arrays/Matrix.h>
33 
34 namespace casa {
35 
36 // SimplePlotter is a concrete class that uses the abstract plotting classes
37 // to perform common tasks. SimplePlotter is meant for users who won't need
38 // any advanced or complicated customization or specialized data types.
40 public:
41  // Constructor that takes a factory to build plotting objects.
43 
44  // Destructor
46 
47 
48  // Accessor methods
49 
50  // Returns the factory.
52 
53  // Returns the Plotter.
55 
56  // Returns the PlotCanvas.
58 
59  // Returns the current PlotLine used to draw the plots.
60  PlotLinePtr getLine() { return m_line; }
61 
62  // Returns the current PlotSymbol used for the plots and points.
64 
65  // Returns the current PlotAreaFill used for shapes, histograms, etc.
67 
68 
69  // Execution methods
70 
71  // Enters the execution loop and returns the result.
72  int execLoop();
73 
74  // Holds/Releases drawing on the canvas. Is NOT recursive.
75  // <group>
76  void holdDrawing();
77  void releaseDrawing();
78  // </group>
79 
80 
81  // Plotter customization
82 
83  // Sets the title of the plotting window to the given.
84  void setWindowTitle(const casacore::String& windowTitle);
85 
86  // Sets the title of the canvas to the given.
87  void setCanvasTitle(const casacore::String& canvasTitle);
88 
89  // Sets the X_BOTTOM and Y_LEFT axes labels to the given.
90  void setAxesLabels(const casacore::String& xLabel, const casacore::String& yLabel);
91 
92  // Show/hide Cartesian axes. (See PlotCanvas::showCartesianAxis()).
93  void showCartesianAxes(bool show = true);
94 
95  // Implies setAxesAutoRescale(false)
96  void setXAxisRange(double from, double to);
97 
98  // Implies setAxesAutoRescale(false)
99  void setYAxisRange(double from, double to);
100 
101  // When future items are added to the canvas, automatically rescale
102  // the axes to show all items.
103  void setAxesAutoRescale(bool on = true);
104 
105  // Automatically rescale the axes to show all items on the canvas.
106  void rescaleAxes();
107 
108 
109  // Plot customization
110 
111  // Turn lines on or off for future plots.
112  void showLines(bool showLines = true);
113 
114  // Turns symbols on or off for future plots and points.
115  void showSymbols(bool showSymbols = true);
116 
117  // Set the line for future plots to the given characteristics. Color can
118  // be hexadecimal form ("000000") or name form ("black").
119  void setLine(const casacore::String& color,
120  PlotLine::Style style = PlotLine::SOLID, double width = 1.0);
121 
122  // Set the symbol for future plots and points to the given characteristics.
123  void setSymbol(PlotSymbol::Symbol symbol, const casacore::String& color = "blue",
124  double size = 5, bool outline = true);
125 
126  // Set the area fill for future histograms, shapes, etc. to the given
127  // characteristics.
128  void setAreaFill(const casacore::String& color,
130 
131 
132  // Plotting methods
133 
134  // IMPORTANT: since the data given to the plotting methods is not copied
135  // (but rather a reference is used) it is important that the data not
136  // go out of scope while the plots are being used!
137 
138  // Plot the given points, using the current line and symbol.
139  // <group>
140  ScatterPlotPtr plotxy(double*& x, double*& y, unsigned int n,
141  bool overplot = true);
142  ScatterPlotPtr plotxy(float*& x, float*& y, unsigned int n,
143  bool overplot = true);
144  ScatterPlotPtr plotxy(int*& x, int*& y, unsigned int n,
145  bool overplot = true);
146 
148  bool overplot = true);
150  bool overplot = true);
152  bool overplot = true);
153 
154  ScatterPlotPtr plotxy(PlotPointDataPtr data, bool overplot = true);
155 
156  ScatterPlotPtr ploty(double*& y, unsigned int n, bool overplot = true);
157  ScatterPlotPtr ploty(float*& y, unsigned int n, bool overplot = true);
158  ScatterPlotPtr ploty(int*& y, unsigned int n, bool overplot = true);
159 
160  ScatterPlotPtr ploty(casacore::Vector<double>& y, bool overplot = true);
161  ScatterPlotPtr ploty(casacore::Vector<float>& y, bool overplot = true);
162  ScatterPlotPtr ploty(casacore::Vector<int>& y, bool overplot = true);
163 
164  ScatterPlotPtr ploty(PlotPointDataPtr data, bool overplot = true);
165  // </group>
166 
167  // Display a bar plot for the given data, using the current line and area
168  // fill.
169  // <group>
170  BarPlotPtr barPlot(double*& x, double*& y, unsigned int n,
171  bool overplot = false);
172  BarPlotPtr barPlot(float*& x, float*& y, unsigned int n,
173  bool overplot = false);
174  BarPlotPtr barPlot(int*& x, int*& y, unsigned int n,
175  bool overplot = false);
176 
178  bool overplot = false);
180  bool overplot = false);
182  bool overplot = false);
183 
184  BarPlotPtr barPlot(PlotPointDataPtr data, bool overplot = false);
185  // </group>
186 
187  // Display a histogram for the given data in the given number of bins,
188  // using the current line and area fill.
189  // <group>
190  BarPlotPtr histogramPlot(double*& data, unsigned int n,
191  unsigned int numBins, bool overplot= false);
192  BarPlotPtr histogramPlot(float*& data, unsigned int n,
193  unsigned int numBins, bool overplot= false);
194  BarPlotPtr histogramPlot(int*& data, unsigned int n,
195  unsigned int numBins, bool overplot= false);
196  BarPlotPtr histogramPlot(casacore::Vector<double>& data, unsigned int numBins,
197  bool overplot = false);
198  BarPlotPtr histogramPlot(casacore::Vector<float>& data, unsigned int numBins,
199  bool overplot = false);
200  BarPlotPtr histogramPlot(casacore::Vector<int>& data, unsigned int numBins,
201  bool overplot = false);
202 
203  BarPlotPtr histogramPlot(PlotSingleDataPtr data, unsigned int numBins,
204  bool overplot = false);
205  // </group>
206 
207  // Display a raster or contour plot for the given data, using the current
208  // line for the contours if applicable.
209  // <group>
210  RasterPlotPtr rasterPlot(casacore::Matrix<double>& data, bool overplot = false);
211  RasterPlotPtr rasterPlot(casacore::Matrix<float>& data, bool overplot = false);
212  RasterPlotPtr rasterPlot(casacore::Matrix<int>& data, bool overplot = false);
213  RasterPlotPtr rasterPlot(casacore::Matrix<casacore::uInt>& data, bool overplot = false);
214  RasterPlotPtr rasterPlot(casacore::Matrix<double>& data, double fromX, double toX,
215  double fromY, double toY, bool overplot = false);
216  RasterPlotPtr rasterPlot(casacore::Matrix<float>& data, double fromX, double toX,
217  double fromY, double toY, bool overplot = false);
218  RasterPlotPtr rasterPlot(casacore::Matrix<int>& data, double fromX, double toX,
219  double fromY, double toY, bool overplot = false);
220  RasterPlotPtr rasterPlot(casacore::Matrix<casacore::uInt>& data, double fromX, double toX,
221  double fromY, double toY, bool overplot = false);
222  RasterPlotPtr rasterPlot(PlotRasterDataPtr data, bool overplot = false);
223 
225  bool overplot = false);
227  bool overplot = false);
229  bool overplot = false);
231  bool overplot = false);
232  RasterPlotPtr contourPlot(casacore::Matrix<double>& data, double fromX, double toX,
233  double fromY,double toY,casacore::Vector<double>& contours,
234  bool overplot = false);
235  RasterPlotPtr contourPlot(casacore::Matrix<float>& data, double fromX, double toX,
236  double fromY,double toY, casacore::Vector<float>& contours,
237  bool overplot = false);
238  RasterPlotPtr contourPlot(casacore::Matrix<int>& data, double fromX, double toX,
239  double fromY, double toY, casacore::Vector<int>& contours,
240  bool overplot = false);
241  RasterPlotPtr contourPlot(casacore::Matrix<casacore::uInt>& data, double fromX, double toX,
242  double fromY, double toY, casacore::Vector<casacore::uInt>& contours,
243  bool overplot = false);
244  RasterPlotPtr contourPlot(PlotRasterDataPtr data, std::vector<double>& contours,
245  bool overplot = false);
246 
247  RasterPlotPtr spectrogram(casacore::Matrix<double>& data, bool overplt = false);
248  RasterPlotPtr spectrogram(casacore::Matrix<float>& data, bool overplot = false);
249  RasterPlotPtr spectrogram(casacore::Matrix<int>& data, bool overplot = false);
250  RasterPlotPtr spectrogram(casacore::Matrix<casacore::uInt>& data, bool overplot = false);
251  RasterPlotPtr spectrogram(casacore::Matrix<double>& data, double fromX, double toX,
252  double fromY, double toY, bool overplot = false);
253  RasterPlotPtr spectrogram(casacore::Matrix<float>& data, double fromX, double toX,
254  double fromY, double toY, bool overplot = false);
255  RasterPlotPtr spectrogram(casacore::Matrix<int>& data, double fromX, double toX,
256  double fromY, double toY, bool overplot = false);
257  RasterPlotPtr spectrogram(casacore::Matrix<casacore::uInt>& data, double fromX, double toX,
258  double fromY, double toY, bool overplot = false);
259  RasterPlotPtr spectrogram(PlotRasterDataPtr data, bool overplot = false);
260 
262  bool overplot = false);
264  bool overplot = false);
266  bool overplot = false);
268  bool overplot = false);
269  RasterPlotPtr spectrogram(casacore::Matrix<double>& d, double fromX, double toX,
270  double fromY,double toY,casacore::Vector<double>& contours,
271  bool overplot = false);
272  RasterPlotPtr spectrogram(casacore::Matrix<float>& data,double fromX,double toX,
273  double fromY,double toY, casacore::Vector<float>& contours,
274  bool overplot = false);
275  RasterPlotPtr spectrogram(casacore::Matrix<int>& data, double fromX, double toX,
276  double fromY, double toY, casacore::Vector<int>& contours,
277  bool overplot = false);
278  RasterPlotPtr spectrogram(casacore::Matrix<casacore::uInt>& data, double fromX,double toX,
279  double fromY, double toY, casacore::Vector<casacore::uInt>& contours,
280  bool overplot = false);
281  RasterPlotPtr spectrogram(PlotRasterDataPtr data, std::vector<double>& contours,
282  bool overplot = false);
283  // </group>
284 
285  // Plot a point at the given location, using the current symbol.
286  PlotPointPtr plotPoint(double x, double y);
287 
288 
289  // Shapes, Annotations, etc.
290 
291  // Draw an annotation (text) on the canvas at the given point.
292  PlotAnnotationPtr annotation(double x, double y, const casacore::String& text);
293 
294  // Draw a rectangle from the given upper left point to the given
295  // lower right point.
296  PlotShapeRectanglePtr rectangle(double left, double top,
297  double right, double bottom);
298 
299  // Draw an ellipse with the given point as the center and the given
300  // x and y radii.
301  // <group>
302  PlotShapeEllipsePtr ellipse(double centerX, double centerY,
303  double xRadius, double yRadius);
304  PlotShapeEllipsePtr ellipse(double x, double y, double radius);
305  // </group>
306 
307  // Draw a line at the given x value.
308  PlotShapeLinePtr xLine(double value);
309 
310  // Draw a line at the given y value.
311  PlotShapeLinePtr yLine(double value);
312 
313  // Draw an arrow from the given point to the given point
314  PlotShapeArrowPtr arrow(double xFrom, double yFrom,
315  double xTo, double yTo);
316 
317  // Draw a line segment from the given point to the given point
318  PlotShapeArrowPtr lineSegment(double xFrom, double yFrom,
319  double xTo, double yTo);
320 
321 
322  // Clearing Methods
323 
324  // Clear all items currently on the canvas.
325  void clear();
326 
327  // Clear just the points that have been accumulated using plotPoint calls.
328  void clearPoints();
329 
330 
331  // Interaction Methods
332 
333  // Show or hide default "hand tools" panel - i.e., zooming, panning, etc.
334  // See Plotter::DefaultPanel::HAND_TOOLS.
335  void showDefaultHandTools(bool show = true);
336 
337  // Show or hide default "export tools" panel - i.e., saving to a file.
338  // See Plotter::DefaultPanel::EXPORT_TOOLS.
339  void showDefaultExportTools(bool show = true);
340 
341  // Returns all selected regions in the canvas' selected region list. This
342  // list will contain all user-selected regions since either its
343  // construction or the last call to clearSelectedRegions().
344  std::vector<PlotRegion> allSelectedRegions();
345 
346  // Clears the canvas' list of selected regions.
347  void clearSelectedRegions();
348 
349 
350  // Export Methods
351 
352  // Show a file chooser dialog with the given optional window title and
353  // starting directory. Returns the absolute filename that the user
354  // selected, or an empty casacore::String if they pushed "Cancel".
355  casacore::String fileChooserDialog(const casacore::String& title = "File Chooser",
356  const casacore::String& directory = "");
357 
358  // Exports the plotter to a PDF file at the given location. If highQuality
359  // is false, a screenshot-like export is used. Dots per inch can be set
360  // using dpi.
361  bool exportPDF(const casacore::String& location, bool highQuality = false,
362  int dpi = -1);
363 
364  // Exports the plotter to a PS file at the given location. If highQuality
365  // is false, a screenshot-like export is used. Dots per inch can be set
366  // using dpi.
367  bool exportPS(const casacore::String& location, bool highQuality = false,
368  int dpi = -1);
369 
370  // Exports the plotter to a JPG file at the given location. If highQuality
371  // is false, a screenshot-like export is used. Width and height of the
372  // image can be set.
373  bool exportJPG(const casacore::String& location, bool highQuality = false,
374  int width = -1, int height = -1);
375 
376  // Exports the plotter to a PNG file at the given location. If highQuality
377  // is false, a screenshot-like export is used. Width and height of the
378  // image can be set.
379  bool exportPNG(const casacore::String& location, bool highQuality = false,
380  int width = -1, int height = -1);
381 
382  // Exports the plotter using the given format.
383  bool exportToFile(const PlotExportFormat& format);
384 
385 private:
386  // Factory
388 
389  // Plotter, with single canvas
391 
392  // Canvas
394 
395  // Mouse tools
396  PlotStandardMouseToolGroupPtr m_mouseTools;
397 
398  // Points accumulated using plotPoint calls.
399  std::vector<PlotPointPtr> m_accumulatedPoints;
400 
401  // Line for future plots.
403 
404  // Symbol for future plots and points.
406 
407  // Area fill for future histograms, shapes, etc.
409 };
410 
412 
413 }
414 
415 #endif /*SIMPLEPLOTTER_H_*/
PlotLinePtr m_line
Line for future plots.
~SimplePlotter()
Destructor.
bool exportPNG(const casacore::String &location, bool highQuality=false, int width=-1, int height=-1)
Exports the plotter to a PNG file at the given location.
void clearSelectedRegions()
Clears the canvas&#39; list of selected regions.
void showCartesianAxes(bool show=true)
Show/hide Cartesian axes.
casacore::String fileChooserDialog(const casacore::String &title="File Chooser", const casacore::String &directory="")
Export Methods.
BarPlotPtr barPlot(double *&x, double *&y, unsigned int n, bool overplot=false)
Display a bar plot for the given data, using the current line and area fill.
void setLine(const casacore::String &color, PlotLine::Style style=PlotLine::SOLID, double width=1.0)
Set the line for future plots to the given characteristics.
PlotFactoryPtr getFactory()
Accessor methods.
Definition: SimplePlotter.h:51
void showDefaultExportTools(bool show=true)
Show or hide default &quot;export tools&quot; panel - i.e., saving to a file.
casacore::CountedPtr< SimplePlotter > SimplePlotterPtr
bool exportPS(const casacore::String &location, bool highQuality=false, int dpi=-1)
Exports the plotter to a PS file at the given location.
PlotAreaFillPtr getAreaFill()
Returns the current PlotAreaFill used for shapes, histograms, etc.
Definition: SimplePlotter.h:66
BarPlotPtr histogramPlot(double *&data, unsigned int n, unsigned int numBins, bool overplot=false)
Display a histogram for the given data in the given number of bins, using the current line and area f...
PlotterPtr m_plotter
Plotter, with single canvas.
SMART POINTER DEFINITIONS PlotItemPtr PlotShapeLinePtr
Definition: PlotShape.h:378
void setAxesAutoRescale(bool on=true)
When future items are added to the canvas, automatically rescale the axes to show all items...
PlotShapeArrowPtr lineSegment(double xFrom, double yFrom, double xTo, double yTo)
Draw a line segment from the given point to the given point.
PlotShapeEllipsePtr ellipse(double centerX, double centerY, double xRadius, double yRadius)
Draw an ellipse with the given point as the center and the given x and y radii.
void setWindowTitle(const casacore::String &windowTitle)
Plotter customization.
A 2-D Specialization of the Array class.
Pattern
Pattern enum, similar in spirit to http://doc.trolltech.com/4.3/qt.html#BrushStyle-enum.
Definition: PlotOptions.h:300
SMART POINTER DEFINITIONS PlotShapeEllipsePtr
Definition: PlotShape.h:374
void setXAxisRange(double from, double to)
Implies setAxesAutoRescale(false)
size_t size() const
void show(const variant &v)
PlotFactoryPtr m_factory
Factory.
ABSTRACT CLASSES Deliberately vague to be general enough to allow for many different types of data
Definition: PlotData.h:48
TableExprNode pattern(const TableExprNode &node)
Definition: ExprNode.h:1444
void showLines(bool showLines=true)
Plot customization.
PlotPointPtr plotPoint(double x, double y)
Plot a point at the given location, using the current symbol.
ScatterPlotPtr ploty(double *&y, unsigned int n, bool overplot=true)
PlotStandardMouseToolGroupPtr m_mouseTools
Mouse tools.
void clear()
Clearing Methods.
PlotCanvasPtr m_canvas
Canvas.
PlotCanvasPtr getCanvas()
Returns the PlotCanvas.
Definition: SimplePlotter.h:57
bool exportPDF(const casacore::String &location, bool highQuality=false, int dpi=-1)
Exports the plotter to a PDF file at the given location.
void showDefaultHandTools(bool show=true)
Interaction Methods.
PlotShapeLinePtr xLine(double value)
Draw a line at the given x value.
ScatterPlotPtr plotxy(double *&x, double *&y, unsigned int n, bool overplot=true)
Plotting methods.
void rescaleAxes()
Automatically rescale the axes to show all items on the canvas.
RasterPlotPtr contourPlot(casacore::Matrix< double > &data, casacore::Vector< double > &contours, bool overplot=false)
PlotAnnotationPtr annotation(double x, double y, const casacore::String &text)
Shapes, Annotations, etc.
void setSymbol(PlotSymbol::Symbol symbol, const casacore::String &color="blue", double size=5, bool outline=true)
Set the symbol for future plots and points to the given characteristics.
PlotLinePtr getLine()
Returns the current PlotLine used to draw the plots.
Definition: SimplePlotter.h:60
Style
Static //.
Definition: PlotOptions.h:373
void setAreaFill(const casacore::String &color, PlotAreaFill::Pattern pattern=PlotAreaFill::FILL)
Set the area fill for future histograms, shapes, etc.
PlotShapeLinePtr yLine(double value)
Draw a line at the given y value.
bool exportToFile(const PlotExportFormat &format)
Exports the plotter using the given format.
void setAxesLabels(const casacore::String &xLabel, const casacore::String &yLabel)
Sets the X_BOTTOM and Y_LEFT axes labels to the given.
RasterPlotPtr spectrogram(casacore::Matrix< double > &data, bool overplt=false)
PlotExportFormat contains parameters for exporting a canvas to a file.
Definition: PlotOptions.h:817
bool exportJPG(const casacore::String &location, bool highQuality=false, int width=-1, int height=-1)
Exports the plotter to a JPG file at the given location.
ScatterPlotPtr
Definition: Plot.h:598
PlotShapeRectanglePtr rectangle(double left, double top, double right, double bottom)
Draw a rectangle from the given upper left point to the given lower right point.
std::vector< PlotRegion > allSelectedRegions()
Returns all selected regions in the canvas&#39; selected region list.
void holdDrawing()
Holds/Releases drawing on the canvas.
void clearPoints()
Clear just the points that have been accumulated using plotPoint calls.
RasterPlotPtr rasterPlot(casacore::Matrix< double > &data, bool overplot=false)
Display a raster or contour plot for the given data, using the current line for the contours if appli...
std::vector< PlotPointPtr > m_accumulatedPoints
Points accumulated using plotPoint calls.
Symbol
Static //.
Definition: PlotOptions.h:456
PlotShapeArrowPtr arrow(double xFrom, double yFrom, double xTo, double yTo)
Draw an arrow from the given point to the given point.
PlotAreaFillPtr m_areaFill
Area fill for future histograms, shapes, etc.
void setCanvasTitle(const casacore::String &canvasTitle)
Sets the title of the canvas to the given.
SimplePlotter is a concrete class that uses the abstract plotting classes to perform common tasks...
Definition: SimplePlotter.h:39
String: the storage and methods of handling collections of characters.
Definition: String.h:223
int execLoop()
Execution methods.
void setYAxisRange(double from, double to)
Implies setAxesAutoRescale(false)
void showSymbols(bool showSymbols=true)
Turns symbols on or off for future plots and points.
ABSTRACT CLASSES Abstract class for colors Any implementation of color should be able to provide a hexadecimal form of the color(i.e.,"000000"for black) and
virtual unsigned int numBins() const =0
ABSTRACT METHODS //.
PlotSymbolPtr m_symbol
Symbol for future plots and points.
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.
PlotterPtr getPlotter()
Returns the Plotter.
Definition: SimplePlotter.h:54
PlotSymbolPtr getSymbol()
Returns the current PlotSymbol used for the plots and points.
Definition: SimplePlotter.h:63
SimplePlotter(PlotFactoryPtr factory)
Constructor that takes a factory to build plotting objects.