casacore
Loading...
Searching...
No Matches
TileStepper.h
Go to the documentation of this file.
1// # TileStepper.h: Steps a cursor optimally through a tiled Lattice
2// # Copyright (C) 1997,1998,1999,2000
3// # Associated Universities, Inc. Washington DC, USA.
4// #
5// # This library is free software; you can redistribute it and/or modify it
6// # under the terms of the GNU Library General Public License as published by
7// # the Free Software Foundation; either version 2 of the License, or (at your
8// # option) any later version.
9// #
10// # This library is distributed in the hope that it will be useful, but WITHOUT
11// # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12// # FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
13// # License for more details.
14// #
15// # You should have received a copy of the GNU Library General Public License
16// # along with this library; if not, write to the Free Software Foundation,
17// # Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
18// #
19// # Correspondence concerning AIPS++ should be addressed as follows:
20// # Internet email: casa-feedback@nrao.edu.
21// # Postal address: AIPS++ Project Office
22// # National Radio Astronomy Observatory
23// # 520 Edgemont Road
24// # Charlottesville, VA 22903-2475 USA
25
26#ifndef LATTICES_TILESTEPPER_H
27#define LATTICES_TILESTEPPER_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/lattices/Lattices/LatticeNavigator.h>
32#include <casacore/lattices/Lattices/LatticeIndexer.h>
33#include <casacore/casa/Arrays/IPosition.h>
34
35namespace casacore { // # NAMESPACE CASACORE - BEGIN
36
37// <summary>
38// traverse a tiled Lattice optimally with a tile cursor
39// </summary>
40
41// <use visibility=export>
42
43// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tTileStepper.cc" demos="">
44// </reviewed>
45
46// <prerequisite>
47// <li> <linkto class=LatticeNavigator> LatticeNavigator </linkto>
48// </prerequisite>
49
50// <etymology>
51// TileStepper is used to step optimally through a tiled Lattice.
52// </etymology>
53
54// <synopsis>
55// When you wish to traverse a Lattice (say, a PagedArray or an Image) you
56// will usually create a LatticeIterator. Once created, you may attach a
57// LatticeNavigator to the iterator. A TileStepper is a concrete class
58// derived from the abstract LatticeNavigator that allows you to step
59// through the Lattice in a way that will minimize the amount of cache
60// memory consumed and maximize the speed.
61// <p>
62// Some Lattices (in particular PagedArrays) are stored (on disk) in
63// tiles. For an N-dimensional Lattice a tile is an N-dimensional
64// subsection with fewer elements along each axis. For example a Lattice of
65// shape [512,512,4,32] may have a tile shape of [32,16,4,16], and there
66// will be 16*32*1*2 (=1024) tiles in the entire Lattice. To allow efficient
67// access of the data in a Lattice some tiles are cached in memory. As each
68// tile may consume a fair bit of memory (in this example 128kBytes,
69// assuming each element consumes 4 bytes), it is desirable to minimise the
70// number of tiles held in the cache. But it is also desirable to minimise
71// the number of times a tiles must be read into or written from the
72// cache as this may require a time consuming operation like disk I/O.
73// <p>
74// TileStepper steps through a lattice in a tile-by-tile way.
75// This means that the cache contains 1 tile only and that a tile is
76// accessed only once.
77// It should be clear that traversing a lattice in this way cannot
78// be used if an entire vector or plane is needed. It is, however, very
79// well suited for purposes like initialising a lattice, where the
80// order in which the lattice pixels are accessed is not important.
81// <p>
82// In constructing a TileStepper, you specify the Lattice shape, the
83// tile shape and optionally the axis path. The axis path defines the order
84// in which the tiles are fetched from the lattice. Default is the natural
85// order (thus x-axis in the inner loop).
86// <br>It is possible to use the function <src>subSection</src> to
87// traverse only a subsection of the lattice.
88// <p>
89// The cursor position can be incremented or decremented to retrieve the next
90// or previous tile in the Lattice. The position of the next tile in the
91// Lattice will depend on the tile shape, and is described above.
92// <br>Note that the cursor shape does not need to be constant when iterating
93// through the lattice. If the lattice shape is not an integer multiple of
94// the tile shape, the cursor will be smaller on the edges of the lattice.
95// </synopsis>
96
97// <example>
98// This example initializes a lattice with the given value.
99// <srcblock>
100// void init (Lattice<Complex>& cArray, Complex value)
101// {
102// const IPosition latticeShape = cArray.shape();
103// const IPosition tileShape = cArray.niceCursorShape();
104// TileStepper tsx(latticeShape, tileShape);
105// LatticeIterator<Complex> lix(cArray, tsx);
106// for (lix.reset();!lix.atEnd();lix++)
107// lix.woCursor() = value;
108// }
109// }
110// </srcblock>
111// Note that a TileStepper is the default navigator for an iterator.
112// So the code above could be made simpler like shown below.
113// Also note that this example is a bit artificial, because the Lattice::set()
114// function should be used to initialize a lattice.
115// <srcblock>
116// void init (Lattice<Complex>& cArray, Complex value)
117// {
118// LatticeIterator<Complex> lix(cArray);
119// for (lix.reset();!lix.atEnd();lix++)
120// lix.woCursor() = value;
121// }
122// }
123// </srcblock>
124// </example>
125
126// <motivation>
127// This class makes it possible to traverse a lattice in the optimal way.
128// </motivation>
129//
130// # <todo asof="1997/11/21">
131// # <li>
132// # </todo>
133
135 public:
136 // Construct a TileStepper by specifying the Lattice shape, a tile shape,
137 // and an optional axis path (default is natural order).
138 // Is is nearly always advisable to make the tileShape identical
139 // to the Lattice tileShape. This can be obtained by
140 // <src>lat.niceCursorShape()</src> where <src>lat</src> is
141 // a Lattice object.
142 // <group>
145 // </group>
146
147 // Copy constructor (copy semantics).
149
151
152 // Assignment (copy semantics).
154
155 // Increment operator (postfix or prefix version) - move the cursor
156 // forward one step. Returns True if the cursor was moved.
157 virtual Bool operator++(int);
158
159 // Decrement operator (postfix or prefix version) - move the cursor
160 // backwards one step. Returns True if the cursor was moved.
161 virtual Bool operator--(int);
162
163 // Function to move the cursor to the beginning of the Lattice. Also
164 // resets the number of steps (<src>nsteps</src> function) to zero.
165 virtual void reset();
166
167 // Function which returns "True" if the cursor is at the beginning of the
168 // Lattice, otherwise, returns "False"
169 virtual Bool atStart() const;
170
171 // Function which returns "True" if an attempt has been made to increment
172 // the cursor beyond the end of the Lattice.
173 virtual Bool atEnd() const;
174
175 // Function to return the number of steps (increments & decrements) taken
176 // since construction (or since last reset). This is a running count of
177 // all cursor movement (operator++ or operator--), even though
178 // N-increments followed by N-decrements will always leave the cursor in
179 // the original position.
180 virtual uInt nsteps() const;
181
182 // Function which returns the current position of the beginning of the
183 // cursor. The <src>position</src> function is relative to the origin
184 // in the main Lattice.
185 virtual IPosition position() const;
186
187 // Function which returns the current position of the end of the
188 // cursor. The <src>endPosition</src> function is relative the origin
189 // in the main Lattice.
190 virtual IPosition endPosition() const;
191
192 // Functions which return the shape of the Lattice being iterated
193 // through. <src>latticeShape</src> always returns the shape of the main
194 // Lattice while <src>subLatticeShape</src> returns the shape of any
195 // sub-Lattice defined using the <src>subSection</src> function.
196 // <group>
197 virtual IPosition latticeShape() const;
198 virtual IPosition subLatticeShape() const;
199 // </group>
200
201 // Function which returns the shape of the cursor. This always includes
202 // all axes (i.e. it includes degenerates axes)
203 virtual IPosition cursorShape() const;
204
205 // Function which returns the axes of the cursor.
206 virtual IPosition cursorAxes() const;
207
208 // Function which returns the shape of the "tile" the cursor will iterate
209 // through before moving onto the next tile.
211
212 // Function which returns "True" if the increment/decrement operators have
213 // moved the cursor position such that part of the cursor beginning or end
214 // is hanging over the edge of the Lattice. This always returns False.
215 virtual Bool hangOver() const;
216
217 // Functions to specify a "section" of the Lattice to step over. A section
218 // is defined in terms of the Bottom Left Corner (blc), Top Right Corner
219 // (trc), and step size (inc), on ALL of its axes, including degenerate
220 // axes. The step size defaults to one if not specified.
221 // <group>
222 virtual void subSection(const IPosition& blc, const IPosition& trc);
223 virtual void subSection(const IPosition& blc, const IPosition& trc, const IPosition& inc);
224 // </group>
225
226 // Return the bottom left hand corner (blc), top right corner (trc) or
227 // step size (increment) used by the current sub-Lattice. If no
228 // sub-Lattice has been defined (with the <src>subSection</src> function)
229 // these functions return blc=0, trc=latticeShape-1, increment=1, ie. the
230 // entire Lattice.
231 // <group>
232 virtual IPosition blc() const;
233 virtual IPosition trc() const;
234 virtual IPosition increment() const;
235 // </group>
236
237 // Return the axis path.
238 virtual const IPosition& axisPath() const;
239
240 // Function which returns a pointer to dynamic memory of an exact copy
241 // of this instance. The pointer returned by this function must
242 // be deleted externally.
243 virtual LatticeNavigator* clone() const;
244
245 // Function which checks the internal data of this class for correct
246 // dimensionality and consistant values.
247 // Returns True if everything is fine otherwise returns False
248 virtual Bool ok() const;
249
250 // Calculate the cache size (in tiles) for this type of access to a lattice
251 // in the given row of the tiled hypercube.
252 virtual uInt calcCacheSize(const IPosition& cubeShape, const IPosition& tileShape,
253 uInt maxCacheSize, uInt bucketSize) const;
254
255 private:
256 // Prevent the default constructor from being used.
258
259 IPosition itsBlc; // # Bottom Left Corner
260 IPosition itsTrc; // # Top Right Corner
261 IPosition itsInc; // # Increment
262 LatticeIndexer itsSubSection; // # The current subsection
263 LatticeIndexer itsTiler; // # For moving between tiles
264 IPosition itsTilerCursorPos; // # The current position of the iterator
265 IPosition itsTileShape; // # The tile shape (= itsTiler cursor shape)
266 IPosition itsAxisPath; // # Path for traversing
267 IPosition itsCurBlc; // # Blc of the current position.
268 IPosition itsCurTrc; // # Trc of the current position.
269 uInt itsNsteps; // # The number of iterator steps taken so far
270 Bool itsEnd; // # Is the cursor beyond the end?
271 Bool itsStart; // # Is the cursor at the beginning?
272};
273
274} // namespace casacore
275
276#endif
LatticeNavigator()
Default constructor.
virtual IPosition endPosition() const
Function which returns the current position of the end of the cursor.
LatticeIndexer itsSubSection
IPosition itsTilerCursorPos
TileStepper(const IPosition &latticeShape, const IPosition &tileShape)
Construct a TileStepper by specifying the Lattice shape, a tile shape, and an optional axis path (def...
virtual IPosition increment() const
virtual IPosition cursorShape() const
Function which returns the shape of the cursor.
virtual Bool atStart() const
Function which returns "True" if the cursor is at the beginning of the Lattice, otherwise,...
virtual void reset()
Function to move the cursor to the beginning of the Lattice.
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 tile...
IPosition tileShape() const
Function which returns the shape of the "tile" the cursor will iterate through before moving onto the...
virtual Bool hangOver() const
Function which returns "True" if the increment/decrement operators have moved the cursor position suc...
virtual IPosition subLatticeShape() const
TileStepper & operator=(const TileStepper &other)
Assignment (copy semantics).
virtual Bool ok() const
Function which checks the internal data of this class for correct dimensionality and consistant value...
virtual IPosition cursorAxes() const
Function which returns the axes of the cursor.
TileStepper()
Prevent the default constructor from being used.
virtual IPosition position() const
Function which returns the current position of the beginning of the cursor.
LatticeIndexer itsTiler
virtual void subSection(const IPosition &blc, const IPosition &trc, const IPosition &inc)
virtual IPosition trc() const
virtual uInt nsteps() const
Function to return the number of steps (increments & decrements) taken since construction (or since l...
virtual LatticeNavigator * clone() const
Function which returns a pointer to dynamic memory of an exact copy of this instance.
virtual void subSection(const IPosition &blc, const IPosition &trc)
Functions to specify a "section" of the Lattice to step over.
virtual IPosition latticeShape() const
Functions which return the shape of the Lattice being iterated through.
virtual Bool operator++(int)
Increment operator (postfix or prefix version) - move the cursor forward one step.
virtual IPosition blc() const
Return the bottom left hand corner (blc), top right corner (trc) or step size (increment) used by the...
virtual Bool atEnd() const
Function which returns "True" if an attempt has been made to increment the cursor beyond the end of t...
virtual const IPosition & axisPath() const
Return the axis path.
TileStepper(const TileStepper &other)
Copy constructor (copy semantics).
TileStepper(const IPosition &latticeShape, const IPosition &tileShape, const IPosition &axisPath)
virtual Bool operator--(int)
Decrement operator (postfix or prefix version) - move the cursor backwards one step.
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40