Point.h

Go to the documentation of this file.
00001 
00009 #ifndef _MESHLIB_POINT_H_
00010 #define _MESHLIB_POINT_H_
00011 
00012 #include <assert.h>
00013 #include <math.h>
00014 #include <string>
00015 #include <sstream>
00016 
00017 
00018 namespace MeshLib{
00019 
00025 class CPoint{
00026 
00027 public:
00031         CPoint( double x, double y, double z ){ v[0] = x; v[1] = y; v[2] = z;};
00035         CPoint() { v[0] = v[1] = v[2] = 0; };
00039         ~CPoint(){};
00040 
00046         double & operator[]( int i)               { assert( 0<=i && i<3 ); return v[i]; };
00052         double   operator()( int i) const { assert( 0<=i && i<3 ); return v[i]; };
00059         double   operator[]( int i) const { assert( 0<=i && i<3 ); return v[i]; };
00060 
00064         double norm() const { return sqrt( fabs( v[0] * v[0] + v[1] * v[1] + v[2] * v[2] ) ); };
00065 
00071         CPoint  & operator += ( const CPoint & p) { v[0] += p(0); v[1] += p(1); v[2] += p(2); return *this; }; 
00077         CPoint  & operator -= ( const CPoint & p)  { v[0] -= p(0); v[1] -= p(1); v[2] -= p(2); return *this; };
00084         CPoint  & operator *= ( const double  s) { v[0] *= s   ; v[1] *=    s; v[2] *=    s; return *this; };
00090         CPoint  & operator /= ( const double  s) { v[0] /= s   ; v[1] /=    s; v[2] /=    s; return *this; };
00091 
00098         double   operator*( const CPoint & p ) const 
00099         {
00100                 return v[0] * p[0] + v[1] * p[1] + v[2] * p[2]; 
00101         };
00102 
00108         CPoint   operator+( const CPoint & p  ) const
00109         {
00110                 CPoint r( v[0] + p[0], v[1] + p[1], v[2] + p[2] );
00111                 return r;
00112         };
00118         CPoint   operator-( const CPoint & p  ) const
00119         {
00120                 CPoint r( v[0] - p[0], v[1] - p[1], v[2] - p[2] );
00121                 return r;
00122         };
00128         CPoint   operator*( const double s  ) const
00129         {
00130                 CPoint r( v[0] * s, v[1] * s, v[2] * s );
00131                 return r;
00132         };
00138         CPoint   operator/( const double s  ) const
00139         {
00140                 CPoint r( v[0] / s, v[1] / s, v[2] / s );
00141                 return r;
00142         };
00143 
00158         CPoint operator^( const CPoint & p2) const
00159         {
00160                 CPoint r( v[1] * p2[2] - v[2] * p2[1],
00161                               v[2] * p2[0] - v[0] * p2[2],
00162                            v[0] * p2[1] - v[1] * p2[0]);
00163                 return r;
00164         };
00165 
00170         CPoint operator-() const
00171         {
00172                 CPoint p(-v[0],-v[1],-v[2]);
00173                 return p;
00174         };
00175 
00176 protected:
00180         double v[3];
00181 };
00182 
00189 inline void operator>>(const std::string & str, CPoint &p )
00190 {
00191         std::string t = str;
00192         t.erase(0, t.find_first_not_of("()") );
00193         t.erase(t.find_last_not_of("()") + 1);
00194         std::istringstream iss( t );
00195 
00196         iss >> p[0] >> p[1] >> p[2];
00197 }
00198 
00199 
00200 }//name space MeshLib
00201 
00202 #endif //_MESHLIB_POINT_H_ defined
 All Classes Namespaces Files Functions Variables Typedefs Enumerator Defines