![]() |
TAPs 0.7.7.3
|
00001 /****************************************************************************** 00002 SPT_Space3.h 00003 00004 A Space class represents a point in 3D. 00005 00006 Modified from "RADIOSITY A Programmer's Perspective" by Ian Ashdown (1994) 00007 00008 Sukitti Punak (10/24/2003) 00009 Latest Update (11/20/2003) 00010 ******************************************************************************/ 00011 #ifndef SPT_SPACE3_H 00012 #define SPT_SPACE3_H 00013 00014 #include <iostream> 00015 #include <cassert> 00016 00017 using std::ostream; 00018 00019 //============================================================================= 00020 // CLASS: SPtSpace3 ******************************************************** 00021 // DECLARATION PART ********************************************************** 00022 // Desc: 3-D coordinates 00023 00024 template< typename T > 00025 class SPtSpace3 00026 { 00027 // Overloaded Operator -------------------------------------------------- 00028 friend ostream &operator<<( ostream &output, const SPtSpace3< T > &s ) 00029 { 00030 output << "(" << s.x << "," << s.y << "," << s.z << ")'"; 00031 return output; 00032 } 00033 00034 00035 // Data Members -------------------------------------------------------------- 00036 protected: 00037 T x; // X-axis coordinate 00038 T y; // Y-axis coordinate 00039 T z; // Z-axis coordinate 00040 00041 // Member Functions ---------------------------------------------------------- 00042 public: 00043 // Constructor 00044 SPtSpace3( T = 0, T = 0, T = 0 ); 00045 00046 // Get/Set member functions 00047 inline const T &GetX() const; 00048 inline const T &GetY() const; 00049 inline const T &GetZ() const; 00050 inline const T &Get( int ) const; 00051 inline void GetXYZ( T, T, T ) const; 00052 inline void SetX( T ); 00053 inline void SetY( T ); 00054 inline void SetZ( T ); 00055 inline void Set( int, T ); 00056 inline void SetXYZ( T, T, T ); 00057 00058 // Overloaded Operators 00059 inline T &operator[]( int ); 00060 inline const T &operator[]( int ) const; 00061 00062 }; 00063 // END CLASS: SPtSpace3 ==================================================== 00064 // END DECLARATION PART ====================================================== 00065 00066 00067 00068 //============================================================================= 00069 // CLASS: SPtSpace3 ******************************************************** 00070 // DEFINITION PART *********************************************************** 00071 // Constructor(s) 00072 template< typename T > 00073 SPtSpace3< T >::SPtSpace3( T xval, T yval, T zval ) : x( xval ), y( yval ), z( zval ) { } 00074 00075 //----------------------------------------------------------------------------- 00076 // Get/Set Member Functions 00077 template< typename T > 00078 inline const T &SPtSpace3< T >::GetX() const { return x; } 00079 //----------------------------------------------------------------------------- 00080 template< typename T > 00081 inline const T &SPtSpace3< T >::GetY() const { return y; } 00082 //----------------------------------------------------------------------------- 00083 template< typename T > 00084 inline const T &SPtSpace3< T >::GetZ() const { return z; } 00085 //----------------------------------------------------------------------------- 00086 template< typename T > 00087 inline const T &SPtSpace3< T >::Get( int i ) const 00088 { 00089 assert( 0 <= i && i < 3 ); 00090 switch ( i ) { 00091 case 0: return x; 00092 case 1: return y; 00093 case 2: return z; 00094 } 00095 return x; 00096 } 00097 //----------------------------------------------------------------------------- 00098 template< typename T > 00099 inline void SPtSpace3< T >::GetXYZ( T vx, T vy, T vz ) const { x = vx; y = vy; z = vz; }; 00100 //----------------------------------------------------------------------------- 00101 template< typename T > 00102 inline void SPtSpace3< T >::SetX( T val ) { x = val; } 00103 //----------------------------------------------------------------------------- 00104 template< typename T > 00105 inline void SPtSpace3< T >::SetY( T val ) { y = val; } 00106 //----------------------------------------------------------------------------- 00107 template< typename T > 00108 inline void SPtSpace3< T >::SetZ( T val ) { z = val; } 00109 //----------------------------------------------------------------------------- 00110 template< typename T > 00111 inline void SPtSpace3< T >::Set( int, T val ) 00112 { 00113 assert( 0 <= i && i < 3 ); 00114 switch ( i ) { 00115 case 0: x = val; break; 00116 case 1: y = val; break; 00117 case 2: z = val; break; 00118 } 00119 } 00120 //----------------------------------------------------------------------------- 00121 template< typename T > 00122 inline void SPtSpace3< T >::SetXYZ( T xval, T yval, T zval ) 00123 { x = xval; y = yval; z = zval; } 00124 00125 00126 // Overloaded Operators *************************************************** 00127 //----------------------------------------------------------------------------- 00128 template< typename T > 00129 T &SPtSpace3< T >::operator []( int i ) 00130 { 00131 assert( 0 <= i && i < 3 ); 00132 switch ( i ) { 00133 case 0: return x; 00134 case 1: return y; 00135 case 2: return z; 00136 } 00137 return x; 00138 } 00139 //----------------------------------------------------------------------------- 00140 template< typename T > 00141 const T &SPtSpace3< T >::operator []( int i ) const 00142 { 00143 assert( 0 <= i && i < 3 ); 00144 switch ( i ) { 00145 case 0: return x; 00146 case 1: return y; 00147 case 2: return z; 00148 } 00149 return x; 00150 } 00151 00152 /* 00153 // Friend Functions ******************************************************* 00154 // Overloaded Operator ******************************************************* 00155 template< typename T > 00156 ostream &operator<<( ostream &output, const SPtSpace3< T > &s ) 00157 { 00158 output << "(" << s.x << "," << s.y << "," << s.z << ")'"; 00159 return output; 00160 } 00161 // END CLASS: SPtSpace3 ==================================================== 00162 // END DEFINITION PART ======================================================= 00163 */ 00164 #endif