00001 //# SubLattice.h: A subset of a Lattice or MaskedLattice 00002 //# Copyright (C) 1997,1998,1999,2000,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$ 00028 00029 #ifndef LATTICES_SUBLATTICE_H 00030 #define LATTICES_SUBLATTICE_H 00031 00032 00033 //# Includes 00034 #include <casa/aips.h> 00035 #include <lattices/Lattices/MaskedLattice.h> 00036 #include <lattices/Lattices/LatticeRegion.h> 00037 #include <casa/Arrays/AxesSpecifier.h> 00038 #include <casa/Arrays/AxesMapping.h> 00039 00040 namespace casa { //# NAMESPACE CASA - BEGIN 00041 00042 //# Forward Declarations 00043 00044 00045 // <summary> 00046 // A subset of a Lattice or MaskedLattice 00047 // </summary> 00048 00049 // <use visibility=export> 00050 00051 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00052 // </reviewed> 00053 00054 // <prerequisite> 00055 // <li> <linkto class="Lattice">Lattice</linkto> 00056 // <li> <linkto class="LatticeRegion">LatticeRegion</linkto> 00057 // </prerequisite> 00058 00059 // <synopsis> 00060 // A SubLattice is a lattice referencing a subset of another lattice 00061 // by means of a <linkto class="Slicer">Slicer</linkto> object. 00062 // <br>It is useful when only a subset of a lattice needs to be accessed. 00063 // <p> 00064 // When the SubLattice is created from a const <src>Lattice</src> object, 00065 // it is not writable, thus it can only be used as an rvalue. 00066 // <p> 00067 // Using an <linkto class=AxesSpecifier>AxesSpecifier</linkto> object 00068 // it is possible to remove some or all degenerate axes (i.e. axes 00069 // with length 1) to get a lattice with a lower dimensionality. 00070 // </synopsis> 00071 00072 // <example> 00073 // <srcblock> 00074 // </srcblock> 00075 // </example> 00076 00077 // <templating arg=T> 00078 // <li> Any type that can be used by the Tables System can also be used by 00079 // this class. 00080 // </templating> 00081 00082 //# <todo asof="yyyy/mm/dd"> 00083 //# </todo> 00084 00085 template<class T> class SubLattice: public MaskedLattice<T> 00086 { 00087 public: 00088 // The default constructor creates a SubLattice that is useless for just 00089 // about everything, except that it can be assigned to with the assignment 00090 // operator. 00091 SubLattice(); 00092 00093 // Create a SubLattice from a Lattice. 00094 // This results in a SubLattice without a real mask. 00095 // <br>The "const Lattice" version yields a non-writable SubLattice, 00096 // while for the non-const version one has to specify if the SubLattice 00097 // should be writable (if the original lattice is non-writable, the 00098 // SubLattice is always set to non-writable). 00099 // <group> 00100 SubLattice (const Lattice<T>& lattice, AxesSpecifier=AxesSpecifier()); 00101 SubLattice (Lattice<T>& lattice, Bool writableIfPossible, 00102 AxesSpecifier=AxesSpecifier()); 00103 // </group> 00104 00105 // Create a SubLattice from a MaskedLattice. 00106 // <br>The "const MaskedLattice" version yields a non-writable SubLattice, 00107 // while for the non-const version one has to specify if the SubLattice 00108 // should be writable (if the original lattice is non-writable, the 00109 // SubLattice is always set to non-writable). 00110 // <group> 00111 SubLattice (const MaskedLattice<T>& lattice, AxesSpecifier=AxesSpecifier()); 00112 SubLattice (MaskedLattice<T>& lattice, Bool writableIfPossible, 00113 AxesSpecifier=AxesSpecifier()); 00114 // </group> 00115 00116 // Create a SubLattice from the given MaskedLattice and region. 00117 // Note that the region can be constructed from an 00118 // <linkto class=LCRegion>LCRegion</linkto> object or 00119 // <linkto class=Slicer>Slicer</linkto> object (with an optional stride). 00120 // <br>An exception is thrown if the lattice shape used in the region 00121 // differs from the shape of the lattice. 00122 // <group> 00123 SubLattice (const Lattice<T>& lattice, const LatticeRegion& region, 00124 AxesSpecifier=AxesSpecifier()); 00125 SubLattice (Lattice<T>& lattice, const LatticeRegion& region, 00126 Bool writableIfPossible, AxesSpecifier=AxesSpecifier()); 00127 SubLattice (const MaskedLattice<T>& lattice, const LatticeRegion& region, 00128 AxesSpecifier=AxesSpecifier()); 00129 SubLattice (MaskedLattice<T>& lattice, const LatticeRegion& region, 00130 Bool writableIfPossible, AxesSpecifier=AxesSpecifier()); 00131 // </group> 00132 00133 // Create a SubLattice from the given (Masked)Lattice and slicer. 00134 // The slicer can be strided. 00135 // <br>An exception is thrown if the slicer exceeds the lattice shape. 00136 // <group> 00137 SubLattice (const Lattice<T>& lattice, const Slicer& slicer, 00138 AxesSpecifier=AxesSpecifier()); 00139 SubLattice (Lattice<T>& lattice, const Slicer& slicer, 00140 Bool writableIfPossible, AxesSpecifier=AxesSpecifier()); 00141 SubLattice (const MaskedLattice<T>& lattice, const Slicer& slicer, 00142 AxesSpecifier=AxesSpecifier()); 00143 SubLattice (MaskedLattice<T>& lattice, const Slicer& slicer, 00144 Bool writableIfPossible, AxesSpecifier=AxesSpecifier()); 00145 // </group> 00146 00147 // Copy constructor (reference semantics). 00148 SubLattice (const SubLattice<T>& other); 00149 00150 virtual ~SubLattice(); 00151 00152 // Assignment (reference semantics). 00153 SubLattice<T>& operator= (const SubLattice<T>& other); 00154 00155 // Make a copy of the object (reference semantics). 00156 virtual MaskedLattice<T>* cloneML() const; 00157 00158 // Is the lattice masked? 00159 // It is if its parent lattice or its region is masked. 00160 virtual Bool isMasked() const; 00161 00162 // A SubLattice is persistent if no region is applied to the parent lattice. 00163 // That is true if the region has the same shape as the parent lattice 00164 // and the region has no mask. 00165 virtual Bool isPersistent() const; 00166 00167 // Is the SubLattice paged to disk? 00168 virtual Bool isPaged() const; 00169 00170 // Can the lattice data be referenced as an array section? 00171 virtual Bool canReferenceArray() const; 00172 00173 // Is the SubLattice writable? 00174 virtual Bool isWritable() const; 00175 00176 // Handle locking of the SubLattice which is delegated to its parent. 00177 // <br>It is strongly recommended to use class 00178 // <linkto class=LatticeLocker>LatticeLocker</linkto> to 00179 // handle lattice locking. It also contains a more detailed 00180 // explanation of the locking process. 00181 // <group> 00182 virtual Bool lock (FileLocker::LockType, uInt nattempts); 00183 virtual void unlock(); 00184 virtual Bool hasLock (FileLocker::LockType) const; 00185 // </group> 00186 00187 // Resynchronize the Lattice object with the lattice file. 00188 // This function is only useful if no read-locking is used, ie. 00189 // if the table lock option is UserNoReadLocking or AutoNoReadLocking. 00190 // In that cases the table system does not acquire a read-lock, thus 00191 // does not synchronize itself automatically. 00192 virtual void resync(); 00193 00194 // Flush the data. 00195 virtual void flush(); 00196 00197 // Close the Lattice temporarily (if it is paged to disk). 00198 // It'll be reopened automatically when needed or when 00199 // <src>reopen</src> is called explicitly. 00200 virtual void tempClose(); 00201 00202 // If needed, reopen a temporarily closed Lattice. 00203 virtual void reopen(); 00204 00205 // Does the SubLattice have a pixelmask? 00206 virtual Bool hasPixelMask() const; 00207 00208 // Get access to the pixelmask. 00209 // An exception is thrown if the SubLattice does not have a pixelmask. 00210 // <group> 00211 virtual const Lattice<Bool>& pixelMask() const; 00212 virtual Lattice<Bool>& pixelMask(); 00213 // </group> 00214 00215 // Use the given mask as the pixelmask. 00216 // If another mask was already used, the new one will be used instead. 00217 // It checks if its shape matches the shape of the sublattice. 00218 // <br>If <code>mayExist=False</code>, setting the pixelmask is only 00219 // possible if the underlying lattice does not have a pixelmask. 00220 // <br>If <code>mayExist=True</code>, the resulting pixelmask is the 00221 // AND of the given pixelmask and the pixelmask of the underlying lattice. 00222 void setPixelMask (const Lattice<Bool>& pixelMask, Bool mayExist); 00223 00224 // Get a pointer the region/mask object describing this sublattice. 00225 virtual const LatticeRegion* getRegionPtr() const; 00226 00227 // Returns the shape of the SubLattice including all degenerate axes 00228 // (i.e. axes with a length of one). 00229 virtual IPosition shape() const; 00230 00231 // Return the name of the parent lattice. 00232 virtual String name (Bool stripPath=False) const; 00233 00234 // This function returns the recommended maximum number of pixels to 00235 // include in the cursor of an iterator. 00236 virtual uInt advisedMaxPixels() const; 00237 00238 // Get or put a single element in the lattice. 00239 // <group> 00240 virtual T getAt (const IPosition& where) const; 00241 virtual void putAt (const T& value, const IPosition& where); 00242 // </group> 00243 00244 // Check class internals - used for debugging. Should always return True 00245 virtual Bool ok() const; 00246 00247 // This function is used by the LatticeIterator class to generate an 00248 // iterator of the correct type for this Lattice. Not recommended 00249 // for general use. 00250 virtual LatticeIterInterface<T>* makeIter (const LatticeNavigator& navigator, 00251 Bool useRef) const; 00252 00253 // Do the actual getting of an array of values. 00254 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section); 00255 00256 // Do the actual getting of an array of values. 00257 virtual void doPutSlice (const Array<T>& sourceBuffer, 00258 const IPosition& where, 00259 const IPosition& stride); 00260 00261 // Get a section of the mask. 00262 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section); 00263 00264 // Get the best cursor shape. 00265 virtual IPosition doNiceCursorShape (uInt maxPixels) const; 00266 00267 // Set the axes mapping from the specification. 00268 const AxesMapping& getAxesMap() const 00269 { return itsAxesMap; } 00270 00271 protected: 00272 // Set the various pointer needed to construct the object. 00273 // One of the pointers should be zero. 00274 // It takes over the pointer and deletes the object in the destructor. 00275 void setPtr (Lattice<T>* latticePtr, 00276 MaskedLattice<T>* maskLatPtr, 00277 Bool writableIfPossible); 00278 00279 // Set the region object. 00280 // It also fills in the parent pointer when the SubLattice is taken 00281 // from a MaskedLattice. 00282 // The default region is the entire lattice. 00283 // <group> 00284 void setRegion (const LatticeRegion& region); 00285 void setRegion (const Slicer& slicer); 00286 void setRegion(); 00287 // </group> 00288 00289 // Set the axes mapping from the specification. 00290 void setAxesMap (const AxesSpecifier&); 00291 00292 00293 private: 00294 // Get mask data from region and mask. 00295 // <group> 00296 Bool getRegionDataSlice (Array<Bool>& buffer, const Slicer& section); 00297 Bool getMaskDataSlice (Array<Bool>& buffer, const Slicer& section); 00298 // </group> 00299 00300 // And tmpbuf into buffer. If buffer is a reference, first a copy is made. 00301 void andMask (Array<Bool>& buffer, Bool ref, 00302 const Array<Bool>& tmpbuf) const; 00303 00304 Lattice<T>* itsLatticePtr; 00305 MaskedLattice<T>* itsMaskLatPtr; 00306 LatticeRegion itsRegion; 00307 Bool itsWritable; 00308 Bool itsHasLattPMask; //# has underlying lattice a pixelmask? 00309 Lattice<Bool>* itsPixelMask; //# AND of lattice and own pixelmask 00310 Lattice<Bool>* itsOwnPixelMask; //# own pixelmask 00311 AxesSpecifier itsAxesSpec; 00312 AxesMapping itsAxesMap; 00313 }; 00314 00315 00316 00317 } //# NAMESPACE CASA - END 00318 00319 #ifndef AIPS_NO_TEMPLATE_SRC 00320 #include <lattices/Lattices/SubLattice.cc> 00321 #endif //# AIPS_NO_TEMPLATE_SRC 00322 #endif
1.5.1