casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
SubImage.h
Go to the documentation of this file.
00001 //# SubImage.h: A (masked) subset of an ImageInterface object
00002 //# Copyright (C) 1998,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: SubImage.h 20739 2009-09-29 01:15:15Z Malte.Marquarding $
00027 
00028 #ifndef IMAGES_SUBIMAGE_H
00029 #define IMAGES_SUBIMAGE_H
00030 
00031 
00032 //# Includes
00033 #include <images/Images/ImageInterface.h>
00034 #include <casa/Arrays/AxesSpecifier.h>
00035 
00036 #include <memory>
00037 
00038 namespace casa { //# NAMESPACE CASA - BEGIN
00039 
00040 //# Forward Declarations
00041 class IPosition;
00042 class LattRegionHolder;
00043 class Slicer;
00044 template <class T> class SubLattice;
00045 template <class T> class Array;
00046 class LatticeNavigator;
00047 template <class T> class LatticeIterInterface;
00048 class String;
00049 
00050 
00051 // <summary>
00052 // A (masked) subset of an ImageInterface object.
00053 // </summary>
00054 //
00055 // <use visibility=export>
00056 //
00057 // <reviewed reviewer="" date="" tests="tSubImage.cc">
00058 // </reviewed>
00059 //
00060 // <prerequisite>
00061 //   <li> <linkto class=ImageInterface>ImageInterface</linkto>
00062 //   <li> <linkto class=SubLattice>SubLattice</linkto>
00063 // </prerequisite>
00064 //
00065 // <synopsis> 
00066 // Class SubImage has to be used to apply a region or mask to an image.
00067 // Several functions are inherited from SubLattice and not declared
00068 // in this class.
00069 // <p>
00070 // Using an <linkto class=AxesSpecifier>AxesSpecifier</linkto> object
00071 // it is possible to remove some or all degenerate axes (i.e. axes
00072 // with length 1) to get an image with a lower dimensionality.
00073 // </synopsis> 
00074 //
00075 // <example>
00076 // <srcblock>
00077 // </srcblock>
00078 // </example>
00079 //
00080 // <motivation>
00081 // </motivation>
00082 //
00083 // <todo asof="1998/02/09">
00084 // </todo>
00085 
00086 
00087 template <class T> class SubImage: public ImageInterface<T>
00088 {
00089 public: 
00090   // The default constructor
00091   SubImage();
00092 
00093   // Create a SubImage from a Image.
00094   // This results in a SubImage without a real mask.
00095   // <br>The "const Image" version yields a non-writable SubImage,
00096   // while for the non-const version one has to specify if the SubImage
00097   // should be writable (if the original image is non-writable, the
00098   // SubImage is always set to non-writable).
00099   // If preserveAxesOrder is True, the axes order will be preserved. This
00100   // is only important in cases where pixel axes are to be dropped, if not
00101   // the axes order will be preserved. If False and pixel axes are dropped,
00102   // the order of the coordinates will be preserved, but not necessarily
00103   // the axes.
00104   // <group>
00105   SubImage (ImageInterface<T>& image, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00106   SubImage (ImageInterface<T>& image, Bool writableIfPossible,
00107             AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00108   // </group>
00109 
00110   // Create a SubImage from the given Image and region.
00111   // <br>An exception is thrown if the image shape used in the region
00112   // differs from the shape of the image.
00113   // <group>
00114   SubImage (const ImageInterface<T>& image, const LattRegionHolder& region,
00115             AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00116   SubImage (ImageInterface<T>& image, const LattRegionHolder& region,
00117             Bool writableIfPossible, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00118   // </group>
00119   
00120   // Create a SubImage from the given Image and slicer.
00121   // The slicer can be strided.
00122   // <br>An exception is thrown if the slicer exceeds the image shape.
00123   // <group>
00124   SubImage (const ImageInterface<T>& image, const Slicer& slicer,
00125             AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00126   SubImage (ImageInterface<T>& image, const Slicer& slicer,
00127             Bool writableIfPossible, AxesSpecifier=AxesSpecifier(), Bool preserveAxesOrder=False);
00128   // </group>
00129   
00130   // Copy constructor (reference semantics).
00131   SubImage (const SubImage<T>& other);
00132     
00133   virtual ~SubImage();
00134 
00135   // Assignment (reference semantics).
00136   SubImage<T>& operator= (const SubImage<T>& other);
00137 
00138   // Make a copy of the object (reference semantics).
00139   // <group>
00140   virtual ImageInterface<T>* cloneII() const;
00141   // </group>
00142 
00143   // Get the image type (returns name of derived class).
00144   virtual String imageType() const;
00145 
00146   // Is the SubImage masked?
00147   // It is if its parent image or its region is masked.
00148   virtual Bool isMasked() const;
00149 
00150   // Does the image object have a pixelmask?
00151   // It does if its parent has a pixelmask.
00152   virtual Bool hasPixelMask() const;
00153 
00154   // Get access to the pixelmask in use (thus to the pixelmask of the parent).
00155   // An exception is thrown if the parent does not have a pixelmask.
00156   // <group>
00157   virtual const Lattice<Bool>& pixelMask() const;
00158   virtual Lattice<Bool>& pixelMask();
00159   // </group>
00160 
00161   // A SubImage is persistent if no region is applied to the parent image.
00162   // That is true if the region has the same shape as the parent image
00163   // and the region has no mask.
00164   virtual Bool isPersistent() const;
00165 
00166   // Is the SubImage paged to disk?
00167   virtual Bool isPaged() const;
00168 
00169   // Can the lattice data be referenced as an array section?
00170   virtual Bool canReferenceArray() const;
00171 
00172   // Is the SubImage writable?
00173   virtual Bool isWritable() const;
00174 
00175   // Get the region/mask object describing this subImage.
00176   virtual const LatticeRegion* getRegionPtr() const;
00177 
00178   // Returns the shape of the SubImage including all degenerate axes
00179   // (i.e. axes with a length of one).
00180   virtual IPosition shape() const;
00181   
00182   // Returns the number of axes in this SubImage. This includes all
00183   // degenerate axes.
00184   virtual uInt ndim() const;
00185   
00186   // Returns the total number of elements in this SubImage.
00187   virtual size_t nelements() const;
00188   
00189   // returns a value of "True" if this instance of Lattice and 'other' have 
00190   // the same shape, otherwise returns a value of "False".
00191   virtual Bool conform (const Lattice<T>& other) const;
00192   
00193   // This function returns the recommended maximum number of pixels to
00194   // include in the cursor of an iterator.
00195   virtual uInt advisedMaxPixels() const;
00196 
00197   // Get or put a single element in the lattice.
00198   // <group>
00199   virtual T getAt (const IPosition& where) const;
00200   virtual void putAt (const T& value, const IPosition& where);
00201   // </group>
00202   
00203   // Function which changes the shape of the SubImage.
00204   // Throws an exception as resizing a SubImage is not possible.
00205   virtual void resize(const TiledShape& newShape);
00206 
00207   // Return the name of the parent ImageInterface object. 
00208   virtual String name (Bool stripPath=False) const;
00209   
00210   // Check class invariants.
00211   virtual Bool ok() const;
00212 
00213   // Do the actual getting of an array of values.
00214   virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00215 
00216   // Do the actual getting of an array of values.
00217   virtual void doPutSlice (const Array<T>& sourceBuffer,
00218                            const IPosition& where,
00219                            const IPosition& stride);
00220   
00221   // Get a section of the mask.
00222   virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00223 
00224   // This function is used by the LatticeIterator class to generate an
00225   // iterator of the correct type for this Lattice. Not recommended
00226   // for general use. 
00227   virtual LatticeIterInterface<T>* makeIter
00228                                (const LatticeNavigator& navigator,
00229                                 Bool useRef) const;
00230 
00231   // Get the best cursor shape.
00232   virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00233 
00234   // Handle the (un)locking and syncing, etc.
00235   // <group>
00236   virtual Bool lock (FileLocker::LockType, uInt nattempts);
00237   virtual void unlock();
00238   virtual Bool hasLock (FileLocker::LockType) const;
00239   virtual void resync();
00240   virtual void flush();
00241   virtual void tempClose();
00242   virtual void reopen();
00243   // </group>
00244 
00245 private:
00246   // Set the coordinates.
00247   // It removes world axes if the subimage has axes removed.
00248   // If preserveAxesOrder is True and axes are dropped, it will preserve
00249   // the order of the axes as well as the order of the coordinates.
00250   void setCoords (const CoordinateSystem& coords, Bool preserveAxesOrder);
00251 
00252   // Set the other members in the parent.
00253   void setMembers(const ImageBeamSet& hpBeams);
00254 
00255   // Helper
00256    void convertIPosition(Vector<Float>& x, const IPosition& pos) const;
00257 
00258   //# itsImagePtr points to the parent image.
00259   std::auto_ptr<ImageInterface<T> > itsImagePtr;
00260   std::auto_ptr<SubLattice<T> >    itsSubLatPtr;
00261 
00262 
00263   // Given an original image shape and coordinate system and a subimage shape and
00264   // coordinate system, get the corresponding per plane beam array. The subimage
00265   // coordinate system must have been made with origCoords.subimage() and both must
00266   // have the same types of axes in the same order. The shapes must have the same
00267   // number of dimensions and all members of <src>subShape</src> must be greater or
00268   // equal to 1 and less than the corresponding members of <src>origShape</src>.
00269   ImageBeamSet _beamsForSubImage(
00270         const IPosition& subShape,
00271         const CoordinateSystem& subCoords
00272   );
00273 
00274 
00275   //# Make members of parent class known.
00276 public:
00277   using ImageInterface<T>::logger;
00278 protected:
00279   using ImageInterface<T>::setCoordsMember;
00280 };
00281 
00282 
00283 
00284 } //# NAMESPACE CASA - END
00285 
00286 #ifndef CASACORE_NO_AUTO_TEMPLATES
00287 #include <images/Images/SubImage.tcc>
00288 #endif //# CASACORE_NO_AUTO_TEMPLATES
00289 #endif