casacore
Loading...
Searching...
No Matches
TSMShape.h
Go to the documentation of this file.
1// # TSMShape.h: Expanded IPosition for shapes
2// # Copyright (C) 1994,1995,1996,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 TABLES_TSMSHAPE_H
27#define TABLES_TSMSHAPE_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// # Forward Declarations
36
37// <summary>
38// Expanded IPosition for shapes.
39// </summary>
40
41// <use visibility=local>
42
43// <reviewed reviewer="UNKNOWN" date="before2004/08/25" tests="">
44// </reviewed>
45
46// <prerequisite>
47// # Classes you should understand before using this one.
48// <li> <linkto class=IPosition>IPosition</linkto>
49// </prerequisite>
50
51// <etymology>
52// TSMShape handles the shapes for the Tiled Storage Manager.
53// </etymology>
54
55// <synopsis>
56// TSMShape is an extension of class
57// <linkto class=IPosition>IPosition</linkto>
58// to handle shapes.
59// It contains some precalculated values to speed up the calculation
60// of an array offset from an array index (and vice-versa).
61// </synopsis>
62
63// <motivation>
64// The Tiled Hypercube Storage Manager is heavily using array shapes
65// and determining offsets from array indices. This class makes these
66// calculations more efficient.
67// </motivation>
68
69// <todo asof="$DATE:$">
70// <li> Integrate in a class like LatticeLayout.
71// </todo>
72
73class TSMShape {
74 public:
75 // A zero-length TSMShape.
77
78 // Construct from a shape and precalculate some values.
80
81 // Copy constructor (copy semantics).
82 TSMShape(const TSMShape& that);
83
84 // Assignment (copy semantics).
85 // "this" and "that" must either be conformant (same size)
86 // or "this" must be 0-length, in which case it will
87 // resize itself to be the same length as "that".
89
91
92 // Index into the TSMShape. Indices are zero-based. If the preprocessor
93 // symbol AIPS_ARRAY_INDEX_CHECK is defined, "index" will be
94 // checked to ensure it is not out of bounds. If this check fails, an
95 // AipsError will be thrown.
96 Int operator()(uInt index) const;
97
98 // The number of elements in this TSMShape. Since TSMShape
99 // objects use zero-based indexing, the maximum available index is
100 // nelements() - 1.
101 uInt nelements() const;
102
103 // conform returns true if nelements() == other.nelements().
104 Bool conform(const TSMShape& other) const;
105
106 // Calculate the offset for a given position.
107 // <group>
108 size_t offset(const IPosition& position) const;
109 size_t offset(const IPosition& position, const IPosition& origin) const;
110 // </group>
111
112 // Calculate the position for a given offset.
113 // <group>
114 IPosition position(size_t offset) const;
115 IPosition position(size_t offset, const IPosition& origin) const;
116 // </group>
117
118 // Calculate the increments when stepping through an array in
119 // a linear way. This can be used to update the array offset
120 // without recalculating it after each step.
121 // For example:
122 // <srcblock>
123 // template<class T>
124 // Array<T> someFunc (const Array<T>& array,
125 // const IPosition& subArrayShape,
126 // const IPosition& subArrayStart) const
127 // {
128 // TSMShape TSM (array.shape());
129 // IPosition offsetIncr = TSM.offsetIncrement (subArrayShape);
130 // Array<T> subArray(subArrayShape);
131 // Bool deleteMain;
132 // const T* mainData = array.getStorage (deleteMain);
133 // mainData += TSM.offset (subArrayStart)
134 // Bool deleteSub;
135 // T* subData = subArray.getStorage (deleteSub);
136 // for (uInt i=0; i<subArrayShape(2); i++) {
137 // for (uInt j=0; j<subArrayShape(1); j++) {
138 // for (uInt k=0; k<subArrayShape(0); k++) {
139 // *subData++ = *mainData++;
140 // }
141 // mainData += offsetIncr(1);
142 // }
143 // mainData += offSetIncr(2);
144 // }
145 // }
146 // </srcblock>
147 // <group>
148 IPosition offsetIncrement(const IPosition& subShape) const;
149 IPosition offsetIncrement(const IPosition& subShape, const IPosition& stride) const;
150 // </group>
151
152 private:
154 uInt size_p; // # Not necessary, but done for speedup
155};
156
157inline uInt TSMShape::nelements() const { return size_p; }
158
159inline Int TSMShape::operator()(uInt index) const { return data_p(index); }
160
161inline Bool TSMShape::conform(const TSMShape& other) const { return data_p.conform(other.data_p); }
162
163} // namespace casacore
164
165#endif
TSMShape(const TSMShape &that)
Copy constructor (copy semantics).
size_t offset(const IPosition &position, const IPosition &origin) const
size_t offset(const IPosition &position) const
Calculate the offset for a given position.
TSMShape()
A zero-length TSMShape.
IPosition offsetIncrement(const IPosition &subShape) const
Calculate the increments when stepping through an array in a linear way.
IPosition position(size_t offset, const IPosition &origin) const
TSMShape & operator=(const TSMShape &that)
Assignment (copy semantics).
uInt nelements() const
The number of elements in this TSMShape.
Definition TSMShape.h:157
IPosition data_p
Definition TSMShape.h:153
IPosition position(size_t offset) const
Calculate the position for a given offset.
IPosition offsetIncrement(const IPosition &subShape, const IPosition &stride) const
TSMShape(const IPosition &shape)
Construct from a shape and precalculate some values.
Bool conform(const TSMShape &other) const
conform returns true if nelements() == other.nelements().
Definition TSMShape.h:161
Int operator()(uInt index) const
Index into the TSMShape.
Definition TSMShape.h:159
For temporary backward namespace compatibility, use casa as alias for casacore.
Definition mainpage.dox:28
unsigned int uInt
Definition aipstype.h:49
IPosition shape(const RecordFieldId &) const
Get the actual shape of this field.
int Int
Definition aipstype.h:48
bool Bool
Define the standard types used by Casacore.
Definition aipstype.h:40