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