PrincipalAxesDD.h

Go to the documentation of this file.
00001 //# PrincipalAxesDD.h: Base class for axis-bound DisplayData objects
00002 //# Copyright (C) 1996,1997,1998,1999,2000,2001,2002,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_PRINCIPALAXESDD_H
00029 #define TRIALDISPLAY_PRINCIPALAXESDD_H
00030 
00031 // aips includes:
00032 #include <casa/aips.h>
00033 
00034 // trial includes:
00035 #include <coordinates/Coordinates/CoordinateSystem.h>
00036 
00037 // display library includes:
00038 #include <display/DisplayDatas/DisplayData.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 // forwards:
00043 class WorldCanvas;
00044 class WorldCanvasHolder;
00045 template <class T> class Vector;
00046 class String;
00047 class AttributeBuffer;
00048 class WCPositionEvent;
00049 class WCMotionEvent;
00050 class WCRefreshEvent;
00051 class CoordinateSystem;
00052 class WCCSNLAxisLabeller;
00053 class PrincipalAxesDM;
00054 
00055 // <summary>
00056 // Interface for DisplayDatas which have data arranged in axes.
00057 // </summary>
00058 //
00059 // <synopsis>
00060 // This class adds to the interface defined by DisplayData to 
00061 // provide the necessary infrastructure for managing data which 
00062 // is arranged in "axes," ie. lattice or column-based data.
00063 // </synopsis>
00064 
00065 class PrincipalAxesDD : public DisplayData {
00066 
00067  public:
00068 
00069   // constructor
00070   PrincipalAxesDD(uInt xAxis, uInt yAxis, Int mAxis = -1,
00071      Bool axisLabels = True);
00072 
00073   // destructor
00074   virtual ~PrincipalAxesDD();
00075 
00076   // Coordinate transformation handlers, called by WorldCanvasHolder
00077   // <group>
00078   virtual Bool linToWorld(Vector<Double> &world, 
00079                           const Vector<Double> &lin);
00080   virtual Bool worldToLin(Vector<Double> &lin,
00081                           const Vector<Double> &world);
00082   virtual Bool linToFullWorld(Vector<Double> &fullWorld,
00083                               const Vector<Double> &lin);
00084   // </group>
00085 
00086   // Format a string containing coordinate and data information at the
00087   // given world coordinate
00088   virtual String showPosition(const Vector<Double> &world, 
00089                               const Bool &displayAxesOnly = False);
00090 
00091   // Format a string containing coordinate and data information at the
00092   // given world coordinate. This function let's you specify output
00093   // conditions (world/pixel and abs/rel)
00094   virtual String showPosition(const Vector<Double> &world, 
00095                  const Bool &showAbs, const Bool &displayAxesOnly);
00096 
00097   
00098   // Is the DD is capable (in its current state) of drawing
00099   // in the current CoordinateSystem of the WCH's WorldCanvas?
00100   virtual Bool conformsToCS(const WorldCanvasHolder& wch);
00101 
00102   // Miscellaneous information supply routines
00103   // <group>
00104   virtual Vector<String> worldAxisNames();
00105   virtual Vector<String> worldAxisUnits();
00106   virtual Vector<Double> worldAxisIncrements();
00107   virtual void worldAxisType(Coordinate::Type &type, Int &coordinate,
00108                              Int &axisincoord, const uInt &worldaxisnum);
00109   virtual String worldAxisCode(const uInt &worldaxisnum);
00110   // </group>
00111 
00112   // Return the number of display elements (eg. drawable images) in this
00113   // DisplayData
00114   // <group>
00115   virtual const uInt nelements(const WorldCanvasHolder &wcHolder) const;
00116   virtual const uInt nelements() const;
00117   // </group>
00118 
00119   // Set and retrieve the minimum and maximum data values
00120   // <group>
00121   virtual void setDataMin(Double datmin);
00122   virtual void setDataMax(Double datmax);
00123   virtual Double getDataMin();
00124   virtual Double getDataMax();
00125   // </group>
00126 
00127   // sizeControlFunction, called by the WorldCanvasHolder to setup the
00128   // WorldCanvas linear coordinate system
00129   virtual Bool sizeControl(WorldCanvasHolder& wcHolder, 
00130                            AttributeBuffer& holderBuf);
00131 
00132   // Position event handler, called by the WorldCanvasHolder
00133   virtual void positionEH(const WCPositionEvent& ev);
00134 
00135   // Motion event handler, called by the WorldCanvasHolder
00136   virtual void motionEH(const WCMotionEvent& ev);
00137   
00138 
00139   // refresh handler, called by the WorldCanvasHolder
00140   virtual void refreshEH(const WCRefreshEvent& ev); 
00141 
00142   // label/draw the axes
00143   virtual Bool labelAxes(const WCRefreshEvent &ev);
00144 
00145   // required function to tidy up our elements, primarily
00146   virtual void cleanup();
00147 
00148   // install the default options for this DisplayData
00149   virtual void setDefaultOptions();
00150 
00151   // apply options stored in val to the DisplayData; return value
00152   // True means a refresh is needed...
00153   virtual Bool setOptions(Record &rec, Record &recOut);
00154 
00155   // retrieve the current and default options and parameter types.
00156   virtual Record getOptions();
00157 
00158   // distribute options to all the axis labellers
00159   virtual Bool setLabellerOptions(Record &rec, Record &recout);
00160 
00161   // retrieve options from the axis labellers
00162   virtual Record getLabellerOptions();
00163 
00164   // Sets which axes are on display and animator, and positions for
00165   // animator and sliders.  Pass 'reset' as False if you don't need
00166   // an unzoom (e.g. when display axes are unchanged).
00167   virtual void setAxes(const uInt xAxis, const uInt yAxis, const uInt mAxis,
00168                        const IPosition fixedPos, Bool reset=True);
00169 
00170   // query the number of dimensions in the data
00171   virtual uInt nDim() 
00172     { return dataDim(); }
00173 
00174   // retrieve the CoordinateSystem
00175   CoordinateSystem coordinateSystem() const
00176     { return itsCoordSys; }
00177 
00178   // retrieve the original CoordinateSystem
00179   CoordinateSystem originalCoordinateSystem() const
00180     { return itsOrigCoordSys; }
00181 
00182   // set the CoordinateSystem and the original CoordinateSystem
00183   void setCoordinateSystem(const CoordinateSystem &coordsys);
00184 
00185   // set the CoordinateSystem to be the same as the original
00186   // CoordinateSystem
00187   void restoreCoordinateSystem();
00188 
00189   // set a Linear Coordinate in case of pixToWorld undefined for the
00190   // blc/trc
00191   void installFakeCoordinateSystem();
00192   void removeFakeCoordinateSystem();
00193 
00194   // Return the class name of this DisplayData; useful mostly for
00195   // debugging purposes, and perhaps future use in the glish widget
00196   // interface.
00197   virtual String className() { return String("PrincipalAxesDD"); }
00198 
00199   // Get the current fixed position
00200   virtual IPosition fixedPosition() const 
00201     { return itsFixedPosition; }
00202 
00203   // Get the current display axis numbers
00204   virtual Vector<Int> displayAxes() const 
00205     { return itsDisplayAxes; }
00206 
00207   // Get the current setting of pixel treatment mode
00208   virtual String pixelTreatment() const
00209     { return itsOptionsPixelTreatment; }
00210 
00211   
00212   //# (dk note 12/04: Axis Label state is maintained by eight different
00213   //# PADD methods; someone has begun using the bool below to bypass that
00214   //# maintenance.  Well, ok; it can work that way as a construction
00215   //# parameter that is unchanged thereafter.  But simply turning it back
00216   //# on later will not make that state available or consistent; it will
00217   //# just cause crashes.  Please see me for what's needed to properly
00218   //# support this method if you need to restore it).
00219   //#  
00220   //# void usesAxisLabels(Bool state) {
00221   //#   itsUsesAxisLabels = state;
00222   //# }
00223 
00224     
00225   // Convert a 2D worldCoordinate of the WorldCanvas to a full worldcoordinate
00226   // and full pixel position
00227   virtual Bool getFullCoord(Vector<Double> &fullWorld, 
00228                             Vector<Double> &fullPixel, 
00229                             const Vector<Double> &world);
00230 
00231   virtual void notifyUnregister(WorldCanvasHolder& wcHolder, 
00232                                 Bool ignoreRefresh = False);
00233 
00234  protected:
00235 
00236   // Set internal index (activeZIndex_) into the list of DMs (which cache
00237   // individual drawings), according to passed animator index.  This is
00238   // called by conformsTo() (via conformsToZIndex()), and serves to
00239   // 'focus' the DD on the current WCH's zIndex.
00240   // Returns True if there is only one frame, in which case activeZIndex_
00241   // is set to 0.  Thus a single frame is considered to apply to any
00242   // canvas zIndex setting (this allows a continuum image to be blinked
00243   // with a chosen channel of a spectral image, e.g.).
00244   // If there is more than one frame, the passed zindex is stored, and
00245   // the return value will indicate whether it lies within the DD's
00246   // current number of frames.
00247   virtual Bool setActiveZIndex_(Int zindex);
00248 
00249   // Derived classes will implement if applicable (at present,
00250   // LatticePADDs may draw if they have an image with beam data).
00251   virtual void drawBeamEllipse_(WorldCanvas* wc) {  }
00252   
00253   // allow PrincipalAxesDM objects to access the coord system in 
00254   // parent PrincipalAxesDD object
00255   friend class PrincipalAxesDM;
00256 
00257   virtual void setNumImages(const uInt nimages)
00258     { itsNumImages = nimages; }
00259 
00260   // Internal state
00261   Bool iAmRubbish;
00262 
00263   // min and max to use for drawing
00264   Double datamin;
00265   Double datamax;
00266 
00267   // internal bookkeeping
00268   // number of axes
00269   uInt nArrayAxes;
00270   uInt nPixelAxes;
00271   uInt nWorldAxes;
00272   
00273   // format for diplaying numbers in the tracker
00274   Coordinate::formatType itsNotation;
00275 
00276   // do some setup work, part of construction and changing dataset
00277   void setup(IPosition fixedPos);
00278 
00279   // functions need by above
00280   virtual const IPosition dataShape() = 0;
00281   virtual const uInt dataDim() = 0;
00282   virtual const Unit dataUnit() = 0;
00283   virtual void setupElements();
00284   virtual void getMinAndMax() = 0;
00285 
00286   // Helper routine for setting up the transpose vectors for the coordinate
00287   // system. 
00288   Bool indexInserted(Int index, Int length, Vector<Int>& testVec);
00289 
00290   // helper to transpose coordinates  
00291   // <group>
00292   void normalToTransposed(Vector<Double>& coord, const Vector<Int>& transPos);
00293   void transposedToNormal(Vector<Double>& coord, const Vector<Int>& transPos);
00294   // </group>
00295 
00296   // Set velocity state
00297   void setVelocityState (CoordinateSystem& cSys, 
00298                          const String& velTypeString, 
00299                          const String& unitString);
00300 
00301   // Set Spectral formatting
00302   void setSpectralFormatting (CoordinateSystem& cSys, 
00303                               const String& velTypeString, 
00304                               const String& unitString);
00305 
00306   // Determine the active image (if any).
00307   // (Deprecated (7/04).  Use  confromsToZIndex(wch)  instead).
00308   Bool findActiveImage(WorldCanvasHolder &wcHolder);
00309 
00310   // (Required) default constructor.
00311   PrincipalAxesDD();
00312 
00313   // (Required) copy constructor.
00314   PrincipalAxesDD(const PrincipalAxesDD &other);
00315 
00316   // (Required) copy assignment.
00317   void operator=(const PrincipalAxesDD &other);
00318 
00319  private:
00320 
00321   // axis numbers IN ORIGINAL COORDINATE SYSTEM; zAxisNum = -1 means 
00322   // no third axis in data set
00323   Int itsXAxisNum;
00324   Int itsYAxisNum;
00325   Int itsZAxisNum;
00326 
00327   // the x (0), y (1) and z/movie (2) axis numbers
00328   Vector<Int> itsDisplayAxes;
00329 
00330   // Store options:
00331   // Axis selection ---
00332   String itsOptionsXAxis, itsOptionsYAxis, itsOptionsZAxis;
00333   IPosition itsFixedPosition;
00334 
00335   // treatment of edge pixels
00336   String itsOptionsPixelTreatment;
00337 
00338   // number of elements (images) in this DisplayData
00339   uInt itsNumImages;
00340 
00341   // This CS is the one we were constructed with
00342   CoordinateSystem itsOrigCoordSys;
00343   CoordinateSystem itsCoordSysBackup;
00344 
00345   // This is the working CS which is transposed and has axes removed
00346   // all over the place
00347   
00348   // (dk note: The authors explain this poorly, and don't seem to make
00349   // the distinction even for themselves very well: there are _two_
00350   // relevant coordinate transformations here, not just one.  itsOrigCoordSys
00351   // defines the world space for the _data_ pixels.  itsCoordSys defines the
00352   // world space for the _canvas_.  Control and setting of the canvas CS is
00353   // poorly modularized, and the DDs remain involved in too much of the
00354   // _canvas's_ coordinate translation chores).
00355 
00356   CoordinateSystem itsCoordSys;
00357 
00358   // List of AxisLabellers.
00359   PtrBlock<void *> itsAxisLabellers;
00360   
00361   // Aspect selection ---
00362   String itsOptionsAspect;
00363 
00364   // Position tracking variables
00365   // This CS is the one we use to set the appropriate state for
00366   // PositionTracking.    It is pretty much the same as itsOriginalCoordSys
00367   // but the formtting and velocity state (if there is a SC) may differ
00368 
00369   CoordinateSystem itsPosTrackCoordSys;
00370   String itsSpectralUnit;
00371   String itsDoppler;
00372   Bool itsAbsolute;
00373   Bool itsFractionalPixels;
00374 
00375   // buffer for string sizecontrol done by this ImageDisplayData
00376   AttributeBuffer sizeControlBuf;
00377   
00378   // the coordinates of the axes that do not vary
00379   Vector<Double>    itsAddPixPos;
00380 
00381   // how the axes are permuted
00382   Vector<Int>       itsTransPixelAxes;
00383   Vector<Int>       itsTransWorldAxes;
00384 
00385   // world ranges for toMix conversions
00386   Vector<Double> itsWorldMin, itsWorldMax;
00387 
00388   // Temporaries  for coordinate conversions.
00389   // You should only use one temporary per function.
00390   Vector<Double> itsWorldInTmp1, itsPixelInTmp1;
00391   Vector<Bool> itsWorldAxesTmp1, itsPixelAxesTmp1;
00392   Vector<Double> itsFullWorldTmp1;
00393   //
00394   Vector<Double> itsPixelInTmp2;
00395   //
00396   Vector<Double> itsWorldInTmp3, itsWorldOutTmp3;
00397   Vector<Double> itsPixelInTmp3, itsPixelOutTmp3;
00398   Vector<Bool> itsWorldAxesTmp3, itsPixelAxesTmp3;
00399   //
00400   Vector<Double> itsFullWorldTmp4, itsFullPixelTmp4;
00401 
00402   Bool itsUsesAxisLabels;
00403 
00404   // Find out if SpectralCoordinate can have velocity units
00405   Bool canHaveVelocityUnit (const CoordinateSystem& cSys) const;
00406 
00407   // Remove list of pixel axes from CS
00408   void removePixelAxes (CoordinateSystem& cSys,
00409                         uInt startAxis,
00410                         const IPosition& fixedPosition);
00411 
00412   // Convert list of world axis names to pixel axis names
00413    Vector<String> worldToPixelAxisNames (const CoordinateSystem& cSys) const;
00414 
00415 };
00416  
00417 
00418 } //# NAMESPACE CASA - END
00419 
00420 #endif

Generated on Thu Aug 27 21:08:43 2009 for NRAOCASA by  doxygen 1.5.1