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