00001 //*****************************************************************************// 00002 // // 00003 // Copyright (c) 2001 // 00004 // INRIA // 00005 // 54600 VILLERS LES NANCY // 00006 // France // 00007 // // 00008 //*****************************************************************************// 00009 // // 00010 // *** NOTICE OF PROPRIETARY INFORMATION *** // 00011 // // 00012 // The information contained in this file is considered proprietary and the // 00013 // exclusive property of INRIA. This information may not be disclosed, // 00014 // duplicated or used, in whole or in part, for any purpose whatsoever // 00015 // without express written authorization from INRIA // 00016 // // 00017 //*****************************************************************************// 00018 00019 00020 #ifndef QC_POINT_H_ 00021 #define QC_POINT_H_ 00022 00023 00024 #include "QCCommon.hpp" 00025 // 00027 enum Coords { COORDX = 0, COORDY, COORDZ }; 00028 00029 00030 00035 00036 template <int dim> 00037 class QCPoint 00038 { 00039 00041 public: 00042 00046 QCPoint (void) { 00047 for (int i=0; i<dim ; i++) 00048 coords[i] = 0e0; 00049 }; 00053 QCPoint (const QCFloat* array) { 00054 memset(coords, 0, dim*sizeof(QCFloat)); 00055 *this += array; 00056 }; 00057 00058 00062 QCPoint (const QCPoint& p) { 00063 memset(coords, 0, dim*sizeof(QCFloat)); 00064 *this += p; 00065 }; 00066 00067 00071 ~QCPoint (void) {}; 00072 00073 00077 int getDimension (void) const { return dim; }; 00078 00079 00085 QCFloat operator [] (int index) const { 00086 #ifndef QC_NO_DEBUG 00087 assert (index < dim); 00088 #endif 00089 return coords[index]; 00090 } 00091 00097 QCFloat& operator [] (int index) { 00098 #ifndef QC_NO_DEBUG 00099 assert (index < dim); 00100 #endif 00101 return coords[index]; 00102 } 00103 00104 00110 QCPoint& operator += (const QCPoint& displacement) { 00111 for (int i=0; i<dim; i++) { 00112 coords[i] += displacement[i]; 00113 } 00114 return *this; 00115 }; 00116 00117 00118 00124 QCPoint& operator -= (const QCPoint& displacement) { 00125 for (int i=0; i<dim; i++) { 00126 coords[i] -= displacement[i]; 00127 } 00128 return *this; 00129 }; 00130 00131 00132 00138 QCPoint& operator += (const QCFloat* displacement) { 00139 for (int i=0; i<dim; i++) { 00140 coords[i] += displacement[i]; 00141 } 00142 return *this; 00143 }; 00144 00145 00146 00152 QCPoint& operator -= (const QCFloat* displacement) { 00153 for (int i=0; i<dim; i++) { 00154 coords[i] -= displacement[i]; 00155 } 00156 return *this; 00157 }; 00158 00159 QCFloat dot(const QCPoint & p) const { 00160 return coords[0]*p[0] + coords[1]*p[1] + coords[2]*p[2] ; 00161 } 00162 QCPoint vect(const QCPoint & p) const { 00163 QCPoint res; 00164 res[2] = coords[0]*p[1] - coords[1]*p[0] ; 00165 res[1] = coords[2]*p[0] - coords[0]*p[2] ; 00166 res[0] = coords[1]*p[2] - coords[2]*p[1] ; 00167 return res; 00168 } 00169 00171 protected: 00172 00173 00175 private: 00176 00177 00179 public: 00180 protected: 00181 private: 00185 QCFloat coords [dim]; 00186 00187 }; 00188 00189 00190 00194 typedef QCPoint<3> QCPoint3D; 00195 00196 00197 00201 const QCPoint<3> QC_ORIGIN3D; 00202 00203 00204 00205 00212 template <int dim> 00213 ostream& operator << (ostream& os, const QCPoint<dim>& p); 00214 00215 00216 00217 #endif // QC_POINT_H_