casacore
Loading...
Searching...
No Matches
LatticeNavigator.h
Go to the documentation of this file.
1// # LatticeNavigator.h: Abstract base class to steer lattice iterators
2// # Copyright (C) 1994,1995,1996,1997,1998,1999
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_LATTICENAVIGATOR_H
27#define LATTICES_LATTICENAVIGATOR_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31
32namespace casacore { // # NAMESPACE CASACORE - BEGIN
33
34// # Forward Declarations
35class IPosition;
37
38// <summary>
39// Abstract base class to steer lattice iterators.
40// </summary>
41
42// <use visibility=local>
43
44// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tLatticeStepper.cc">
45// </reviewed>
46
47// <prerequisite>
48// <li> <linkto class=LatticeIterator>LatticeIterator</linkto>
49// <li> <linkto class=Lattice>Lattice</linkto>
50// </prerequisite>
51
52// <etymology>
53// Lattice iteration can proceed with a number of different strategies -
54// all of which answer the question: where do I go from here?
55// You could travel through by making calculations on the lattice subscripts,
56// viewing ascending planes in an image cube, for example, or you could
57// travel through by making calculations on the data, viewing small
58// subimage planes in order of descending brightness over the whole cube.
59// Concrete classes derived from this base class implement different
60// navigation strategies - but they are all "navigators".
61// </etymology>
62
63// <synopsis>
64// This abstract base class defines the interface for objects which generate
65// positions for LatticeIterators. This position is not just a single point
66// in the Lattice but a region or "cursor" that is moved through the
67// Lattice. The LatticeIterator classes actually retrieve the data in the
68// cursor from the Lattice. The class decribed here (and those derived from it)
69// are responsible for moving the cursor to the next position and determining
70// its shape.
71//
72// There may eventually be a large collection of tools for traversing
73// Lattices. At this writing (December 1999) there are three concrete
74// classes derived from LatticeNavigator:
75// <linkto class="LatticeStepper">LatticeStepper</linkto>,
76// <linkto class="TiledLineStepper">TiledLineStepper</linkto>, and
77// <linkto class="TileStepper">TileStepper</linkto>.
78//
79// The <src>LatticeStepper</src> class moves through a Lattice in fixed
80// steps defined by the user specified cursor, incrementing to the next
81// portion of the Lattice with each step, and wrapping around axes as
82// needed. Other position generators might follow the brightest pixel,
83// traverse a number of predefined subregions, or change size automatically
84// when near the edges.
85//
86// The <src>TiledLineStepper</src> class moves a Vector cursor through a
87// Lattice, until all the lines in the set of tiles along the specified
88// axis have been exhausted. It then moves to the next set of tiles. This is
89// a memory-efficient way to move a Vector cursor through a Lattice.
90//
91// The most important member functions of this class are those which move
92// the cursor to the next position. These are the <src>operator++</src> and
93// <src>operator--</src> member functions, (in postfix and prefix forms).
94//
95// The cursor shape need not be constant as it moves through the Lattice,
96// but may change depending on its current position. For the LatticeStepper
97// and TiledLineStepper classes , however, the cursor shape is constant
98// as it steps through the Lattice.
99//
100// It is not possible to randomly move the cursor to an arbitrary place in
101// the Lattice, although the cursor can be moved to the starting position at
102// any time using the <src>reset</src> member function.
103//
104// The position of the cursor can be queried at any time using the
105// <src>position</src> member function. This gives the position of the
106// bottom left hand corner of the cursor. The position of the top right hand
107// corner of the cursor is obtained using the <src>endPosition</src> member
108// function, and the current cursor shape is obtained using the
109// <src>cursorShape</src> member function. Note that the endPosition
110// does not take an overhang into account.
111//
112// It is possible that for some positions of the cursor, part of it will
113// "hang over" the edge of the Lattice. When this occurs the
114// <src>hangOver</src> member function will return True. This will occur
115// with a LatticeStepper if the Lattice shape is not a multiple of the
116// cursor shape. Hangover cannot occur with the TiledLineStepper as the length
117// of the Vector cursor is defined by the Lattice Shape.
118//
119// It may be possible (depending on the concrete LatticeNavigator actually
120// used) to specify that only a region of the Lattice (defined by a top
121// right hand corner, bottom left hand corner, and step increment) be
122// traversed by the LatticeNavigator. This is done using the
123// <src>subSection</src> member function. At any time the region can be
124// redefined by calling the <src>subSection</src> function again. This
125// replaces the previously defined region with the new one.
126//
127// Using the subSection function always sets the cursor position to the
128// origin of the currently defined sub-lattice. This is a backdoor way to
129// move the cursor to random locations in the Lattice.
130//
131// It is an error to define a sub-lattice that is bigger than the current
132// Lattice. If using a LatticeStepper it may also be necessary to resize the
133// cursor (using the <src>setCursorShape</src> member function) prior to
134// calling the subSection function as the cursor cannot be bigger than the
135// sub-Lattice on any axis.
136//
137// The arguments (<src>trc</src>, <src>blc</src> and <src>inc</src>)
138// to the <src>subSection</src> function are always
139// relative to the main Lattice. This is also true of the <src>position</src>
140// and <src>endPosition</src> functions. To get the position of the cursor
141// relative to the currently defined sub-Lattice use the
142// <src>relativePosition</src> and <src>relativeEndPosition</src> member
143// functions.
144//
145// Many of the LatticeIterator member functions are directly forwarded to
146// virtual functions of this class, and classes derived from it. For
147// instance, LatticeIterator<T>::operator++() calls
148// LatticeIterInterface->operator++() which calls
149// LatticeNavigator->operator++() which might resolve to
150// LatticeStepper->operator++(). Other functions like this are documented in
151// the <linkto class="LatticeIterator">LatticeIterator</linkto> class.
152// </synopsis>
153
154// <example>
155// See the examples in the
156// <linkto class="LatticeStepper">LatticeStepper</linkto> class, the
157// <linkto class="TiledLineStepper">TiledLineStepper</linkto> class, and the
158// <linkto class="TileStepper">TileStepper</linkto> class.
159// </example>
160//
161// <motivation>
162// Iterator classes are quite common in C++. What's novel about the design
163// which includes this class is the separation of iterator mechanisms from
164// traversal strategy. The iterator provides a lot of functionality: it
165// provides a cursor, damage notification and tracking, and reading and
166// writing to the underlying data structure. Traversal strategies can and
167// should be isolated from these things. Because every LatticeIterator
168// uses a Navigator, it gets the benefits of a derived concrete navigator
169// without getting involved in its mechanism.
170// </motivation>
171//
172// <todo asof="1997/31/01">
173// <li> Think about how to implement Navigators which can traverse
174// arbitrary shaped regions.
175// </todo>
176
178 public:
179 // Default constructor.
181
182 // Copy constructor.
184
185 // Assignment.
186 LatticeNavigator& operator=(const LatticeNavigator&) { return *this; }
187
188 // A virtual destructor. A virtual is needed to ensure that derived
189 // classes accessed through pointers to a LatticeNavigator will scope
190 // their destructor to the derived class destructor.
192
193 // Increment operator - increment the cursor to the next position. The
194 // implementation of the prefix operator calls the postfix one.
195 // <group>
196 virtual Bool operator++(int) = 0;
198 // </group>
199
200 // Decrement operator - decrement the cursor to the previous position. The
201 // implementation of the prefix operator calls the postfix one.
202 // <group>
203 virtual Bool operator--(int) = 0;
205 // </group>
206
207 // Function to reset the cursor to the beginning of the Lattice and
208 // reset the number of steps taken to zero.
209 virtual void reset() = 0;
210
211 // Function which returns "True" if the cursor is at the beginning of the
212 // Lattice, otherwise, returns "False"
213 virtual Bool atStart() const = 0;
214
215 // Function which returns "True" if an attempt has been made to increment
216 // the cursor beyond the end of the Lattice.
217 virtual Bool atEnd() const = 0;
218
219 // Function to return the number of steps (increments or decrements) taken
220 // since construction (or since last reset). This is a running count of
221 // all cursor movement since doing N increments followed by N decrements
222 // does not necessarily put the cursor back at the origin of the Lattice.
223 virtual uInt nsteps() const = 0;
224
225 // Functions which return the current position of the beginning of the
226 // cursor. The <src>position</src> function is relative to the origin in
227 // the main Lattice and the <src>relativePosition</src> function is
228 // relative to the origin and increment used in the sub-Lattice (defined
229 // using the <src>subSection</src> function).
230 // The returned IPosition will have the same number of axes as
231 // the underlying Lattice.
232 // <br>The default implementation of the <src>relativePosition</src>
233 // function returns <src>(position() - blc()) / increment()</src>.
234 // <group>
235 virtual IPosition position() const = 0;
237 // </group>
238
239 // Functions which return the current position of the end of the
240 // cursor. The <src>endPosition</src> function is relative to the origin in
241 // the main Lattice and the <src>relativeEndPosition</src> function is
242 // relative to the origin and increment used in the sub-Lattice (defined
243 // using the <src>subSection</src> function).
244 // The returned IPosition will have the same number of axes as
245 // the underlying Lattice.
246 // <note role=caution> It returns the end position in the lattice and
247 // does not take overhang into account. </note>
248 // <br>The default implementation of the <src>relativeEndPosition</src>
249 // function returns <src>(endPosition() - blc()) / increment()</src>.
250 // <group>
251 virtual IPosition endPosition() const = 0;
253 // </group>
254
255 // Functions which return the shape of the Lattice being iterated
256 // through. <src>latticeShape</src> always returns the shape of the main
257 // Lattice while <src>subLatticeShape</src> returns the shape of any
258 // sub-Lattice defined using the <src>subSection</src> function. In the
259 // default implementation of this class it is not possible to use the
260 // <src>subsection</src> function (it throws an exception) so the default
261 // implementation of the <src>subLatticeShape</src> function calls the
262 // <src>latticeShape</src> function. The returned IPosition will always
263 // have the same number of axes as the underlying Lattice.
264 // <group>
265 virtual IPosition latticeShape() const = 0;
266 virtual IPosition subLatticeShape() const;
267 // </group>
268
269 // Function which returns the current shape of the cursor which is
270 // iterating through the Lattice. The returned IPosition will have the
271 // same number of axes as the underlying Lattice.
272 virtual IPosition cursorShape() const = 0;
273
274 // Function which returns the axes of the cursor.
275 // These are the axes which should not be removed by the
276 // iterator functions <src>vectorCursor()</src>, etc..
277 virtual IPosition cursorAxes() const = 0;
278
279 // Function which returns "True" if the increment/decrement operators have
280 // moved the cursor position such that part of the cursor is hanging over
281 // the edge of the Lattice. This function may always return a value of
282 // "False" for some iteration methods that do not move the cursor past the
283 // Lattice boundaries.
284 virtual Bool hangOver() const = 0;
285
286 // Functions which return the "bottom left corner" and the "top right corner"
287 // of the cursor that does not hangover. Use these functions to extract the
288 // valid part of the cursor when the hangover member function is true. If
289 // there is no hangover then hangOverBLC returns an IPosition of zero and
290 // hangOverTRC() returns the cursorShape - 1;
291 // <group>
292 virtual IPosition hangOverBlc() const;
293 virtual IPosition hangOverTrc() const;
294 // </group>
295
296 // Function to specify a "section" of the Lattice to Navigate over. A
297 // section is defined in terms of the Bottom Left Corner (blc), Top Right
298 // Corner (trc), and step size (inc), on ALL of its axes, including
299 // degenerate axes. The step size defaults to one if not specified.
300 // In the default implementation of this class subsectioning is not
301 // supported and using the <src>subsection</src> function will throw an
302 // exception (AipsError).
303 // <group>
304 virtual void subSection(const IPosition& blc, const IPosition& trc);
305 virtual void subSection(const IPosition& blc, const IPosition& trc, const IPosition& inc);
306 // </group>
307
308 // Return the bottom left hand corner (blc), top right corner (trc) or
309 // step size (increment) used by the current sub-Lattice. In the default
310 // implementation of this class sub-sectioning is not supported and these
311 // functions will always return blc=0, trc=latticeShape-1, increment=1,
312 // ie. the entire Lattice.
313 // <group>
314 virtual IPosition blc() const;
315 virtual IPosition trc() const;
316 virtual IPosition increment() const;
317 // </group>
318
319 // Return the axis path.
320 // See <linkto class=LatticeStepper>LatticeStepper</linkto> for a
321 // description and examples.
322 virtual const IPosition& axisPath() const = 0;
323
324 // Calculate the cache size (in tiles) for this type of access to a lattice
325 // in the given row of the tiled hypercube.
326 // A zero bucket size indicates that the data are not tiled, but in memory.
327 // Then a cache size of 0 is returned.
328 virtual uInt calcCacheSize(const IPosition& cubeShape, const IPosition& tileShape,
329 uInt maxCacheSize, uInt bucketSize) const = 0;
330
331 // Function which returns a pointer to dynamic memory of an exact copy
332 // of this LatticeNavigator. It is the responsibility of the caller to
333 // release this memory.
334 virtual LatticeNavigator* clone() const = 0;
335
336 // Function which checks the internals of the class for consistency.
337 // Returns True if everything is fine otherwise returns False. The default
338 // implementation always returns True.
339 virtual Bool ok() const;
340};
341
344
345} // namespace casacore
346
347#endif
virtual IPosition hangOverTrc() const
virtual IPosition cursorAxes() const =0
Function which returns the axes of the cursor.
virtual IPosition cursorShape() const =0
Function which returns the current shape of the cursor which is iterating through the Lattice.
virtual IPosition relativeEndPosition() const
virtual Bool hangOver() const =0
Function which returns "True" if the increment/decrement operators have moved the cursor position suc...
virtual IPosition blc() const
Return the bottom left hand corner (blc), top right corner (trc) or step size (increment) used by the...
virtual Bool operator--(int)=0
Decrement operator - decrement the cursor to the previous position.
virtual IPosition endPosition() const =0
Functions which return the current position of the end of the cursor.
virtual IPosition subLatticeShape() const
virtual IPosition hangOverBlc() const
Functions which return the "bottom left corner" and the "top right corner" of the cursor that does no...
virtual IPosition trc() const
virtual uInt calcCacheSize(const IPosition &cubeShape, const IPosition &tileShape, uInt maxCacheSize, uInt bucketSize) const =0
Calculate the cache size (in tiles) for this type of access to a lattice in the given row of the tile...
virtual Bool atStart() const =0
Function which returns "True" if the cursor is at the beginning of the Lattice, otherwise,...
virtual const IPosition & axisPath() const =0
Return the axis path.
virtual ~LatticeNavigator()
A virtual destructor.
virtual IPosition increment() const
virtual IPosition latticeShape() const =0
Functions which return the shape of the Lattice being iterated through.
virtual IPosition relativePosition() const
virtual void reset()=0
Function to reset the cursor to the beginning of the Lattice and reset the number of steps taken to z...
virtual void subSection(const IPosition &blc, const IPosition &trc)
Function to specify a "section" of the Lattice to Navigate over.
LatticeNavigator(const LatticeNavigator &)
Copy constructor.
virtual void subSection(const IPosition &blc, const IPosition &trc, const IPosition &inc)
virtual IPosition position() const =0
Functions which return the current position of the beginning of the cursor.
virtual LatticeNavigator * clone() const =0
Function which returns a pointer to dynamic memory of an exact copy of this LatticeNavigator.
LatticeNavigator()
Default constructor.
LatticeNavigator & operator=(const LatticeNavigator &)
Assignment.
virtual Bool atEnd() const =0
Function which returns "True" if an attempt has been made to increment the cursor beyond the end of t...
virtual Bool ok() const
Function which checks the internals of the class for consistency.
virtual uInt nsteps() const =0
Function to return the number of steps (increments or decrements) taken since construction (or since ...
virtual Bool operator++(int)=0
Increment operator - increment the cursor to the next position.
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