Loading...
Searching...
No Matches
casacore::TileStepper Class Reference
lattices package (libcasa_lattices) » Lattices_module

More...

`#include <TileStepper.h>`

## Public Member Functions

| TileStepper (const IPosition &latticeShape, const IPosition &tileShape)
| Construct a TileStepper by specifying the Lattice shape, a tile shape, and an optional axis path (default is natural order).
| TileStepper (const IPosition &latticeShape, const IPosition &tileShape, const IPosition &axisPath)
| TileStepper (const TileStepper &other)
| Copy constructor (copy semantics).
| ~TileStepper ()
TileStepper & | operator= (const TileStepper &other)
| Assignment (copy semantics).
virtual Bool | operator++ (int)
| Increment operator (postfix or prefix version) - move the cursor forward one step.
virtual Bool | operator-- (int)
| Decrement operator (postfix or prefix version) - move the cursor backwards one step.
virtual void | reset ()
| Function to move the cursor to the beginning of the Lattice.
virtual Bool | atStart () const
| Function which returns "True" if the cursor is at the beginning of the Lattice, otherwise, returns "False".
virtual Bool | atEnd () const
| Function which returns "True" if an attempt has been made to increment the cursor beyond the end of the Lattice.
virtual uInt | nsteps () const
| Function to return the number of steps (increments & decrements) taken since construction (or since last reset).
virtual IPosition | position () const
| Function which returns the current position of the beginning of the cursor.
virtual IPosition | endPosition () const
| Function which returns the current position of the end of the cursor.
virtual IPosition | latticeShape () const
| Functions which return the shape of the Lattice being iterated through.
virtual IPosition | subLatticeShape () const
virtual IPosition | cursorShape () const
| Function which returns the shape of the cursor.
virtual IPosition | cursorAxes () const
| Function which returns the axes of the cursor.
IPosition | tileShape () const
| Function which returns the shape of the "tile" the cursor will iterate through before moving onto the next tile.
virtual Bool | hangOver () const
| Function which returns "True" if the increment/decrement operators have moved the cursor position such that part of the cursor beginning or end is hanging over the edge of the Lattice.
virtual void | subSection (const IPosition &blc, const IPosition &trc)
| Functions to specify a "section" of the Lattice to step over.
virtual void | subSection (const IPosition &blc, const IPosition &trc, const IPosition &inc)
virtual IPosition | blc () const
| Return the bottom left hand corner (blc), top right corner (trc) or step size (increment) used by the current sub-Lattice.
virtual IPosition | trc () const
virtual IPosition | increment () const
virtual const IPosition & | axisPath () const
| Return the axis path.
virtual LatticeNavigator * | clone () const
| Function which returns a pointer to dynamic memory of an exact copy of this instance.
virtual Bool | ok () const
| Function which checks the internal data of this class for correct dimensionality and consistant values.
virtual uInt | calcCacheSize (const IPosition &cubeShape, const IPosition &tileShape, uInt maxCacheSize, uInt bucketSize) const
| Calculate the cache size (in tiles) for this type of access to a lattice in the given row of the tiled hypercube.
Public Member Functions inherited from casacore::LatticeNavigator
| LatticeNavigator ()
| Default constructor.
| LatticeNavigator (const LatticeNavigator &)
| Copy constructor.
LatticeNavigator & | operator= (const LatticeNavigator &)
| Assignment.
virtual | ~LatticeNavigator ()
| A virtual destructor.
Bool | operator++ ()
Bool | operator-- ()
virtual IPosition | relativePosition () const
virtual IPosition | relativeEndPosition () const
virtual IPosition | hangOverBlc () const
| Functions which return the "bottom left corner" and the "top right corner" of the cursor that does not hangover.
virtual IPosition | hangOverTrc () const

## Private Member Functions

| TileStepper ()
| Prevent the default constructor from being used.

## Private Attributes

IPosition | itsBlc
IPosition | itsTrc
IPosition | itsInc
LatticeIndexer | itsSubSection
LatticeIndexer | itsTiler
IPosition | itsTilerCursorPos
IPosition | itsTileShape
IPosition | itsAxisPath
IPosition | itsCurBlc
IPosition | itsCurTrc
uInt | itsNsteps
Bool | itsEnd
Bool | itsStart

## Detailed Description

traverse a tiled Lattice optimally with a tile cursor

### Intended use:

Public interface

### Review Status

Reviewed By:
  Peter Barnes
Date Reviewed:
  1999/10/30
Test programs:
  tTileStepper

### Prerequisite

- LatticeNavigator

### Etymology

TileStepper is used to step optimally through a tiled Lattice.

### Synopsis

When you wish to traverse a Lattice (say, a PagedArray or an Image) you will usually create a LatticeIterator. Once created, you may attach a LatticeNavigator to the iterator. A TileStepper is a concrete class derived from the abstract LatticeNavigator that allows you to step through the Lattice in a way that will minimize the amount of cache memory consumed and maximize the speed.

Some Lattices (in particular PagedArrays) are stored (on disk) in tiles. For an N-dimensional Lattice a tile is an N-dimensional subsection with fewer elements along each axis. For example a Lattice of shape [512,512,4,32] may have a tile shape of [32,16,4,16], and there will be 16*32*1*2 (=1024) tiles in the entire Lattice. To allow efficient access of the data in a Lattice some tiles are cached in memory. As each tile may consume a fair bit of memory (in this example 128kBytes, assuming each element consumes 4 bytes), it is desirable to minimise the number of tiles held in the cache. But it is also desirable to minimise the number of times a tiles must be read into or written from the cache as this may require a time consuming operation like disk I/O.

TileStepper steps through a lattice in a tile-by-tile way. This means that the cache contains 1 tile only and that a tile is accessed only once. It should be clear that traversing a lattice in this way cannot be used if an entire vector or plane is needed. It is, however, very well suited for purposes like initialising a lattice, where the order in which the lattice pixels are accessed is not important.

In constructing a TileStepper, you specify the Lattice shape, the tile shape and optionally the axis path. The axis path defines the order in which the tiles are fetched from the lattice. Default is the natural order (thus x-axis in the inner loop).
It is possible to use the function subSection to traverse only a subsection of the lattice.

The cursor position can be incremented or decremented to retrieve the next or previous tile in the Lattice. The position of the next tile in the Lattice will depend on the tile shape, and is described above.
Note that the cursor shape does not need to be constant when iterating through the lattice. If the lattice shape is not an integer multiple of the tile shape, the cursor will be smaller on the edges of the lattice.

### Example

This example initializes a lattice with the given value.

void init (Lattice<Complex>& cArray, Complex value)
{
const IPosition latticeShape = cArray.shape();
const IPosition tileShape = cArray.niceCursorShape();
TileStepper tsx(latticeShape, tileShape);
LatticeIterator<Complex> lix(cArray, tsx);
for (lix.reset();!lix.atEnd();lix++)
lix.woCursor() = value;
}
}
casacore::IPosition
Definition IPosition.h:117
casacore::LatticeBase::shape
virtual IPosition shape() const =0
Return the shape of the Lattice including all degenerate axes (ie.
casacore::LatticeBase::niceCursorShape
IPosition niceCursorShape(uInt maxPixels) const
Returns a recommended cursor shape for iterating through all the pixels in the Lattice.
Definition LatticeBase.h:206
casacore::LatticeIterator
A read/write lattice iterator.
Definition LatticeIterator.h:423
casacore::Lattice
Definition Lattice.h:230
casacore::TileStepper::TileStepper
TileStepper(const IPosition &latticeShape, const IPosition &tileShape)
Construct a TileStepper by specifying the Lattice shape, a tile shape, and an optional axis path (def...
casacore::TileStepper::tileShape
IPosition tileShape() const
Function which returns the shape of the "tile" the cursor will iterate through before moving onto the...
casacore::TileStepper::latticeShape
virtual IPosition latticeShape() const
Functions which return the shape of the Lattice being iterated through.
casacore::init
void init()
Other internal helper function(s).
casacore::value
NewDelAllocator< T > NewDelAllocator< T >::value
Definition Allocator.h:368

Note that a TileStepper is the default navigator for an iterator. So the code above could be made simpler like shown below. Also note that this example is a bit artificial, because the Lattice::set() function should be used to initialize a lattice.

void init (Lattice<Complex>& cArray, Complex value)
{
LatticeIterator<Complex> lix(cArray);
for (lix.reset();!lix.atEnd();lix++)
lix.woCursor() = value;
}
}

### Motivation

This class makes it possible to traverse a lattice in the optimal way.

Definition at line 136 of file TileStepper.h.

## Constructor & Destructor Documentation

## TileStepper() [1/4]

casacore::TileStepper::TileStepper | ( | const IPosition & | latticeShape,
|  | const IPosition & | tileShape )

Construct a TileStepper by specifying the Lattice shape, a tile shape, and an optional axis path (default is natural order).

Is is nearly always advisable to make the tileShape identical to the Lattice tileShape. This can be obtained by lat.niceCursorShape() where lat is a Lattice object.

References latticeShape(), and tileShape().

Referenced by operator=(), and TileStepper().

## TileStepper() [2/4]

casacore::TileStepper::TileStepper | ( | const IPosition & | latticeShape,
|  | const IPosition & | tileShape,
|  | const IPosition & | axisPath )

References axisPath(), latticeShape(), and tileShape().

## TileStepper() [3/4]

casacore::TileStepper::TileStepper | ( | const TileStepper & | other | ) |

Copy constructor (copy semantics).

References TileStepper().

## ~TileStepper()

casacore::TileStepper::~TileStepper | ( |  | ) |

## TileStepper() [4/4]

casacore::TileStepper::TileStepper | ( |  | ) |

private

Prevent the default constructor from being used.

## Member Function Documentation

## atEnd()

virtual Bool casacore::TileStepper::atEnd | ( |  | ) | const

virtual

Function which returns "True" if an attempt has been made to increment the cursor beyond the end of the Lattice.

Implements casacore::LatticeNavigator.

## atStart()

virtual Bool casacore::TileStepper::atStart | ( |  | ) | const

virtual

Function which returns "True" if the cursor is at the beginning of the Lattice, otherwise, returns "False".

Implements casacore::LatticeNavigator.

## axisPath()

virtual const IPosition & casacore::TileStepper::axisPath | ( |  | ) | const

virtual

Return the axis path.

Implements casacore::LatticeNavigator.

Referenced by TileStepper().

## blc()

virtual IPosition casacore::TileStepper::blc | ( |  | ) | const

virtual

Return the bottom left hand corner (blc), top right corner (trc) or step size (increment) used by the current sub-Lattice.

If no sub-Lattice has been defined (with the subSection function) these functions return blc=0, trc=latticeShape-1, increment=1, ie. the entire Lattice.

Reimplemented from casacore::LatticeNavigator.

Referenced by subSection(), and subSection().

## calcCacheSize()

virtual uInt casacore::TileStepper::calcCacheSize | ( | const IPosition & | cubeShape,
|  | const IPosition & | tileShape,
|  | uInt | maxCacheSize,
|  | uInt | bucketSize ) const

virtual

Calculate the cache size (in tiles) for this type of access to a lattice in the given row of the tiled hypercube.

Implements casacore::LatticeNavigator.

References tileShape().

## clone()

virtual LatticeNavigator * casacore::TileStepper::clone | ( |  | ) | const

virtual

Function which returns a pointer to dynamic memory of an exact copy of this instance.

The pointer returned by this function must be deleted externally.

Implements casacore::LatticeNavigator.

References casacore::LatticeNavigator::LatticeNavigator().

## cursorAxes()

virtual IPosition casacore::TileStepper::cursorAxes | ( |  | ) | const

virtual

Function which returns the axes of the cursor.

Implements casacore::LatticeNavigator.

## cursorShape()

virtual IPosition casacore::TileStepper::cursorShape | ( |  | ) | const

virtual

Function which returns the shape of the cursor.

This always includes all axes (i.e. it includes degenerates axes)

Implements casacore::LatticeNavigator.

## endPosition()

virtual IPosition casacore::TileStepper::endPosition | ( |  | ) | const

virtual

Function which returns the current position of the end of the cursor.

The endPosition function is relative the origin in the main Lattice.

Implements casacore::LatticeNavigator.

## hangOver()

virtual Bool casacore::TileStepper::hangOver | ( |  | ) | const

virtual

Function which returns "True" if the increment/decrement operators have moved the cursor position such that part of the cursor beginning or end is hanging over the edge of the Lattice.

This always returns False.

Implements casacore::LatticeNavigator.

## increment()

virtual IPosition casacore::TileStepper::increment | ( |  | ) | const

virtual

Reimplemented from casacore::LatticeNavigator.

## latticeShape()

virtual IPosition casacore::TileStepper::latticeShape | ( |  | ) | const

virtual

Functions which return the shape of the Lattice being iterated through.

latticeShape always returns the shape of the main Lattice while subLatticeShape returns the shape of any sub-Lattice defined using the subSection function.

Implements casacore::LatticeNavigator.

Referenced by TileStepper(), and TileStepper().

## nsteps()

virtual uInt casacore::TileStepper::nsteps | ( |  | ) | const

virtual

Function to return the number of steps (increments & decrements) taken since construction (or since last reset).

This is a running count of all cursor movement (operator++ or operator--), even though N-increments followed by N-decrements will always leave the cursor in the original position.

Implements casacore::LatticeNavigator.

## ok()

virtual Bool casacore::TileStepper::ok | ( |  | ) | const

virtual

Function which checks the internal data of this class for correct dimensionality and consistant values.

Returns True if everything is fine otherwise returns False

Reimplemented from casacore::LatticeNavigator.

## operator++()

virtual Bool casacore::TileStepper::operator++ | ( | int |  | ) |

virtual

Increment operator (postfix or prefix version) - move the cursor forward one step.

Returns True if the cursor was moved.

Implements casacore::LatticeNavigator.

## operator--()

virtual Bool casacore::TileStepper::operator-- | ( | int |  | ) |

virtual

Decrement operator (postfix or prefix version) - move the cursor backwards one step.

Returns True if the cursor was moved.

Implements casacore::LatticeNavigator.

## operator=()

TileStepper & casacore::TileStepper::operator= | ( | const TileStepper & | other | ) |

Assignment (copy semantics).

References TileStepper().

## position()

virtual IPosition casacore::TileStepper::position | ( |  | ) | const

virtual

Function which returns the current position of the beginning of the cursor.

The position function is relative to the origin in the main Lattice.

Implements casacore::LatticeNavigator.

## reset()

virtual void casacore::TileStepper::reset | ( |  | ) |

virtual

Function to move the cursor to the beginning of the Lattice.

Also resets the number of steps (nsteps function) to zero.

Implements casacore::LatticeNavigator.

## subLatticeShape()

virtual IPosition casacore::TileStepper::subLatticeShape | ( |  | ) | const

virtual

Reimplemented from casacore::LatticeNavigator.

## subSection() [1/2]

virtual void casacore::TileStepper::subSection | ( | const IPosition & | blc,
|  | const IPosition & | trc )

virtual

Functions to specify a "section" of the Lattice to step over.

A section is defined in terms of the Bottom Left Corner (blc), Top Right Corner (trc), and step size (inc), on ALL of its axes, including degenerate axes. The step size defaults to one if not specified.

Reimplemented from casacore::LatticeNavigator.

References blc(), and trc().

## subSection() [2/2]

virtual void casacore::TileStepper::subSection | ( | const IPosition & | blc,
|  | const IPosition & | trc,
|  | const IPosition & | inc )

virtual

Reimplemented from casacore::LatticeNavigator.

References blc(), and trc().

## tileShape()

IPosition casacore::TileStepper::tileShape | ( |  | ) | const

Function which returns the shape of the "tile" the cursor will iterate through before moving onto the next tile.

Referenced by calcCacheSize(), TileStepper(), and TileStepper().

## trc()

virtual IPosition casacore::TileStepper::trc | ( |  | ) | const

virtual

Reimplemented from casacore::LatticeNavigator.

Referenced by subSection(), and subSection().

## Member Data Documentation

## itsAxisPath

IPosition casacore::TileStepper::itsAxisPath

private

Definition at line 276 of file TileStepper.h.

## itsBlc

IPosition casacore::TileStepper::itsBlc

private

Definition at line 269 of file TileStepper.h.

## itsCurBlc

IPosition casacore::TileStepper::itsCurBlc

private

Definition at line 277 of file TileStepper.h.

## itsCurTrc

IPosition casacore::TileStepper::itsCurTrc

private

Definition at line 278 of file TileStepper.h.

## itsEnd

Bool casacore::TileStepper::itsEnd

private

Definition at line 280 of file TileStepper.h.

## itsInc

IPosition casacore::TileStepper::itsInc

private

Definition at line 271 of file TileStepper.h.

## itsNsteps

uInt casacore::TileStepper::itsNsteps

private

Definition at line 279 of file TileStepper.h.

## itsStart

Bool casacore::TileStepper::itsStart

private

Definition at line 281 of file TileStepper.h.

## itsSubSection

LatticeIndexer casacore::TileStepper::itsSubSection

private

Definition at line 272 of file TileStepper.h.

## itsTiler

LatticeIndexer casacore::TileStepper::itsTiler

private

Definition at line 273 of file TileStepper.h.

## itsTilerCursorPos

IPosition casacore::TileStepper::itsTilerCursorPos

private

Definition at line 274 of file TileStepper.h.

## itsTileShape

IPosition casacore::TileStepper::itsTileShape

private

Definition at line 275 of file TileStepper.h.

## itsTrc

IPosition casacore::TileStepper::itsTrc

private

Definition at line 270 of file TileStepper.h.

The documentation for this class was generated from the following file:

- lattices/Lattices/TileStepper.h