QtProfile.qo.h

Go to the documentation of this file.
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 #include <imageanalysis/ImageAnalysis/ImageCollapserData.h>
00052 
00053 #include <display/region/Region.qo.h>
00054 
00055 #include <graphics/X11/X_enter.h>
00056 #include <QDir>
00057 #include <QColor>
00058 #include <QHash>
00059 #include <QMainWindow>
00060 #include <QMouseEvent>
00061 #include <QToolButton>
00062 #include <QDialog>
00063 #include <QCheckBox>
00064 #include <QPixmap>
00065 #include <QLineEdit>
00066 #include <QComboBox>
00067 #include <map>
00068 #include <vector>
00069 #include <QHash>
00070 #include <QHashIterator>
00071 #include <graphics/X11/X_exit.h>
00072 #include <display/QtPlotter/QtProfileGUI.ui.h>
00073 
00074 inline void initPlotterResource() {
00075         Q_INIT_RESOURCE(QtPlotter);
00076 }
00077 
00078 
00079 namespace casa {
00080 
00081         class QtProfilePrefs;
00082         class ColorSummaryWidget;
00083         class LegendPreferences;
00084         class SmoothPreferences;
00085         class QtCanvas;
00086 
00087 //Note:  The purpose of the SpecFitMonitor interface is to provide
00088 //a communications interface between the class doing spectral line
00089 //fitting and this class.  By using an interface, we can decouple
00090 //this class and the class doing the work of spectral fitting as
00091 //much as possible.
00092 
00093         class QtProfile : public QMainWindow, Ui::QtProfileGUI, public ProfileTaskMonitor {
00094                 Q_OBJECT
00095 
00096         public:
00097                 enum ExtrType {
00098                     MEAN     =ImageCollapserData::MEAN,
00099                     MEDIAN   =ImageCollapserData::MEDIAN,
00100                     SUM      =ImageCollapserData::SUM,
00101                     MSE      =ImageCollapserData::VARIANCE,
00102                     RMSE     =ImageCollapserData::STDDEV,
00103                     SQRTSUM  =ImageCollapserData::SQRTSUM,
00104                     NSQRTSUM =ImageCollapserData::SQRTSUM_NPIX,
00105                     FLUX     =ImageCollapserData::FLUX,
00106                     EFLUX    =ImageCollapserData::SQRTSUM_NPIX_BEAM
00107                 };
00108 
00109                 enum PlotType {
00110                     PMEAN = MEAN,
00111                     PMEDIAN = MEDIAN,
00112                     PSUM = SUM,
00113                     //PVRMSE,
00114                     PFLUX=FLUX,
00115                 };
00116 
00117                 enum ErrorType {
00118                     PNOERROR,
00119                     PERMSE,
00120                     PPROPAG
00121                 };
00122 
00123 
00124 
00125                 QtProfile(SHARED_PTR<ImageInterface<Float> > img, const char *name = 0,
00126                           QWidget *parent = 0, std::string rcstr="prf");
00127 
00128                 ~QtProfile();
00129                 MFrequency::Types determineRefFrame(SHARED_PTR<ImageInterface<Float> > img, bool check_native_frame = false );
00130 
00131                 virtual std::string rcid( ) const {
00132                         return rcid_;
00133                 }
00134                 void setPath( QString filePath ) {
00135                         imagePath = filePath;
00136                 }
00137 
00138                 //Allows the profiler to come up specialized to do spectroscopy
00139                 //or another task.
00140                 void setPurpose( ProfileTaskMonitor::PURPOSE purpose );
00141 
00142                 //These methods are from the ProfileTaskMoniter interface.
00143                 //Their purpose is to provide the class doing the spectral
00144                 //profile fitting with initial input values, to inform
00145                 //this class of status and log messages indicated the result
00146                 //of a spectral fit, and to perform moments/collapsing.
00147                 void postStatus( String status );
00148                 Vector<Float> getXValues() const;
00149                 Vector<Float> getYValues() const;
00150                 Vector<Float> getZValues() const;
00151                 Vector<Double> getRegionXValues() const;
00152                 Vector<Double> getRegionYValues() const;
00153                 QString getYUnit() const;
00154                 QString getYUnitPrefix() const;
00155                 String getXAxisUnit() const;
00156                 QString getFileName() const;
00157                 QString getImagePath() const;
00158                 String getRegionShape() const;
00159                 SHARED_PTR<const ImageInterface<Float> > getImage( const QString& imageName="") const;
00160                 virtual bool getBeamInfo( const QString& curveName, Double& beamAngle, Double& beamArea ) const;
00161                 void getPixelBounds(Vector<double>& pixelX, Vector<double>& pixelY) const;
00162                 void persist( const QString& key, const QString& value );
00163                 QString read( const QString & key ) const;
00164                 void imageCollapsed(String path, String dataType, String displayType,
00165                                 Bool autoRegister, Bool tmpData, SHARED_PTR<ImageInterface<Float> > img);
00166                 void setPosition( const QList<double>& xValues, const QList<double>& yValues );
00167                 void processTrackRecord( const String& dataName, const String& positionInfo );
00168                 virtual MFrequency::Types getReferenceFrame() const;
00169                 QString getBrightnessUnit( SHARED_PTR<ImageInterface<Float> > img ) const;
00170                 typedef std::pair<QString, SHARED_PTR<ImageInterface<float> > > OverplotInterface;
00171                 //typedef pair<QString,ImageAnalysis*> OverplotAnalysis;
00172 
00173                 static const String SHAPE_ELLIPSE;
00174                 static const String SHAPE_RECTANGLE;
00175                 static const String SHAPE_POINT;
00176                 static const String SHAPE_POLY;
00177                 static const QString FREQUENCY;
00178                 static const QString CHANNEL;
00179 
00180         public slots:
00181                 void zoomIn();
00182                 void zoomOut();
00183                 void zoomNeutral();
00184                 void print();
00185                 void saveGraphic();
00186                 void printExp();
00187                 void saveExp();
00188                 void exportProfile();
00189                 void up();
00190                 void down();
00191                 void left();
00192                 void right();
00193                 void preferences();
00194                 void frameChanged( int );
00195                 void setPreferences(bool stateAutoX, bool stateAutoY, int showGrid,
00196                                     int stateMProf, int stateRel, bool showToolTips, bool showTopAxis,
00197                                     bool displayStepFunction, bool opticalFitter,
00198                                     bool showChannelLine, bool singleChannelImage );
00199                 void curveColorPreferences();
00200                 void legendPreferences();
00201                 void togglePalette( int modeIndex );
00202 
00203                 void setPlotError(int);
00204                 void changeCoordinate(const QString &text);
00205                 void changeFrame(const QString &text);
00206 
00207                 void changeCoordinateType( const QString & text );
00208 
00209                 void changeTopAxisCoordinateType( const QString & text );
00210                 virtual void closeEvent ( QCloseEvent *);
00211                 void resetProfile(SHARED_PTR<ImageInterface<Float> > img, const char *name = 0);
00212                 void wcChanged( const String,
00213                                 const Vector<Double>, const Vector<Double>,
00214                                 const Vector<Double>, const Vector<Double>,
00215                                 const ProfileType);
00216                 void redraw( );
00217                 void changePlotType(const QString &text);
00218                 void changeErrorType(const QString &text);
00219 
00220                 void changeAxis(String xa, String ya, String za, std::vector<int>);
00221                 void changeSpectrum(String spcTypeUnit, String spcRval, String spcSys);
00222 
00223                 void plotMainCurve();
00224                 void clearPlots();
00225                 void setCollapseRange(double xmin, double xmax);
00226 
00227                 void overplot(QList<OverplotInterface>);
00228 
00229                 void newRegion( int, const QString &shape, const QString &name,
00230                                 const QList<double> &world_x, const QList<double> &world_y,
00231                                 const QList<int> &pixel_x, const QList<int> &pixel_y,
00232                                 const QString &linecolor, const QString &text, const QString &font, int fontsize, int fontstyle );
00233 
00234                 void updateRegion( int, viewer::region::RegionChanges,
00235                                    const QList<double> &world_x, const QList<double> &world_y,
00236                                    const QList<int> &pixel_x, const QList<int> &pixel_y );
00237                 void pixelsChanged(int, int );
00238                 void clearPaletteModes();
00239 
00243                 bool isImageSupported(SHARED_PTR<ImageInterface<float> > img );
00244 
00245         signals:
00246                 void hideProfile();
00247                 void coordinateChange(const String&);
00248                 void showCollapsedImg(String path, String dataType, String displayType,
00249                                 Bool autoRegister, Bool tmpData, SHARED_PTR<ImageInterface<Float> > img);
00250                 void channelSelect( int channelIndex );
00251                 void adjustPosition( double tlcx, double tlcy, double brcx, double brcy );
00252                 void movieChannel( int startChannel, int endChannel );
00253                 void reloadImages();
00254 
00255         private:
00256                 void stringToPlotType(const QString &text,  QtProfile::PlotType &pType);
00257                 void stringToErrorType(const QString &text, QtProfile::ErrorType &eType);
00258                 void fillPlotTypes(const SHARED_PTR<ImageInterface<Float> > img);
00259                 void getcoordTypeUnit(String &ctypeUnitStr, String &cTypeStr, String &unitStr);
00260                 void printIt(QPrinter*);
00261                 bool exportASCIISpectrum(QString &fn);
00262                 bool exportFITSSpectrum(QString &fn);
00263                 void messageFromProfile(QString &msg);
00264                 void setUnitsText( String unitStr );
00265                 void resetYUnits( const QString& units);
00266                 void outputCurve( int k, QTextStream& ts, Float scaleFactor );
00267                 int getFreqProfileTabularIndex(SHARED_PTR<const ImageInterface<Float> > img);
00268                 SpectralCoordinate resetTabularConversion(SHARED_PTR< const ImageInterface<Float> > imagePtr, Bool& valid);
00269                 bool isSpectralAxis() const;
00270                 void initializeSpectralProperties();
00271                 SpectralCoordinate getSpectralAxis( SHARED_PTR<const ImageInterface<Float> > imagePtr, Bool& valid );
00272                 void resetXUnits( bool spectralAxis);
00273                 void updateSpectralReferenceFrame();
00274 
00275                 int computeCB( const String& xa, const String& ya, const String& za );
00276                 void getBeamInfo( SHARED_PTR<const ImageInterface<Float> > imagePtr, Double& beamArea, Double& beamSolidAngle) const;
00277                 SpectralCoordinate getSpectralCoordinate( SHARED_PTR<const ImageInterface<Float> > imagePtr, Bool& valid );
00278                 bool parseRestFrequency( const String& restStr, Quantity& result ) const;
00279 
00280                 bool generateProfile( Vector<Float>& resultXValues, Vector<Float>& resultYValues,
00281                                         SHARED_PTR<casa::ImageInterface<Float> > imagePtr,
00282                                         const Vector<Double>& regionX, const Vector<Double>& regionY, String shape,
00283                                         QtProfile::ExtrType combineType, String& unit, const String& coordinateType,
00284                                         int qualityAxis, String restFreq="", const String& frame="");
00285 
00286                 pair<Vector<float>, Vector<float> > convertIntensity( const Vector<float>& sourceXVals, const Vector<float>& sourceYVals,
00287                                                         SHARED_PTR<ImageInterface<Float> > imagePtr, const QString& xUnits,
00288                                                         const QString& yUnitsOld, const QString& yUnitsNew );
00289                 void saveAsPDF( const QString& fileName );
00294                 bool isAxisAscending(const Vector<Float>& axisValues ) const;
00295                 bool isVelocityUnit( const QString& unit ) const;
00296                 bool isFrequencyUnit( const QString& unit ) const;
00297                 bool isWavelengthUnit( const QString& unit ) const;
00298                 void setTitle( const QString& shape );
00299                 void setTitle(const ProfileType ptype);
00300                 void copyToLastEvent( const String& c, const Vector<Double> &px,
00301                                       const Vector<Double> &py,
00302                                       const Vector<Double> &wx,
00303                                       const Vector<Double> &wy );
00304                 void setPlotType( int wcArraySize );
00305                 bool checkCube();
00306                 void assignCoordinate(const String& c);
00307                 void initializeCoordinateVectors(const Vector<double> &px, const Vector<double> &py,
00308                                                  const Vector<double> &wx, const Vector<double> &wy, Vector<double> &pxv,
00309                                                  Vector<double> &pyv, Vector<double> &wxv, Vector<double> &wyv) const;
00310                 void setPositionStatus(const Vector<double> &pxv, const Vector<double> &pyv,
00311                                        const Vector<double> &wxv, const Vector<double> &wyv );
00312                 /*bool getFrequencyProfileWrapper( SHARED_PTR<ImageInterface<Float> >& img, const Vector<double> &wxv, const Vector<double> &wyv,
00313                                                  Vector<Float> &z_xval, Vector<Float> &z_yval,
00314                                                  const String& xytype, const String& specaxis,
00315                                                  const Int& whichStokes, const Int& whichTabular,
00316                                                  const Int& whichLinear, String& xunits,
00317                                                  const String& specFrame, QtProfile::ExtrType combineType,
00318                                                  const Int& whichQuality, const String& restValue,
00319                                                  const String& shape);*/
00320                 bool assignFrequencyProfile( const Vector<double> &wxv, const Vector<double> &wyv,
00321                                              const String& coordinateType, String& xAxisUnit,
00322                                              Vector<Float> &z_xval, Vector<Float> &z_yval, const String& shape );
00323                 bool setErrorPlotting( const Vector<double> &wxv, const Vector<double> &wyv);
00324                 void storeCoordinates( const Vector<double> pxv, const Vector<double> pyv,
00325                                        const Vector<double> wxv, const Vector<double> wyv );
00326                 void addCanvasMainCurve( const Vector<Float>& xVals, const Vector<Float>& yVals,
00327                                          const QString& label, double beamAngle, double beamArea,
00328                                          SpectralCoordinate coord);
00329                 bool adjustTopAxisSettings();
00330                 void initializeXAxisUnits();
00331                 void setXAxisUnits();
00332                 void initSmoothing();
00333                 void setPixelCanvasYUnits( const QString& yUnitPrefix, const QString& yUnit );
00334                 void toggleAction( QAction* action );
00335                 Int scaleAxis();
00336                 void addImageAnalysisGraph( const Vector<double> &wxv, const Vector<double> &wyv, Int ordersOfM );
00337                 void initializeSolidAngle() const;
00338                 //Conversion
00339                 QString getRaDec(double x, double y);
00340 
00341                 //Finds the channel index closest to the passed in value.
00342                 int findNearestChannel( float xval ) const;
00343                 void initPreferences();
00344                 void updateAxisUnitCombo( const QString& textToMatch, QComboBox* axisUnitCombo );
00345                 void setYUnitConversionVisibility( bool visible );
00346                 //ImageAnalysis* analysis;
00347                 SHARED_PTR<ImageInterface<Float> > image;
00348 
00349                 //For deciding whether or not it makes sense to show the top axis when
00350                 //multiple images are loaded.
00351                 bool isXUnitsMatch(const QString& matchUnits);
00352                 bool isFrequencyMatch();
00353                 bool isVelocityMatch();
00354                 //int getChannelCount( ImageAnalysis* analysis );
00355                 int getChannelCount( SHARED_PTR<ImageInterface<float> >& img);
00356                 SHARED_PTR<ImageInterface<float> > findImageWithMaximumChannels();
00357                 void restrictTopAxisOptions( bool restrictOptions, const QString& bottomUnits, bool allowFrequency = true,
00358                                 bool allowVelocity=true );
00359                 double getUnitsPerChannel( SHARED_PTR<ImageInterface<Float> > img , bool* ok, const QString& matchUnits );
00360                 QString readTopAxis() const;
00361                 void persistTopAxis( const QString& units );
00362                 void assignProfileType( const String& shape, int regionPointCount );
00363                 void addOverplotToCanvas( SHARED_PTR<ImageInterface<Float> > imagePtr, const Vector<Float>& xVals, const
00364                                         Vector<Float>& yVals, const QString& ky );
00365                 bool isProfileChanged( const String& c, const Vector<Double> & px, const Vector<Double>& py,
00366                                         const Vector<Double>& wx, const Vector<Double>& wy,
00367                                         const ProfileType pType );
00368 
00369                 bool _generateProfile( Vector<Float>& resultXValues, Vector<Float>& resultYValues,
00370                                         SHARED_PTR<const casa::ImageInterface<Float> > imagePtr,
00371                                         const Vector<Double>& regionX, const Vector<Double>& regionY, String shape,
00372                                         QtProfile::ExtrType combineType, String& unit, const String& coordinateType,
00373                                         String restFreq, const String& frame);
00374 
00375                 //Handle custom spectral reference frames such as REST and Undefined
00376                 //for which conversions are not possible.
00377                 bool customizeSpectralReferenceFrame( const QString& specialType );
00378                 QList<OverplotInterface> *over;
00379                 const String WORLD_COORDINATES;
00380                 String coordinate;
00381                 String coordinateType;
00382                 String xaxisUnit;
00383                 String ctypeUnit;
00384                 String spcRefFrame;
00385 
00386                 //Rest frequency quantity and unit.
00387                 String cSysRval;
00388 
00389                 QString fileName;
00390                 QString imagePath;
00391                 QString position;
00392                 QString yUnit;
00393                 QString yUnitPrefix;
00394                 //Holds the available x-axis units
00395                 QStringList xUnitsList;
00396                 QString xpos;
00397                 QString ypos;
00398                 int cube;
00399 
00400                 int npoints;
00401                 int npoints_old;
00402 
00403                 int stateMProf;
00404                 int stateRel;
00405 
00406                 Vector<Float> z_xval;
00407                 Vector<Float> z_yval;
00408                 Vector<Double> lastPX, lastPY;
00409                 Vector<Double> lastWX, lastWY;
00410                 Vector<Float> z_eval;
00411                 QString region;
00412 
00413                 String last_event_cs;
00414                 Vector<Double> last_event_px, last_event_py;
00415                 Vector<Double> last_event_wx, last_event_wy;
00416 
00417                 // connection to rc file
00418                 Casarc &rc;
00419                 // rc id for this panel type
00420                 std::string rcid_;
00421 
00422                 QtProfile::PlotType  itsPlotType;
00423                 QtProfile::ErrorType itsErrorType;
00424 
00425 
00426                 LogIO *itsLog;
00427                 Int ordersOfM_;
00428                 Bool newCollapseVals;
00429                 bool showTopAxis;
00430                 bool showSingleChannelImage;
00431                 static bool topAxisDefaultSet;
00432 
00433                 static const QString PLOT_TYPE_FLUX;
00434                 static const QString PLOT_TYPE_MEAN;
00435                 static const QString PLOT_TYPE_MEDIAN;
00436                 static const QString PLOT_TYPE_SUM;
00437 
00438                 static const QString VELOCITY;
00439                 static const QString OPTICAL;
00440                 static const QString AIR;
00441                 static const QString FRAME_REST;
00442                 static const QString FRAME_NONE;
00443                 static const QString PERSIST_FREQUENCY_BOTTOM;
00444                 static const QString PERSIST_FREQUENCY_TOP;
00445                 static const QString IMAGE_MISSING_ERROR;
00446                 static const QString MISSING_REGION_ERROR;
00447                 static const QString NO_PROFILE_ERROR;
00448                 static const QString REGION_ELLIPSE;
00449                 static const QString REGION_RECTANGLE;
00450                 static const QString REGION_POINT;
00451                 static const QString REGION_POLY;
00452 
00453 
00454                 class spectra_info {
00455                 public:
00456                         spectra_info( ) { }
00457                         spectra_info( const QString &s ) : shape_(s) { }
00458                         spectra_info( const spectra_info &other ) : shape_(other.shape_) { }
00459                         const spectra_info &operator=( const spectra_info &other ) {
00460                                 shape_ = other.shape_;
00461                                 return *this;
00462                         }
00463                         const QString &shape( ) {
00464                                 return shape_;
00465                         }
00466                 private:
00467                         QString shape_;
00468                 };
00469 
00470 
00471                 typedef std::map<int,spectra_info> SpectraInfoMap;
00472                 const int NO_REGION_ID;
00473                 int current_region_id;
00474                 SpectraInfoMap spectra_info_map;
00475                 ProfileType profileType;
00476                 String lastShape;
00477 
00478                 ColorSummaryWidget* colorSummaryWidget;
00479                 LegendPreferences* legendPreferencesDialog;
00480                 QtCanvas* pixelCanvas;
00481                 QtProfilePrefs* profilePrefs;
00482                 SmoothPreferences* smoothWidget;
00483                 int frameIndex;
00484                 bool newOverplots;
00485                 pair<double,double> getMaximumTemperature();
00486                 void postConversionWarning( QString unitStr);
00487                 void adjustPlotUnits( );
00488         private slots:
00489                 void changeTopAxis();
00490                 void updateXAxisLabel( const QString &text, QtPlotSettings::AxisIndex axisIndex );
00491                 void setDisplayYUnits( const QString& unitStr );
00492                 void channelSelect(float xval);
00493                 void channelRangeSelect( float channelStart, float channelEnd );
00494                 void showSmoothingPreferences();
00495                 void replotCurves();
00496         };
00497 
00498 }
00499 #endif
00500 
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1