|
virtual | ~Lattice () |
| a virtual destructor is needed so that it will use the actual destructor in the derived class More...
|
|
virtual Lattice< T > * | clone () const =0 |
| Make a copy of the derived object (reference semantics). More...
|
|
virtual DataType | dataType () const |
| Get the data type of the lattice. More...
|
|
T | operator() (const IPosition &where) const |
| Return the value of the single element located at the argument IPosition. More...
|
|
virtual T | getAt (const IPosition &where) const |
|
virtual void | putAt (const T &value, const IPosition &where) |
| Put the value of a single element. More...
|
|
Bool | get (COWPtr< Array< T > > &buffer, Bool removeDegenerateAxes=False) const |
| Functions which extract an Array of values from a Lattice. More...
|
|
Bool | getSlice (COWPtr< Array< T > > &buffer, const Slicer §ion, Bool removeDegenerateAxes=False) const |
|
Bool | getSlice (COWPtr< Array< T > > &buffer, const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) const |
|
Bool | getSlice (COWPtr< Array< T > > &buffer, const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) const |
|
Bool | get (Array< T > &buffer, Bool removeDegenerateAxes=False) |
|
Bool | getSlice (Array< T > &buffer, const Slicer §ion, Bool removeDegenerateAxes=False) |
|
Bool | getSlice (Array< T > &buffer, const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) |
|
Bool | getSlice (Array< T > &buffer, const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) |
|
Array< T > | get (Bool removeDegenerateAxes=False) const |
|
Array< T > | getSlice (const Slicer §ion, Bool removeDegenerateAxes=False) const |
|
Array< T > | getSlice (const IPosition &start, const IPosition &shape, Bool removeDegenerateAxes=False) const |
|
Array< T > | getSlice (const IPosition &start, const IPosition &shape, const IPosition &stride, Bool removeDegenerateAxes=False) const |
|
void | putSlice (const Array< T > &sourceBuffer, const IPosition &where, const IPosition &stride) |
| A function which places an Array of values within this instance of the Lattice at the location specified by the IPosition "where", incrementing by "stride". More...
|
|
void | putSlice (const Array< T > &sourceBuffer, const IPosition &where) |
|
void | put (const Array< T > &sourceBuffer) |
|
virtual void | set (const T &value) |
| Set all elements in the Lattice to the given value. More...
|
|
virtual void | apply (T(*function)(T)) |
| Replace every element, x, of the Lattice with the result of f(x). More...
|
|
virtual void | apply (T(*function)(const T &)) |
|
virtual void | apply (const Functional< T, T > &function) |
|
void | operator+= (const Lattice< T > &other) |
| Add, subtract, multiple, or divide by another Lattice. More...
|
|
void | operator-= (const Lattice< T > &other) |
|
void | operator*= (const Lattice< T > &other) |
|
void | operator/= (const Lattice< T > &other) |
|
virtual void | copyData (const Lattice< T > &from) |
| Copy the data from the given lattice to this one. More...
|
|
virtual void | copyDataTo (Lattice< T > &to) const |
| Copy the data from this lattice to the given lattice. More...
|
|
virtual uInt | advisedMaxPixels () const |
| This function returns the advised maximum number of pixels to include in the cursor of an iterator. More...
|
|
virtual LatticeIterInterface< T > * | makeIter (const LatticeNavigator &navigator, Bool useRef) const |
| These functions are used by the LatticeIterator class to generate an iterator of the correct type for a specified Lattice. More...
|
|
virtual Bool | doGetSlice (Array< T > &buffer, const Slicer §ion)=0 |
| The functions (in the derived classes) doing the actual work. More...
|
|
virtual void | doPutSlice (const Array< T > &buffer, const IPosition &where, const IPosition &stride)=0 |
|
template<class T>
class casacore::Lattice< T >
A templated, abstract base class for array-like objects.
Intended use:
Public interface
Review Status
- Reviewed By:
- Peter Barnes
- Date Reviewed:
- 1999/10/30
- Test programs:
- tArrayLattice
- Demo programs:
- dLattice
Prerequisite
Etymology
Lattice: "A regular, periodic configuration of points, particles,
or objects, throughout an area of a space..." (American Heritage Directory) This definition matches our own: an n-dimensional arrangement of items, on regular orthogonal axes.
Synopsis
This pure abstract base class defines the operations which may be performed on any concrete class derived from it. It has only a few non-pure virtual member functions. The fundamental contribution of this class, therefore, is that it defines the operations derived classes must provide:
-
how to extract a "slice" (or sub-array, or subsection) from a Lattice.
-
how to copy a slice in.
-
how to get and put a single element
-
how to apply a function to all elements
-
various shape related functions.
The base class LatticeBase contains several functions not dependent on the template parameter.
Tip: Lattices always have a zero origin;
Example
Because Lattice is an abstract base class, an actual instance of this class cannot be constructed. However the interface it defines can be used inside a function. This is always recommended as it allows functions which have Lattices as arguments to work for any derived class.
I will give a few examples here and then refer the reader to the ArrayLattice class (a memory resident Lattice) and the PagedArray class (a disk based Lattice) which contain further examples with concrete classes (rather than an abstract one). All the examples shown below are used in the dLattice.cc
demo program.
Example 1:
This example calculates the mean of the Lattice. Because Lattices can be too large to fit into physical memory it is not good enough to simply use getSlice
to read all the elements into an Array. Instead the Lattice is accessed in chunks which can fit into memory (the size is determined by the advisedMaxPixels
and niceCursorShape
functions). The LatticeIterator::cursor()
function then returns each of these chunks as an Array and the standard Array based functions are used to calculate the mean on each of these chunks. Functions like this one are the recommended way to access Lattices as the LatticeIterator will correctly setup any required caches.
Complex latMean(
const Lattice<Complex>& lat) {
const uInt cursorSize = lat.advisedMaxPixels();
const IPosition cursorShape = lat.niceCursorShape(cursorSize);
const IPosition latticeShape = lat.shape();
size_t nPixels = 0u;
RO_LatticeIterator<Complex> iter(lat,
LatticeStepper(latticeShape, cursorShape));
for (iter.reset(); !iter.atEnd(); iter++){
currentSum +=
sum(iter.cursor());
nPixels += iter.cursor().nelements();
}
return currentSum/nPixels;
}
Example 2:
Sometimes it will be neccesary to access slices of a Lattice in a nearly random way. Often this can be done using the subSection commands in the LatticeStepper class. But it is also possible to use the getSlice and putSlice functions. The following example does a two-dimensional Real to Complex Fourier transform. This example is restricted to four-dimensional Arrays (unlike the previous example) and does not set up any caches (caching is currently only used with PagedArrays). So only use getSlice and putSlice when things cannot be done using LatticeIterators.
void FFT2DReal2Complex(Lattice<Complex>& result,
const Lattice<Float>& input){
const IPosition
shape = input.shape();
const IPosition resultShape = result.shape();
const IPosition inputSliceShape(4,nx,ny,1,1);
const IPosition resultSliceShape(4,nx/2+1,ny,1,1);
COWPtr<Array<Float> >
inputArrPtr(new Array<Float>(inputSliceShape.nonDegenerate()));
Array<Complex> resultArray(resultSliceShape.nonDegenerate());
FFTServer<Float, Complex> FFT2D(inputSliceShape.nonDegenerate());
IPosition start(4,0);
for (
uInt p = 0; p < npol; p++){
isARef = input.getSlice(inputArrPtr,
Slicer(start,inputSliceShape),
True);
FFT2D.fft(resultArray, *inputArrPtr);
result.putSlice(resultArray, start);
start(2) += 1;
}
start(2) = 0;
start(3) += 1;
}
}
Note that the LatticeFFT class offers a nice way to do lattice based FFTs.
Example 3:
Occasionally you may want to access a few elements of a Lattice without all the difficulty involved in setting up Iterators or calling getSlice and putSlice. This is demonstrated in the example below. Setting a single element can be done with the putAt
function, while getting a single element can be done with the parenthesis operator. Using these functions to access many elements of a Lattice is not recommended as this is the slowest access method.
In this example an ideal point spread function will be inserted into an empty Lattice. As with the previous examples all the action occurs inside a function because Lattice is an interface (abstract) class.
void makePsf(Lattice<Float>& psf) {
const IPosition centrePos = psf.shape()/2;
psf.set(0.0f);
psf.putAt (1, centrePos);
}
Motivation
Creating an abstract base class which provides a common interface between memory and disk based arrays has a number of advantages.
-
It allows functions common to all arrays to be written independent of the way the data is stored. This is illustrated in the three examples above.
-
It reduces the learning curve for new users who only have to become familiar with one interface (ie. Lattice) rather than distinct interfaces for different array types.
To Do
-
Make PagedArray cache functions virtual in this base class.
Definition at line 37 of file Functional.h.