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
00030
00031
00032
00033
00034
00035
00036
00037
00038 #ifndef POINT3D_H_DEFINED
00039 #define POINT3D_H_DEFINED
00040
00041 #include "Image/Dims.H"
00042 #include "Image/Image.H"
00043 #include "Util/Promotions.H"
00044 #include "Util/log.H"
00045 #include <cmath>
00046 #include <string>
00047 #include <vector>
00048
00049
00050
00051
00052
00053 template <class T>
00054 class Point3D
00055 {
00056 public:
00057
00058 inline Point3D();
00059
00060
00061 inline Point3D(const T xx, const T yy, const T zz);
00062
00063
00064 inline Point3D(const Image<T>& mat);
00065
00066
00067
00068
00069 template <class U>
00070 explicit inline Point3D(const Point3D<U>& a);
00071
00072
00073
00074
00075 inline Point3D<T>& operator+=(const Point3D<T> &p);
00076
00077 inline Point3D<T>& operator-=(const Point3D<T> &p);
00078
00079 inline Point3D<T>& operator*=(const Point3D<T> &p);
00080
00081 inline Point3D<T>& operator/=(const Point3D<T> &p);
00082
00083
00084 template <class U>
00085 inline Point3D<typename promote_trait<T,U>::TP>
00086 operator+(const Point3D<U> &p) const;
00087
00088 template <class U>
00089 inline Point3D<typename promote_trait<T,U>::TP>
00090 operator-(const Point3D<U> &p) const;
00091
00092 template <class U>
00093 inline Point3D<typename promote_trait<T,U>::TP>
00094 operator*(const Point3D<U> &p) const;
00095
00096 template <class U>
00097 inline Point3D<typename promote_trait<T,U>::TP>
00098 operator/(const Point3D<U> &p) const;
00099
00100
00101 inline Point3D<T>& operator+=(const T val);
00102
00103 inline Point3D<T>& operator-=(const T val);
00104
00105 inline Point3D<T>& operator*=(const T val);
00106
00107 inline Point3D<T>& operator/=(const T val);
00108
00109
00110 template <class U>
00111 inline Point3D<typename promote_trait<T,U>::TP> operator+(const U val) const;
00112
00113
00114 template <class U>
00115 inline Point3D<typename promote_trait<T,U>::TP> operator-(const U val) const;
00116
00117
00118 template <class U>
00119 inline Point3D<typename promote_trait<T,U>::TP> operator*(const U val) const;
00120
00121
00122 template <class U>
00123 inline Point3D<typename promote_trait<T,U>::TP> operator/(const U val) const;
00124
00125
00126 inline bool isValid() const;
00127
00128
00129 inline typename promote_trait<T,float>::TP
00130 squdist(const Point3D<T>& p) const;
00131
00132
00133 inline typename promote_trait<T,float>::TP
00134 distance(const Point3D<T>& p) const;
00135
00136
00137 inline typename promote_trait<T,float>::TP
00138 magnitude() const;
00139
00140
00141 inline Image<T> getImage();
00142
00143
00144 T x, y, z;
00145 };
00146
00147
00148
00149 template <class T, class U>
00150 inline bool operator==(const Point3D<T>& p1, const Point3D<U>& p2);
00151
00152
00153 template <class T, class U>
00154 inline bool operator!=(const Point3D<T>& p1, const Point3D<U>& p2);
00155
00156
00157 template <class T, class U>
00158 inline bool operator>(const Point3D<T>& p1, const Point3D<U>& p2);
00159
00160
00161 template <class T, class U>
00162 inline bool operator<(const Point3D<T>& p1, const Point3D<U>& p2);
00163
00164
00165
00166 template <class T>
00167 std::string convertToString(const Point3D<T>& val);
00168
00169
00170 template <class T>
00171 void convertFromString(const std::string& str, Point3D<T>& val);
00172
00173
00174 template <class T>
00175 inline Point3D<T>::Point3D()
00176 { z = 0; y = 0; z = 0;}
00177
00178
00179 template <class T>
00180 inline Point3D<T>::Point3D(const T xx, const T yy, const T zz)
00181 { x = xx; y = yy; z= zz;}
00182
00183
00184 template <class T>
00185 inline Point3D<T>::Point3D(const Image<T>& mat)
00186 {
00187 ASSERT(mat.size() == 3);
00188 x = mat[0]; y = mat[1]; z= mat[2];
00189 }
00190
00191
00192 template <class T>
00193 template <class U>
00194 inline Point3D<T>::Point3D(const Point3D<U>& a)
00195 : x(clamped_convert<T>(a.x)), y(clamped_convert<T>(a.y)), z(clamped_convert<T>(a.z))
00196 { }
00197
00198
00199 template <class T>
00200 inline Point3D<T>& Point3D<T>::operator+=(const Point3D<T> &p)
00201 { x += p.x; y += p.y; z += p.z; return *this; }
00202
00203
00204 template <class T>
00205 inline Point3D<T>& Point3D<T>::operator-=(const Point3D<T> &p)
00206 { x -= p.x; y -= p.y; z -= p.z; return *this; }
00207
00208
00209 template <class T>
00210 inline Point3D<T>& Point3D<T>::operator*=(const Point3D<T> &p)
00211 { x *= p.x; y *= p.y; z *= p.z; return *this; }
00212
00213
00214 template <class T>
00215 inline Point3D<T>& Point3D<T>::operator/=(const Point3D<T> &p)
00216 { x /= p.x; y /= p.y; z /- p.z; return *this; }
00217
00218
00219 template <class T>
00220 template <class U>
00221 inline Point3D<typename promote_trait<T,U>::TP>
00222 Point3D<T>::operator+(const Point3D<U> &p) const
00223 { return Point3D<typename promote_trait<T,U>::TP>(x + p.x, y + p.y, z + p.z); }
00224
00225
00226 template <class T>
00227 template <class U>
00228 inline Point3D<typename promote_trait<T,U>::TP>
00229 Point3D<T>::operator-(const Point3D<U> &p) const
00230 { return Point3D<typename promote_trait<T,U>::TP>(x - p.x, y - p.y, z - p.z); }
00231
00232
00233 template <class T>
00234 template <class U>
00235 inline Point3D<typename promote_trait<T,U>::TP>
00236 Point3D<T>::operator*(const Point3D<U> &p) const
00237 { return Point3D<typename promote_trait<T,U>::TP>(x * p.x, y * p.y, z * p.z); }
00238
00239
00240 template <class T>
00241 template <class U>
00242 inline Point3D<typename promote_trait<T,U>::TP>
00243 Point3D<T>::operator/(const Point3D<U> &p) const
00244 { return Point3D<typename promote_trait<T,U>::TP>(x / p.x, y / p.y, z / p.z); }
00245
00246
00247 template <class T>
00248 inline Point3D<T>& Point3D<T>::operator+=(const T val)
00249 { x += val; y += val; z += val; return *this; }
00250
00251
00252 template <class T>
00253 inline Point3D<T>& Point3D<T>::operator-=(const T val)
00254 { x -= val; y -= val; z -= val; return *this; }
00255
00256
00257 template <class T>
00258 inline Point3D<T>& Point3D<T>::operator*=(const T val)
00259 { x *= val; y *= val; z *= val; return *this; }
00260
00261
00262 template <class T>
00263 inline Point3D<T>& Point3D<T>::operator/=(const T val)
00264 { x /= val; y /= val; z /= val; return *this; }
00265
00266
00267 template <class T>
00268 template <class U>
00269 inline Point3D<typename promote_trait<T,U>::TP>
00270 Point3D<T>::operator+(const U val) const
00271 { return Point3D<typename promote_trait<T,U>::TP>(this->x+val, this->y+val, this->z+val); }
00272
00273
00274 template <class T>
00275 template <class U>
00276 inline Point3D<typename promote_trait<T,U>::TP>
00277 Point3D<T>::operator-(const U val) const
00278 { return Point3D<typename promote_trait<T,U>::TP>(this->x-val, this->y-val, this->z-val); }
00279
00280
00281 template <class T>
00282 template <class U>
00283 inline Point3D<typename promote_trait<T,U>::TP>
00284 Point3D<T>::operator*(const U val) const
00285 { return Point3D<typename promote_trait<T,U>::TP>(this->x*val, this->y*val, this->z*val); }
00286
00287
00288 template <class T>
00289 template <class U>
00290 inline Point3D<typename promote_trait<T,U>::TP>
00291 Point3D<T>::operator/(const U val) const
00292 { return Point3D<typename promote_trait<T,U>::TP>(this->x/val, this->y/val, this->z/val); }
00293
00294
00295 template <class T, class U>
00296 inline bool operator==(const Point3D<T>& p1, const Point3D<U>& p2)
00297 { return p1.x == p2.x && p1.y == p2.y && p1.z == p2.z; }
00298
00299
00300 template <class T, class U>
00301 inline bool operator!=(const Point3D<T>& p1, const Point3D<U>& p2)
00302 { return p1.x != p2.x || p1.y != p2.y || p1.z != p2.z; }
00303
00304
00305 template <class T, class U>
00306 inline bool operator>(const Point3D<T>& p1, const Point3D<U>& p2)
00307 { return p1.x > p2.x && p1.y > p2.y && p1.z > p2.z; }
00308
00309
00310 template <class T, class U>
00311 inline bool operator<(const Point3D<T>& p1, const Point3D<U>& p2)
00312 { return p1.x < p2.x && p1.y < p2.y && p1.z < p2.z; }
00313
00314
00315 template <class T>
00316 inline bool Point3D<T>::isValid() const
00317 { return ((x >= 0) && (y >= 0) && (z >= 0)); }
00318
00319
00320 template <class T>
00321 inline typename promote_trait<T,float>::TP
00322 Point3D<T>::squdist(const Point3D<T>& p) const
00323 {
00324 typedef typename promote_trait<T,float>::TP TF;
00325 TF d1 = p.x - x, d2 = p.y - y, d3 = p.z - z;
00326 return (d1 * d1 + d2 * d2 + d3 * d3);
00327 }
00328
00329
00330 template <class T>
00331 inline typename promote_trait<T,float>::TP
00332 Point3D<T>::distance(const Point3D<T>& p) const
00333 { return sqrt(squdist(p)); }
00334
00335
00336 template <class T>
00337 inline typename promote_trait<T,float>::TP
00338 Point3D<T>::magnitude() const
00339 { return sqrt((x*x) + (y*y) + (z*z)); }
00340
00341
00342 template <class T>
00343 inline Image<T> Point3D<T>::getImage()
00344 {
00345 Image<T> mat(1,3,NO_INIT);
00346 mat[0] = x;
00347 mat[1] = y;
00348 mat[2] = z;
00349
00350 return mat;
00351 }
00352
00353
00354
00355
00356
00357
00358 #endif