casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
RebinImage.h
Go to the documentation of this file.
00001 //# RebinImage.h: rebin an image
00002 //# Copyright (C) 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: RebinImage.h 20505 2009-01-19 14:37:24Z gervandiepen $
00027 
00028 #ifndef IMAGES_REBINIMAGE_H
00029 #define IMAGES_REBINIMAGE_H
00030 
00031 
00032 //# Includes
00033 #include <images/Images/ImageInterface.h>
00034 
00035 namespace casa { //# NAMESPACE CASA - BEGIN
00036 
00037 //# Forward Declarations
00038 template <class T> class RebinLattice;
00039 class LogIO;
00040 
00041 // <summary>
00042 // Rebin an image
00043 // </summary>
00044 //
00045 // <use visibility=export>
00046 //
00047 // <reviewed reviewer="" date="" tests="tRebinImage.cc">
00048 // </reviewed>
00049 //
00050 // <prerequisite>
00051 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00052 //   <li> <linkto class=RebinLattice>RebinLattice</linkto>
00053 // </prerequisite>
00054 //
00055 // <synopsis> 
00056 // Class RebinImage can be used to rebin (data averaged over bin) an image 
00057 // by integer amounts per axis.
00058 // </synopsis> 
00059 //
00060 // <example>
00061 // <srcblock>
00062 //    IPosition factors(2,2,2);
00063 //    PagedImage<Float> imageIn(String("myImage")):
00064 //    RebinLattice<Float> rb(imageIn, factors);
00065 //    IPosition shapeOut = rb.shape();
00066 //    TiledShape tShapeOut(shapeOut);
00067 //    TempImage<Float> imageOut(tShapeOut, rb.coordinates());
00068 //    LatticeUtilities::copyDataAndMask(os, imageOut, rb);
00069 //    ImageUtilities::copyMiscellaneous (imageOut, imageIn);
00070 // </srcblock>
00071 // </example>
00072 //
00073 // <motivation>
00074 // Users like to rebin images...
00075 // </motivation>
00076 //
00077 // <todo asof="2004/04/07">
00078 // </todo>
00079 
00080 
00081 template <class T> class RebinImage: public ImageInterface<T>
00082 {
00083 public: 
00084 
00085   // Default constructor (object useless)
00086   RebinImage ();
00087 
00088   // Constructor. The bin factors don't have to be integral. Anything left over
00089   // at the end is treated as a full bin.
00090   RebinImage (const ImageInterface<T>&, const IPosition& factors);
00091 
00092   // Copy constructor (reference semantics).
00093   RebinImage (const RebinImage<T>& other);
00094     
00095   virtual ~RebinImage();
00096 
00097   // Assignment (reference semantics).
00098   RebinImage<T>& operator= (const RebinImage<T>& other);
00099 
00100   // Make a copy of the object (reference semantics).
00101   // <group>
00102   virtual ImageInterface<T>* cloneII() const;
00103   // </group>
00104 
00105   // Get the image type (returns name of derived class).
00106   virtual String imageType() const;
00107 
00108   // Is the RebinImage masked?
00109   // It is if its parent image is masked.
00110   virtual Bool isMasked() const;
00111 
00112   // Does the image object have a pixelmask?
00113   // It does if its parent has a pixelmask.
00114   virtual Bool hasPixelMask() const;
00115 
00116   // Get access to the pixelmask in use (thus to the pixelmask of the parent).
00117   // An exception is thrown if the parent does not have a pixelmask.
00118   // <group>
00119   virtual const Lattice<Bool>& pixelMask() const;
00120   virtual Lattice<Bool>& pixelMask();
00121   // </group>
00122 
00123   // Get the region used (always returns 0).
00124   virtual const LatticeRegion* getRegionPtr() const;
00125 
00126   // A RebinImage is not persistent.
00127   virtual Bool isPersistent() const;
00128 
00129   // Is the RebinImage paged to disk?
00130   virtual Bool isPaged() const;
00131 
00132   // An RebinImage is not writable
00133   virtual Bool isWritable() const;
00134 
00135   // Returns the shape of the RebinImage
00136   virtual IPosition shape() const;
00137   
00138   // This function returns the recommended maximum number of pixels to
00139   // include in the cursor of an iterator.
00140   virtual uInt advisedMaxPixels() const;
00141 
00142   // Function which changes the shape of the RebinImage.
00143   // Throws an exception as resizing an RebinImage is not possible.
00144   virtual void resize(const TiledShape& newShape);
00145 
00146   // Return the name of the parent ImageInterface object. 
00147   virtual String name (Bool stripPath=False) const;
00148   
00149   // Check class invariants.
00150   virtual Bool ok() const;
00151 
00152   // Do the actual getting of an array of values.
00153   // Non-unit strides are not yet supported.
00154   virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00155 
00156   // Putting data is not possible as the lattice is not writable.
00157   virtual void doPutSlice (const Array<T>& sourceBuffer,
00158                            const IPosition& where,
00159                            const IPosition& stride);
00160   
00161   // Get a section of the mask.
00162   // Non-unit strides are not yet supported.
00163   virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00164 
00165   // This function is used by the LatticeIterator class to generate an
00166   // iterator of the correct type for this Lattice. Not recommended
00167   // for general use. 
00168   virtual LatticeIterInterface<T>* makeIter
00169                             (const LatticeNavigator& navigator,
00170                              Bool useRef) const;
00171 
00172   // Get the best cursor shape.
00173   virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00174 
00175   // Handle the (un)locking and syncing, etc.
00176   // <group>
00177   virtual Bool lock (FileLocker::LockType, uInt nattempts);
00178   virtual void unlock();
00179   virtual Bool hasLock (FileLocker::LockType) const;
00180   virtual void resync();
00181   virtual void flush();
00182   virtual void tempClose();
00183   virtual void reopen();
00184   // </group>
00185 
00186 private:
00187   //# itsImagePtr points to the parent image.
00188   ImageInterface<T>* itsImagePtr;
00189   RebinLattice<T>*   itsRebinPtr;
00190 
00191   //# Make members of parent class known.
00192 public:
00193   using ImageInterface<T>::logger;
00194 protected:
00195   using ImageInterface<T>::setCoordsMember;
00196 };
00197 
00198 
00199 
00200 } //# NAMESPACE CASA - END
00201 
00202 #ifndef CASACORE_NO_AUTO_TEMPLATES
00203 #include <images/Images/RebinImage.tcc>
00204 #endif //# CASACORE_NO_AUTO_TEMPLATES
00205 #endif