00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef SCIMATH_RIGIDVECTOR_H
00030 #define SCIMATH_RIGIDVECTOR_H
00031
00032 #include <casacore/casa/aips.h>
00033 #include <casacore/casa/Arrays/Vector.h>
00034 #include <casacore/casa/BasicSL/Complex.h>
00035 #include <casacore/casa/iosfwd.h>
00036
00037 namespace casacore {
00038
00039
00040 template <class T, Int n> class SquareMatrix;
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102 template <class T, Int n> class RigidVector {
00103
00104
00105
00106 friend RigidVector<T,n> operator+(const RigidVector<T,n>& l,
00107 const RigidVector<T,n>& r) {
00108 RigidVector<T,n> result=l;
00109 return result+=r;
00110 }
00111
00112 friend RigidVector<T,n> operator-(const RigidVector<T,n>& l,
00113 const RigidVector<T,n>& r) {
00114 RigidVector<T,n> result=l;
00115 return result-=r;
00116 }
00117
00118 friend T operator*(const RigidVector<T,n>& l,
00119 const RigidVector<T,n>& r) {
00120 T sum=T(0);
00121 for (Int i=0; i<n; i++) sum+=l.v_p[i]*r.v_p[i];
00122 return sum;
00123 }
00124
00125 friend RigidVector<T,n> operator*(const T& f, const RigidVector<T,n>& v) {
00126 RigidVector<T,n> r(v);
00127 return r*=f;
00128 }
00129
00130 friend RigidVector<T,n> operator*(const RigidVector<T,n>& v, const T& f) {
00131 RigidVector<T,n> r(v);
00132 return r*=f;
00133 }
00134
00135 friend ostream& operator<<(ostream& os, const RigidVector<T,n>& v) {
00136 os << v.vector();
00137 return os;
00138 }
00139
00140 friend RigidVector<Complex,4> operator*(const SquareMatrix<Complex,4>& m,
00141 const RigidVector<Float,4>& v);
00142 public:
00143
00144
00145
00146
00147 RigidVector() {
00148 for (Int i=0; i<n; i++) v_p[i]=T(0);
00149 }
00150
00151 RigidVector(const T& c) {
00152 for (Int i=0; i<n; i++) v_p[i]=c;
00153 }
00154
00155 RigidVector(const T& v0, const T& v1) {
00156 if (n!=2) exit(1);
00157 v_p[0]=v0; v_p[1]=v1;
00158 }
00159
00160 RigidVector(const T& v0, const T& v1, const T& v2) {
00161 if (n!=3) exit(1);
00162 v_p[0]=v0; v_p[1]=v1; v_p[2]=v2;
00163 }
00164
00165 RigidVector(const T& v0, const T& v1, const T& v2, const T& v3) {
00166 if (n!=4) exit(1);
00167 v_p[0]=v0; v_p[1]=v1; v_p[2]=v2; v_p[3]=v3;
00168 }
00169
00170 RigidVector(const T& v0, const T& v1, const T& v2, const T& v3,
00171 const T& v4) {
00172 if (n!=5) exit(1);
00173 v_p[0]=v0; v_p[1]=v1; v_p[2]=v2; v_p[3]=v3; v_p[4]=v4;
00174 }
00175
00176 RigidVector(const T& v0, const T& v1, const T& v2, const T& v3,
00177 const T& v4, const T& v5) {
00178 if (n!=6) exit(1);
00179 v_p[0]=v0; v_p[1]=v1; v_p[2]=v2; v_p[3]=v3; v_p[4]=v4; v_p[5]=v5;
00180 }
00181
00182 RigidVector(const T v[n]) {
00183 for (Int i=0; i<n; i++) v_p[i]=v[i];
00184 }
00185
00186 RigidVector(const Vector<T> & v) {
00187 for (Int i=0; i<n; i++) v_p[i]=v(i);
00188 }
00189
00190 RigidVector(const RigidVector<T,n>& v) {
00191 for (Int i=0; i<n; i++) v_p[i]=v.v_p[i];
00192 }
00193
00194 RigidVector<T,n>& operator=(const RigidVector<T,n>& v) {
00195 for (Int i=0; i<n; i++) v_p[i]=v.v_p[i];
00196 return *this;
00197 }
00198
00199 RigidVector<T,n>& operator=(const Vector<T>& v) {
00200 for (Int i=0; i<n; i++) v_p[i]=v(i);
00201 return *this;
00202 }
00203
00204 RigidVector<T,n>& operator=(const T& c) {
00205 for (Int i=0; i<n; i++) v_p[i]=c;
00206 return *this;
00207 }
00208
00209 RigidVector<T,n>& operator-() {
00210 for (Int i=0; i<n ;i++) v_p[i]=-v_p[i];
00211 return *this;
00212 }
00213
00214 RigidVector<T,n>& operator+=(const RigidVector<T,n>& v) {
00215 for (Int i=0; i<n; i++) v_p[i]+=v.v_p[i];
00216 return *this;
00217 }
00218 RigidVector<T,n>& operator*=(const RigidVector<T,n>& v) {
00219 for (Int i=0; i<n; i++) v_p[i]*=v.v_p[i];
00220 return *this;
00221 }
00222
00223 RigidVector<T,n>& operator-=(const RigidVector<T,n>& v) {
00224 for (Int i=0; i<n; i++) v_p[i]-=v.v_p[i];
00225 return *this;
00226 }
00227
00228 RigidVector<T,n>& operator*=(const T& val) {
00229 for (Int i=0; i<n; i++) v_p[i]*=val;
00230 return *this;
00231 }
00232
00233 RigidVector<T,n>& operator*=(const SquareMatrix<T,n>& m);
00234
00235
00236 T& operator()(Int i) { return v_p[i];}
00237
00238 const T& operator()(Int i) const { return v_p[i];}
00239
00240
00241
00242 Vector<T> vector() const {
00243 Vector<T> v(n);
00244 for (Int i=0; i<n; i++) v(i)=v_p[i];
00245 return v;
00246 }
00247
00248 RigidVector<T,n> sqrt(const RigidVector<T,n>& v);
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266 protected:
00267 T v_p[n];
00268 };
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279
00280
00281
00282 inline RigidVector<Float,4> operator*(const SquareMatrix<Float,4>& m,
00283 const RigidVector<Float,4>& v) {
00284 RigidVector<Float,4> result(v);
00285 return result*=m;
00286 }
00287
00288 inline RigidVector<Complex,4> operator*(const SquareMatrix<Complex,4>& m,
00289 const RigidVector<Complex,4>& v) {
00290 RigidVector<Complex,4> result(v);
00291 return result*=m;
00292 }
00293
00294
00295 }
00296
00297 #ifndef CASACORE_NO_AUTO_TEMPLATES
00298 #include <casacore/scimath/Mathematics/RigidVector.tcc>
00299 #endif //# CASACORE_NO_AUTO_TEMPLATES
00300 #endif