casacore
Loading...
Searching...
No Matches
LatticeIndexer.h
Go to the documentation of this file.
1//# LatticeIndexer.h: A helper class for stepping through Lattices
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_LATTICEINDEXER_H
27#define LATTICES_LATTICEINDEXER_H
28
29//# Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/IPosition.h>
32
33
34namespace casacore { //# NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// A helper class for stepping through Lattices.
38// </summary>
39
40// <use visibility=local>
41
42// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tLatticeIndexer">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class="Lattice"> Lattice </linkto>
47// <li> <linkto class="IPosition"> IPosition </linkto>
48// </prerequisite>
49
50// <etymology>
51// This class does various calculations involved with indexing in
52// Lattices. LatticeIndexer is not a good name, but it is
53// better than the previous name of LatticeLayout.
54// </etymology>
55
56// <synopsis>
57// A LatticeIndexer contains all the information necessary to define the
58// shape of a Lattice or sub-Lattice. It is currently a repository of
59// functions that provide indexing calculations.
60// <p>
61// A sub-Lattice is a section of a Lattice defined by a bottom left corner
62// (blc), a top right corner (trc), and a step size or increment on each
63// axis. The blc and trc pixels will always be included in the sub-Lattice
64// if the step increment is one. If the step increment is greater than one,
65// the pixel in top right corner may not be included in the sub-Lattice.
66// <p>
67// This class knows the shape of the parent Lattice (including all
68// degenerate axes), and allows the user to specify a sub-Lattice that is
69// embedded in the parent Lattice. The default sub-Lattice, if none is
70// specified, is one identical in shape to the main Lattice.
71// <p>
72// A sub-Lattice can be defined on the Lattice by specifying a trc, blc,
73// and step increment using the <src>subSection</src> function, or the
74// appropriate constructor. A sub-Lattice must be smaller than (or the same
75// size as) the Lattice that it is derived from. A sub-Lattice can be further
76// created from an already existing sub-Lattice eg.
77// <br>
78// If we have a 128 by 128 Lattice, we can specify the centre quarter by
79// using blc=[32,32] and trc=[95,95]. Then specifying a sub-Lattice of
80// blc=[0,0] and trc = [31,31] results in a sub-Lattice that has a blc
81// of [32,32] and trc of [63,63] with respect to the parent Lattice.
82// <p>
83// The only way to increase the size of a sub-Lattice is to first revert to
84// the parent Lattice (using the <src>fullSize</src> function) and then
85// generate the new, bigger sub-Lattice.
86// <p>
87// Indexing calculations (eg. the <src>tiledCursorMove</src> or the
88// <src>isInside</src> function) are performed on the specified sub-Lattice.
89// <p>
90// The role of this class is to centralise the information and functions
91// needed to operate on sub-Lattices. It will normally be used by other
92// Lattice classes, and is currently used by navigator classes like
93// <linkto class="LatticeStepper">LatticeStepper</linkto>.
94// </synopsis>
95
96// <motivation>
97// The shape, structure or geometry of a lattice is quite separable from
98// its actual contents, and the operations you can do on the contents. Also,
99// there are operations which apply only to the layout such as subsectioning.
100// </motivation>
101
102//# <todo asof="1997/01/12">
103//# </todo>
104
105
107{
108public:
109 // Default constructor (one dimensional, unit-length instance).
111
112 // Specify the size of the Lattice. Assume a full size sub-Lattice.
113 explicit LatticeIndexer (const IPosition& shape);
114
115 // Specify a Lattice and define a sub-Lattice within it.
117 const IPosition& trc, const IPosition& inc);
118
119 // The copy constructor uses copy semantics.
121
123
124 // The assignment operator uses copy semantics.
126
127 // Function to change the shape of the Lattice. Resets the sub-Lattice to
128 // fullsize.
129 void resize (const IPosition& newShape);
130
131 // Returns the length of each axis (or the requested one) in the parent
132 // Lattice.
133 // <group>
134 const IPosition& fullShape() const;
135 uInt fullShape (uInt axis) const;
136 // </group>
137
138 // Returns the length of each axis (or the requested one) in the sub-Lattice.
139 // <group>
140 const IPosition& shape() const;
141 uInt shape (uInt axis) const;
142 // </group>
143
144 // Function to return the increments along each axis (or the requested
145 // one) of the Lattice.
146 // <group>
147 const IPosition& increment() const;
148 uInt increment (uInt axis) const;
149 // </group>
150
151 // Function to return the offset (on a specified axis) between the
152 // sub-Lattice and the parent one.
153 // <group>
154 const IPosition& offset() const;
155 uInt offset (uInt axis) const;
156 // </group>
157
158 // Function which returns the number of dimensions in the Lattice (or
159 // sub-Lattice).
160 uInt ndim() const;
161
162 // Revert from a sub-Lattice description back to the main Lattice. This is
163 // the only way to "increase" the the size of the sub-Lattice used by the
164 // LatticeIndexer.
165 void fullSize();
166
167 // Function which returns the number of elements in the sub-Lattice;
168 // this value is equal to the product of shape().
169 size_t nelements() const;
170
171 // Function which increments (incr=True) or decrements (incr=False) the
172 // cursor position (the first IPosition argument) by a cursor shape (the
173 // second IPosition argument), tiling to the next/previous axis if
174 // necessary. The path of movement is based upon the third IPosition
175 // argument (a cursor heading) that is zero-based e.g. IPosition(3,0,2,1)
176 // implies starting movement along the x-axis, then the z-axis, and then
177 // the y-axis. Returns a value of False if the beginning/end of the
178 // sub-Lattice is reached. The cursorPosition is relative to the origin of
179 // the sub-Lattice. To get its location relative to the main Lattice use
180 // the absolutePosition() function.
181 Bool tiledCursorMove (Bool incr, IPosition& cursorPos,
182 const IPosition& cursorShape,
183 const IPosition& cursorHeading) const;
184
185 // Function which returns a value of True if the IPosition argument
186 // is within the sub-Lattice. Returns False if the IPosition argument is
187 // outside the sub-Lattice or if the argument doesn't conform to the
188 // data members.
189 // <note role=warning> Due to zero-origins, an index argument equal to the
190 // shape of this sub-Lattice lies outside and returns False.
191 // </note>
192 Bool isInside (const IPosition& index) const;
193
194 // Function which subsections a LatticeIndexer. The argument IPositions
195 // specify "bottom left" and "upper right" corners and axis increments
196 // (which default to one). The origins are cumulative. i.e. specifying a
197 // blc of (2,2), and then (1,1) results in the sub-Lattice having an
198 // origin at pixel (3,3) in the parent Lattice. Similarly the increment is
199 // cumulative, i.e. an increment of 2 on top of an increment of 3 results
200 // in a total increment of 6. This function can only decrease the size of
201 // the sub-Lattice (i.e. blc >= 0, and trc <= shape(), and inc >= 1). The
202 // fullSize() function should be used to revert back to the maximum
203 // possible Lattice size. Also note that the trc might not be used if an
204 // integral number of increments does not end on the trc (in which case
205 // the last position below the trc will be used).
206 // <group>
207 void subSection (const IPosition& blc, const IPosition& trc,
208 const IPosition& inc);
209 void subSection (const IPosition& blc, const IPosition& trc);
210 // </group>
211
212 // Function which returns an IPosition in the parent Lattice given an
213 // IPostion in the sub-Lattice. Accounting is taken of any offsets and
214 // increments caused by subSectioning. No checks are made to ensure the
215 // supplied IPosition or the returned one are within the bounds of the
216 // Lattice(s).
217 IPosition absolutePosition (const IPosition& position) const;
218
219 //# function which returns True if all the elements in this
220 //# LatticeIndexer, or LatticeIndexer subsection, are arranged contiguously,
221 //# i.e. without any gaps caused by increments or subSectioning.
222//# Bool isContiguous() const;
223
224 // Is this LatticeIndexer consistent, i.e. are the class invariants valid?
225 // Returns True if every thing is fine otherwise returns False
226 Bool ok() const;
227
228private:
229 IPosition itsFullShape; //# Size of the main-Lattice.
230 uInt itsNdim; //# Number of dimensions in the main/sub-Lattice
231 IPosition itsShape; //# Shape of the sub-Lattice
232 IPosition itsAxisInc; //# Increment along each axis of main Lattice
233 IPosition itsOffset; //# Offset between a sub-Lattice and the main one.
234};
235
236
238{
239 return itsFullShape;
240}
241inline const IPosition& LatticeIndexer::shape() const
242{
243 return itsShape;
244}
246{
247 return itsAxisInc;
248}
250{
251 return itsOffset;
252}
254{
255 return itsNdim;
256}
257inline size_t LatticeIndexer::nelements() const
258{
259 return itsShape.product();
260}
261
262
263
264
265} //# NAMESPACE CASACORE - END
266
267#endif
long long product() const
Returns 0 if nelements() == 0, otherwise it returns the product of its elements.
LatticeIndexer()
Default constructor (one dimensional, unit-length instance).
void fullSize()
Revert from a sub-Lattice description back to the main Lattice.
LatticeIndexer & operator=(const LatticeIndexer &other)
The assignment operator uses copy semantics.
const IPosition & shape() const
Returns the length of each axis (or the requested one) in the sub-Lattice.
const IPosition & fullShape() const
Returns the length of each axis (or the requested one) in the parent Lattice.
Bool tiledCursorMove(Bool incr, IPosition &cursorPos, const IPosition &cursorShape, const IPosition &cursorHeading) const
Function which increments (incr=True) or decrements (incr=False) the cursor position (the first IPosi...
LatticeIndexer(const LatticeIndexer &other)
The copy constructor uses copy semantics.
void resize(const IPosition &newShape)
Function to change the shape of the Lattice.
const IPosition & offset() const
Function to return the offset (on a specified axis) between the sub-Lattice and the parent one.
LatticeIndexer(const IPosition &shape, const IPosition &blc, const IPosition &trc, const IPosition &inc)
Specify a Lattice and define a sub-Lattice within it.
uInt fullShape(uInt axis) const
size_t nelements() const
Function which returns the number of elements in the sub-Lattice; this value is equal to the product ...
uInt ndim() const
Function which returns the number of dimensions in the Lattice (or sub-Lattice).
LatticeIndexer(const IPosition &shape)
Specify the size of the Lattice.
uInt offset(uInt axis) const
IPosition absolutePosition(const IPosition &position) const
Function which returns an IPosition in the parent Lattice given an IPostion in the sub-Lattice.
void subSection(const IPosition &blc, const IPosition &trc)
const IPosition & increment() const
Function to return the increments along each axis (or the requested one) of the Lattice.
Bool isInside(const IPosition &index) const
Function which returns a value of True if the IPosition argument is within the sub-Lattice.
void subSection(const IPosition &blc, const IPosition &trc, const IPosition &inc)
Function which subsections a LatticeIndexer.
Bool ok() const
Is this LatticeIndexer consistent, i.e.
uInt increment(uInt axis) const
uInt shape(uInt axis) const
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