casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
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/Lattices/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 
00193   // <group>
00194   // Install the default options for this DisplayData.
00195   virtual void setDefaultOptions();
00196 
00197   // Apply options stored in <src>rec</src> to the DisplayData. A
00198   // return value of <src>True</src> means a refresh is needed.
00199   // <src>recOut</src> contains any fields which were implicitly
00200   // changed as a result of the call to this function.
00201   virtual Bool setOptions(Record &rec, Record &recOut);
00202 
00203   // Retrieve the current and default options and parameter types.
00204   virtual Record getOptions();
00205   // </group>
00206 
00207   // Return the type of this DisplayData.
00208   virtual Display::DisplayDataType classType() {return Display::Vector;}
00209   
00210   // Create a new CachingDisplayMethod for drawing on the given
00211   // WorldCanvas when the AttributeBuffers are suitably matched to the
00212   // current state of this DisplayData and of the WorldCanvas/Holder.
00213   // The tag is a unique number used to identify the age of the newly
00214   // constructed CachingDisplayMethod.
00215   virtual CachingDisplayMethod *newDisplayMethod(WorldCanvas *worldCanvas,
00216                                          AttributeBuffer *wchAttributes,
00217                                          AttributeBuffer *ddAttributes,
00218                                          CachingDisplayData *dd);
00219  
00220   // Return the current options of this DisplayData as an
00221   // AttributeBuffer.
00222   virtual AttributeBuffer optionsAsAttributes();
00223 
00224   // Take actions on removal from WC[H] (notably, deletion of drawlists).
00225   virtual void notifyUnregister(WorldCanvasHolder& wcHolder, 
00226                                 Bool ignoreRefresh = False);
00227   
00228   // <group>
00229   // Return Profile Color
00230   virtual const String profileColor() const {
00231     return itsParamColor->value();
00232   }
00233   // Return Profile Line Width
00234   virtual const Float profileLineWidth() const {
00235     return itsParamLineWidth->value();
00236   }
00237   // Return Profile LineStyle
00238   virtual const Display::LineStyle profileLineStyle() {
00239     return static_cast<Display::LineStyle>(itsParamLineStyle->keyValue());
00240   }
00241 
00242   // Return True if the last requested profile was for a
00243   // region. Return False if the last requested profile was for a
00244   // single point
00245   virtual const Bool isRegionProfile() const {return itsIsRegionProfile;
00246   }
00247 
00248   // get the region dimensions, in pixels, of the last region
00249   // submitted to Profile2dDD.
00250   virtual void regionDimensions(Vector<Double> &regionBlc,
00251                                 Vector<Double> &regionTrc);
00252 
00253   // Return Minimum Y value
00254   virtual const Double profileYMin() const {
00255     return itsCurrentBlc(1);
00256   }
00257   // Return Maximum Y value
00258   virtual const Double profileYMax() const {
00259     return itsCurrentTrc(1);
00260   }
00261   // Return Minimum X value
00262   virtual const Double profileXMin() const {
00263     return itsCurrentBlc(0);
00264   }
00265   // Return Maximum X value
00266   virtual const Double profileXMax() const {
00267     return itsCurrentTrc(0);
00268   }
00269   // Return the autoscale status (On or Off)
00270   virtual const Bool profileAutoscale() const {
00271     return itsParamAutoscale->value();
00272   }
00273   // Return the rest frequency display status (to draw or not to draw)
00274   virtual const Bool showRestFrequency()  const {
00275     return itsParamShowRestFrequency->value();
00276   }
00277   // Return rest frequency.
00278   virtual const Double restFrequency()  const {return itsRestFrequency;}  
00279 
00280   // Return the statistics used for region calculations.
00281   virtual const LatticeStatsBase::StatisticsTypes  regionStatType()  const {
00282     return static_cast<LatticeStatsBase::StatisticsTypes>
00283       (itsParamRegionStatType->keyValue());
00284   }
00285 
00286   // Return the x value added to the pixel at a pixel position to
00287   // create a region
00288   virtual const Int regionXRadius()  const {return itsParamRegionXRadius->value();}
00289 
00290   // Return the y value added to the pixel at a pixel position to
00291   // create a region
00292   virtual const Int regionYRadius()  const {
00293     return itsParamRegionYRadius->value();
00294   }
00295   // Return the profile axis number (from the original image)
00296   virtual const Int profileAxis();
00297 
00298   // </group>
00299 
00300   protected:
00301   
00302   friend class Profile2dDM;
00303 
00304   // (Required) copy constructor.
00305   Profile2dDD(const Profile2dDD &other);
00306 
00307   // (Required) copy assignment.
00308   void operator=(const Profile2dDD &other);
00309 
00310   private:  
00311  
00312   // Helper function. Initialise Profile2dDD with a CoordinateSystem
00313   // put together from the parent DD
00314   Bool createCoordinateSystem();
00315 
00316   // Update the coordinate system of this Display Data and the axis
00317   // labeller. Set new minimum and maximum Y values if necessary
00318   Bool updateCoordinateSys(CoordinateSystem &cs);
00319 
00320   // Extract the profile data from the provided pixel region and place
00321   // it into itsData. The statistics used is determined by the
00322   // options. Return True if new profile data has been extracted
00323   // (i.e. a refresh is needed) otherwise return False
00324   Bool getRegionProfile(Vector<Double> &fpixelBlc,
00325                         Vector<Double> &fpixelTrc);
00326 
00327   // Extract the profile data from the provided world position and
00328   // place it into itsData. Also extract the Mask data (if it exists)
00329   // and place it into itsMask. Return True if new profile data has
00330   // been extracted (i.e. a refresh is needed) otherwise return False
00331   Bool getPointProfile(const Vector<Double> &world);
00332 
00333   // Crop the region so that it does not define areas outside the
00334   // data. Returns False if the entire region is outside image data
00335   Bool cropRegion(Vector<Double> &fpixelBlc,
00336                   Vector<Double> &fpixelTrc);
00337 
00338   // Construct the parameters for getOptions and setOptions
00339   virtual void constructParameters();
00340   // Delete the parameters for getOptions() and setOptions()
00341   virtual void destructParameters();
00342 
00343   // A pointer to the attached DisplayData
00344   LatticePADisplayData<Float>* itsDD;
00345 
00346   // Flag to indicate whether the last drawn profile was for a region
00347   // or for a single point.
00348   Bool itsIsRegionProfile;
00349 
00350   // A flag to indicate whether tracking is on. If True, a new profile
00351   // is extracted each time a new motion event is received.
00352   Bool itsTrackingState;
00353 
00354   // The dependent (world) axis of itsDD. For example, if a RA axis is
00355   // the profile axis, then the DEC axis will be the dependent axis.
00356   Int itsDependentAxis;
00357 
00358   // Increment value for the linear coordinate on the Y axis
00359   Double itsYAxisInc;
00360 
00361   // Rest Frequency
00362   Double itsRestFrequency;
00363 
00364   // Minimum and maximum X/Y values
00365   Vector<Double> itsCurrentBlc;
00366   Vector<Double> itsCurrentTrc;
00367 
00368   // <group> The pixel position on the world canvas when the last
00369   // motion' event was received. This position is in the format of
00370   // itsDD, NOT the original image.
00371   Vector<Double> itsPixelPosition;
00372   // The world position on the world canvas when the last motion'
00373   // event was received. This position is in the format of
00374   // itsDD, NOT the original image.
00375   Vector<Double> itsWorldPosition;
00376 
00377   // The region dimensions, in pixels, of the last region event
00378   // received by Profile2dDD
00379   Vector<Double> itsRegionBlc;
00380   Vector<Double> itsRegionTrc;
00381 
00382   // </group>
00383   // The Profile Data
00384   Matrix<Double> itsData;
00385   // The Mask Data
00386   Vector<Bool> itsMask;
00387 
00388   // The axis map between input DD's Coordinate system and
00389   // itsCompleteCS
00390   Vector<Int> itsWorldAxisMap;
00391   Vector<Int> itsPixelAxisMap;
00392 
00393   // The choices for region calculations. eg, mean, median, etc
00394   Vector<String> itsRegionCalcChoices;
00395 
00396   // The default x and y axis labels. The x and y labels change to
00397   // indicate region profiles.
00398   Vector<String> itsDefaultAxisLabels;
00399 
00400   // The Axis Labeller used to draw Axes
00401   WCCSNLAxisLabeller itsAxisLabeller;
00402 
00403   // Display Parameters for
00404   DParameterColorChoice* itsParamColor;
00405   DParameterRange<Float>* itsParamLineWidth;
00406   DParameterMapKeyChoice* itsParamLineStyle;
00407   DParameterSwitch* itsParamAutoscale;
00408   DParameterSwitch* itsParamShowRestFrequency;
00409   DParameterMapKeyChoice* itsParamRegionStatType;
00410   DParameterRange<Int>* itsParamRegionXRadius;
00411   DParameterRange<Int>* itsParamRegionYRadius;
00412 };
00413 
00414 } //# NAMESPACE CASA - END
00415 
00416 #endif