casacore
Loading...
Searching...
No Matches
Lattices.h
Go to the documentation of this file.
1// # Lattices.h: Regular N-dimensional data structures.
2// # Copyright (C) 1996,1997,1998,1999,2003
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_LATTICES_H
27#define LATTICES_LATTICES_H
28
29// #include <casacore/casa/Arrays/ArrayLattice.h>
30// #include <casacore/casa/Arrays/PagedArray.h>
31// #include <casacore/casa/Arrays/TempLattice.h>
32// #include <casacore/casa/Arrays/LatticeLocker.h>
33// #include <casacore/casa/Arrays/TiledShape.h>
34
35// #include <casacore/casa/Arrays/LatticeApply.h>
36// #include <casacore/casa/Arrays/LatticeIterator.h>
37// #include <casacore/casa/Arrays/LatticeStepper.h>
38// #include <casacore/casa/Arrays/TileStepper.h>
39// #include <casacore/casa/Arrays/TiledLineStepper.h>
40
41// #include <casacore/lattices/Lattices/SubLattice.h>
42
43// #include <casacore/lattices/LRegions.h>
44// #include <casacore/lattices/LEL.h>
45// #include <casacore/lattices/LatticeMath.h>
46
47namespace casacore { // # NAMESPACE CASACORE - BEGIN
48
49// <module>
50
51// <summary>
52// Regular N-dimensional data structures.
53// </summary>
54
55// <prerequisite>
56// <li> Programmers of new Lattice classes should understand Inheritance
57// <li> Users of the Lattice classes should understand Polymorphism.
58// <li> class <linkto class=IPosition>IPosition</linkto>
59// <li> class <linkto class=Array>Array</linkto>
60// </prerequisite>
61
62// <reviewed reviewer="Peter Barnes" date="1999/10/30" demos="">
63// </reviewed>
64
65// <etymology>
66// Lattice: "A regular, periodic configuration of points, particles, or
67// objects, throughout an area of a space..." (American Heritage Directory)
68// This definition matches our own: an N-dimensional arrangement of data
69// on regular orthogonal axes.
70// <p>
71// In Casacore, we have used the ability to call many things by one generic
72// name (Lattice) to create a number of classes which have different storage
73// techniques (e.g. core memory, disk, etc...). The name Lattice should
74// make the user think of a class interface (or member functions) which all
75// Lattice objects have in common. If functions require a Lattice
76// argument, the classes described here may be used interchangeably, even
77// though their actual internal workings are very different.
78// </etymology>
79
80// <synopsis>
81// The Lattice module may be broken up into a few areas:
82// <ol>
83//
84// <li> Lattices - the actual holders of lattice-like data which all share a
85// common <linkto class="Lattice">interface</linkto>. The following items
86// are all Lattices and may be used polymorphically wherever a Lattice is
87// called for.
88// <ul>
89// <li>The <linkto class="ArrayLattice">ArrayLattice</linkto> class adds
90// the interface requirements of a Lattice to a Casacore
91// <linkto class="Array">Array</linkto>. The data inside an ArrayLattice
92// are not stored on disk. This n-dimensional array class is the simplest
93// of the Lattices. Users construct the ArrayLattice with an argument
94// which is either an IPosition which describes the array shape or a
95// previously instantiated Array object that may already contain data. In
96// the former case, some Lattice operation must be done to fill the data.
97// The ArrayLattice, like all Lattices, may be iterated through with a
98// <linkto class=LatticeIterator>LatticeIterator</linkto> (see below).
99// <br>Iteration can also be done using
100// <linkto class=LatticeApply>LatticeApply</linkto> and some helper
101// classes. It makes it possible to concentrate on the algorithm.
102// <srcblock>
103// // Make an Array of shape 3x4x5
104//
105// Array<Float> simpleArray(IPosition(3,3,4,5));
106//
107// // fill it with a gradient
108//
109// for (Int k=0; k<5; k++)
110// for (Int j=0; j<4; j++)
111// for (Int i=0; i<3; i++)
112// simpleArray(IPosition(3,i,j,k)) = i+j+k;
113//
114// // use the array to create an ArrayLattice.
115//
116// ArrayLattice<Float> lattice(simpleArray);
117// </srcblock>
118//
119// <li>The <linkto class="PagedArray">PagedArray</linkto> class stores its
120// data on disk in the Table format
121// and pages it into random access memory for use. Paging is
122// used here to describe the process of getting pieces of data small
123// enough to fit into active memory even if the whole data set is much too
124// large. This class "feels" like an array but may hold very large amounts
125// of data. The paging has an added effect: all the data may be made
126// persistent, so it stays around after the application ends.
127// When you use PagedArrays - use
128// them because you need persistent data and/or paging into large data sets.
129// <br>
130// The persistence is done using a <linkto module="Tables">Table</linkto>,
131// and uses the <linkto module="Tables:TiledStMan">tiled storage
132// manager</linkto>. This means that accessing the data along any axis is
133// equally efficient (depending on the tile shape used).
134// <br>
135// A PagedArray constructor allows previously created PagedArrays to be
136// recalled from disk. Much of the time, the PagedArray will be
137// constructed with a <linkto class=TiledShape>TiledShape</linkto>
138// argument which describes the array and tile shape
139// and a Table argument for use as the place of storage. Then the
140// PagedArray may be filled using any of the access functions of Lattices
141// (like the LatticeIterator.)
142//
143// <srcblock>
144// // Create a PagedArray from a Table already existing on disk.
145//
146// PagedArray<Float> lattice(fileName);
147//
148// // Create a LatticeIterator to access the Lattice in optimal tile
149// // shaped chunks.
150//
151// LatticeIterator<Float> iter(lattice);
152//
153// // Iterate through and do something simple; here we just
154// // sum up all the values in the Lattice
155//
156// Float dSum = 0;
157// for(iter.reset(); !iter.atEnd(); iter++) {
158// dSum += sum(iter.cursor());
159// }
160// </srcblock>
161//
162// <li>The <linkto class="HDF5Lattice">HDF5Lattice</linkto> class stores its
163// data on disk in <a href="http://www.hdfgroup.org/HDF5">HDF5</a> format.
164// It works in the same way as PagedArray.
165//
166// </ul>
167//
168// <li> <linkto class="LatticeIterator">LatticeIterator</linkto> - the
169// object which allows iteration through any Lattice's data. This comes in
170// two types: the <src>RO_LatticeIterator</src> which should be used if you
171// are not going to change the Lattice's data, and the
172// <src>LatticeIterator</src> if you need to change the data in the Lattice.
173// <br>Note that iteration can also be done using
174// <linkto class=LatticeApply>LatticeApply</linkto> and some helper
175// classes. It makes it possible to concentrate on the algorithm.
176// <ul>
177// <li> The <linkto class="RO_LatticeIterator">RO_LatticeIterator</linkto>
178// class name reflects its role as a means of iterating a "Read-Only" array
179// (hereafter refered to as a "cursor") through a Lattice based object,
180// from beginning to end. Think of a window into the Lattice that moves to
181// a new location when requested. The Lattice doesn't change but you may
182// see all or part of its data as the cursor "window" moves around. This
183// class allows optimized read-only iteration through any instance of a
184// class derived from Lattice. The cursor's shape is defined by the user and
185// moved through the Lattice in an orderly fashion also defined by the user.
186// Since the cursor is "read-only" it can only be used to "get" the data
187// out of the Lattice. RO_LatticeIterators are constructed with the Lattice
188// to be iterated as the first argument. The optional second constructor
189// argument is either an IPosition which defines the shape of the cursor
190// or a <linkto class=LatticeNavigator>LatticeNavigator</linkto> argument.
191// The IPosition argument cause the iterator
192// to move the cursor in a simple pattern; the cursor starts at the Lattice's
193// origin and moves in the direction of the x-axis, then the y-axis, then
194// the z-axis, etc.. If a LatticeNavigator argument is given, more
195// control over the cursor shape and path are available. If no second
196// argument is given, the optimal
197// <linkto class=TileStepper>TileStepper</linkto> navigator will be used.
198// <srcblock>
199// // simple route - define a cursor shape that is the xy plane of our
200// lattice.
201//
202// IPosition cursorShape(2, lattice.shape()(0), lattice.shape()(1));
203// LatticeIterator<Float> iter(lattice, cursorShape);
204// for (iter.reset(); !iter.atEnd(); iter++) {
205// minMax(iter.cursor(), min, max);
206// }
207// </srcblock>
208//
209// <li> The <linkto class="LatticeIterator">LatticeIterator</linkto> class
210// name reflects its role as a means of iterating a read and write cursor
211// through a Lattice based object. Not only does the cursor allow you to
212// inspect the Lattice data but you may also change the Lattice via
213// operations on the cursor. This class provides optimized read and write
214// iteration through any class derived from Lattice. The technique is
215// identical to the RO_LatticeIterator. But the cursor, in this case, is
216// a reference back to the data in the Lattice. This means that changes
217// made to the cursor propagate back to the Lattice. This is especially
218// useful for the PagedArray and PagedImage classes. These two classes
219// are constructed empty and need iteration to fill in the Lattice data.
220// <srcblock>
221// // make an empty PagedArray and fill it. The Table that stores the
222// // PagedArray is deleted when the PagedArray goes out of scope
223//
224// PagedArray<Float> lattice(IPosition(4,100,200,300,50));
225// LatticeIterator<Float> iter(lattice, IPosition(2, 100, 200));
226//
227// // fill each plane with the "distance" of the iterator from the origin
228//
229// for(iter.reset();!iter.atEnd(); iter++) {
230// iter.woCursor() = iter.nsteps();
231// }
232// </srcblock>
233// </ul>
234//
235// <li> LatticeNavigators - the objects which define the method and path used
236// by a LatticeIterator to move the cursor through a Lattice. Many
237// different paths are possible. We leave it you to choose the
238// <linkto class=LatticeNavigator>LatticeNavigator</linkto>
239// (method and path) when using a LatticeIterator.
240// <ul>
241// <li> The <linkto class="LatticeStepper">LatticeStepper</linkto> class
242// is used to define the steps which the cursor takes during its path
243// through the Lattice. Every element of the Lattice will be covered,
244// starting at the origin and ending at the "top right corner." This
245// class provides the information needed by a LatticeIterator to do
246// non-standard movements of the cursor during iteration. The shape of
247// the cursor is specified by the second IPosition argument of the
248// LatticeStepper. The order of the axis is important. An IPosition(1,5)
249// is a five element vector along the x-axis. An IPosition(3,1,1,5) is a
250// five element vector along the z-axis. The degenerate axes (axes with
251// lengths of one) act as place holders. The third argument in the
252// LatticeStepper constructor is the "orientation" IPosition. This
253// describes the order of the axis for the cursor to follow. Again, we
254// treat the elements, in order, of the IPosition as the designators of
255// the appropriate axis. The zeroth element indicates which axis is the
256// fastest moving, the first element indicates which axis is the second
257// fastest moving etc. eg. The IPosition(3,2,0,1) says the LatticeIterator
258// should start with the z-axis, next follow the x-axis, and finish with
259// the y-axis. A single element cursor would thus move through a cube of
260// dimension(x,y,z) from (0,0,0) up the z-axis until reaching the maximum
261// (0,0,z-1) and then start on (1,0,0) and move to (1,0,z-1), etc.
262// <srcblock>
263// // The shape of our Lattice - a 4 dimensional image of shape (x,y,z,t) -
264// // and the shape of the cursor
265//
266// IPosition latticeShape(image.shape());
267// IPosition cursorShape(3, lattticeShape(0), 1, latticeShape(2));
268//
269// // Define the path the cursor should follow, we list x and z first, even though
270// // no iterations will be done along those axes since the cursor is an
271// // integral subshape of the Lattice. The cursor will move along the y-axis
272// // and then increment the t-axis. The construct the Navigator and Iterator
273//
274// IPosition order(4,0,2,1,3);
275// LatticeStepper nav(latticeShape, cursorShape, order);
276// LatticeIterator<Float> iter(image, nav);
277// </srcblock>
278//
279// <li>
280// The <linkto class="TiledLineStepper">TiledLineStepper</linkto> class
281// allows you to iterate through a Lattice with a Vector cursor.
282// However, it steps through the Lattice in an order which is
283// optimum with regard to the I/O of the tiles with which the Lattice is
284// constructed.
285//
286// <srcblock>
287//
288// // Set up a TiledLineStepper to return profiles along the specified
289// // axis from a PagedArray (not all Lattices have the tileShape member
290// // function). Then create the iterator as well.
291//
292// TiledLineStepper nav(lattice.shape(), lattice.tileShape(), axis);
293// LatticeIterator<Complex> nav(lattice, nav);
294// </srcblock>
295//
296// <li>
297// The <linkto class="TileStepper">TileStepper</linkto> class
298// allows you to iterate through a Lattice in the optimum way.
299// It steps through the lattice tile by tile minimizing I/O and memory usage.
300// It is very well suited for pixel based operations.
301// However, its iteration order is such that it cannot be used for
302// a certain subset of pixels (e.g. a vector) is needed.
303// <br>This navigator is the default when no navigator is given when
304// constructing a (RO_)LatticeIterator.
305//
306// </ul>
307//
308// <li> <linkto class="MaskedLattice">MaskedLattice</linkto> - a
309// Lattice with a mask. It is an abstract base class for
310// various types of MaskedLattices. A MaskedLattice does not need
311// to contain a mask (see e.g. SubLattice below), although the user
312// can always ask for the mask. The function <src>isMasked()</src>
313// tells if there is really a mask. If not, users could take
314// advantage by shortcutting some code for better performance.
315// I.e. a function can test if a the MaskedLattice is really masked
316// and can take a special route if not.
317// Of course, doing that requires more coding, so it should only
318// be done where performance is a real issue.
319// <ul>
320// <li> A <linkto class="SubLattice">SubLattice</linkto> represents
321// a rectangular subset of a Lattice. The SubLattice can be a simple
322// box, but it can also be a circle, polygon, etc.
323// In the latter case the SubLattice contains a mask
324// telling which pixels in the bounding box actually belong to the
325// circle or polygon. In the case of a box there is no mask, because
326// there is no need to (because a box is already rectangular).
327// <br> A SubLattice can be constructed from any Lattice and a
328// <linkto class=LatticeRegion>LatticeRegion</linkto> telling which
329// part to take from the Lattice.
330// If the SubLattice is constructed from a <src>const Lattice</src>,
331// the SubLattice is not writable. Otherwise it is writable if the
332// lattice is writable.
333// <p>
334// There is a rich variety of <linkto class=LCRegion>region</linkto>
335// classes which can be used to define a LatticeRegion in pixel coordinates.
336// They are described in module
337// <a href="group__LRegions__module.html">LRegions</a>.
338//
339// <li> Module <a href="group__LEL__module.html">LEL</a> contains classes to
340// form a mathematical expression of lattices. All standard operators, regions,
341// and many, many <linkto class=LatticeExprNode>functions</linkto>
342// can be used in an expression.
343// </ul>
344//
345// <li> <linkto class=LatticeLocker>LatticeLocker</linkto>
346// can be used to acquire a (user) lock on a lattice.
347// The lock can be a read or write lock.
348// The destructor releases the lock when needed.
349// <br>Lattices on disk can be used (read and write) by multiple processes.
350// The Table locking/synchronization mechanism takes care that sharing
351// such a lattice is done in an orderly way.
352// Usually the default locking mechanism is sufficient.
353// LatticeLocker is useful when finer locking control is needed for a
354// disk-based lattice.
355//
356// <note role=warning> The following are listed for low-level programmers.
357// Lattice users need not understand them.</note> The Lattice directory
358// contains several files relevant only to implementation.
359//
360// <ul>
361// <li> <linkto class="LatticeBase">LatticeBase</linkto> - a non-templated
362// abstract base class defining the type-independent interface to classes
363// which must act as Lattices do.
364// <li> <linkto class="Lattice">Lattice</linkto> - a templated
365// abstract base class (derived from LatticeBase)
366// defining the interface to classes which must act as Lattices do.
367// The user simply publicly inherits from Lattice and defines the member
368// functions declared as pure abstract in the Lattice header file.
369// <li> The <linkto class="LatticeNavigator">LatticeNavigator</linkto>
370// class name defines the interface used for navigating through a Lattice
371// by iteration. This class is an abstract base. Classes derived from
372// this (currently
373// <linkto class="LatticeStepper">LatticeStepper</linkto>,
374// <linkto class="TiledLineStepper">TiledLineStepper</linkto>, and
375// <linkto class="TileStepper">TileStepper</linkto>) must
376// define the path the iterator cursor follows, the size of the movement
377// of the cursor with each iteration, and the behaviour of that cursor
378// shape as it moves through a Lattice.
379// <li> <linkto class="LatticeIndexer">LatticeIndexer</linkto> - this
380// class contains the currently defined Lattice and sub-Lattice shape. It
381// is used only by navigator classes as it contains
382// member functions for moving a cursor through a defined sub-Lattice.
383// <li> The
384// <linkto class="LatticeIterInterface">LatticeIterInterface</linkto>
385// class defines the interface for a specific Lattice's iterator. This
386// class is a base class with a default iterator implementation.
387// Lattice based classes may need to derive an iterator from
388// LatticeIterInterface to optimize for the LatticeIterator
389// internals which impact upon the new Lattice.
390// <li> <linkto class="PagedArrIter">PagedArrIter</linkto> - this class is
391// the PagedArray's optimized method of iterating. This class is a
392// "letter" utilized within the LatticeIterator "envelope" and cannot
393// be instantiated by any user.
394// <li> <linkto class="LCRegion">LCRegion</linkto> - this class is the
395// (abstract) base class for regions in pixel coordinates.
396// </ul>
397// </ol>
398// </synopsis>
399
400// <motivation>
401// Lattices allow the various holders of data to assume a general method
402// of treatment; by making interfaces in terms of the Lattice class,
403// the programmer can polymorphically operate on objects derived from the
404// Lattice class.
405// </motivation>
406
407// <todo asof="1998/10/10">
408// <li> Make MaskedIterator class?
409// </todo>
410
411// </module>
412
413} // namespace casacore
414
415#endif
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28