![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 TAPsPoint3.hpp 00003 00004 Point3 class is a class for 3D point. 00005 00006 SUKITTI PUNAK (10/29/2004) 00007 UPDATE (10/31/2004) 00008 ******************************************************************************/ 00009 #ifndef TAPs_POINT3_HPP 00010 #define TAPs_POINT3_HPP 00011 00012 #include "../Core/TAPsStdLib.hpp" 00013 #include "../Core/TAPsVector3.hpp" 00014 00015 BEGIN_NAMESPACE_TAPs 00016 //============================================================================= 00017 template <typename T> 00018 class Point3 { 00019 //============================================================================= 00020 protected: 00021 T m_t[3]; // x, y, and z coordinates 00022 //============================================================================= 00023 public: 00024 //------------------------------------------------------------------------- 00025 // Output Operator << 00026 friend std::ostream & operator<< ( std::ostream &output, Point3<T> const &p ) 00027 { 00028 output << "Point3<" << typeid(T).name() << ">( " 00029 << p.m_t[0] << ", " << p.m_t[1] << ", " << p.m_t[2] << " )"; 00030 return output; 00031 } 00032 //------------------------------------------------------------------------- 00033 // Constructors 00034 Point3 ( T x = T(), T y = T(), T z = T() ); // default constructor 00035 Point3 ( T a[3] ); // constructor by an array 00036 Point3 ( Point3<T> const &p ); // copy constructor 00037 virtual ~Point3 (); // destructor 00038 //------------------------------------------------------------------------- 00039 // Member Access 00040 inline T & operator[] ( int i ); 00041 inline T const & operator[] ( int i ) const; 00042 inline T GetX() const { return m_t[0]; } 00043 inline T GetY() const { return m_t[1]; } 00044 inline T GetZ() const { return m_t[2]; } 00045 inline void GetXYZ( T &x, T &y, T &z ) const { x = m_t[0]; y = m_t[1]; z = m_t[2]; } 00046 inline void SetX( T x ) { m_t[0] = x; } 00047 inline void SetY( T y ) { m_t[1] = y; } 00048 inline void SetZ( T z ) { m_t[2] = z; } 00049 inline void SetXYZ( T x, T y, T z ) { m_t[0] = x; m_t[1] = y; m_t[2] = z; } 00050 //------------------------------------------------------------------------- 00051 // Assignment Operator 00052 inline Point3<T> & operator= ( Point3<T> const &p ); 00053 //------------------------------------------------------------------------- 00054 // Comparison Operators 00055 inline bool operator== ( Point3<T> const &p ) const; 00056 inline bool operator< ( Point3<T> const &p ) const; 00057 inline bool operator>= ( Point3<T> const &p ) const; 00058 inline bool operator> ( Point3<T> const &p ) const; 00059 inline bool operator<= ( Point3<T> const &p ) const; 00060 //------------------------------------------------------------------------- 00061 // Find the dominate vertex between vertex a and vertex b: 00062 // return 1 if a dominates b 00063 // return -1 if b dominates a 00064 // return 0 if neither dominates the other 00065 static inline int Dominate ( Point3<T> const &a, Point3<T> const &b ); 00066 //------------------------------------------------------------------------- 00067 // Find the vector from point a to point b 00068 static inline Vector3<T> GetVectorFromAtoB( Point3<T> const &a, Point3<T> const &b ); 00069 // Find the vector from point p to this point 00070 inline Vector3<T> operator- ( Point3<T> const &p ) const; 00071 //------------------------------------------------------------------------- 00072 // Arithmetic Operators 00073 //inline Vector3<T> operator- () const; // negation 00074 //inline Vector3<T> operator+ ( Vector3<T> const &v ) const; 00075 //inline Vector3<T> operator- ( Vector3<T> const &v ) const; 00076 }; // END CLASS Point3 00077 //============================================================================= 00078 //----------------------------------------------------------------------------- 00079 // Define Point3s 00080 typedef Point3<int> Point3i; 00081 typedef Point3<float> Point3f; 00082 typedef Point3<double> Point3d; 00083 typedef Point3<long double> Point3ld; 00084 //============================================================================= 00085 END_NAMESPACE_TAPs 00086 //----------------------------------------------------------------------------- 00087 // Include definition if TAPs_USE_EXPORT is not defined 00088 //#if !defined( TAPs_USE_EXPORT ) 00089 #include "TAPsPoint3.cpp" 00090 //#endif 00091 //----------------------------------------------------------------------------- 00092 #endif 00093 //345678901234567890123456789012345678901234567890123456789012345678901234567890 00094 //--+----1----+----2----+----3----+----4----+----5----+----6----+----7----+----8 00095 00096 00097 /* 00098 // Test Point3 class 00099 #include "../GeometricDataStructure/TAPsPoint3.hpp" 00100 using namespace TAPs; 00101 using namespace std; 00102 int main() 00103 { 00104 Point3d a; 00105 Point3d b( 1, 2, 3 ); 00106 Point3d c( 2, 4, 3 ); 00107 Point3d d( c ); 00108 cout << "a = " << a << endl; 00109 cout << "b = " << b << endl; 00110 cout << "c = " << c << endl; 00111 cout << "d = " << d << endl; 00112 cout << "Point3d::Dominate(a,b) = " << Point3d::Dominate( a, b ) << endl; 00113 cout << "Point3d::Dominate(c,d) = " << Point3d::Dominate( c, d ) << endl; 00114 cout << "c==d = " << (c == d) << endl; 00115 cout << "c[0] = " << c[0] << endl; 00116 cout << "c[1] = " << c[1] << endl; 00117 cout << "c[2] = " << c[2] << endl; 00118 c[0] = 5.5; 00119 cout << "c[0] = 5.5 ==> c[0] = " << c[0] << endl; 00120 c[1] = 7.5; 00121 cout << "c[1] = 7.5 ==> c[1] = " << c[1] << endl; 00122 c[2] = 9.5; 00123 cout << "c[2] = 9.5 ==> c[2] = " << c[2] << endl; 00124 return 0; 00125 } 00126 */