casa
$Rev:20696$
|
00001 //# Gaussian3DParam.h: Parameter handling for 3 dimensional Gaussian class 00002 //# Copyright (C) 2001,2002,2005 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 //# 00027 //# $Id: Gaussian3DParam.h 21024 2011-03-01 11:46:18Z gervandiepen $ 00028 00029 #ifndef SCIMATH_GAUSSIAN3DPARAM_H 00030 #define SCIMATH_GAUSSIAN3DPARAM_H 00031 00032 #include <casa/aips.h> 00033 #include <casa/BasicSL/String.h> 00034 #include <scimath/Functionals/Function.h> 00035 #include <scimath/Mathematics/AutoDiff.h> 00036 00037 namespace casa { //# NAMESPACE CASA - BEGIN 00038 //# Forward Declarations. 00039 template<class T> class Vector; 00040 00041 00042 // <summary> Parameter handling for 3 dimensional Gaussian class 00043 // </summary> 00044 00045 // <use visibility=local> 00046 00047 // <reviewed reviewer="" date="" tests="tGaussian3DParam"> 00048 // </reviewed> 00049 00050 // <prerequisite> 00051 // <li> <linkto class="FunctionParam">FunctionParam</linkto> class 00052 // <li> <linkto class="Function">Function</linkto> class 00053 // </prerequisite> 00054 00055 // <etymology> 00056 // A 3-dimensional Gaussian's parameters. 00057 // </etymology> 00058 00059 // <synopsis> 00060 00061 // A <src>Gaussian3D</src> is described by a height, center, width, 00062 // and two position angles. 00063 00064 // The width of the Gaussian is now specified in terms of the full width 00065 // at half maximum (FWHM), as with the 1D and 2D Gaussian functional classes. 00066 00067 // The three axis values refer to the x, y, and z axes, and unlike with the 00068 // 2D Gaussian any of the three axes may be the longest. Instead, the position 00069 // angles are restricted: The first position angle, theta, is the longitudinal 00070 // angle, referring to the rotation (counterclockwise) around the z-axis. The 00071 // second, phi, is the latidudinal angle, referring to the rotation around 00072 // the theta-rotated y axis. The domain of both angles is -pi/4 < A < pi/4. 00073 // (Note that the use of theta and phi corresponds to the mathematical 00074 // convention for these angles, not the physics convention.) 00075 00076 // The parameter interface (see 00077 // <linkto class="FunctionParam">FunctionParam</linkto> class), 00078 // is used to provide an interface to the 00079 // <linkto module="Fitting"> Fitting </linkto> classes. 00080 // 00081 // There are 9 parameters that are used to describe the Gaussian: 00082 // <ol> 00083 // <li> The height of the Gaussian. This is identical to the value 00084 // returned using the <src> height </src> member function. 00085 // <li> The center of the Gaussian in the x direction. This is identical to 00086 // the value returned using the <src> xCenter </src> member function. 00087 // <li> The center of the Gaussian in the y direction. This is identical to 00088 // the value returned using the <src> yCenter </src> member function. 00089 // <li> The center of the Gaussian in the z direction. This is identical to 00090 // the value returned using the <src> zCenter </src> member function. 00091 // <li> The width of the Gaussian along the x-axis. 00092 // <li> The width of the Gaussian along the y-axis. 00093 // <li> The width of the Gaussian along the z-axis. 00094 // <li> The longitudinal position angle, theta (in radians) 00095 // <li> The latitudinal position angle, phi (also in radians). 00096 // </ol> 00097 00098 00099 // An enumeration for the <src>H</src>, <src>CX</src>, 00100 // <src>CY</src>,<src>CZ</src>, <src>AX</src>, <src>AY</src>, 00101 // <src>AZ</src>, <src>THETA</src>, <src>PHI</src> 00102 // parameter index is provided, enabling the setting 00103 // and reading of parameters with the <src>[]</src> operator. The 00104 // <src>mask()</src> methods can be used to check and set the parameter masks. 00105 // 00106 // This class is in general used implicitly by the <src>Gaussian3D</src> 00107 // class only. 00108 // 00109 // <note role=tip> 00110 // Other points to bear in mind when fitting this class to measured data 00111 // are: 00112 // <ul> 00113 // <li> If you need to fit a circular Gaussian to data you should mask one or 00114 // both position angles. This avoids rank deficiency in the fitting 00115 // routines as the position angle is meaningless when the axes are 00116 // equal. 00117 // </ul> 00118 // </note> 00119 // 00120 // </synopsis> 00121 00122 // <example> 00123 // <srcblock> 00124 // Gaussian3D<Double> g(9.0, 0.0, 0.0, 0.0, 1.0, 1.0, 1.0, 0.0, 0.0); 00125 // Vector<Double> x(3); 00126 // x(0) = 1.0; x(1) = 0.5; x(2) = 0.0 00127 // cout << "g(" << x(0) << "," << x(1) << "," << x(2) << ")=" << g(x) << endl; 00128 // </srcblock> 00129 // </example> 00130 00131 00132 // <templating arg=T> 00133 // <li> T should have standard numerical operators and exp() function. Current 00134 // implementation only tested for real types (and AutoDiff of them). 00135 // </templating> 00136 00137 // <thrown> 00138 // <li> Assertion in debug mode if attempt is made to set a negative width 00139 // <li> AipsError if incorrect parameter number specified. 00140 // <li> others? 00141 // </thrown> 00142 00143 // <todo asof="2002/07/19"> 00144 // <li> Gaussians that know about their DFT's could be required eventually. 00145 // </todo> 00146 00147 00148 00149 template<class Type> class Gaussian3DParam : public Function<Type> 00150 { 00151 // Parameter handling for the functional for 3D Gaussian Class. 00152 // Similar to Gaussian2DParam, but width parameters are not adjusted 00153 // for FWHM; they are identical to the parameters used in the function. 00154 00155 // Position angle parameters are restricted to -PI/4 < angle < PI/4. 00156 00157 public: 00158 00159 //#Enumerations 00160 enum 00161 { 00162 H=0, // value of Gaussian at the center 00163 CX, // X center value 00164 CY, // Y center value 00165 CZ, // Z center value 00166 AX, // width along X axis when T = P = 0 00167 AY, // width along Y axis when T = P = 0 00168 AZ, // width along Z axis when T = P = 0 00169 THETA, // rotation about Z axis. 00170 PHI, // rotation around X and Y axes (which depends on T). 00171 NPAR // number of total parameters (9) 00172 }; 00173 00174 // Constructs the three dimensional Gaussians. Defaults: 00175 // height = 1, center = {0,0,0}, width = {1,1,1}, theta = phi = 0 00176 // <group> 00177 Gaussian3DParam(); 00178 Gaussian3DParam(Type height, const Vector<Type>& center, 00179 const Vector<Type>& width, Type theta, Type phi); 00180 Gaussian3DParam(Type &height, Type &xCenter, Type &yCenter, Type &zCenter, 00181 Type &xWidth, Type &yWidth, Type &zWidth, 00182 Type &theta, Type &phi); 00183 // </group> 00184 00185 // Copy construcor 00186 // <group> 00187 Gaussian3DParam(const Gaussian3DParam<Type> &other); 00188 template <class W> 00189 Gaussian3DParam(const Gaussian3DParam<W> &other) : 00190 Function<Type>(other), 00191 fwhm2int(Type(1.0)/sqrt(log(Type(16.0)))) { settrigvals(); } 00192 // </group> 00193 00194 // Copy assignment 00195 Gaussian3DParam<Type> &operator=(const Gaussian3DParam<Type> &other); 00196 00197 // Destructor 00198 virtual ~Gaussian3DParam(); 00199 00200 //# Member functions 00201 // Give name of function 00202 virtual const String &name() const { static String x("gaussian3d"); 00203 return x; } 00204 00205 // Return dimensionality 00206 virtual uInt ndim() const {return 3;} 00207 00208 // Get or set the peak height of the Gaussian 00209 // <group> 00210 Type height() const; 00211 void setHeight(const Type & height); 00212 // </group> 00213 00214 // Get or set the total flux of the Gaussian. (Note: Since this changes 00215 // the height of the Gaussian but not its width, always set the width 00216 // before setting the flux.) 00217 // <group> 00218 Type flux() const; 00219 void setFlux(const Type & flux); 00220 // </group> 00221 00222 // Get or cet the center coordinates of the Gaussian 00223 // <group> 00224 Vector<Type> center() const; 00225 void setCenter(const Vector<Type>& center); 00226 Type xCenter() const; 00227 void setXcenter(const Type & xcenter); 00228 Type yCenter() const; 00229 void setYcenter(const Type & ycenter); 00230 Type zCenter() const; 00231 void setZcenter(const Type & zcenter); 00232 // </group> 00233 00234 // Get or set the sigma-width of the Gaussian 00235 // <group> 00236 Vector<Type> width() const; 00237 void setWidth(const Vector<Type>& width); 00238 void setXwidth(const Type & xwidth); 00239 Type xWidth() const; 00240 void setYwidth(const Type & ywidth); 00241 Type yWidth() const; 00242 void setZwidth(const Type & zwidth); 00243 Type zWidth() const; 00244 // </group> 00245 00246 // Get or set the rotation angles of the Gaussian. 00247 // Theta=logitude, phi=latitude 00248 // <group> 00249 Type theta() const; 00250 void settheta(const Type & sT); 00251 Type phi() const; 00252 void setphi(const Type & sP); 00253 // </group> 00254 00255 protected: 00256 00257 void settrigvals() const; 00258 00259 Type fwhm2int; // const to scale halfwidth at 1/e to FWHM 00260 00261 mutable Type stoT_p; // used to check if cached values below are updated 00262 mutable Type stoP_p; // 00263 mutable Type cosT_p,sinT_p; // cached values of the cos and sine of THETA 00264 mutable Type cosP_p,sinP_p; // PHI 00265 mutable Type cosTcosP_p; //cached values of products of cos/sine of angles 00266 mutable Type cosTsinP_p; 00267 mutable Type sinTcosP_p; 00268 mutable Type sinTsinP_p; 00269 00270 //# Make members of parent classes known. 00271 protected: 00272 using Function<Type>::param_p; 00273 public: 00274 using Function<Type>::nparameters; 00275 }; 00276 00277 00278 } //# NAMESPACE CASA - END 00279 00280 #ifndef CASACORE_NO_AUTO_TEMPLATES 00281 #include <scimath/Functionals/Gaussian3DParam.tcc> 00282 #endif //# CASACORE_NO_AUTO_TEMPLATES 00283 #endif 00284 00285 00286 00287