00001
00002
00003
00004
00005
00006 #ifndef _GMTL_OUTPUT_H_
00007 #define _GMTL_OUTPUT_H_
00008
00009 #include <iostream>
00010 #include <gmtl/Util/Assert.h>
00011 #include <gmtl/VecBase.h>
00012 #include <gmtl/Matrix.h>
00013 #include <gmtl/Quat.h>
00014 #include <gmtl/Tri.h>
00015 #include <gmtl/Plane.h>
00016 #include <gmtl/Sphere.h>
00017 #include <gmtl/EulerAngle.h>
00018 #include <gmtl/AABox.h>
00019 #include <gmtl/Ray.h>
00020 #include <gmtl/LineSeg.h>
00021 #include <gmtl/Coord.h>
00022
00023 namespace gmtl
00024 {
00025 namespace output
00026 {
00028 #ifndef GMTL_NO_METAPROG
00029 template<typename DATA_TYPE, unsigned SIZE, typename REP>
00030 struct VecOutputter
00031 {
00032 static std::ostream& outStream(std::ostream& out, const VecBase<DATA_TYPE,SIZE,REP>& v)
00033 {
00034 VecBase<DATA_TYPE,SIZE, gmtl::meta::DefaultVecTag> temp_vec(v);
00035 VecOutputter<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>::outStream(out,v);
00036 return out;
00037 }
00038 };
00039
00040 template<typename DATA_TYPE, unsigned SIZE>
00041 struct VecOutputter<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>
00042 {
00043 static std::ostream& outStream(std::ostream& out, const VecBase<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>& v)
00044 {
00045 out << "(";
00046 for ( unsigned i=0; i<SIZE; ++i )
00047 {
00048 if ( i != 0 )
00049 {
00050 out << ", ";
00051 }
00052 out << v[i];
00053 }
00054 out << ")";
00055 return out;
00056 }
00057 };
00058 #endif
00059 }
00060
00075 #ifdef GMTL_NO_METAPROG
00076 template<typename DATA_TYPE, unsigned SIZE>
00077 std::ostream& operator<<(std::ostream& out, const VecBase<DATA_TYPE, SIZE>& v)
00078 {
00079 out << "(";
00080 for ( unsigned i=0; i<SIZE; ++i )
00081 {
00082 if ( i != 0 )
00083 {
00084 out << ", ";
00085 }
00086 out << v[i];
00087 }
00088 out << ")";
00089 return out;
00090 }
00091 #else
00092 template<typename DATA_TYPE, unsigned SIZE, typename REP>
00093 std::ostream& operator<<(std::ostream& out, const VecBase<DATA_TYPE, SIZE, REP>& v)
00094 {
00095 return output::VecOutputter<DATA_TYPE,SIZE,REP>::outStream(out,v);
00096 }
00097 #endif
00098
00108 template< class DATA_TYPE, typename ROTATION_ORDER>
00109 std::ostream& operator<<( std::ostream& out,
00110 const EulerAngle<DATA_TYPE, ROTATION_ORDER>& e )
00111 {
00112 const DATA_TYPE* angle_data(e.getData());
00113 out << "{" << angle_data[0] << ", " << angle_data[1] << ", " << angle_data[2] << "}";
00114 return out;
00115 }
00116
00131 template< class DATA_TYPE, unsigned ROWS, unsigned COLS >
00132 std::ostream& operator<<( std::ostream& out,
00133 const Matrix<DATA_TYPE, ROWS, COLS>& m )
00134 {
00135 for ( unsigned row=0; row<ROWS; ++row )
00136 {
00137 out << "|";
00138 for ( unsigned col=0; col<COLS; ++col )
00139 {
00140 out << " " << m(row, col);
00141 }
00142 out << " |" << std::endl;
00143 }
00144 return out;
00145 }
00146
00157 template< typename DATA_TYPE >
00158 std::ostream& operator<<( std::ostream& out, const Quat<DATA_TYPE>& q )
00159 {
00160 out << q.mData;
00161 return out;
00162 }
00163
00179 template< typename DATA_TYPE >
00180 std::ostream& operator<<( std::ostream& out, const Tri<DATA_TYPE> &t )
00181 {
00182 out << t[0] << ", " << t[1] << ", " << t[2];
00183 return out;
00184 }
00185
00200 template< typename DATA_TYPE >
00201 std::ostream& operator<<( std::ostream& out, const Plane<DATA_TYPE> &p )
00202 {
00203 out << p.mNorm << ", " << p.mOffset;
00204 return out;
00205 }
00206
00221 template< typename DATA_TYPE >
00222 std::ostream& operator<<( std::ostream& out, const Sphere<DATA_TYPE> &s )
00223 {
00224 out << s.mCenter << ", " << s.mRadius;
00225 return out;
00226 }
00227
00242 template< typename DATA_TYPE >
00243 std::ostream& operator<<( std::ostream& out, const AABox<DATA_TYPE>& b)
00244 {
00245 out << b.mMin << " " << b.mMax << " ";
00246 out << (b.mEmpty ? "true" : "false");
00247 return out;
00248 }
00249
00264 template< typename DATA_TYPE >
00265 std::ostream& operator<<( std::ostream& out, const Ray<DATA_TYPE>& b )
00266 {
00267 out << b.getOrigin() << " " << b.getDir();
00268 return out;
00269 }
00270
00285 template< typename DATA_TYPE >
00286 std::ostream& operator<<( std::ostream& out, const LineSeg<DATA_TYPE>& b )
00287 {
00288 out << b.getOrigin() << " " << b.getDir();
00289 return out;
00290 }
00291
00292 template< typename POS_TYPE, typename ROT_TYPE>
00293 std::ostream& operator<<( std::ostream& out, const Coord<POS_TYPE,ROT_TYPE>& c)
00294 {
00295 out << "p:" << c.getPos() << " r:" << c.getRot();
00296 return out;
00297 }
00299
00300 }
00301
00302 #endif