ImageExpr.h

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

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1