casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
ImageConcat.h
Go to the documentation of this file.
00001 //# ImageConcat.h: concatenate images along an axis
00002 //# Copyright (C) 1996,1997,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: ImageConcat.h 20505 2009-01-19 14:37:24Z gervandiepen $
00027 
00028 #ifndef IMAGES_IMAGECONCAT_H
00029 #define IMAGES_IMAGECONCAT_H
00030 
00031 
00032 //# Includes
00033 #include <casa/aips.h>
00034 #include <casa/Arrays/Vector.h>
00035 #include <casa/Containers/Block.h>
00036 #include <lattices/Lattices/Lattice.h>
00037 #include <lattices/Lattices/LatticeConcat.h>
00038 #include <images/Images/ImageInterface.h>
00039 
00040 namespace casa { //# NAMESPACE CASA - BEGIN
00041 
00042 //# Forward Declarations
00043 class CoordinateSystem;
00044 template <class T> class ImageSummary;
00045 template <class T> class MaskedLattice;
00046 
00047 
00048 // <summary>
00049 // Concatenates images along a specified axis
00050 // </summary>
00051 
00052 // <use visibility=export>
00053 
00054 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00055 // </reviewed>
00056 
00057 // <prerequisite>
00058 //   <li> <linkto class=LatticeConcat>LatticeConcat</linkto> 
00059 //   <li> <linkto class=ImageInterface>ImageInterface</linkto> 
00060 // </prerequisite>
00061 
00062 // <etymology>
00063 // This is a class designed to concatenate images along a specified axis
00064 // </etymology>
00065 
00066 // <synopsis>
00067 // This is a class designed to concatenate images along a specified
00068 // axis. This means you can join them together.  E.g.,
00069 // join images of shape  [10,20,30] and [10,20,40] into a lattice
00070 // of shape [10,20,70].
00071 //
00072 // The ImageConcat object does not copy the input images, it
00073 // just references them.  You can use the Lattice<T>::copyData(Lattice<T>)
00074 // function to fill an output image with the concatenated input images
00075 //
00076 // If you use the putSlice function, be aware that it will change the
00077 // underlying images if they are writable.
00078 //
00079 // You can also concatenate  a lattice to an image.  
00080 // </synopsis>
00081 //
00082 // <example>
00083 // <srcblock>
00084 //      IPosition shape(2, 10, 20);
00085 //      PagedImage<Float> im1(shape, CoordinateUtil::defaultCoords2D(),
00086 //                            "tImageConcat_tmp1.img");
00087 //      im1.set(1.0);
00088 //      PagedImage<Float> im2(shape, CoordinateUtil::defaultCoords2D(),
00089 //                            "tImageConcat_tmp2.img");
00090 //      im2.set(2.0);
00091 //
00093 //
00094 //      ImageConcat<Float> concat(0);
00095 //
00097 //
00098 //      concat.setImage(im1, True);
00099 //      concat.setImage(im2, True);
00100 //
00102 //
00103 //      PagedImage<Float> im3(concat.shape(), CoordinateUtil::defaultCoords2D(),
00104 //                            "tImageConcat_tmp3.img");
00105 //
00107 //
00108 //      im3.copyData(concat);
00109 //
00110 // </srcblock>
00111 // See tImageConcat.cc for more examples.
00112 // </example>
00113 
00114 
00115 // <motivation>
00116 // Image concatentation is a useful enduser requirement.  
00117 // </motivation>
00118 
00119 // <todo asof="1999/10/23">
00120 //   <li> Offer the ability to increase the dimensionality of
00121 //        the output image
00122 // </todo>
00123 
00124 
00125 template <class T> class ImageConcat : public ImageInterface<T>
00126 {
00127 public:
00128 
00129 // Constructor. Specify the pixel axis for concatenation
00130    explicit ImageConcat (uInt axis, Bool tempClose=True);
00131 
00132 // Default constructor, Sets the concatenation axis to 0
00133    ImageConcat();
00134 
00135 // Copy constructor (reference semantics)
00136    ImageConcat (const ImageConcat<T> &other);
00137 
00138 // Destructor
00139    virtual ~ImageConcat();
00140 
00141 // Assignment operator (reference semantics)
00142    ImageConcat<T> &operator= (const ImageConcat<T> &other);
00143 
00144 // Make a copy of the object (reference semantics).
00145    virtual ImageInterface<T>* cloneII() const;
00146 
00147 // Get the image type (returns name of derived class).
00148    virtual String imageType() const;
00149 
00150 // Sets a new image into the list to be concatenated.  
00151 // If relax is False, throws an exception if the images
00152 // are not contiguous along the concatenation axis.
00153 // If relax is True, it will create a non-regular TabularCoordinate
00154 // for non-contiguous images if the coordinates are monotonic.
00155 // Otherwise, it just uses the coordinates of the image
00156    void setImage (ImageInterface<T>& image, Bool relax);
00157 
00158 // Sets a new lattice into the list to be concatenated.  
00159 // You can only concatenate a lattice with an image if
00160 // you have first used setImage to set an image (this
00161 // provides the CooridinateSystem information)
00162    void setLattice (MaskedLattice<T>& lattice);
00163 
00164 // Return the number of images/lattices set so far
00165    uInt nimages() const
00166      { return latticeConcat_p.nlattices(); }
00167 
00168 // Returns the current concatenation axis (0 relative)
00169    uInt axis () const
00170      { return latticeConcat_p.axis(); }
00171 
00172 // Returns the number of dimensions of the *input* images/lattices
00173 // Returns 0 if none yet set. 
00174    uInt imageDim() const
00175      { return latticeConcat_p.latticeDim(); }
00176 
00177 // Handle the (un)locking and syncing, etc.
00178 // <group>
00179    virtual Bool lock (FileLocker::LockType, uInt nattempts);
00180    virtual void unlock();
00181    virtual Bool hasLock (FileLocker::LockType) const;
00182    virtual void resync();
00183    virtual void flush();
00184    virtual void tempClose();
00185    virtual void reopen();
00186 // </group>
00187 
00188 // Return the name of the current ImageInterface object.
00189 // Since many images may be concatenated, there is no
00190 // sensible name.  So returns the string "Concatenation :"
00191    virtual String name (Bool stripPath=False) const;
00192 
00193 // Has the object really a mask?
00194    virtual Bool isMasked() const;
00195 
00196 // Does the image have a pixelmask?
00197    virtual Bool hasPixelMask() const;
00198 
00199 // Get access to the pixelmask.
00200 // An exception is thrown if the image does not have a pixelmask
00201 // <group>
00202    virtual const Lattice<Bool>& pixelMask() const;
00203    virtual Lattice<Bool>& pixelMask();
00204   // </group>
00205   
00206 // Get the region used (always returns 0)
00207    virtual const LatticeRegion* getRegionPtr() const;
00208 
00209 // If all of the underlying lattices are writable returns True
00210    virtual Bool isWritable() const;
00211    
00212 // Return the shape of the concatenated image
00213    virtual IPosition shape() const;
00214 
00215   
00216 // Return the best cursor shape.  This isn't very meaningful for an ImageConcat
00217 // Image since it isn't on disk !  But if you do copy it out, this is
00218 // what you should use.  The maxPixels aregument is ignored.   
00219    virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00220 
00221 // Do the actual get of the data.
00222 // The return value is always False, thus the buffer does not reference
00223 // another array.  Generally the user should use function getSlice
00224    virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00225    
00226 // Do the actual get of the mask data.
00227 // The return value is always False, thus the buffer does not reference
00228 // another array. Generally the user should use function getMaskSlice
00229    virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00230 
00231 // Do the actual put of the data into the Lattice.  This will change the
00232 // underlying images (if they are writable) that were used to create the
00233 // ImageConcat object. It throws an exception if not writable.
00234 // Generally the user should use function putSlice
00235    virtual void doPutSlice (const Array<T>& sourceBuffer,
00236                             const IPosition& where,
00237                             const IPosition& stride);      
00238 
00239 // Throws an excpetion as you cannot reshape an ImageConcat object
00240    virtual void resize(const TiledShape&);
00241 
00242 // Check class invariants.
00243   virtual Bool ok() const;
00244   
00245 // These are the implementations of the LatticeIterator letters.
00246 // <note> not for public use </note>
00247   virtual LatticeIterInterface<T> *makeIter
00248                                (const LatticeNavigator &navigator,
00249                                 Bool useRef) const;
00250 
00251 
00252 private:
00253    LatticeConcat<T> latticeConcat_p;
00254    Bool warnAxisNames_p, warnAxisUnits_p, warnImageUnits_p;
00255    Bool warnContig_p, warnRefPix_p, warnRefVal_p, warnInc_p, warnTab_p;
00256    Bool isContig_p, _warnBeam;
00257    Vector<Bool> isImage_p;
00258    Vector<Double> pixelValues_p;
00259    Vector<Double> worldValues_p;
00260    Coordinate::Type originalAxisType_p;
00261 
00262    Double coordConvert(Int& worldAxis, LogIO& os,
00263                        const CoordinateSystem& cSys,
00264                        uInt axis, Double pixelCoord) const;
00265    void _checkContiguous(
00266                    Bool& isContig, Bool& warnContig, const IPosition& shape1,
00267                    const CoordinateSystem& cSys1,
00268                    const CoordinateSystem& cSys2,
00269                    LogIO& os, uInt axis, Bool relax
00270    );
00271 
00272    void checkNonConcatAxisCoordinates (Bool& warnRefPix, Bool& warnRefVal,
00273                                        Bool& warnInc, LogIO& os,
00274                                        const ImageInterface<T>& image,
00275                                        Bool relax);
00276    Vector<Int> makeNewStokes(const Vector<Int>& stokes1,
00277                              const Vector<Int>& stokes2);
00278    void setCoordinates();
00279 
00280    void _doBeam(const ImageInterface<T>& image, const Bool relax);
00281 
00282    void _doSingleBeam(const ImageInterface<T>& image, const Bool relax);
00283 
00284    void _doMultiBeams(const ImageInterface<T>& image, const Bool relax);
00285 
00286    static Bool _areBeamsEquivalent(
00287                    const ImageInfo& infoThis, const ImageInfo& infoThat
00288    );
00289 
00290    /*
00291    static Bool _areBeamsEqual(
00292                    const Vector<Quantity>& beamThis,
00293                    const Vector<Quantity>& beamThat
00294    );
00295    */
00296 
00297    static Bool _areBeamsEqual(
00298                 const GaussianBeam& beamThis,
00299                 const ImageBeamSet& beamThat
00300    );
00301 
00302    /*
00303    static Bool _areBeamsEqual(
00304                    const Array<Vector<Quantity> >& beamThis,
00305                    const Array<Vector<Quantity> >& beamThat
00306          );
00307         */
00308     void _logBeamMessages(
00309                    const Bool relax, const String& msg1, const String msg2
00310         );
00311 
00312     void _appendBeams(const ImageInterface<T>& image);
00313 
00314   //# Make members of parent class known.
00315 public:
00316   using ImageInterface<T>::logger;
00317   using ImageInterface<T>::coordinates;
00318   using ImageInterface<T>::units;
00319   using ImageInterface<T>::miscInfo;
00320 protected:
00321   using ImageInterface<T>::setCoordsMember;
00322   using ImageInterface<T>::setMiscInfoMember;
00323 };
00324 
00325 
00326 
00327 } //# NAMESPACE CASA - END
00328 
00329 #ifndef CASACORE_NO_AUTO_TEMPLATES
00330 #include <images/Images/ImageConcat.tcc>
00331 #endif //# CASACORE_NO_AUTO_TEMPLATES
00332 #endif