casa
$Rev:20696$
|
00001 //# ImageExpr.h: contains expressions involving images 00002 //# Copyright (C) 1994,1995,1996,1997,1999,2000,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 //# $Id: ImageExpr.h 20299 2008-04-03 05:56:44Z gervandiepen $ 00027 00028 #ifndef IMAGES_IMAGEEXPR_H 00029 #define IMAGES_IMAGEEXPR_H 00030 00031 00032 //# Includes 00033 #include <images/Images/ImageInterface.h> 00034 #include <lattices/Lattices/LatticeExpr.h> 00035 #include <casa/Containers/Record.h> 00036 #include <casa/Quanta/Unit.h> 00037 00038 namespace casa { //# NAMESPACE CASA - BEGIN 00039 00040 //# Forward Declarations 00041 class IPosition; 00042 class Slicer; 00043 template <class T> class Array; 00044 class LatticeNavigator; 00045 template <class T> class LatticeIterInterface; 00046 class String; 00047 00048 00049 // <summary> 00050 // Hold mathematical expressions involving ImageInterface objects 00051 // </summary> 00052 // 00053 // <use visibility=export> 00054 // 00055 // <reviewed reviewer="" date="" tests="tImageExpr.cc"> 00056 // </reviewed> 00057 // 00058 // <prerequisite> 00059 // <li> LatticeExpr 00060 // <li> ImageInterface 00061 // </prerequisite> 00062 // 00063 // <etymology> 00064 // This class holds a LatticeExpr object but inherits from 00065 // ImageInterface hence ImageExpr 00066 // </etymology> 00067 // 00068 // <synopsis> 00069 // An ImageExpr object holds a LatticeExpr object which can be used 00070 // to evaluate mathematical expressions involving Lattices. ImageExpr 00071 // exists so that direct manipulation of LatticeExpr objects by methods 00072 // expecting an ImageInterface, rather than a Lattice can occur. 00073 // 00074 // The ImageExpr object is constructed from a LatticeExpr object, but 00075 // only if the latter has true Coordinates associated with it. 00076 // The ImageExpr object is not writable, so the ImageExpr object 00077 // functions like a read only ImageInterface. 00078 // </synopsis> 00079 // 00080 // <example> 00081 // <srcblock> 00082 // PagedImage<Float> a("imageB"); // Open PagedImages 00083 // PagedImage<Float> b("imageB"); 00084 // 00085 // LatticeExprNode node(a+b); // Create ImageExpr 00086 // LatticeExpr<Float> lExpr(node); 00087 // ImageExpr<Float> iExpr(lExpr); 00088 // 00089 // LogOrigin or("imageImpl", "main()", WHERE); // Create statistics object 00090 // LogIO logger(or); 00091 // ImageStatistics<Float> stats(iExpr, logger); 00092 // Bool ok = stats.display(); // Display statistics 00093 // 00094 // </srcblock> 00095 // The ImageExpr object is evaluated during the call to 00096 // <src>stats.dislay()</src>. Previously, the expression tree 00097 // has been constructed, but not evaluated. 00098 // </example> 00099 // 00100 // <motivation> 00101 // This enables one to evaluate expressions but not to have to write them 00102 // out to an output image. 00103 // </motivation> 00104 // 00105 // <todo asof="1998/02/09"> 00106 // </todo> 00107 00108 00109 template <class T> class ImageExpr: public ImageInterface<T> 00110 { 00111 public: 00112 // The default constructor 00113 ImageExpr(); 00114 00115 // Construct an ImageExpr from a LatticeExpr. 00116 // The name given could be the original expression string. 00117 // The prefix "Expression: " is added to the name if not empty. 00118 // The function name() returns this name (including possible prefix). 00119 ImageExpr(const LatticeExpr<T>& latticeExpr, const String& name); 00120 00121 // Copy constructor (reference semantics) 00122 ImageExpr(const ImageExpr<T>& other); 00123 00124 // Destructor does nothing 00125 ~ImageExpr(); 00126 00127 // Assignment (reference semantics) 00128 ImageExpr<T>& operator=(const ImageExpr<T>& other); 00129 00130 // Make a copy of the object (reference semantics). 00131 virtual ImageInterface<T>* cloneII() const; 00132 00133 // Get the image type (returns name of derived class). 00134 virtual String imageType() const; 00135 00136 // Has the object really a mask? 00137 virtual Bool isMasked() const; 00138 00139 // Get the region used. 00140 virtual const LatticeRegion* getRegionPtr() const; 00141 00142 // return the shape of the ImageExpr 00143 virtual IPosition shape() const; 00144 00145 // Function which changes the shape of the ImageExpr. 00146 // Throws an exception as ImageExpr is not writable. 00147 virtual void resize(const TiledShape& newShape); 00148 00149 // Do the actual get of the mask data. 00150 // The return value is always False, thus the buffer does not reference 00151 // another array. 00152 virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section); 00153 00154 // Do the actual get of the data. 00155 virtual Bool doGetSlice (Array<T>& buffer, const Slicer& theSlice); 00156 00157 // putSlice is not possible on an expression, so it throws an exception. 00158 virtual void doPutSlice (const Array<T>& sourceBuffer, 00159 const IPosition& where, 00160 const IPosition& stride); 00161 00162 // Return the name of the current ImageInterface object. 00163 // Returns the expression string given in the constructor. 00164 virtual String name (Bool stripPath=False) const; 00165 00166 // Check class invariants. 00167 virtual Bool ok() const; 00168 00169 // These are the implementations of the LatticeIterator letters. 00170 // <note> not for public use </note> 00171 virtual LatticeIterInterface<T>* makeIter( 00172 const LatticeNavigator& navigator, 00173 Bool useRef) const; 00174 00175 // Returns False, as the ImageExpr is not writable. 00176 virtual Bool isWritable() const; 00177 00178 // Help the user pick a cursor for most efficient access if they only want 00179 // pixel values and don't care about the order or dimension of the 00180 // cursor. 00181 virtual IPosition doNiceCursorShape (uInt maxPixels) const; 00182 00183 // Handle the (un)locking and syncing. 00184 // <group> 00185 virtual Bool lock (FileLocker::LockType, uInt nattempts); 00186 virtual void unlock(); 00187 virtual Bool hasLock (FileLocker::LockType) const; 00188 virtual void resync(); 00189 virtual void tempClose(); 00190 virtual void reopen(); 00191 // </group> 00192 00193 // Get the lattice expression. 00194 const LatticeExpr<T>& expression() const 00195 { return latticeExpr_p; } 00196 00197 00198 private: 00199 LatticeExpr<T> latticeExpr_p; 00200 Unit unit_p; 00201 00202 // These are used to return null object by reference 00203 00204 Lattice<Bool>* pBool_p; 00205 Record rec_p; 00206 String name_p; 00207 00208 //# Make members of parent class known. 00209 protected: 00210 using ImageInterface<T>::setCoordsMember; 00211 // using ImageInterface<T>::setImageInfoMember; 00212 }; 00213 00214 00215 00216 00217 } //# NAMESPACE CASA - END 00218 00219 #ifndef CASACORE_NO_AUTO_TEMPLATES 00220 #include <images/Images/ImageExpr.tcc> 00221 #endif //# CASACORE_NO_AUTO_TEMPLATES 00222 #endif