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