casa
$Rev:20696$
|
00001 //# Copyright (C) 2005 00002 //# Associated Universities, Inc. Washington DC, USA. 00003 //# 00004 //# This library is free software; you can redistribute it and/or modify it 00005 //# under the terms of the GNU Library General Public License as published by 00006 //# the Free Software Foundation; either version 2 of the License, or (at your 00007 //# option) any later version. 00008 //# 00009 //# This library is distributed in the hope that it will be useful, but WITHOUT 00010 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00011 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00012 //# License for more details. 00013 //# 00014 //# You should have received a copy of the GNU Library General Public License 00015 //# along with this library; if not, write to the Free Software Foundation, 00016 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00017 //# 00018 //# Correspondence concerning AIPS++ should be addressed as follows: 00019 //# Internet email: aips2-request@nrao.edu. 00020 //# Postal address: AIPS++ Project Office 00021 //# National Radio Astronomy Observatory 00022 //# 520 Edgemont Road 00023 //# Charlottesville, VA 22903-2475 USA 00024 //# 00025 00026 #ifndef QtProfile_H 00027 #define QtProfile_H 00028 00029 #include <casa/aips.h> 00030 #include <casa/BasicSL/String.h> 00031 #include <casa/Containers/Record.h> 00032 #include <casa/Arrays/Array.h> 00033 #include <casa/Arrays/ArrayMath.h> 00034 #include <casa/Arrays/Vector.h> 00035 #include <casa/Arrays/Matrix.h> 00036 #include <casa/Inputs/Input.h> 00037 #include <casa/Arrays/IPosition.h> 00038 #include <display/QtPlotter/ProfileTaskMonitor.h> 00039 #include <display/QtPlotter/canvasMode/CanvasMode.h> 00040 #include <display/DisplayEvents/MWCCrosshairTool.h> 00041 #include <display/QtPlotter/QtMWCTools.qo.h> 00042 00043 #include <display/Display/PanelDisplay.h> 00044 #include <display/Utilities/Lowlevel.h> 00045 00046 #include <images/Regions/ImageRegion.h> 00047 #include <images/Images/ImageInterface.h> 00048 #include <measures/Measures/Stokes.h> 00049 #include <imageanalysis/ImageAnalysis/ImageAnalysis.h> 00050 #include <imageanalysis/ImageAnalysis/SpectralCollapser.h> 00051 00052 #include <display/region/Region.qo.h> 00053 00054 #include <graphics/X11/X_enter.h> 00055 #include <QDir> 00056 #include <QColor> 00057 #include <QHash> 00058 #include <QMainWindow> 00059 #include <QMouseEvent> 00060 #include <QToolButton> 00061 #include <QDialog> 00062 #include <QCheckBox> 00063 #include <QPixmap> 00064 #include <QLineEdit> 00065 #include <QComboBox> 00066 #include <map> 00067 #include <vector> 00068 #include <QHash> 00069 #include <QHashIterator> 00070 #include <graphics/X11/X_exit.h> 00071 #include <display/QtPlotter/QtProfileGUI.ui.h> 00072 00073 inline void initPlotterResource() { Q_INIT_RESOURCE(QtPlotter); } 00074 00075 00076 namespace casa { 00077 00078 class QtProfilePrefs; 00079 class ColorSummaryWidget; 00080 class LegendPreferences; 00081 class QtCanvas; 00082 00083 //Note: The purpose of the SpecFitMonitor interface is to provide 00084 //a communications interface between the class doing spectral line 00085 //fitting and this class. By using an interface, we can decouple 00086 //this class and the class doing the work of spectral fitting as 00087 //much as possible. 00088 00089 class QtProfile : public QMainWindow, Ui::QtProfileGUI, public ProfileTaskMonitor 00090 { 00091 Q_OBJECT 00092 00093 public: 00094 enum ExtrType { 00095 MEAN =0, 00096 MEDIAN =1, 00097 SUM =2, 00098 MSE =3, 00099 RMSE =4, 00100 SQRTSUM =5, 00101 NSQRTSUM =6, 00102 FLUX =7, 00103 EFLUX =8, 00104 }; 00105 00106 enum PlotType { 00107 PMEAN, 00108 PMEDIAN, 00109 PSUM, 00110 //PVRMSE, 00111 PFLUX=7, 00112 }; 00113 00114 enum ErrorType { 00115 PNOERROR, 00116 PERMSE, 00117 PPROPAG 00118 }; 00119 00120 00121 00122 QtProfile(ImageInterface<Float>* img, const char *name = 0, 00123 QWidget *parent = 0, std::string rcstr="prf"); 00124 00125 ~QtProfile(); 00126 MFrequency::Types determineRefFrame( ImageInterface<Float>* img, bool check_native_frame = false ); 00127 00128 virtual std::string rcid( ) const { return rcid_; } 00129 void setPath( QString filePath ){ 00130 imagePath = filePath; 00131 } 00132 00133 00134 //Allows the profiler to come up specialized to do spectroscopy 00135 //or another task. 00136 void setPurpose( ProfileTaskMonitor::PURPOSE purpose ); 00137 00138 //These methods are from the ProfileTaskMoniter interface. 00139 //Their purpose is to provide the class doing the spectral 00140 //profile fitting with initial input values, to inform 00141 //this class of status and log messages indicated the result 00142 //of a spectral fit, and to perform moments/collapsing. 00143 void postStatus( String status ); 00144 Vector<Float> getXValues() const; 00145 Vector<Float> getYValues() const; 00146 Vector<Float> getZValues() const; 00147 QString getYUnit() const; 00148 QString getYUnitPrefix() const; 00149 String getXAxisUnit() const; 00150 QString getFileName() const; 00151 QString getImagePath() const; 00152 const ImageInterface<Float>* getImage( const QString& imageName="") const; 00153 const void getPixelBounds(Vector<double>& pixelX, Vector<double>& pixelY) const; 00154 void persist( const QString& key, const QString& value ); 00155 QString read( const QString & key ) const; 00156 void imageCollapsed(String path, String dataType, String displayType, Bool autoRegister, Bool tmpData, ImageInterface<Float>* img); 00157 void setPosition( const QList<double>& xValues, const QList<double>& yValues ); 00158 void processTrackRecord( const String& dataName, const String& positionInfo ); 00159 public slots: 00160 void zoomIn(); 00161 void zoomOut(); 00162 void zoomNeutral(); 00163 void print(); 00164 void saveGraphic(); 00165 void printExp(); 00166 void saveExp(); 00167 void exportProfile(); 00168 void up(); 00169 void down(); 00170 void left(); 00171 void right(); 00172 void preferences(); 00173 void frameChanged( int ); 00174 void setPreferences(bool stateAutoX, bool stateAutoY, int showGrid, 00175 int stateMProf, int stateRel, bool showToolTips, bool showTopAxis, 00176 bool displayStepFunction, bool opticalFitter, bool showChannelLine ); 00177 void curveColorPreferences(); 00178 void legendPreferences(); 00179 void togglePalette( int modeIndex ); 00180 00181 void setPlotError(int); 00182 void changeCoordinate(const QString &text); 00183 void changeFrame(const QString &text); 00184 00185 void changeCoordinateType( const QString & text ); 00186 00187 void changeTopAxisCoordinateType( const QString & text ); 00188 virtual void closeEvent ( QCloseEvent *); 00189 void resetProfile(ImageInterface<Float>* img, const char *name = 0); 00190 void wcChanged( const String, 00191 const Vector<Double>, const Vector<Double>, 00192 const Vector<Double>, const Vector<Double>, 00193 const ProfileType); 00194 void redraw( ); 00195 void changePlotType(const QString &text); 00196 void changeErrorType(const QString &text); 00197 00198 void changeAxisOld(String xa, String ya, String za, std::vector<int>); 00199 void changeAxis(String xa, String ya, String za, std::vector<int>); 00200 void changeSpectrum(String spcTypeUnit, String spcRval, String spcSys); 00201 00202 void plotMainCurve(); 00203 void setCollapseRange(double xmin, double xmax); 00204 00205 void overplot(QHash<QString, ImageInterface<float>*>); 00206 00207 void newRegion( int, const QString &shape, const QString &name, 00208 const QList<double> &world_x, const QList<double> &world_y, 00209 const QList<int> &pixel_x, const QList<int> &pixel_y, 00210 const QString &linecolor, const QString &text, const QString &font, int fontsize, int fontstyle ); 00211 00212 void updateRegion( int, viewer::region::RegionChanges, 00213 const QList<double> &world_x, const QList<double> &world_y, 00214 const QList<int> &pixel_x, const QList<int> &pixel_y ); 00215 void pixelsChanged(int, int ); 00216 void clearPaletteModes(); 00217 00218 signals: 00219 void hideProfile(); 00220 void coordinateChange(const String&); 00221 void showCollapsedImg(String path, String dataType, String displayType, Bool autoRegister, Bool tmpData, ImageInterface<Float>* img); 00222 void channelSelect( int channelIndex ); 00223 void adjustPosition( double tlcx, double tlcy, double brcx, double brcy ); 00224 void movieChannel( int startChannel, int endChannel ); 00225 00226 private: 00227 void stringToPlotType(const QString &text, QtProfile::PlotType &pType); 00228 void stringToErrorType(const QString &text, QtProfile::ErrorType &eType); 00229 void fillPlotTypes(const ImageInterface<Float>* img); 00230 void getcoordTypeUnit(String &ctypeUnitStr, String &cTypeStr, String &unitStr); 00231 void printIt(QPrinter*); 00232 bool exportASCIISpectrum(QString &fn); 00233 bool exportFITSSpectrum(QString &fn); 00234 void messageFromProfile(QString &msg); 00235 void setUnitsText( String unitStr ); 00236 void resetYUnits( const QString& units); 00237 00242 bool isAxisAscending(const Vector<Float>& axisValues ) const; 00243 00244 void setTitle( const QString& shape ); 00245 void copyToLastEvent( const String& c, const Vector<Double> &px, 00246 const Vector<Double> &py, 00247 const Vector<Double> &wx, 00248 const Vector<Double> &wy ); 00249 void setPlotType( int wcArraySize ); 00250 bool checkCube(); 00251 void assignCoordinate(const String& c); 00252 void initializeCoordinateVectors(const Vector<double> &px, const Vector<double> &py, 00253 const Vector<double> &wx, const Vector<double> &wy, Vector<double> &pxv, 00254 Vector<double> &pyv, Vector<double> &wxv, Vector<double> &wyv) const; 00255 void setPositionStatus(const Vector<double> &pxv, const Vector<double> &pyv, 00256 const Vector<double> &wxv, const Vector<double> &wyv ); 00257 bool getFrequencyProfileWrapper( const Vector<double> &wxv, const Vector<double> &wyv, 00258 Vector<Float> &z_xval, Vector<Float> &z_yval, 00259 const String& xytype, const String& specaxis, 00260 const Int& whichStokes, const Int& whichTabular, 00261 const Int& whichLinear, const String& xunits, 00262 const String& specFrame, const Int &combineType, 00263 const Int& whichQuality, const String& restValue ); 00264 bool assignFrequencyProfile( const Vector<double> &wxv, const Vector<double> &wyv, 00265 const String& coordinateType, const String& xAxisUnit, 00266 Vector<Float> &z_xval, Vector<Float> &z_yval ); 00267 bool setErrorPlotting( const Vector<double> &wxv, const Vector<double> &wyv); 00268 void storeCoordinates( const Vector<double> pxv, const Vector<double> pyv, 00269 const Vector<double> wxv, const Vector<double> wyv ); 00270 void addCanvasMainCurve( const Vector<Float>& xVals, const Vector<Float>& yVals, 00271 const QString& label ); 00272 void adjustTopAxisSettings(); 00273 void setPixelCanvasYUnits( const QString& yUnitPrefix, const QString& yUnit ); 00274 void toggleAction( QAction* action ); 00275 Int scaleAxis(); 00276 void addImageAnalysisGraph( const Vector<double> &wxv, const Vector<double> &wyv, Int ordersOfM ); 00277 void initializeSolidAngle() const; 00278 //Conversion 00279 QString getRaDec(double x, double y); 00280 00281 //Finds the channel index closest to the passed in value. 00282 int findNearestChannel( float xval ) const; 00283 void initPreferences(); 00284 void updateAxisUnitCombo( const QString& textToMatch, QComboBox* axisUnitCombo ); 00285 void setYUnitConversionVisibility( bool visible ); 00286 ImageAnalysis* analysis; 00287 ImageInterface<Float>* image; 00288 00289 QHash<QString, ImageAnalysis*> *over; 00290 const String WORLD_COORDINATES; 00291 String coordinate; 00292 String coordinateType; 00293 String xaxisUnit; 00294 String ctypeUnit; 00295 String spcRefFrame; 00296 String cSysRval; 00297 QString fileName; 00298 QString imagePath; 00299 QString position; 00300 QString yUnit; 00301 QString yUnitPrefix; 00302 00303 QString xpos; 00304 QString ypos; 00305 int cube; 00306 00307 int npoints; 00308 int npoints_old; 00309 00310 int stateMProf; 00311 int stateRel; 00312 00313 Vector<Float> z_xval; 00314 Vector<Float> z_yval; 00315 Vector<Double> lastPX, lastPY; 00316 Vector<Double> lastWX, lastWY; 00317 Vector<Float> z_eval; 00318 QString region; 00319 00320 String last_event_cs; 00321 Vector<Double> last_event_px, last_event_py; 00322 Vector<Double> last_event_wx, last_event_wy; 00323 00324 // connection to rc file 00325 Casarc &rc; 00326 // rc id for this panel type 00327 std::string rcid_; 00328 00329 QtProfile::PlotType itsPlotType; 00330 QtProfile::ErrorType itsErrorType; 00331 00332 LogIO *itsLog; 00333 Int ordersOfM_; 00334 Bool newCollapseVals; 00335 00336 static const QString PLOT_TYPE_FLUX; 00337 static const QString PLOT_TYPE_MEAN; 00338 static const QString PLOT_TYPE_MEDIAN; 00339 static const QString PLOT_TYPE_SUM; 00340 00341 class spectra_info { 00342 public: 00343 spectra_info( ) { } 00344 spectra_info( const QString &s ) : shape_(s) { } 00345 spectra_info( const spectra_info &other ) : shape_(other.shape_) { } 00346 const spectra_info &operator=( const spectra_info &other ) { shape_ = other.shape_; return *this; } 00347 const QString &shape( ) { return shape_; } 00348 private: 00349 QString shape_; 00350 }; 00351 00352 00353 typedef std::map<int,spectra_info> SpectraInfoMap; 00354 const int NO_REGION_ID; 00355 int current_region_id; 00356 SpectraInfoMap spectra_info_map; 00357 00358 00359 ColorSummaryWidget* colorSummaryWidget; 00360 LegendPreferences* legendPreferencesDialog; 00361 QtCanvas* pixelCanvas; 00362 QtProfilePrefs* profilePrefs; 00363 int frameIndex; 00364 bool newOverplots; 00365 pair<double,double> getMaximumTemperature(); 00366 void postConversionWarning( QString unitStr); 00367 void adjustPlotUnits( ); 00368 private slots: 00369 void changeTopAxis(); 00370 void updateXAxisLabel( const QString &text, QtPlotSettings::AxisIndex axisIndex ); 00371 void setDisplayYUnits( const QString& unitStr ); 00372 void channelSelect(float xval); 00373 void channelRangeSelect( float channelStart, float channelEnd ); 00374 00375 00376 }; 00377 00378 } 00379 #endif 00380