casa
$Rev:20696$
|
A memory resident Lattice. More...
#include <ArrayLattice.h>
Public Member Functions | |
ArrayLattice () | |
The default constructor creates a ArrayLattice that is useless for just about everything, except that it can be assigned to with the assignment operator. | |
ArrayLattice (const IPosition &shape) | |
Construct an ArrayLattice with the specified shape. | |
ArrayLattice (Array< T > &array, Bool isWritable=True) | |
Construct an ArrayLattice that references the given Array. | |
ArrayLattice (const Array< T > &array) | |
Construct an ArrayLattice that references the given Array. | |
ArrayLattice (const ArrayLattice< T > &other) | |
The copy constructor uses reference semantics. | |
virtual | ~ArrayLattice () |
ArrayLattice< T > & | operator= (const ArrayLattice< T > &other) |
The assignment operator uses copy semantics. | |
virtual Lattice< T > * | clone () const |
Make a copy of the object (reference semantics). | |
virtual Bool | canReferenceArray () const |
The lattice data can be referenced as an array section. | |
virtual Bool | isWritable () const |
Is the lattice writable? | |
virtual IPosition | shape () const |
returns the shape of the ArrayLattice. | |
virtual void | set (const T &value) |
Set all of the elements in the Lattice to a value. | |
Array< T > & | asArray () |
Return the Array of the data within this Lattice. | |
const Array< T > & | asArray () const |
virtual T | getAt (const IPosition &where) const |
Return the value of the single element located at the argument IPosition. | |
virtual void | putAt (const T &value, const IPosition &where) |
Put the value of a single element. | |
virtual Bool | ok () const |
Check for internal consistency. | |
virtual uInt | advisedMaxPixels () const |
Returns the maximum recommended number of pixels for a cursor. | |
void | getIterSlice (Array< T > &buffer, const IPosition &start, const IPosition &end, const IPosition &incr) |
Get a slice in an optimized way (specifically for ArrLatticeIter). | |
Protected Member Functions | |
virtual Bool | doGetSlice (Array< T > &buffer, const Slicer §ion) |
Do the actual getting of an array of values. | |
virtual void | doPutSlice (const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride) |
Do the actual putting of an array of values. | |
Private Attributes | |
Array< T > | itsData |
Bool | itsWritable |
A memory resident Lattice.
Public interface
The ArrayLattice name reflects its role as a Lattice interface to an Array object.
An ArrayLattice is a concrete Lattice class where the data is stored in memory as opposed to the PagedArray class where the data is stored on disk. As a result this class is much more suitable to problems which require small Lattices that can fit into the memory of a computer.
ArrayLattice imposes another layer of function calls on top of a an Array. As a result they should not be used for generic Array manipulation. They are useful if you have an Array that needs to use Lattice functions or needs to be used with PagedArrays or other Lattice derivatives (like LatticeExpr or SubLattice ). For example the LatticeIterator class can iterate through an Array in more ways than any of the ArrayIterator classes can. The examples below illustrate some uses for ArrayLattices.
All the examples in this section are available in dArrayLattice.cc
In this example an Array of data is converted into an ArrayLattice so that the copyData function can be used to write the data to a PagedArray which will be stored on disk.
// make an Array and fill it with data. Array<Float> myArray(IPosition(3, 64, 64, 2)); indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1 // construct the ArrayLattice ArrayLattice<Float> myLattice(myArray); // make a PagedArray to store the data on disk PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array"); // now copy the data onto disk myPagedArray.copyData (myLattice);
Note that it could be done in a somewhat simpler way as:
// make an Array and fill it with data. Array<Float> myArray(IPosition(3, 64, 64, 2)); indgen(myArray); // fills the Array with 0,1,2,....,64*64*2-1 // make a PagedArray to store the data on disk PagedArray<Float> myPagedArray(myLattice.shape(), "myTestData.array"); // now put the data onto disk myPagedArray.put (myArray);
The ArrayIterator class (or its derivatives the VectorIterator and the MatrixIterator classes) do not allow the user to specify a cursor shape. In this example a Cube class will be converted into an ArrayLattice so that an ArrLatticeIter can be used to access the data spectrum by spectrum (assuming the z-axis is frequency).
Cube<Float> arr(64,64,128); // assume that the data gets put into the cube somehow // now construct an ArrayLattice from this cube. ArrayLattice<Float> lat(arr); // Construct an iterator that returns the 128-element spectra one at a time ArrLatticeIter<Float> iter(lat, IPosition(3,1,1,128)); // construct a Matrix to hold the results Matrix<Float> channelSum(64,64); // and do the summation one spectrum at a time for (iter.reset(); !iter.atEnd(); iter++) channelSum(iter.position().getFirst(2)) = sum(iter.cursor());
There are more examples in the Lattice class and many of the examples in the PagedArray class will also be instructive.
We needed a way of creating Lattices but with AIPS++ Array characteristics.
Definition at line 145 of file ArrayLattice.h.
casa::ArrayLattice< T >::ArrayLattice | ( | ) |
The default constructor creates a ArrayLattice that is useless for just about everything, except that it can be assigned to with the assignment operator.
casa::ArrayLattice< T >::ArrayLattice | ( | const IPosition & | shape | ) | [explicit] |
Construct an ArrayLattice with the specified shape.
It results in a writable lattice.
casa::ArrayLattice< T >::ArrayLattice | ( | Array< T > & | array, |
Bool | isWritable = True |
||
) |
Construct an ArrayLattice that references the given Array.
By default it results in a writable lattice.
casa::ArrayLattice< T >::ArrayLattice | ( | const Array< T > & | array | ) |
Construct an ArrayLattice that references the given Array.
It results in a non-writable lattice.
casa::ArrayLattice< T >::ArrayLattice | ( | const ArrayLattice< T > & | other | ) |
The copy constructor uses reference semantics.
virtual casa::ArrayLattice< T >::~ArrayLattice | ( | ) | [virtual] |
virtual uInt casa::ArrayLattice< T >::advisedMaxPixels | ( | ) | const [virtual] |
Returns the maximum recommended number of pixels for a cursor.
For this class this is equal to the number of pixels in the lattice.
Reimplemented from casa::Lattice< T >.
Array<T>& casa::ArrayLattice< T >::asArray | ( | ) |
const Array<T>& casa::ArrayLattice< T >::asArray | ( | ) | const |
virtual Bool casa::ArrayLattice< T >::canReferenceArray | ( | ) | const [virtual] |
The lattice data can be referenced as an array section.
Reimplemented from casa::LatticeBase.
virtual Lattice<T>* casa::ArrayLattice< T >::clone | ( | ) | const [virtual] |
Make a copy of the object (reference semantics).
Implements casa::Lattice< T >.
virtual Bool casa::ArrayLattice< T >::doGetSlice | ( | Array< T > & | buffer, |
const Slicer & | section | ||
) | [protected, virtual] |
Do the actual getting of an array of values.
Implements casa::Lattice< T >.
virtual void casa::ArrayLattice< T >::doPutSlice | ( | const Array< T > & | sourceBuffer, |
const IPosition & | where, | ||
const IPosition & | stride | ||
) | [protected, virtual] |
Do the actual putting of an array of values.
Implements casa::Lattice< T >.
virtual T casa::ArrayLattice< T >::getAt | ( | const IPosition & | where | ) | const [virtual] |
Return the value of the single element located at the argument IPosition.
Note that operator() (defined in the base class) can also be used.
Reimplemented from casa::Lattice< T >.
void casa::ArrayLattice< T >::getIterSlice | ( | Array< T > & | buffer, |
const IPosition & | start, | ||
const IPosition & | end, | ||
const IPosition & | incr | ||
) |
Get a slice in an optimized way (specifically for ArrLatticeIter).
It returns in buffer
a reference to the lattice array.
virtual Bool casa::ArrayLattice< T >::isWritable | ( | ) | const [virtual] |
Is the lattice writable?
Reimplemented from casa::LatticeBase.
virtual Bool casa::ArrayLattice< T >::ok | ( | ) | const [virtual] |
Check for internal consistency.
Returns False if something nasty has happened to the ArrayLattice.
Reimplemented from casa::LatticeBase.
ArrayLattice<T>& casa::ArrayLattice< T >::operator= | ( | const ArrayLattice< T > & | other | ) |
The assignment operator uses copy semantics.
virtual void casa::ArrayLattice< T >::putAt | ( | const T & | value, |
const IPosition & | where | ||
) | [virtual] |
Put the value of a single element.
Reimplemented from casa::Lattice< T >.
virtual void casa::ArrayLattice< T >::set | ( | const T & | value | ) | [virtual] |
Set all of the elements in the Lattice to a value.
Reimplemented from casa::Lattice< T >.
virtual IPosition casa::ArrayLattice< T >::shape | ( | ) | const [virtual] |
returns the shape of the ArrayLattice.
Implements casa::LatticeBase.
Array<T> casa::ArrayLattice< T >::itsData [private] |
Definition at line 229 of file ArrayLattice.h.
Bool casa::ArrayLattice< T >::itsWritable [private] |
Definition at line 230 of file ArrayLattice.h.