casa
$Rev:20696$
|
00001 //# TiledShape.h: Define the shape and tile shape 00002 //# Copyright (C) 1997,1998,1999,2001 00003 //# Associated Universities, Inc. Washington DC, USA. 00004 //# 00005 //# This library is free software; you can redistribute it and/or modify it 00006 //# under the terms of the GNU Library General Public License as published by 00007 //# the Free Software Foundation; either version 2 of the License, or (at your 00008 //# option) any later version. 00009 //# 00010 //# This library is distributed in the hope that it will be useful, but WITHOUT 00011 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 00012 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public 00013 //# License for more details. 00014 //# 00015 //# You should have received a copy of the GNU Library General Public License 00016 //# along with this library; if not, write to the Free Software Foundation, 00017 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA. 00018 //# 00019 //# Correspondence concerning AIPS++ should be addressed as follows: 00020 //# Internet email: aips2-request@nrao.edu. 00021 //# Postal address: AIPS++ Project Office 00022 //# National Radio Astronomy Observatory 00023 //# 520 Edgemont Road 00024 //# Charlottesville, VA 22903-2475 USA 00025 //# 00026 //# $Id: TiledShape.h 19779 2006-12-12 23:20:42Z gvandiep $ 00027 00028 #ifndef LATTICES_TILEDSHAPE_H 00029 #define LATTICES_TILEDSHAPE_H 00030 00031 //# Includes 00032 #include <casa/Arrays/IPosition.h> 00033 00034 namespace casa { //# NAMESPACE CASA - BEGIN 00035 00036 //# Forward Declarations 00037 template<class T> class Vector; 00038 00039 00040 // <summary> 00041 // Define the shape and tile shape 00042 // </summary> 00043 00044 // <use visibility=export> 00045 00046 // <reviewed reviewer="Peter Barnes" date="1999/10/30" tests="tTiledShape.cc"> 00047 // </reviewed> 00048 00049 // <prerequisite> 00050 // <li> <linkto class=IPosition>IPosition</linkto> 00051 // </prerequisite> 00052 00053 // <etymology> 00054 // TiledShape defines the shape and tile shape of a tiled array. 00055 // </etymology> 00056 00057 // <synopsis> 00058 // TiledShape is a class defining the shape and optionally the tile 00059 // shape of a lattice. It is used in the constructors of 00060 // <linkto class=PagedArray>PagedArray</linkto> and 00061 // <linkto class=PagedImage>PagedImage</linkto>. 00062 // <p> 00063 // In principle it serves as a place holder for the lattice shape and 00064 // tile shape. The functions <src>shape</src> and <src>tileShape</src> 00065 // can be used to retrieve the shapes. 00066 // However, when the tile shape is not given, the function 00067 // <src>tileShape</src> calculates a default tile shape using the 00068 // given maximum tile size in pixel elements. The default tile shape 00069 // is calculated in such a way that the sizes of its axes 00070 // are proportional to the sizes of the lattice axes. Per axis it is 00071 // tried as much as possible to fit an integral number of tiles 00072 // in the lattice. 00073 // <br>In this way getting the tile shape is completely transparent. 00074 // </synopsis> 00075 00076 // <example> 00077 // <srcblock> 00078 // // Do not explicitly define a tile shape. 00079 // // This results in a default tile shape (of 32,32,32). 00080 // TiledShape shape(IPosition(3,128,128,128)); 00081 // cout << shape.shape() << ' ' << shape.tileShape() << endl; 00082 // 00083 // // Use with an explicitly given tile shape. 00084 // TiledShape shape(IPosition(3,128,128,128), IPosition(3,64,32,8)); 00085 // cout << shape.shape() << ' ' << shape.tileShape() << endl; 00086 // </srcblock> 00087 // </example> 00088 00089 // <motivation> 00090 // Classes <src>PagedArray</src> and <src>PagedImage</src> contained 00091 // several duplicated constructors to be able to pass a tile shape. 00092 // This class makes it possible to have only one constructor 00093 // instead of two. Furthermore it contains the logic to check if the 00094 // shapes are conforming and the logic to calculate a default tile shape. 00095 // </motivation> 00096 00097 00098 class TiledShape 00099 { 00100 public: 00101 // Default constructor has empty shape and tile shape. 00102 TiledShape(); 00103 00104 // Use the given shape. 00105 // No tile shape is given, so function <src>tileShape</src> 00106 // will calculate it using the size of a tile. 00107 TiledShape (const IPosition& shape); 00108 00109 // Use the given shape and tile shape. 00110 // Both shapes must be conforming (i.e. have same number of elements). 00111 TiledShape (const IPosition& shape, const IPosition& tileShape); 00112 00113 // Copy constructor (copy semantics). 00114 TiledShape (const TiledShape& that); 00115 00116 ~TiledShape(); 00117 00118 // Assignment (copy semantics). 00119 TiledShape& operator= (const TiledShape& that); 00120 00121 // Is the tile shape defined? 00122 Bool isTileShapeDefined() const; 00123 00124 // Return the shape. 00125 const IPosition& shape() const; 00126 00127 // Return the tile shape. 00128 // When the tile shape is undefined, the default tile shape will be 00129 // calculated using the given tile size and tolerance. 00130 // <br> The tolerance is used to determine the boundaries where 00131 // it is tried to fit an integral number of tiles. 00132 IPosition tileShape (uInt nrPixelsPerTile = 32768, 00133 Double tolerance = 0.5) const; 00134 00135 // Derive the default tile shape from the shape for the given 00136 // number of pixels per tile. It is tried to get the same number 00137 // of tiles for each dimension. 00138 // When a weight vector is given, the number of tiles for a dimension 00139 // is proportional to the weight. 00140 // <br>After the initial guess it tries to optimize it by trying to 00141 // waste as little space as possible, while trying to keep as close as 00142 // possible to the initial guess. The given tolerance (possibly per axis) 00143 // gives the minimum and maximum possible length of a tile axis 00144 // (minimum = initial_guess*tolerance; maximum = initial_guess/tolerance). 00145 // The heuristic is such that a tile axis length dividing the cube length 00146 // exactly is always favoured. 00147 // The test program <src>tTiledShape</src> can be used to see how 00148 // the algorithm works out for a given shape and tile size. 00149 // <group> 00150 IPosition defaultTileShape (uInt nrPixelsPerTile, Double tolerance) const; 00151 IPosition defaultTileShape (uInt nrPixelsPerTile, 00152 const Vector<Double>& tolerance, 00153 const Vector<Double>& weight) const; 00154 // </group> 00155 00156 private: 00157 IPosition itsShape; 00158 IPosition itsTileShape; 00159 Bool itsTileDefined; 00160 }; 00161 00162 00163 inline Bool TiledShape::isTileShapeDefined() const 00164 { 00165 return itsTileDefined; 00166 } 00167 inline const IPosition& TiledShape::shape() const 00168 { 00169 return itsShape; 00170 } 00171 inline IPosition TiledShape::tileShape (uInt nrPixelsPerTile, 00172 Double tolerance) const 00173 { 00174 return (itsTileDefined ? itsTileShape : 00175 defaultTileShape (nrPixelsPerTile, tolerance)); 00176 } 00177 00178 00179 00180 } //# NAMESPACE CASA - END 00181 00182 #endif