casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ExtendLattice.h
Go to the documentation of this file.
00001 //# ExtendLattice.h: A subset of a Lattice or MaskedLattice
00002 //# Copyright (C) 2001,2003
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 //#
00027 //# $Id: ExtendLattice.h 20229 2008-01-29 15:19:06Z gervandiepen $
00028 
00029 #ifndef LATTICES_EXTENDLATTICE_H
00030 #define LATTICES_EXTENDLATTICE_H
00031 
00032 
00033 //# Includes
00034 #include <casa/aips.h>
00035 #include <lattices/Lattices/MaskedLattice.h>
00036 #include <casa/Arrays/ExtendSpecifier.h>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 
00042 
00043 // <summary>
00044 // An extension of a Lattice or MaskedLattice
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //   <li> <linkto class="Lattice">Lattice</linkto>
00054 //   <li> <linkto class="LatticeRegion">LatticeRegion</linkto>
00055 // </prerequisite>
00056 
00057 // <synopsis>
00058 // An ExtendLattice is a lattice virtually extending another lattice
00059 // by stretching axes with length 1 and/or by adding new axes.
00060 // It is useful for e.g. LEL to have the same shapes for lattices.
00061 // An ExtendLattice is not writable (since many pixels map to the same
00062 // underlying pixel).
00063 // </synopsis>
00064 
00065 // <example>
00066 // <srcblock>
00067 // </srcblock>
00068 // </example>
00069 
00070 // <templating arg=T>
00071 //  <li> Any type that can be used by the Tables System can also be used by
00072 //       this class.
00073 // </templating>
00074 
00075 //# <todo asof="yyyy/mm/dd">
00076 //# </todo>
00077 
00078 template<class T> class ExtendLattice: public MaskedLattice<T>
00079 {
00080 public:
00081   // The default constructor creates a ExtendLattice that is useless for just
00082   // about everything, except that it can be assigned to with the assignment
00083   // operator.
00084   ExtendLattice();
00085 
00086   // Create a ExtendLattice from a Lattice.
00087   // <br><src>newShape</src> gives the new shape.
00088   // <br><src>newAxes</src> gives the new axes in newShape.
00089   // <br><src>stretchAxes</src> gives the stretched axes in newShape.
00090   // <br>E.g. lattice has shape [32,1,5,1], newShape=[32,1,4,5,10],
00091   // newAxes=[2], and stretchAxes=[4]. It means that axes 2 in the newShape
00092   // is a new axes and that axes 4 in the new shape is stretched. The other
00093   // axes in the new shape have to match the other axes in the old shape.
00094   // Note that stretched axes have to have length 1 in the old shape.
00095   // <group>
00096   ExtendLattice (const Lattice<T>& lattice, const IPosition& newShape,
00097                  const IPosition& extendAxes, const IPosition& stretchAxes);
00098   ExtendLattice (const MaskedLattice<T>& lattice, const IPosition& newShape,
00099                  const IPosition& newAxes, const IPosition& stretchAxes);
00100   // </group>
00101 
00102   // Copy constructor (reference semantics).
00103   ExtendLattice (const ExtendLattice<T>& other);
00104     
00105   virtual ~ExtendLattice();
00106 
00107   // Assignment (reference semantics).
00108   ExtendLattice<T>& operator= (const ExtendLattice<T>& other);
00109 
00110   // Make a copy of the object (reference semantics).
00111   virtual MaskedLattice<T>* cloneML() const;
00112 
00113   // Is the lattice masked?
00114   // It is if its parent lattice is masked.
00115   virtual Bool isMasked() const;
00116 
00117   // An ExtendLattice is not persistent.
00118   virtual Bool isPersistent() const;
00119 
00120   // Is the ExtendLattice paged to disk?
00121   virtual Bool isPaged() const;
00122 
00123   // An ExtendLattice is not writable.
00124   virtual Bool isWritable() const;
00125 
00126   // Handle locking of the ExtendLattice which is delegated to its parent.
00127   // <br>It is strongly recommended to use class
00128   // <linkto class=LatticeLocker>LatticeLocker</linkto> to
00129   // handle lattice locking. It also contains a more detailed
00130   // explanation of the locking process.
00131   // <group>
00132   virtual Bool lock (FileLocker::LockType, uInt nattempts);
00133   virtual void unlock();
00134   virtual Bool hasLock (FileLocker::LockType) const;
00135   // </group>
00136 
00137   // Resynchronize the Lattice object with the lattice file.
00138   // This function is only useful if no read-locking is used, ie.
00139   // if the table lock option is UserNoReadLocking or AutoNoReadLocking.
00140   // In that cases the table system does not acquire a read-lock, thus
00141   // does not synchronize itself automatically.
00142   virtual void resync();
00143 
00144   // Flush the data.
00145   virtual void flush();
00146 
00147   // Close the Lattice temporarily (if it is paged to disk).
00148   // It'll be reopened automatically when needed or when
00149   // <src>reopen</src> is called explicitly.
00150   virtual void tempClose();
00151 
00152   // If needed, reopen a temporarily closed Lattice.
00153   virtual void reopen();
00154 
00155   // Does the ExtendLattice have a pixelmask?
00156   virtual Bool hasPixelMask() const;
00157 
00158   // Get access to the pixelmask.
00159   // An exception is thrown if the ExtendLattice does not have a pixelmask.
00160   // <group>
00161   virtual const Lattice<Bool>& pixelMask() const;
00162   virtual Lattice<Bool>& pixelMask();
00163   // </group>
00164 
00165   // Get the region used (always returns 0).
00166   virtual const LatticeRegion* getRegionPtr() const;
00167  
00168   // Returns the shape of the ExtendLattice.
00169   virtual IPosition shape() const;
00170   
00171   // Return the name of the parent lattice.
00172   virtual String name (Bool stripPath=False) const;
00173 
00174   // This function returns the recommended maximum number of pixels to
00175   // include in the cursor of an iterator.
00176   virtual uInt advisedMaxPixels() const;
00177 
00178   // Check class internals - used for debugging. Should always return True
00179   virtual Bool ok() const;
00180 
00181   // Do the actual getting of an array of values.
00182   virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00183 
00184   // Putting data is not possible.
00185   virtual void doPutSlice (const Array<T>& sourceBuffer,
00186                            const IPosition& where,
00187                            const IPosition& stride);
00188   
00189   // Get a section of the mask.
00190   virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00191 
00192   // Get the best cursor shape.
00193   virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00194 
00195 private:
00196   // Set the various pointer needed to construct the object.
00197   // One of the pointers should be zero.
00198   // It takes over the pointer and deletes the object in the destructor.
00199   void setPtr (Lattice<T>* latticePtr, MaskedLattice<T>* maskLatPtr);
00200 
00201   // Get mask data from mask.
00202   Bool getMaskDataSlice (Array<Bool>& buffer, const Slicer& section);
00203 
00204   Lattice<T>*          itsLatticePtr;
00205   MaskedLattice<T>*    itsMaskLatPtr;
00206   Bool                 itsHasPixelMask;
00207   ExtendLattice<Bool>* itsPixelMask;
00208   ExtendSpecifier      itsExtendSpec;
00209 };
00210 
00211 
00212 
00213 } //# NAMESPACE CASA - END
00214 
00215 #ifndef CASACORE_NO_AUTO_TEMPLATES
00216 #include <lattices/Lattices/ExtendLattice.tcc>
00217 #endif //# CASACORE_NO_AUTO_TEMPLATES
00218 #endif