casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LELCoordinates.h
Go to the documentation of this file.
00001 //# LELCoordinates.h: Envelope class for Lattice coordinates in LEL
00002 //# Copyright (C) 1998,1999,2000,2001
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: LELCoordinates.h 18093 2004-11-30 17:51:10Z ddebonis $
00027 
00028 #ifndef LATTICES_LELCOORDINATES_H
00029 #define LATTICES_LELCOORDINATES_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Utilities/CountedPtr.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class LELLattCoordBase;
00040 
00041 
00042 // <summary>
00043 // Envelope class to handle Lattice Coordinates in LEL.
00044 // </summary>
00045 
00046 // <use visibility=export>
00047 
00048 // <reviewed reviewer="Bob Garwood" date="2000/01/25" tests="tLatticeExpr">
00049 // </reviewed>
00050 
00051 // <prerequisite>
00052 //   <li> <linkto class="Lattice">Lattice</linkto>
00053 //   <li> <linkto class="LELLattCoordBase">LELLattCoordBase</linkto>
00054 // </prerequisite>
00055 
00056 // <synopsis> 
00057 //  The LatticeExpression classes (LatticeExpr, LatticeExprNode, LEL*)
00058 //  exist so that the C++ programmer can manipulate mathematical 
00059 //  expressions involving Lattices.  A further usage of these classes 
00060 //  is to manipulate ImageInterface objects (which inherit from Lattice) such 
00061 //  as PagedImages.  These objects have Coordinates as well as the Lattice 
00062 //  pixels.  In order that Coordinate conformance be enforcable, we must 
00063 //  give the LatticeExpression classes access to the Coordinates of the 
00064 //  ImageInterface objects.
00065 //
00066 //  This is done through the interface of the LELCoordinates class.
00067 //  It is actually an envelope class which holds letter classes which
00068 //  are the actual implementation of the objects which hold the Lattice
00069 //  CoordinateSystems.
00070 //  Lattice objects have a member function called <src>lelCoordinates</src>.
00071 //  This returns a LELCoordinates object.  This object contains a
00072 //  pointer (actually a CountedPtr) of type
00073 //  <linkto class=LELLattCoordBase>LELLattCoordBase</linkto>.  This is the
00074 //  base class of the letter classes.  For Lattices such as ImageInterface,
00075 //  this pointer actually points at the derived letter class LELImageCoord.
00076 //  This class in turn contains a pointer (a CountedPtr) to the actual
00077 //  CoordinateSystem object.   
00078 // 
00079 //  Note that every time the <src>lelCoordinates</src> function is called,
00080 //  the <linkto class=LELLattCoord>LELLattCoord</linkto>
00081 //  and <linkto class=LELImageCoord>LELImageCoord</linkto>
00082 //  (or whatever the letter class actually being invoked is)
00083 //  objects are constructed.  For example
00084 //  the internals of <src>ImageInterface::lelCoordinates</src> are
00085 //  <br><src>return LELCoordinates (new LELImageCoord (coords_p));</src>
00086 //  <br>so that the LELCoordinates constructor invokes the LELImageCoord
00087 //  constructor with the CoordinateSystem as its argument.  However,
00088 //  the internal use of CountedPtrs makes subsequent constructions inexpensive.
00089 //
00090 //  Having a LELCoordinates object in hand, the programmer then has access
00091 //  to the CoordinateSystem that it ultimately contains.  This is via the
00092 //  LELCoordinates member function <src>coordinates</src> which returns
00093 //  a reference to the letter base class LELLattCoordBase.
00094 //  For example, if the actual letter class object was LELImageCoord,
00095 //  one has to then cast the reference returned by
00096 //  <src>LELCoordinates::coordinates()</src> to an LELImageCoord.
00097 //  This is because the LELImageCoord class functions that actually deal
00098 //  with the CoordinateSystem are not virtual (otherwise LELLattCoordBase
00099 //  needs to know about Coordinates).
00100 // </synopsis>
00101 
00102 // <example>
00103 // <srcblock>
00104 //    PagedImage<Float> im("myimage");
00105 //    const LELCoordinates* pLatCoord = &(im.lelCoordinates());
00106 //    const LELImageCoord* pImCoord =
00107 //                  dynamic_cast<const LELImageCoord*>(pLatCoord);
00108 //    CoordinateSystem coords = pImCoord->coordinates();
00109 // </srcblock>
00110 // </example>
00111 
00112 // <motivation>
00113 //  We needed access to CoordinateSystems in the Lattice Expression classes
00114 //  without making the Lattices module dependent on the Images or Coordinates
00115 //  module.
00116 // </motivation>
00117 
00118 //# <todo asof="1995/09/12">
00119 //#  <li>
00120 //# </todo>
00121 
00122 
00123 class LELCoordinates
00124 {
00125 public:
00126     // Define the possible comparison results.
00127     // The default constructor creates a null object.
00128     LELCoordinates();
00129 
00130     // Construct the object from the given letter class.
00131     // It takes over the pointer and takes care of destructing
00132     // the LELLattCoordBase object.
00133     LELCoordinates (LELLattCoordBase* coordinates);
00134 
00135     // Copy constructor (reference semantics).
00136     LELCoordinates (const LELCoordinates& that);
00137 
00138     ~LELCoordinates();
00139 
00140     // Assignment (reference semantics).
00141     LELCoordinates& operator= (const LELCoordinates& that);
00142 
00143     // Is the coordinates a null object?
00144     Bool isNull() const
00145       { return coords_p.null(); }
00146 
00147     // Does the class have true coordinates?
00148     // It returns False if this is a null object.
00149     Bool hasCoordinates() const;
00150 
00151     // Check how the coordinates of this and that compare.
00152     // The return value tells how they compare.
00153     // <br>-1: this is subset
00154     // <br>0: equal 
00155     // <br>1: this is superset
00156     // <br>9: invalid (mismatch)
00157     Int compare (const LELCoordinates& other) const;
00158 
00159     // Return the underlying letter object.
00160     // This should in general not be used, but for specific (Image) cases
00161     // it might be needed.
00162     const LELLattCoordBase& coordinates() const;
00163 
00164 private:
00165     // The pointer to the underlying object.
00166     CountedPtr<LELLattCoordBase> coords_p;
00167 };
00168 
00169 
00170 
00171 } //# NAMESPACE CASA - END
00172 
00173 #endif