Profile2dDD.h

Go to the documentation of this file.
00001 //# Profile2dDD.h: 2D Profile DisplayData
00002 //# Copyright (C) 2003,2004
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 
00028 #ifndef TRIALDISPLAY_PROFILE2DDD_H
00029 #define TRIALDISPLAY_PROFILE2DDD_H
00030 
00031 #include <casa/aips.h>
00032 #include <casa/Arrays/Array.h>
00033 #include <casa/Arrays/Vector.h>
00034 #include <casa/Arrays/Matrix.h>
00035 #include <display/Display/DParameterColorChoice.h>
00036 #include <display/Display/DParameterFontChoice.h>
00037 #include <display/Display/DParameterMapKeyChoice.h>
00038 #include <display/Display/DParameterRange.h>
00039 #include <display/Display/DParameterSwitch.h>
00040 #include <display/DisplayDatas/ActiveCaching2dDD.h>
00041 #include <display/DisplayCanvas/WCCSNLAxisLabeller.h>
00042 #include <display/DisplayEvents/DisplayEH.h>
00043 #include <lattices/LatticeMath/LatticeStatsBase.h>
00044 
00045 namespace casa { //# NAMESPACE CASA - BEGIN
00046 
00047         template <class T> class LatticePADisplayData;
00048         template <class T> class DParameterRange;
00049 
00050         class WorldCanvas;
00051         class Profile2dDM;
00052         class DParameterColorChoice;
00053         class DParameterMapKeyChoice;
00054         class DParameterSwitch;
00055 
00056 // <summary>
00057 // A DisplayData to draw Profiles
00058 // </summary>
00059 //
00060 // <use visibility=export>
00061 //
00062 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00063 // </reviewed>
00064 //
00065 // <prerequisite>
00066 //   <li> DisplayData
00067 //   <li> CachingDisplayData
00068 //   <li> ActiveCaching2dDD
00069 // </prerequisite>
00070 //
00071 // <etymology> </etymology>
00072 
00073 // <synopsis> This Display Data attaches to itself, another Display
00074 // Data whos profile (at a point) is to be extracted and drawn.  The
00075 // Display Data attached to Profile2dDD must have atleast 3 world Axes
00076 // and atleast 2 pixels on it's profile axis (3rd axis).  An axis from
00077 // a Linear Coordinate or Stokes Coordinate presently can not be on
00078 // the profile axis.  All other AIPS++ coordinate types are supported.
00079 //
00080 // Profile2dDD is an implements WCMotionEH and WCPositionEH and
00081 // listens to motion and position events generated by the attached
00082 // Display Data. A motion event comes with a new world position on
00083 // the attached Display Data. Profile2dDD uses this world position to
00084 // extract and draw a profile on its world canvas. A Position event
00085 // (key press) switches the profiling on and off. The default switch
00086 // is the space bar.
00087 //
00088 // Profile2dDD is a DisplayEH (all DisplayDatas are) and listens to
00089 // DisplayEvents sent out by the attached DisplayData. This is so it
00090 // can listen for Tool events such as Crosshair event.
00091 //
00092 // Each time the profile is refreshed (with new data), Profile2dDD
00093 // sends out a DDModEvent to all listening DisplayEHs, to indicate
00094 // that the data has been modified.
00095 //
00096 // Since Profile2dDD inherit's from ActiveCaching2dDD and uses
00097 // WCCSNLAxisLabeller, all the options such as position tracking and
00098 // axis labelling are available.  Options specific to Profilng, such
00099 // as profile color, line width, line style and autoscaling are also
00100 // available. </synopsis>
00101 //
00102 // <example>
00103 // </example>
00104 //
00105 // <motivation>
00106 // Existing Glish implementation is too slow and limited.
00107 // </motivation>
00108 //
00109 // <todo>
00110 // <li> Mixed axes sometimes result in slow and messy axis labelling
00111 // <li> Update Profile2dDD in real time when axis of attached dd
00112 // changes
00113 // <li> Option to start Profile from a specific channel.
00114 // <li> Add support for Display Datas with profile of a linear
00115 // coordinate axis.
00116 // <li> Flux and integrated flux calculations
00117 // <li> Ability to add multiple display datas and overlay their
00118 // profiles
00119 
00120 // </todo>
00121 
00122         class Profile2dDD : public ActiveCaching2dDD, public WCMotionEH,
00123                 public WCPositionEH {
00124 
00125         public:
00126                 // <group>
00127                 // (Required) default constructor.
00128                 Profile2dDD();
00129 
00130                 // Constructor taking a pointer to an already constructed
00131                 // ImageInterface.The Display Data dd must have atleast 3 World Axes
00132                 // and atleast 2 elements in the profile (3rd) world axis.
00133                 Profile2dDD(LatticePADisplayData<Float>* dd);
00134 
00135                 // Destructor.
00136                 virtual ~Profile2dDD();
00137                 // </group>
00138 
00139                 // <group>
00140                 // Attach a Display Data to this Profile2dDD. The Display Data dd
00141                 // must have atleast 3 World Axes and atleast 2 elements in the
00142                 // profile (3rd) world axis. If any of the above conditions are not
00143                 // met or a Display Data is already attached, False is
00144                 // returned. Otherwise True is returned.
00145                 virtual Bool attachDD(LatticePADisplayData<Float>* dd);
00146 
00147                 // Detach the currently attached Display Data.
00148                 virtual void detachDD();
00149                 // </group>
00150 
00151                 // Overloading ActiveCaching2dDD::sizeControl. Zooming is modified
00152                 // for autoscaling feature.
00153                 virtual Bool sizeControl(WorldCanvasHolder &wcHolder,
00154                                          AttributeBuffer &holderBuf);
00155 
00156                 // <group>
00157                 // Store the data to be drawn in the data Matrix. If world is false,
00158                 // pixel coordinates are used. If world is true, then world
00159                 // coordinates are used.
00160                 virtual void getDrawData(Matrix<Double> &data,
00161                                          const Bool world=False);
00162 
00163                 // Store the mask in mask vector
00164                 virtual void getMaskData(Vector<Bool> &mask);
00165 
00166                 // Store the details of the current profile in rec
00167                 // Record structure similar to position event structure.
00168                 virtual void getProfileAsRecord(Record &rec);
00169                 // </group>
00170 
00171 
00172                 // Return the data unit.
00173                 virtual const Unit dataUnit();
00174 
00175                 // Returns an empty string.
00176                 virtual String showValue(const Vector<Double> &world);
00177 
00178                 // Motion Event Handler
00179                 virtual void operator()(const WCMotionEvent &ev);
00180 
00181                 // Position Event Handler
00182                 virtual void operator()(const WCPositionEvent &ev);
00183 
00184                 // Display Event Handler
00185                 virtual void handleEvent(DisplayEvent &ev);
00186 
00187                 // Send out DDModEvents to all DisplayEHs listening
00188                 virtual void sendDDModEvent();
00189 
00190                 // Draws and labels the axes based on the refresh event
00191                 virtual Bool labelAxes(const WCRefreshEvent &ev);
00192                 virtual Bool canLabelAxes() const;
00193 
00194                 // <group>
00195                 // Install the default options for this DisplayData.
00196                 virtual void setDefaultOptions();
00197 
00198                 // Apply options stored in <src>rec</src> to the DisplayData. A
00199                 // return value of <src>True</src> means a refresh is needed.
00200                 // <src>recOut</src> contains any fields which were implicitly
00201                 // changed as a result of the call to this function.
00202                 virtual Bool setOptions(Record &rec, Record &recOut);
00203 
00204                 // Retrieve the current and default options and parameter types.
00205                 virtual Record getOptions( bool scrub=false ) const;
00206                 // </group>
00207 
00208                 // Return the type of this DisplayData.
00209                 virtual Display::DisplayDataType classType() {
00210                         return Display::Vector;
00211                 }
00212 
00213                 // Create a new CachingDisplayMethod for drawing on the given
00214                 // WorldCanvas when the AttributeBuffers are suitably matched to the
00215                 // current state of this DisplayData and of the WorldCanvas/Holder.
00216                 // The tag is a unique number used to identify the age of the newly
00217                 // constructed CachingDisplayMethod.
00218                 virtual CachingDisplayMethod *newDisplayMethod(WorldCanvas *worldCanvas,
00219                         AttributeBuffer *wchAttributes,
00220                         AttributeBuffer *ddAttributes,
00221                         CachingDisplayData *dd);
00222 
00223                 // Return the current options of this DisplayData as an
00224                 // AttributeBuffer.
00225                 virtual AttributeBuffer optionsAsAttributes();
00226 
00227                 // Take actions on removal from WC[H] (notably, deletion of drawlists).
00228                 virtual void notifyUnregister(WorldCanvasHolder& wcHolder,
00229                                               Bool ignoreRefresh = False);
00230 
00231                 // <group>
00232                 // Return Profile Color
00233                 virtual String profileColor() const {
00234                         return itsParamColor->value();
00235                 }
00236                 // Return Profile Line Width
00237                 virtual Float profileLineWidth() const {
00238                         return itsParamLineWidth->value();
00239                 }
00240                 // Return Profile LineStyle
00241                 virtual Display::LineStyle profileLineStyle() {
00242                         return static_cast<Display::LineStyle>(itsParamLineStyle->keyValue());
00243                 }
00244 
00245                 // Return True if the last requested profile was for a
00246                 // region. Return False if the last requested profile was for a
00247                 // single point
00248                 virtual Bool isRegionProfile() const {
00249                         return itsIsRegionProfile;
00250                 }
00251 
00252                 // get the region dimensions, in pixels, of the last region
00253                 // submitted to Profile2dDD.
00254                 virtual void regionDimensions(Vector<Double> &regionBlc,
00255                                               Vector<Double> &regionTrc);
00256 
00257                 // Return Minimum Y value
00258                 virtual Double profileYMin() const {
00259                         return itsCurrentBlc(1);
00260                 }
00261                 // Return Maximum Y value
00262                 virtual Double profileYMax() const {
00263                         return itsCurrentTrc(1);
00264                 }
00265                 // Return Minimum X value
00266                 virtual Double profileXMin() const {
00267                         return itsCurrentBlc(0);
00268                 }
00269                 // Return Maximum X value
00270                 virtual Double profileXMax() const {
00271                         return itsCurrentTrc(0);
00272                 }
00273                 // Return the autoscale status (On or Off)
00274                 virtual Bool profileAutoscale() const {
00275                         return itsParamAutoscale->value();
00276                 }
00277                 // Return the rest frequency display status (to draw or not to draw)
00278                 virtual Bool showRestFrequency()  const {
00279                         return itsParamShowRestFrequency->value();
00280                 }
00281                 // Return rest frequency.
00282                 virtual Double restFrequency()  const {
00283                         return itsRestFrequency;
00284                 }
00285 
00286                 // Return the statistics used for region calculations.
00287                 virtual LatticeStatsBase::StatisticsTypes  regionStatType()  const {
00288                         return static_cast<LatticeStatsBase::StatisticsTypes>
00289                                (itsParamRegionStatType->keyValue());
00290                 }
00291 
00292                 // Return the x value added to the pixel at a pixel position to
00293                 // create a region
00294                 virtual Int regionXRadius()  const {
00295                         return itsParamRegionXRadius->value();
00296                 }
00297 
00298                 // Return the y value added to the pixel at a pixel position to
00299                 // create a region
00300                 virtual Int regionYRadius()  const {
00301                         return itsParamRegionYRadius->value();
00302                 }
00303                 // Return the profile axis number (from the original image)
00304                 virtual  Int profileAxis();
00305 
00306                 // </group>
00307 
00308         protected:
00309 
00310                 friend class Profile2dDM;
00311 
00312                 // (Required) copy constructor.
00313                 Profile2dDD(const Profile2dDD &other);
00314 
00315                 // (Required) copy assignment.
00316                 void operator=(const Profile2dDD &other);
00317 
00318         private:
00319 
00320                 // Helper function. Initialise Profile2dDD with a DisplayCoordinateSystem
00321                 // put together from the parent DD
00322                 Bool createCoordinateSystem();
00323 
00324                 // Update the coordinate system of this Display Data and the axis
00325                 // labeller. Set new minimum and maximum Y values if necessary
00326                 Bool updateCoordinateSys(DisplayCoordinateSystem &cs);
00327 
00328                 // Extract the profile data from the provided pixel region and place
00329                 // it into itsData. The statistics used is determined by the
00330                 // options. Return True if new profile data has been extracted
00331                 // (i.e. a refresh is needed) otherwise return False
00332                 Bool getRegionProfile(Vector<Double> &fpixelBlc,
00333                                       Vector<Double> &fpixelTrc);
00334 
00335                 // Extract the profile data from the provided world position and
00336                 // place it into itsData. Also extract the Mask data (if it exists)
00337                 // and place it into itsMask. Return True if new profile data has
00338                 // been extracted (i.e. a refresh is needed) otherwise return False
00339                 Bool getPointProfile(const Vector<Double> &world);
00340 
00341                 // Crop the region so that it does not define areas outside the
00342                 // data. Returns False if the entire region is outside image data
00343                 Bool cropRegion(Vector<Double> &fpixelBlc,
00344                                 Vector<Double> &fpixelTrc);
00345 
00346                 // Construct the parameters for getOptions and setOptions
00347                 virtual void constructParameters();
00348                 // Delete the parameters for getOptions() and setOptions()
00349                 virtual void destructParameters();
00350 
00351                 // A pointer to the attached DisplayData
00352                 LatticePADisplayData<Float>* itsDD;
00353 
00354                 // Flag to indicate whether the last drawn profile was for a region
00355                 // or for a single point.
00356                 Bool itsIsRegionProfile;
00357 
00358                 // A flag to indicate whether tracking is on. If True, a new profile
00359                 // is extracted each time a new motion event is received.
00360                 Bool itsTrackingState;
00361 
00362                 // The dependent (world) axis of itsDD. For example, if a RA axis is
00363                 // the profile axis, then the DEC axis will be the dependent axis.
00364                 Int itsDependentAxis;
00365 
00366                 // Increment value for the linear coordinate on the Y axis
00367                 Double itsYAxisInc;
00368 
00369                 // Rest Frequency
00370                 Double itsRestFrequency;
00371 
00372                 // Minimum and maximum X/Y values
00373                 Vector<Double> itsCurrentBlc;
00374                 Vector<Double> itsCurrentTrc;
00375 
00376                 // <group> The pixel position on the world canvas when the last
00377                 // motion' event was received. This position is in the format of
00378                 // itsDD, NOT the original image.
00379                 Vector<Double> itsPixelPosition;
00380                 // The world position on the world canvas when the last motion'
00381                 // event was received. This position is in the format of
00382                 // itsDD, NOT the original image.
00383                 Vector<Double> itsWorldPosition;
00384 
00385                 // The region dimensions, in pixels, of the last region event
00386                 // received by Profile2dDD
00387                 Vector<Double> itsRegionBlc;
00388                 Vector<Double> itsRegionTrc;
00389 
00390                 // </group>
00391                 // The Profile Data
00392                 Matrix<Double> itsData;
00393                 // The Mask Data
00394                 Vector<Bool> itsMask;
00395 
00396                 // The axis map between input DD's Coordinate system and
00397                 // itsCompleteCS
00398                 Vector<Int> itsWorldAxisMap;
00399                 Vector<Int> itsPixelAxisMap;
00400 
00401                 // The choices for region calculations. eg, mean, median, etc
00402                 Vector<String> itsRegionCalcChoices;
00403 
00404                 // The default x and y axis labels. The x and y labels change to
00405                 // indicate region profiles.
00406                 Vector<String> itsDefaultAxisLabels;
00407 
00408                 // The Axis Labeller used to draw Axes
00409                 WCCSNLAxisLabeller itsAxisLabeller;
00410 
00411                 // Display Parameters for
00412                 DParameterColorChoice* itsParamColor;
00413                 DParameterRange<Float>* itsParamLineWidth;
00414                 DParameterMapKeyChoice* itsParamLineStyle;
00415                 DParameterSwitch* itsParamAutoscale;
00416                 DParameterSwitch* itsParamShowRestFrequency;
00417                 DParameterMapKeyChoice* itsParamRegionStatType;
00418                 DParameterRange<Int>* itsParamRegionXRadius;
00419                 DParameterRange<Int>* itsParamRegionYRadius;
00420         };
00421 
00422 } //# NAMESPACE CASA - END
00423 
00424 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1