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