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 <display/Display/DisplayCoordinateSystem.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 DisplayCoordinateSystem;
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                 virtual void setSubstituteTitleText( const String text );
00101                 // Is the DD is capable (in its current state) of drawing
00102                 // in the current DisplayCoordinateSystem 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 uInt nelements(const WorldCanvasHolder &wcHolder) const;
00119                 virtual 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() const;
00127                 virtual Double getDataMax() const;
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                 virtual Bool canLabelAxes() const;
00148 
00149                 // required function to tidy up our elements, primarily
00150                 virtual void cleanup();
00151 
00152                 // install the default options for this DisplayData
00153                 virtual void setDefaultOptions();
00154 
00155                 // apply options stored in val to the DisplayData; return value
00156                 // True means a refresh is needed...
00157                 virtual Bool setOptions(Record &rec, Record &recOut);
00158 
00159 
00160                 // retrieve the current and default options and parameter types.
00161                 virtual Record getOptions( bool scrub ) const;
00162 
00163                 // distribute options to all the axis labellers
00164                 virtual Bool setLabellerOptions(Record &rec, Record &recout);
00165 
00166                 // retrieve options from the axis labellers
00167                 virtual Record getLabellerOptions( bool scrub=false ) const;
00168 
00169                 // Sets which axes are on display and animator, and positions for
00170                 // animator and sliders.  Pass 'reset' as False if you don't need
00171                 // an unzoom (e.g. when display axes are unchanged).
00172                 virtual void setAxes(const uInt xAxis, const uInt yAxis, const uInt mAxis,
00173                                      const IPosition fixedPos, Bool reset=True);
00174 
00175                 // query the number of dimensions in the data
00176                 virtual uInt nDim() {
00177                         return dataDim();
00178                 }
00179 
00180                 // retrieve the DisplayCoordinateSystem
00181                 DisplayCoordinateSystem coordinateSystem() const {
00182                         return itsCoordSys;
00183                 }
00184 
00185                 // retrieve the original DisplayCoordinateSystem
00186                 DisplayCoordinateSystem originalCoordinateSystem() const {
00187                         return itsOrigCoordSys;
00188                 }
00189 
00190                 // set the DisplayCoordinateSystem and the original DisplayCoordinateSystem
00191                 void setCoordinateSystem(const DisplayCoordinateSystem &coordsys);
00192 
00193                 // set the DisplayCoordinateSystem to be the same as the original
00194                 // DisplayCoordinateSystem
00195                 void restoreCoordinateSystem();
00196 
00197                 // set a Linear Coordinate in case of pixToWorld undefined for the
00198                 // blc/trc
00199                 void installFakeCoordinateSystem();
00200                 void removeFakeCoordinateSystem();
00201 
00202                 // Return the class name of this DisplayData; useful mostly for
00203                 // debugging purposes, and perhaps future use in the glish widget
00204                 // interface.
00205                 virtual String className() {
00206                         return String("PrincipalAxesDD");
00207                 }
00208 
00209                 // Get the current fixed position
00210                 virtual IPosition fixedPosition() const {
00211                         return itsFixedPosition;
00212                 }
00213 
00214                 // Get the current display axis numbers
00215                 virtual vector<int> displayAxes() const {
00216                         return itsDisplayAxes;
00217                 }
00218 
00219                 // Get the current setting of pixel treatment mode
00220                 virtual String pixelTreatment() const {
00221                         return itsOptionsPixelTreatment;
00222                 }
00223 
00224 
00225                 //# (dk note 12/04: Axis Label state is maintained by eight different
00226                 //# PADD methods; someone has begun using the bool below to bypass that
00227                 //# maintenance.  Well, ok; it can work that way as a construction
00228                 //# parameter that is unchanged thereafter.  But simply turning it back
00229                 //# on later will not make that state available or consistent; it will
00230                 //# just cause crashes.  Please see me for what's needed to properly
00231                 //# support this method if you need to restore it).
00232                 //#
00233                 //# void usesAxisLabels(Bool state) {
00234                 //#   itsUsesAxisLabels = state;
00235                 //# }
00236 
00237 
00238                 // Convert a 2D worldCoordinate of the WorldCanvas to a full worldcoordinate
00239                 // and full pixel position
00240                 virtual Bool getFullCoord(Vector<Double> &fullWorld,
00241                                           Vector<Double> &fullPixel,
00242                                           const Vector<Double> &world);
00243 
00244                 virtual void notifyUnregister(WorldCanvasHolder& wcHolder,
00245                                               Bool ignoreRefresh = False);
00246 
00247                 // allow external functions to translate axes...
00248                 Int xlatePixelAxes( Int idx ) const {
00249                         return itsTransPixelAxes[idx];
00250                 }
00251                 Int xlateFixedPixelAxes( Int idx ) const {
00252                         return itsFixedPosition[idx];
00253                 }
00254                 const String &xaxisStr( ) const {
00255                         return itsOptionsXAxis;
00256                 }
00257                 const String &yaxisStr( ) const {
00258                         return itsOptionsYAxis;
00259                 }
00260                 const String &zaxisStr( ) const {
00261                         return itsOptionsZAxis;
00262                 }
00263                 const String &spectStr( ) const;
00264 
00265                 // Convert list of world axis names to pixel axis names
00266                 Vector<String> worldToPixelAxisNames (const DisplayCoordinateSystem& cSys) const;
00267 
00268                 const String &spectralunitStr( ) const;
00269                 const static String HISTOGRAM_RANGE;
00270 
00271                 bool hasMovieDimension( ) const {
00272                         return has_nonsingleton_nondegenerate_nondisplayed_axis( *this );
00273                 }
00274 
00275                 std::string errorMessage( ) const { return error_string; }
00276 
00277         protected:
00278 
00279                 // Set internal index (activeZIndex_) into the list of DMs (which cache
00280                 // individual drawings), according to passed animator index.  This is
00281                 // called by conformsTo() (via conformsToZIndex()), and serves to
00282                 // 'focus' the DD on the current WCH's zIndex.
00283                 // Returns True if there is only one frame, in which case activeZIndex_
00284                 // is set to 0.  Thus a single frame is considered to apply to any
00285                 // canvas zIndex setting (this allows a continuum image to be blinked
00286                 // with a chosen channel of a spectral image, e.g.).
00287                 // If there is more than one frame, the passed zindex is stored, and
00288                 // the return value will indicate whether it lies within the DD's
00289                 // current number of frames.
00290                 virtual Bool setActiveZIndex_(Int zindex);
00291 
00292                 // Derived classes will implement if applicable (at present,
00293                 // LatticePADDs may draw if they have an image with beam data).
00294                 virtual void drawBeamEllipse_(WorldCanvas* /*wc*/) {  }
00295 
00296                 // allow PrincipalAxesDM objects to access the coord system in
00297                 // parent PrincipalAxesDD object
00298                 friend class PrincipalAxesDM;
00299 
00300                 virtual void setNumImages(const uInt nimages) {
00301                         itsNumImages = nimages;
00302                 }
00303 
00304                 static bool has_nonsingleton_nondegenerate_nondisplayed_axis( const DisplayData &other );
00305 
00306                 // Internal state
00307                 Bool iAmRubbish;
00308 
00309                 // min and max to use for drawing
00310                 Double datamin;
00311                 Double datamax;
00312 
00313                 // internal bookkeeping
00314                 // number of axes
00315                 uInt nArrayAxes;
00316                 uInt nPixelAxes;
00317                 uInt nWorldAxes;
00318 
00319                 // format for diplaying numbers in the tracker
00320                 Coordinate::formatType itsNotation;
00321 
00322                 // do some setup work, part of construction and changing dataset
00323                 void setup(IPosition fixedPos);
00324 
00325                 // functions need by above
00326                 virtual void setupElements();
00327                 virtual void getMinAndMax() = 0;
00328 
00329                 // Helper routine for setting up the transpose vectors for the coordinate
00330                 // system.
00331                 Bool indexInserted(Int index, Int length, Vector<Int>& testVec);
00332 
00333                 // helper to transpose coordinates
00334                 // <group>
00335                 void normalToTransposed(Vector<Double>& coord, const Vector<Int>& transPos);
00336                 void transposedToNormal(Vector<Double>& coord, const Vector<Int>& transPos);
00337                 // </group>
00338 
00339                 // Set velocity state
00340                 void setVelocityState (DisplayCoordinateSystem& cSys,
00341                                        const String& velTypeString,
00342                                        const String& unitString);
00343 
00344                 // Set Spectral formatting
00345                 void setSpectralFormatting (DisplayCoordinateSystem& cSys,
00346                                             const String& velTypeString,
00347                                             const String& unitString,
00348                                             const String& frequency_system = "");
00349 
00350                 // Determine the active image (if any).
00351                 // (Deprecated (7/04).  Use  confromsToZIndex(wch)  instead).
00352                 Bool findActiveImage(WorldCanvasHolder &wcHolder);
00353 
00354                 // (Required) default constructor.
00355                 PrincipalAxesDD();
00356 
00357                 // (Required) copy constructor.
00358                 PrincipalAxesDD(const PrincipalAxesDD &other);
00359 
00360                 // (Required) copy assignment.
00361                 void operator=(const PrincipalAxesDD &other);
00362 
00363                 // ImageAnalysis class does not support complex images...
00364                 // so these functions are used to allow only the
00365                 // LatticePADisplayData<T> template to only return an
00366                 // image analysis object for the non-complex version...
00367                 ImageAnalysis *create_image_analysis( SHARED_PTR<ImageInterface<float> > ) const;
00368                 ImageAnalysis *create_image_analysis( SHARED_PTR<ImageInterface<Complex> > ) const {
00369                         return 0;
00370                 }
00371 
00372                 std::string error_string;
00373 
00374         private:
00375 
00376                 // axis numbers IN ORIGINAL COORDINATE SYSTEM; zAxisNum = -1 means
00377                 // no third axis in data set
00378                 Int itsXAxisNum;
00379                 Int itsYAxisNum;
00380                 Int itsZAxisNum;
00381 
00382                 // the x (0), y (1) and z/movie (2) axis numbers
00383                 vector<int> itsDisplayAxes;
00384 
00385                 // Store options:
00386                 // Axis selection ---
00387                 String itsOptionsXAxis, itsOptionsYAxis, itsOptionsZAxis;
00388                 IPosition itsFixedPosition;
00389 
00390                 // treatment of edge pixels
00391                 String itsOptionsPixelTreatment;
00392 
00393                 // number of elements (images) in this DisplayData
00394                 uInt itsNumImages;
00395 
00396                 // This CS is the one we were constructed with
00397                 DisplayCoordinateSystem itsOrigCoordSys;
00398                 DisplayCoordinateSystem itsCoordSysBackup;
00399 
00400                 // This is the working CS which is transposed and has axes removed
00401                 // all over the place
00402 
00403                 // (dk note: The authors explain this poorly, and don't seem to make
00404                 // the distinction even for themselves very well: there are _two_
00405                 // relevant coordinate transformations here, not just one.  itsOrigCoordSys
00406                 // defines the world space for the _data_ pixels.  itsCoordSys defines the
00407                 // world space for the _canvas_.  Control and setting of the canvas CS is
00408                 // poorly modularized, and the DDs remain involved in too much of the
00409                 // _canvas's_ coordinate translation chores).
00410 
00411                 DisplayCoordinateSystem itsCoordSys;
00412 
00413                 // List of AxisLabellers.
00414                 PtrBlock<void *> itsAxisLabellers;
00415 
00416                 // Aspect selection ---
00417                 String itsOptionsAspect;
00418 
00419                 // Position tracking variables
00420                 // This CS is the one we use to set the appropriate state for
00421                 // PositionTracking.    It is pretty much the same as itsOriginalCoordSys
00422                 // but the formtting and velocity state (if there is a SC) may differ
00423 
00424                 DisplayCoordinateSystem itsPosTrackCoordSys;
00425                 String itsSpectralUnit;
00426                 String itsSpectralQuantity;
00427                 Bool itsAbsolute;
00428                 Bool itsFractionalPixels;
00429 
00430                 // buffer for string sizecontrol done by this ImageDisplayData
00431                 AttributeBuffer sizeControlBuf;
00432 
00433                 // the coordinates of the axes that do not vary
00434                 Vector<Double>    itsAddPixPos;
00435 
00436                 // how the axes are permuted
00437                 Vector<Int>       itsTransPixelAxes;
00438                 Vector<Int>       itsTransWorldAxes;
00439 
00440                 // world ranges for toMix conversions
00441                 Vector<Double> itsWorldMin, itsWorldMax;
00442 
00443                 // Temporaries  for coordinate conversions.
00444                 // You should only use one temporary per function.
00445                 Vector<Double> itsWorldInTmp1, itsPixelInTmp1;
00446                 Vector<Bool> itsWorldAxesTmp1, itsPixelAxesTmp1;
00447                 Vector<Double> itsFullWorldTmp1;
00448                 //
00449                 Vector<Double> itsPixelInTmp2;
00450                 //
00451                 Vector<Double> itsWorldInTmp3, itsWorldOutTmp3;
00452                 Vector<Double> itsPixelInTmp3, itsPixelOutTmp3;
00453                 Vector<Bool> itsWorldAxesTmp3, itsPixelAxesTmp3;
00454                 //
00455                 Vector<Double> itsFullWorldTmp4, itsFullPixelTmp4;
00456 
00457                 Bool itsUsesAxisLabels;
00458 
00459                 // Find out if SpectralCoordinate can have velocity units
00460                 Bool canHaveVelocityUnit (const DisplayCoordinateSystem& cSys) const;
00461 
00462                 // Remove list of pixel axes from CS
00463                 void removePixelAxes (DisplayCoordinateSystem& cSys,
00464                                       uInt startAxis,
00465                                       const IPosition& fixedPosition);
00466 
00467                 viewer::StatusSink *ssink;
00468                 String titleText;
00469 
00470         };
00471 
00472 
00473 } //# NAMESPACE CASA - END
00474 
00475 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1