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