casa
$Rev:20696$
|
00001 //# TPPlotter.h: Plotter class for the TablePlot (tableplot) tool 00002 //# Copyright (C) 1994,1995,1996,1997,1998,1999,2000,2001,2002,2003-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 receied 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 //# ------------------------------------------------------------------------- 00028 //# CHANGE LOG 00029 //# Date Name Comments 00030 //# 11/11/2006 S. Jaeger Switched to use Matplotlib by default, by 00031 //# removing the AIPS_USEMATPLOTLIB compile flag. 00032 //# This may need to be added back in later, since 00033 //# those using pgplot will be compiling both in. 00034 //# 11/29/2006 S. Jaeger Changed clearplot to allow flagged and 00035 //# unflagged data to be displayed together when 00036 //# the overplot option is set to True. 00037 //# Added pointlabels param to thePlot() and plotXY() 00038 //# to allow point labels to be applied to each layer 00039 //# being plotted. 00040 //# 12/22/2006 Urvashi R.V. Added/Updated code documentation. 00041 //# Modified condition in clearPlot, to allow for 00042 //# correct 'memory' of plot parameters, when a 00043 //# plot is replotted, after flagging. 00044 //# 01/11/2007 Urvashi R.V. Removed PGPLOT. Refactored the data structure 00045 //# that deals with plot parameters per panel and 00046 //# layer. 00047 //# 08/24/2007 Urvashi R.V. Lots of changes + Removed the Python interpreter handing 00048 //# from here into the CasaPyInterpreter class. 00049 00050 #ifndef TPPLOTTER_H 00051 #define TPPLOTTER_H 00052 00053 //# Includes 00054 #include <Python.h> 00055 00056 #include <casa/aips.h> 00057 #include <casa/BasicSL/String.h> 00058 #include <casa/Containers/Record.h> 00059 #include <casa/Arrays/Vector.h> 00060 00061 #include <tableplot/TablePlot/BasePlot.h> 00062 #include <tableplot/TablePlot/PanelParams.h> 00063 #include <tableplot/TablePlot/CasaPyInterpreter.h> 00064 #include <tableplot/TablePlot/SLog.h> 00065 00066 //#include <CCM_Python/PySub.h> 00067 00068 00069 // <summary> 00070 // Plotter class for the TablePlot (tableplot) tool 00071 // </summary> 00072 00073 // <use visibility=export> 00074 00075 // <reviewed reviewer="" date="" tests=""> 00076 // </reviewed> 00077 00078 // <prerequisite> 00079 //#! Classes or concepts you should understand before using this class. 00080 // <li> BasePlot 00081 // <li> PanelParams 00082 // <li> PlotOptions 00083 // <li> CasaPyInterpreter 00084 // <li> Matplotlib, Python-Binding (numarray) 00085 // </prerequisite> 00086 00087 // <etymology> 00088 // TPPlotter is the class that controls all plot operations 00089 // for the TablePlot (TP) class. 00090 // </etymology> 00091 00092 // <synopsis> 00093 // Class TPPlotter is the plotting interface that the TablePlot class 00094 // uses. It has to be used along with the BasePlot and TablePlot classes. 00095 // It currently manages direct binding to Python for the 00096 // matplotlib plotting package. 00097 // 00098 // Other plotting packages can be attached to TPPlotter. 00099 // For this, a set of functions need to be implemented using commands 00100 // pertaining to this other plotting package. The set of functions that need 00101 // to be duplicated are listed in TPPlotter.cc after the heading 00102 // "PLOTTING PACKAGE DEPENDANT FUNCTIONS " and in this file, with the symbol "PPDF" 00103 // </synopsis> 00104 00105 // <example> 00106 // See TablePlot.cc 00107 // </example> 00108 00109 // <motivation> 00110 // This class was written to keep all plotting function calls and 00111 // display window management issues independant of the BasePlot class 00112 // that handles the actual tables. Also if the current plotting 00113 // package has to be replaced, changes need be made only in this one 00114 // class. The TablePlot manipulates the TPPlotter objects. 00115 // </motivation> 00116 00117 // <templating arg=T> 00118 // <li> 00119 // </templating> 00120 00121 // <thrown> 00122 // <li> 00123 // <li> 00124 // </thrown> 00125 00126 00127 // <todo asof="$DATE:$"> 00128 //# A List of bugs, limitations, extensions or planned refinements. 00129 // <li> Figure out how to properly free the PyArrayObject memory : in the destructor. 00130 // </todo> 00131 00132 00133 namespace CCM_Python 00134 { 00135 class Py; 00136 class PySub; 00137 } 00138 00139 namespace casa { //# NAMESPACE CASA - BEGIN 00140 00141 enum {PGPLOT=0, MATPLOTLIB=1}; 00142 00143 class TPPlotter 00144 { 00145 public: 00146 // Default Constructor 00147 TPPlotter(); 00148 00149 // Constructor that is to be used to decide between 00150 // GUI + command-line vs only commmand-line mode. 00151 TPPlotter(Bool usegui); 00152 00153 // Destructor 00154 ~TPPlotter(); 00155 00156 // Set Plotting options from an input record of plot options. 00157 Int setPlotOptions(PtrBlock<PanelParams* > &ppar); 00158 00159 // Read data from Baseplots and plot the data. 00160 // For the chosen panel, this function reads the data from 00161 // all BasePlots in the input list, applies the stored flags, 00162 // and 00163 // (Will be improved to optionally plot with/without applying 00164 // flags, or plotting only flagged or unflagged data) 00165 Int plotData(PtrBlock<BasePlot* > &PBP,Int panel,Int newplot); 00166 00167 // Mark a rectangular region on the chosen panel with two 00168 // mouse clicks at diagonally opposite corners. 00169 // For matplotlib 00170 // This functions responds to a user-controlled rubber-band box 00171 // on the plot, to mark the flag region. 00172 // For pgplot 00173 // This function grabs two mouse click events via the plotting 00174 // package,and draws a hatched rectangle on the plot panel. 00175 // 00176 // It then 00177 // appends the area co-ordinates to a list of flag regions 00178 // maintained per panel in the TPPlotter class. 00179 Int markRegions(Int nrows, Int ncols, Int panel,Vector<Double> ®ion); 00180 00181 // Passes on the list of marked flag regions (created by single 00182 // or multiple calls to MarkFlags) to each of the tables/subtables 00183 // in the input list of BasePlot objects. 00184 // Returns a vector of the number of flags per panel. 00185 Vector<Int> setMarkedRegions(PtrBlock<PtrBlock<BasePlot* >* > &PPBP); 00186 00187 // PPDF : Back door for issuing commands to matplotlib 00188 Int runPlotCommand(String command); 00189 00190 // PPDF : Clear the plot window 00191 Int clearPlot(Int panel=0, Bool delaxes=True); 00192 00193 // Set up the plotter 00194 Int setupPlotter(); 00195 00196 // Change the state of a button 00197 // button : 'iternext','markregion','flag','unflag','locate' 00198 // PPDF : state : 'enable','disable' 00199 Bool changeGuiButtonState(String button, String state); 00200 00201 // function to close the plot window...... 00202 // PPDF : needs to be called just before the destructor. 00203 Bool closeWindow(); 00204 00205 Int show(); //RI 00206 00207 private: 00208 // Consolidate ranges from all BasePlots and set plot range. 00209 // For the chosen panel, this function queries all the 00210 // BasePlot objects held in the input list for the ranges 00211 // of data being plotted from each BasePlot object. It then 00212 // combines these ranges along with zooming ranges (if applicable) 00213 // to create the final world-coordinate plot range for the 00214 // panel. 00215 Int setPlotRange(PtrBlock<BasePlot* > &PBP,Int panel); 00216 00217 // Do the actual plotting. Read xdata,ydata,flags from the input 00218 // BasePlot object, accumulate data-to-be-plotted (usually unflagged 00219 // data) into plot arrays and call the plotting package draw routines. 00220 // (Modify (if possible) to not have to accumulate data into 00221 // separate plot arrays before calling the plot draw routines. This 00222 // would be trivial if the plotting package draw routines could work 00223 // with a (Bool) mask.) 00224 Int thePlot(BasePlot &BP,Int panel, Int layer); 00225 00226 // PPDF : Set plot environment parameters for a panel. 00227 // Sets up the viewport and window (world) coordinates from SetFlagRegions 00228 Int startPlot(Int panel, Int newplot); 00229 Int endPlot(Int panel); 00230 00231 // The following are Plotting Package Specific functions. 00232 // If a new plotting package is to be used, these are the 00233 // functions that need 00234 // to be modified. 00235 00236 // PPDF : Initialize the plotter object 00237 Int initPlot(); 00238 00239 // PPDF : Clean up leftovers from the python interpreter. 00240 Int closePlot(); 00241 00242 // PPDF : Set windowsize, aspectratio 00243 Int setWindowOptions(Double windowsize, Double aspectratio); 00244 00245 // PPDF : Set Plot labels from internally stored Vector of label strings. 00246 Int setPlotLabels(Int panel); 00247 00248 // PPDF :Mark a Rectangular region (currently via 2 mouse clicks) and 00249 // draw a hatched rectangle to mark the region. 00250 Int markInteractiveRegion(); 00251 00252 // PPDF : Read in the user-selected flag regions from the plotting device. 00253 Int readInRegions(); 00254 00255 // PPDF : Manage memory for plot arrays into which data-to-be-plotted is 00256 // accumulated while plotting. 00257 Int allocPlotArrays(Int size); 00258 Int fillPlotArrays(Double xvalue, Double yvalue, Int index); 00259 Int resizePlotArrays(Int numpoints); 00260 00261 // PPDF : Call the plotting function draw routines. 00262 Int plotXY(Int panel, Int layer, Int colour); 00263 00264 // Adjust the plot range 00265 Int adjustPlotRange(Int panel); 00266 00267 // Exceptions ! 00268 void TPPlotterError(String msg); 00269 00270 Int PlotPackage_p; 00271 00272 // Execute and check python commands 00273 CasaPyInterpreter *PyInterp_p; 00274 00275 // Pointers for PyArrayObject. 00276 PyObject *px_p,*py_p; 00277 Int nelem_p; 00278 Vector<String> pointlabels_p; 00279 Vector<Vector<Int> > layernplots_p; 00280 00281 Double Xmin_p, Xmax_p, Ymin_p, Ymax_p; 00282 Int pcnt_p, totalpcnt_p, totalflagpcnt_p; 00283 Double oldwindowsize_p,oldaspectratio_p; 00284 00285 Int nflagmarks_p; 00286 00287 Timer tmr,tmr1,tmr2; 00288 Double tcount1,tcount2,tcount3,tcount4,tcount5; 00289 00290 SLog* log; 00291 static String clname; 00292 00293 // PlotOption and Panel-specific parameters. 00294 PtrBlock<PanelParams*> PPar_p; 00295 00296 Bool usegui_p; 00297 00298 }; 00299 00300 00301 } //# NAMESPACE CASA - END 00302 00303 #endif 00304