casa  $Rev:20696$
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
LatticeConcat.h
Go to the documentation of this file.
00001 //# LatticeConcat.h: concatenate lattices along an axis
00002 //# Copyright (C) 1996,1997,1998,1999,2000,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: LatticeConcat.h 20229 2008-01-29 15:19:06Z gervandiepen $
00027 
00028 #ifndef LATTICES_LATTICECONCAT_H
00029 #define LATTICES_LATTICECONCAT_H
00030 
00031 
00032 //# Includes
00033 #include <lattices/Lattices/MaskedLattice.h>
00034 #include <casa/Containers/Block.h>
00035 
00036 namespace casa { //# NAMESPACE CASA - BEGIN
00037 
00038 //# Forward Declarations
00039 class IPosition;
00040 class Slicer;
00041 
00042 
00043 // <summary>
00044 // Concatenates lattices along a specified axis
00045 // </summary>
00046 
00047 // <use visibility=export>
00048 
00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos="">
00050 // </reviewed>
00051 
00052 // <prerequisite>
00053 //   <li> <linkto class=MaskedLattice>MaskedLattice</linkto> (base class)
00054 // </prerequisite>
00055 
00056 // <etymology>
00057 // This is a class designed to concatenate lattices along a specified axis
00058 // </etymology>
00059 
00060 // <synopsis>
00061 // This is a class designed to concatenate lattices along a specified 
00062 // axis. This means you can join them together.  E.g., 
00063 // join lattices of shape  [10,20,30] and [10,20,40] into a lattice 
00064 // of shape [10,20,70]. 
00065 //
00066 // In addition, you can increase the dimensionality
00067 // and join lattices [10,20] and [10,20] to [10,20,2].  This is
00068 // done by specifying the concatenation axis to be higher than
00069 // currently exists in the input lattices
00070 //
00071 // The LatticeConcat object does not copy the input lattices, it
00072 // just references them.  You can use the Lattice<T>::copyData(Lattice<T>)
00073 // function to fill an output lattice with the concatenated input lattices.
00074 //
00075 // If you use the putSlice function, be aware that it will change the
00076 // underlying lattices if they are writable.
00077 // </synopsis>
00078 //
00079 // <example>
00080 // <srcBlock>
00081 //
00083 //
00084 //    ArrayLattice<Float> al1(a1); al1.set(1.0);
00085 //    ArrayLattice<Float> al2(a2); al2.set(10.0);
00086 //
00088 //
00089 //   SubLattice<Float> ml1(al1, True);
00090 //   SubLattice<Float> ml2(al2, True);
00091 //
00093 //         
00094 //   LatticeConcat<Float> lc (1);
00095 //   lc.setLattice(ml1);
00096 //   lc.setLattice(ml2);
00097 //         
00099 //         
00100 //   ArrayLattice<Float> al3(lc.shape());
00101 //   SubLattice<Float> ml3(al3, True);
00102 //
00104 //         
00105 //   ml3.copyData(lc);
00106 //   
00107 // 
00108 // </srcBlock>
00109 // In this example no masks are involved.   See tLatticeConcat
00110 // for more examples.
00111 // </example>
00112 
00113 // 
00114 // <motivation>
00115 // Image concatentation is a useful enduser requirement.  An object of
00116 // this class is contained by an ImageConcat object.
00117 // </motivation>
00118 
00119 // <todo asof="1999/10/23">
00120 // </todo>
00121 
00122 
00123 template <class T> class LatticeConcat : public MaskedLattice<T>
00124 {
00125 public:
00126 
00127 // Constructor. Argument <src>axis</src> specifies the concatenation 
00128 // axis (0 relative).  If this is one more than the number of axes
00129 // in the input lattices (set with function <src>setLattice</src>)
00130 // then the resultant concatenated lattice has dimension
00131 // one greater than that the input lattices.
00132 // Argument <src>tempClose</src> specifies whether you wish 
00133 // all internal lattice copies to be
00134 // opened/closed on demand, rather than just being left open.
00135 // This prevents open file limits being reached
00136    LatticeConcat (uInt axis, Bool tempClose=True);
00137 
00138 // Default constructor.  Sets the concatenation axis to 0
00139 // and tempClose is True
00140    LatticeConcat ();
00141 
00142 // Copy constructor (reference semantics)
00143    LatticeConcat(const LatticeConcat<T> &other);
00144 
00145 // Destructor
00146    virtual ~LatticeConcat ();
00147 
00148 // Assignment operator (reference semantics)
00149    LatticeConcat<T> &operator=(const LatticeConcat<T> &other);
00150 
00151 // Sets a new lattice into the list to be concatenated.  
00152 // Exception thrown if lattices are incompatible
00153    void setLattice (MaskedLattice<T>& lattice);
00154 
00155 // Return the number of lattices set so far
00156    uInt nlattices() const
00157      {return lattices_p.nelements();}
00158 
00159 // Returns the current concatenation axis (0 relative)
00160    uInt axis () const
00161      {return axis_p;}
00162 
00163 // Returns the tempClose constructor state
00164    Bool isTempClose () const 
00165      {return tempClose_p;} 
00166 
00167 // Returns the number of dimensions of the *input* lattices (may be different 
00168 // by one from output lattice).  Returns 0 if none yet set.
00169    uInt latticeDim() const;
00170 
00171 // Return pointer for specified lattice.  Do not delete this.
00172    MaskedLattice<T>* lattice(uInt i) const
00173      { return lattices_p[i]; }
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 // Close/reopen a specific lattice.  It is your responsibility to leave the
00187 // LatticeConcat object in a fully closed state.  So always pair
00188 // a reopen with a tempClose.
00189 // <group>
00190    void tempClose(uInt which);
00191    void reopen(uInt which);
00192 // </group>
00193 
00194 // Name.  Since many lattices may go into the concatenation, the name 
00195 // is rather meaningless.  Returns the string "Concatenation :"
00196    virtual String name (Bool stripPath=False) const;
00197 
00198 // Make a copy of the derived object (reference semantics).
00199    virtual LatticeConcat<T>* cloneML() const;
00200 
00201 // Has the object really a mask?
00202    virtual Bool isMasked() const;
00203 
00204 // Get the region used (always returns 0).
00205    virtual const LatticeRegion* getRegionPtr() const;
00206    
00207 // If all of the underlying lattices are writable returns True
00208    virtual Bool isWritable() const;
00209 
00210 // Does the lattice have a pixelmask?
00211    virtual Bool hasPixelMask() const;
00212 
00213 // Get access to the pixelmask.
00214 // An exception is thrown if the lattice does not have a pixelmask
00215 // <group>
00216    virtual const Lattice<Bool>& pixelMask() const;
00217    virtual Lattice<Bool>& pixelMask();
00218 // </group>
00219 
00220 // Find the shape that the concatenated lattice will be.
00221 // Returns a null IPosition if function setLattice has not yet 
00222 // been called
00223    virtual IPosition shape () const;
00224 
00225 // Return the best cursor shape.  This isn't very meaningful  for a LatticeConcat
00226 // Lattice since it isn't on disk !  But if you do copy it out, this is 
00227 // what you should use.  The maxPixels aregument is ignored.
00228    virtual IPosition doNiceCursorShape (uInt maxPixels) const;
00229 
00230 // Do the actual get of the data.
00231 // The return value is always False, thus the buffer does not reference
00232 // another array.  Generally the user should use function getSlice
00233    virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00234    
00235 // Do the actual get of the mask data.
00236 // The return value is always False, thus the buffer does not reference
00237 // another array. Generally the user should use function getMaskSlice
00238    virtual Bool doGetMaskSlice (Array<Bool>& buffer, const Slicer& section);
00239    
00240 // Do the actual put of the data into the Lattice.  This will change the underlying
00241 // lattices (if they are writable) that were used to create the
00242 // LatticeConcat object. It throws an exception if not writable.
00243 // Generally the user should use function putSlice
00244    virtual void doPutSlice (const Array<T>& sourceBuffer,
00245                             const IPosition& where,
00246                             const IPosition& stride);
00247 
00248  
00249 private:
00250    PtrBlock<MaskedLattice<T>* > lattices_p;
00251    uInt axis_p;
00252    IPosition shape_p;
00253    Bool isMasked_p, dimUpOne_p, tempClose_p;
00254    LatticeConcat<Bool>* pPixelMask_p;
00255 //
00256    void checkAxis(uInt axis, uInt ndim) const;
00257 //
00258    void setup1 (IPosition& blc, IPosition& trc, IPosition& stride,
00259                 IPosition& blc2, IPosition& trc2,
00260                 IPosition& blc3, IPosition& trc3, IPosition& stride3,
00261                 const Slicer& section);
00262    Slicer setup2 (Bool& first, IPosition& blc2, IPosition& trc2,
00263                   Int shape2, Int axis, const IPosition& blc,
00264                   const IPosition& trc, const IPosition& stride, Int start);
00265    Bool getSlice1 (Array<T>& buffer, const Slicer& section,
00266                    uInt nLattices);
00267    Bool getSlice2 (Array<T>& buffer, const Slicer& section,
00268                    uInt nLattices);
00269    Bool putSlice1 (const Array<T>& buffer, const IPosition& where,
00270                    const IPosition& stride, uInt nLattices);
00271 
00272    Bool putSlice2 (const Array<T>& buffer, const IPosition& where,
00273                    const IPosition& stride, uInt nLattices);
00274    Bool getMaskSlice1 (Array<Bool>& buffer, const Slicer& section,
00275                        uInt nLattices);
00276    Bool getMaskSlice2 (Array<Bool>& buffer, const Slicer& section,
00277                        uInt nLattices);
00278 };
00279 
00280 
00281 
00282 } //# NAMESPACE CASA - END
00283 
00284 #ifndef CASACORE_NO_AUTO_TEMPLATES
00285 #include <lattices/Lattices/LatticeConcat.tcc>
00286 #endif //# CASACORE_NO_AUTO_TEMPLATES
00287 #endif