casa
$Rev:20696$
|
00001 //# TiledCollapser.h: Abstract base class to collapse chunks for LatticeApply 00002 //# Copyright (C) 1996,1997,1998 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: TiledCollapser.h 20229 2008-01-29 15:19:06Z gervandiepen $ 00027 00028 #ifndef LATTICES_TILEDCOLLAPSER_H 00029 #define LATTICES_TILEDCOLLAPSER_H 00030 00031 00032 //# Includes 00033 #include <casa/aips.h> 00034 #include <scimath/Mathematics/NumericTraits.h> 00035 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 00039 //# Forward Declarations 00040 template <class T> class Array; 00041 class IPosition; 00042 00043 // <summary> 00044 // Abstract base class to collapse chunks for LatticeApply 00045 // </summary> 00046 00047 // <use visibility=export> 00048 00049 // <reviewed reviewer="" date="yyyy/mm/dd" tests="" demos=""> 00050 // </reviewed> 00051 00052 // <prerequisite> 00053 // <li> <linkto class=LatticeApply>LatticeApply</linkto> 00054 // </prerequisite> 00055 00056 // <etymology> 00057 // </etymology> 00058 00059 // <synopsis> 00060 // This is an abstract base class for the collapsing of chunks to 00061 // be used in function <src>tiledApply</src> 00062 // in class <linkto class=LatticeApply>LatticeApply</linkto>. 00063 // It is meant for cases where an entire line or plane is not needed 00064 // (e.g. calculation of maximum). If that is needed (e.g. to calculate moment), 00065 // it is better to use function <src>LatticeApply::lineApply</src> 00066 // with class <linkto class=LineCollapser>LineCollapser</linkto>. 00067 // <p> 00068 // The user has to derive a concrete class from this base class 00069 // and implement the (pure) virtual functions. 00070 // <br> The main function is <src>process</src>, which needs to do the 00071 // calculation. 00072 // <br> Other functions make it possible to perform an initial check. 00073 // <p> 00074 // The class is Doubly templated. Ths first template type 00075 // is for the data type you are processing. The second type is 00076 // for what type you want the results of the processing assigned to. 00077 // For example, if you are computing sums of squares for statistical 00078 // purposes, you might use higher precision (FLoat->Double) for this. 00079 // No check is made that the template types are self-consistent. 00080 // </synopsis> 00081 00082 // <example> 00083 // <srcblock> 00084 // </srcblock> 00085 // </example> 00086 00087 // <motivation> 00088 // </motivation> 00089 00090 // <todo asof="1997/08/01"> 00091 // <li> 00092 // </todo> 00093 00094 00095 template <class T, class U=T> class TiledCollapser 00096 { 00097 public: 00098 00099 // Destructor 00100 virtual ~TiledCollapser(); 00101 00102 // The init function for a derived class. 00103 // It can be used to check if <src>nOutPixelsPerCollapse</src> 00104 // corresponds with the number of pixels produced per collapsed chunk. 00105 // <br><src>processAxis</src> is the axis of the line being passed 00106 // to the <src>process</src> function. 00107 virtual void init (uInt nOutPixelsPerCollapse) = 0; 00108 00109 // Can the process function in the derived class handle a null mask pointer? 00110 // If not, LatticeApply ensures that it'll always pass a mask block, 00111 // even if the lattice does not have a mask (in that case that mask block 00112 // contains all True values). 00113 // <br>The default implementation returns False. 00114 // <br>The function is there to make optimization possible when no masks 00115 // are involved. On the other side, it allows the casual user to ignore 00116 // optimization. 00117 virtual Bool canHandleNullMask() const; 00118 00119 // Create and initialize the accumulator. 00120 // The accumulator can be a cube with shape [n1,n2,n3], 00121 // where <src>n2</src> is equal to <src>nOutPixelsPerCollapse</src>. 00122 // However, one can also use several matrices as accumulator. 00123 // <br> The data type of the accumulator can be any. E.g. when 00124 // accumulating Float lattices, the accumulator could be of 00125 // type Double to have enough precision. 00126 // <br>In the <src>endAccumulator</src> function the accumulator 00127 // data has to be copied into an Array object with the correct 00128 // shape and data type. 00129 virtual void initAccumulator (uInt n1, uInt n3) = 0; 00130 00131 // Collapse the given input data containing (<src>nrval</src> values 00132 // with an increment of <src>inIncr</src> elements). 00133 // <src>inMask</src> is a Bool block representing a mask with the 00134 // same nr of values and increment as the input data. If a mask 00135 // value is False, the corresponding input value is masked off. 00136 // <br>When function <src>canHandleNullMask</src> returned True, 00137 // it is possible that <src>inMask</src> is a null pointer indicating 00138 // that the input has no mask, thus all values are valid. 00139 // <br> 00140 // The result(s) have to be stored in the accumulator at the given indices. 00141 // <br><src>startPos</src> gives the lattice position of the first value. 00142 // The position of other values can be calculated from index and shape 00143 // using function <src>toPositionInArray</src> in class 00144 // <linkto class=IPosition>IPosition</linkto>. 00145 virtual void process ( 00146 uInt accumIndex1, uInt accumIndex3, 00147 const T* inData, const Bool* inMask, 00148 uInt inDataIncr, uInt inMaskIncr, 00149 uInt nrval, 00150 const IPosition& startPos, 00151 const IPosition& shape 00152 ) = 0; 00153 00154 // End the accumulator. It should return the accumulator as an 00155 // Array of datatype U (e.g. double the precision of type T) 00156 // with the given shape. The accumulator should thereafter be deleted when needed. 00157 virtual void endAccumulator (Array<U>& result, 00158 Array<Bool>& resultMask, 00159 const IPosition& shape) = 0; 00160 }; 00161 00162 00163 00164 } //# NAMESPACE CASA - END 00165 00166 #ifndef CASACORE_NO_AUTO_TEMPLATES 00167 #include <lattices/Lattices/TiledCollapser.tcc> 00168 #endif //# CASACORE_NO_AUTO_TEMPLATES 00169 #endif