ArrayLattice.h

Go to the documentation of this file.
00001 //# ArrayLattice: Object which converts an Array to a Lattice.
00002 //# Copyright (C) 1994,1995,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 //#
00027 //# $Id$
00028 
00029 #ifndef LATTICES_ARRAYLATTICE_H
00030 #define LATTICES_ARRAYLATTICE_H
00031 
00032 //# Includes
00033 #include <casacore/casa/aips.h>
00034 #include <casacore/lattices/Lattices/Lattice.h>
00035 #include <casacore/casa/Arrays/Array.h>
00036 
00037 
00038 namespace casacore { //# NAMESPACE CASACORE - BEGIN
00039 
00040 // <summary>
00041 // A memory resident Lattice
00042 // </summary>
00043 
00044 // <use visibility=export>
00045 
00046 // <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tArrayLattice" demos="">
00047 // </reviewed>
00048 
00049 // <prerequisite>
00050 //   <li> <linkto class=Lattice>Lattice</linkto>
00051 //   <li> <linkto class=Array>Array</linkto>
00052 // </prerequisite>
00053 
00054 // <etymology>
00055 // The ArrayLattice name reflects its role as a Lattice interface to an Array
00056 // object.
00057 // </etymology>
00058 
00059 // <synopsis> 
00060 // An ArrayLattice is a concrete Lattice class where the data is stored in
00061 // memory as opposed to the <linkto class=PagedArray>PagedArray</linkto> class
00062 // where the data is stored on disk. As a result this class is much more
00063 // suitable to problems which require small Lattices that can fit into the
00064 // memory of a computer. 
00065 //
00066 // ArrayLattice imposes another layer of function calls on top of a an
00067 // Array. As a result they should not be used for generic Array
00068 // manipulation. They are useful if you have an Array that needs to use
00069 // Lattice functions or needs to be used with PagedArrays or other Lattice
00070 // derivatives (like <linkto class=LatticeExpr>LatticeExpr</linkto> or
00071 // <linkto class=SubLattice>SubLattice</linkto>).
00072 // For example the LatticeIterator class can iterate through an Array in
00073 // more ways than any of the ArrayIterator classes can. The examples below
00074 // illustrate some uses for ArrayLattices. 
00075 // </synopsis> 
00076 
00077 // <example>
00078 // All the examples in this section are available in
00079 // <src>dArrayLattice.cc</src>
00080 //
00081 // <h4>Example 1:</h4>
00082 // In this example an Array of data is converted into an ArrayLattice so that
00083 // the copyData function can be used to write the data to a PagedArray which
00084 // will be stored on disk.
00085 // <srcblock>
00086 // // make an Array and fill it with data.
00087 // Array<Float> myArray(IPosition(3, 64, 64, 2));
00088 // indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
00089 // // construct the ArrayLattice
00090 // ArrayLattice<Float> myLattice(myArray);
00091 // // make a PagedArray to store the data on disk
00092 // PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
00093 // // now copy the data onto disk
00094 // myPagedArray.copyData (myLattice);
00095 // </srcblock>
00096 // Note that it could be done in a somewhat simpler way as:
00097 // <srcblock>
00098 // // make an Array and fill it with data.
00099 // Array<Float> myArray(IPosition(3, 64, 64, 2));
00100 // indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1
00101 // // make a PagedArray to store the data on disk
00102 // PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array");
00103 // // now put the data onto disk
00104 // myPagedArray.put (myArray);
00105 // </srcblock>
00106 //
00107 // <h4>Example 2:</h4>
00108 // The <linkto class=ArrayIterator>ArrayIterator</linkto> class (or its
00109 // derivatives the <linkto class=VectorIterator>VectorIterator</linkto> and the
00110 // <linkto class=MatrixIterator>MatrixIterator</linkto> classes) do not allow
00111 // the user to specify a cursor shape. In this example a Cube class will be
00112 // converted into an ArrayLattice so that an ArrLatticeIter can be used to
00113 // access the data spectrum by spectrum (assuming the z-axis is frequency).
00114 //
00115 // <srcblock>
00116 // Cube<Float> arr(64,64,128);
00117 // // assume that the data gets put into the cube somehow
00118 // // now construct an ArrayLattice from this cube.
00119 // ArrayLattice<Float> lat(arr);
00120 // // Construct an iterator that returns the 128-element spectra one at a time
00121 // ArrLatticeIter<Float> iter(lat, IPosition(3,1,1,128));
00122 // // construct a Matrix to hold the results
00123 // Matrix<Float> channelSum(64,64);
00124 // // and do the summation one spectrum at a time
00125 // for (iter.reset(); !iter.atEnd(); iter++)
00126 //    channelSum(iter.position().getFirst(2)) = sum(iter.cursor());
00127 // </srcblock>
00128 //
00129 //  There are more examples in the <linkto class=Lattice>Lattice</linkto> class
00130 //  and many of the examples in the 
00131 // <linkto class=PagedArray>PagedArray</linkto> class will also be instructive.
00132 // </example>
00133 
00134 // <motivation>
00135 // We needed a way of creating Lattices but with Casacore Array characteristics.
00136 // </motivation>
00137 
00138 //# <todo asof="1997/05/31">
00139 //# </todo>
00140 
00141 // <linkfrom anchor="ArrayLattice" classes="Lattice PagedArray">
00142 //  <here>ArrayLattice</here> - a memory based Lattice.
00143 // </linkfrom>
00144 
00145 
00146 template <class T> class ArrayLattice : public Lattice<T>
00147 {
00148   //# Make members of parent class known.
00149 public:
00150   using Lattice<T>::ndim;
00151 
00152 public: 
00153   // The default constructor creates a ArrayLattice that is useless for just
00154   // about everything, except that it can be assigned to with the assignment
00155   // operator.
00156   ArrayLattice();
00157 
00158   // Construct an ArrayLattice with the specified shape.
00159   // It results in a writable lattice.
00160   explicit ArrayLattice (const IPosition& shape);
00161 
00162   // Construct an ArrayLattice that references the given Array.
00163   // By default it results in a writable lattice.
00164   ArrayLattice (Array<T>& array, Bool isWritable = True);
00165 
00166   // Construct an ArrayLattice that references the given Array.
00167   // It results in a non-writable lattice.
00168   ArrayLattice (const Array<T>& array);
00169 
00170   // The copy constructor uses reference semantics.
00171   ArrayLattice (const ArrayLattice<T>& other);
00172 
00173   virtual ~ArrayLattice();
00174 
00175   // The assignment operator uses copy semantics.
00176   ArrayLattice<T>& operator= (const ArrayLattice<T>& other);
00177 
00178   // Make a copy of the object (reference semantics).
00179   virtual Lattice<T>* clone() const;
00180 
00181   // The lattice data can be referenced as an array section.
00182   virtual Bool canReferenceArray() const;
00183 
00184   // Is the lattice writable?
00185   virtual Bool isWritable() const;
00186 
00187   // returns the shape of the ArrayLattice.
00188   virtual IPosition shape() const; 
00189   
00190   // Set all of the elements in the Lattice to a value.
00191   virtual void set (const T& value);
00192 
00193   // Return the Array of the data within this Lattice.
00194   // <group>
00195   Array<T>& asArray();
00196   const Array<T>& asArray() const;
00197   // </group>
00198 
00199   // Return the value of the single element located at the argument
00200   // IPosition.  
00201   // Note that operator() (defined in the base class) can also be used.
00202   virtual T getAt (const IPosition& where) const;
00203   
00204   // Put the value of a single element.
00205   virtual void putAt (const T& value, const IPosition& where);
00206 
00207   // Check for internal consistency. Returns False if
00208   // something nasty has happened to the ArrayLattice.
00209   virtual Bool ok() const;
00210   
00211   // Returns the maximum recommended number of pixels for a cursor.
00212   // For this class this is equal to the number of pixels in the lattice.
00213   virtual uInt advisedMaxPixels() const;
00214 
00215   // Get a slice in an optimized way (specifically for ArrLatticeIter).
00216   // It returns in <src>buffer</src> a reference to the lattice array.
00217   void getIterSlice (Array<T>& buffer, const IPosition& start,
00218                      const IPosition& end, const IPosition& incr);
00219 
00220 protected:
00221   // Do the actual getting of an array of values.
00222   virtual Bool doGetSlice (Array<T>& buffer, const Slicer& section);
00223 
00224   // Do the actual putting of an array of values.
00225   virtual void doPutSlice (const Array<T>& sourceBuffer,
00226                            const IPosition& where,
00227                            const IPosition& stride);
00228   
00229 private:
00230   Array<T> itsData;
00231   Bool     itsWritable;
00232 };
00233 
00234 
00235 
00236 } //# NAMESPACE CASACORE - END
00237 
00238 #ifndef CASACORE_NO_AUTO_TEMPLATES
00239 #include <casacore/lattices/Lattices/ArrayLattice.tcc>
00240 #endif //# CASACORE_NO_AUTO_TEMPLATES
00241 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1