casacore
Loading...
Searching...
No Matches
TiledShape.h
Go to the documentation of this file.
1// # TiledShape.h: Define the shape and tile shape
2// # Copyright (C) 1997,1998,1999,2001
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_TILEDSHAPE_H
27#define LATTICES_TILEDSHAPE_H
28
29// # Includes
30#include <casacore/casa/aips.h>
31#include <casacore/casa/Arrays/ArrayFwd.h>
32#include <casacore/casa/Arrays/IPosition.h>
33
34namespace casacore { // # NAMESPACE CASACORE - BEGIN
35
36// <summary>
37// Define the shape and tile shape
38// </summary>
39
40// <use visibility=export>
41
42// <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tTiledShape.cc">
43// </reviewed>
44
45// <prerequisite>
46// <li> <linkto class=IPosition>IPosition</linkto>
47// </prerequisite>
48
49// <etymology>
50// TiledShape defines the shape and tile shape of a tiled array.
51// </etymology>
52
53// <synopsis>
54// TiledShape is a class defining the shape and optionally the tile
55// shape of a lattice. It is used in the constructors of
56// <linkto class=PagedArray>PagedArray</linkto> and
57// <linkto class=PagedImage>PagedImage</linkto>.
58// <p>
59// In principle it serves as a place holder for the lattice shape and
60// tile shape. The functions <src>shape</src> and <src>tileShape</src>
61// can be used to retrieve the shapes.
62// However, when the tile shape is not given, the function
63// <src>tileShape</src> calculates a default tile shape using the
64// given maximum tile size in pixel elements. The default tile shape
65// is calculated in such a way that the sizes of its axes
66// are proportional to the sizes of the lattice axes. Per axis it is
67// tried as much as possible to fit an integral number of tiles
68// in the lattice.
69// <br>In this way getting the tile shape is completely transparent.
70// </synopsis>
71
72// <example>
73// <srcblock>
74// // Do not explicitly define a tile shape.
75// // This results in a default tile shape (of 32,32,32).
76// TiledShape shape(IPosition(3,128,128,128));
77// cout << shape.shape() << ' ' << shape.tileShape() << endl;
78//
79// // Use with an explicitly given tile shape.
80// TiledShape shape(IPosition(3,128,128,128), IPosition(3,64,32,8));
81// cout << shape.shape() << ' ' << shape.tileShape() << endl;
82// </srcblock>
83// </example>
84
85// <motivation>
86// Classes <src>PagedArray</src> and <src>PagedImage</src> contained
87// several duplicated constructors to be able to pass a tile shape.
88// This class makes it possible to have only one constructor
89// instead of two. Furthermore it contains the logic to check if the
90// shapes are conforming and the logic to calculate a default tile shape.
91// </motivation>
92
94 public:
95 // Default constructor has empty shape and tile shape.
97
98 // Use the given shape.
99 // No tile shape is given, so function <src>tileShape</src>
100 // will calculate it using the size of a tile.
102
103 // Use the given shape and tile shape.
104 // Both shapes must be conforming (i.e. have same number of elements).
106
107 // Copy constructor (copy semantics).
108 TiledShape(const TiledShape& that);
109
111
112 // Assignment (copy semantics).
114
115 // Is the tile shape defined?
116 Bool isTileShapeDefined() const;
117
118 // Return the shape.
119 const IPosition& shape() const;
120
121 // Return the tile shape.
122 // When the tile shape is undefined, the default tile shape will be
123 // calculated using the given tile size and tolerance.
124 // <br> The tolerance is used to determine the boundaries where
125 // it is tried to fit an integral number of tiles.
126 IPosition tileShape(uInt nrPixelsPerTile = 32768, Double tolerance = 0.5) const;
127
128 // Derive the default tile shape from the shape for the given
129 // number of pixels per tile. It is tried to get the same number
130 // of tiles for each dimension.
131 // When a weight vector is given, the number of tiles for a dimension
132 // is proportional to the weight.
133 // <br>After the initial guess it tries to optimize it by trying to
134 // waste as little space as possible, while trying to keep as close as
135 // possible to the initial guess. The given tolerance (possibly per axis)
136 // gives the minimum and maximum possible length of a tile axis
137 // (minimum = initial_guess*tolerance; maximum = initial_guess/tolerance).
138 // The heuristic is such that a tile axis length dividing the cube length
139 // exactly is always favoured.
140 // The test program <src>tTiledShape</src> can be used to see how
141 // the algorithm works out for a given shape and tile size.
142 // <group>
143 IPosition defaultTileShape(uInt nrPixelsPerTile, Double tolerance) const;
144 IPosition defaultTileShape(uInt nrPixelsPerTile, const Vector<Double>& tolerance,
145 const Vector<Double>& weight) const;
146 // </group>
147
148 private:
152};
153
155inline const IPosition& TiledShape::shape() const { return itsShape; }
156inline IPosition TiledShape::tileShape(uInt nrPixelsPerTile, Double tolerance) const {
157 return (itsTileDefined ? itsTileShape : defaultTileShape(nrPixelsPerTile, tolerance));
158}
159
160} // namespace casacore
161
162#endif
TiledShape()
Default constructor has empty shape and tile shape.
IPosition tileShape(uInt nrPixelsPerTile=32768, Double tolerance=0.5) const
Return the tile shape.
Definition TiledShape.h:156
TiledShape(const IPosition &shape)
Use the given shape.
TiledShape(const TiledShape &that)
Copy constructor (copy semantics).
TiledShape & operator=(const TiledShape &that)
Assignment (copy semantics).
Bool isTileShapeDefined() const
Is the tile shape defined?
Definition TiledShape.h:154
IPosition defaultTileShape(uInt nrPixelsPerTile, Double tolerance) const
Derive the default tile shape from the shape for the given number of pixels per tile.
const IPosition & shape() const
Return the shape.
Definition TiledShape.h:155
TiledShape(const IPosition &shape, const IPosition &tileShape)
Use the given shape and tile shape.
IPosition defaultTileShape(uInt nrPixelsPerTile, const Vector< Double > &tolerance, const Vector< Double > &weight) 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
double Double
Definition aipstype.h:53