source: projectionDesigner/trunk/projdesigner/include/gmtl/Output.h @ 62

Last change on this file since 62 was 4, checked in by Torben Dannhauer, 15 years ago
File size: 9.6 KB
Line 
1/************************************************************** ggt-head beg
2 *
3 * GGT: Generic Graphics Toolkit
4 *
5 * Original Authors:
6 *   Allen Bierbaum
7 *
8 * -----------------------------------------------------------------
9 * File:          Output.h,v
10 * Date modified: 2005/05/12 21:42:10
11 * Version:       1.17
12 * -----------------------------------------------------------------
13 *
14 *********************************************************** ggt-head end */
15/*************************************************************** ggt-cpr beg
16*
17* GGT: The Generic Graphics Toolkit
18* Copyright (C) 2001,2002 Allen Bierbaum
19*
20* This library is free software; you can redistribute it and/or
21* modify it under the terms of the GNU Lesser General Public
22* License as published by the Free Software Foundation; either
23* version 2.1 of the License, or (at your option) any later version.
24*
25* This library is distributed in the hope that it will be useful,
26* but WITHOUT ANY WARRANTY; without even the implied warranty of
27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
28* Lesser General Public License for more details.
29*
30* You should have received a copy of the GNU Lesser General Public
31* License along with this library; if not, write to the Free Software
32* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
33*
34 ************************************************************ ggt-cpr end */
35#ifndef _GMTL_OUTPUT_H_
36#define _GMTL_OUTPUT_H_
37
38#include <iostream>
39#include <gmtl/Util/Assert.h>
40#include <gmtl/VecBase.h>
41#include <gmtl/Matrix.h>
42#include <gmtl/Quat.h>
43#include <gmtl/Tri.h>
44#include <gmtl/Plane.h>
45#include <gmtl/Sphere.h>
46#include <gmtl/EulerAngle.h>
47#include <gmtl/AABox.h>
48#include <gmtl/Ray.h>
49#include <gmtl/LineSeg.h>
50#include <gmtl/Coord.h>
51
52namespace gmtl
53{
54   namespace output
55   {
56      /** Outputters for vector types. */
57#ifndef GMTL_NO_METAPROG
58      template<typename DATA_TYPE, unsigned SIZE, typename REP>
59      struct VecOutputter
60      {
61         static std::ostream& outStream(std::ostream& out, const VecBase<DATA_TYPE,SIZE,REP>& v)
62         {
63            VecBase<DATA_TYPE,SIZE, gmtl::meta::DefaultVecTag> temp_vec(v);
64            VecOutputter<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>::outStream(out,v);
65            return out;
66         }
67      };
68
69      template<typename DATA_TYPE, unsigned SIZE>
70      struct VecOutputter<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>
71      {
72         static std::ostream& outStream(std::ostream& out, const VecBase<DATA_TYPE,SIZE,gmtl::meta::DefaultVecTag>& v)
73         {
74            out << "(";
75            for ( unsigned i=0; i<SIZE; ++i )
76            {
77               if ( i != 0 )
78               {
79                  out << ", ";
80               }
81               out << v[i];
82            }
83            out << ")";
84            return out;
85         }
86      };
87#endif
88   }
89
90   /** @ingroup Output
91    *  @name Output Stream Operators
92    */
93   //@{
94   /**
95    * Outputs a string representation of the given VecBase type to the given
96    * output stream. This works for both Point and Vec types. The output is
97    * formatted such that Vec<int, 4>(1,2,3,4) will appear as "(1, 2, 3, 4)".
98    *
99    * @param out     the stream to write to
100    * @param v       the VecBase type to output
101    *
102    * @return  out after it has been written to
103    */
104#ifdef GMTL_NO_METAPROG
105   template<typename DATA_TYPE, unsigned SIZE>
106   std::ostream& operator<<(std::ostream& out, const VecBase<DATA_TYPE, SIZE>& v)
107   {
108      out << "(";
109      for ( unsigned i=0; i<SIZE; ++i )
110      {
111         if ( i != 0 )
112         {
113            out << ", ";
114         }
115         out << v[i];
116      }
117      out << ")";
118      return out;
119   }
120#else
121   template<typename DATA_TYPE, unsigned SIZE, typename REP>
122   std::ostream& operator<<(std::ostream& out, const VecBase<DATA_TYPE, SIZE, REP>& v)
123   {
124      return output::VecOutputter<DATA_TYPE,SIZE,REP>::outStream(out,v);
125   }
126#endif
127
128   /**
129    * Outputs a string representation of the given EulerAngle type to the given
130    * output stream.  Format is {ang1,ang2,ang3}
131    *
132    * @param out     the stream to write to
133    * @param e       the EulerAngle type to output
134    *
135    * @return  out after it has been written to
136    */
137   template< class DATA_TYPE, typename ROTATION_ORDER>
138   std::ostream& operator<<( std::ostream& out,
139                             const EulerAngle<DATA_TYPE, ROTATION_ORDER>& e )
140   {
141      const DATA_TYPE* angle_data(e.getData());
142      out << "{" << angle_data[0] << ", " << angle_data[1] << ", " << angle_data[2] << "}";
143      return out;
144   }
145
146   /**
147    * Outputs a string representation of the given Matrix to the given output
148    * stream. The output is formatted along the lines of:
149    * <pre>
150    *    | 1 2 3 4 |
151    *    | 5 6 7 8 |
152    *    | 9 10 11 12 |
153    * </pre>
154    *
155    * @param out     the stream to write to
156    * @param m       the Matrix to output
157    *
158    * @return  out after it has been written to
159    */
160   template< class DATA_TYPE, unsigned ROWS, unsigned COLS >
161   std::ostream& operator<<( std::ostream& out,
162                             const Matrix<DATA_TYPE, ROWS, COLS>& m )
163   {
164      for ( unsigned row=0; row<ROWS; ++row )
165      {
166         out << "|";
167         for ( unsigned col=0; col<COLS; ++col )
168         {
169            out << " " << m(row, col);
170         }
171         out << " |" << std::endl;
172      }
173      return out;
174   }
175
176   /**
177    * Outputs a string representation of the given Matrix to the given output
178    * stream. The output is formatted such that Quat<int>(1,2,3,4) will appear
179    * as "(1, 2, 3, 4)".
180    *
181    * @param out     the stream to write to
182    * @param q       the Quat to output
183    *
184    * @return  out after it has been written to
185    */
186   template< typename DATA_TYPE >
187   std::ostream& operator<<( std::ostream& out, const Quat<DATA_TYPE>& q )
188   {
189      out << q.mData;
190      return out;
191   }
192
193   /**
194    * Outputs a string representation of the given Tri to the given output
195    * stream. The output is formatted such that
196    *    Tri<int>(
197    *       Point<int, 3>(1,2,3),
198    *       Point<int, 3>(4,5,6),
199    *       Point<int, 3>(7,8,9)
200    *    )
201    * will appear as "(1, 2, 3), (4, 5, 6), (7, 8, 9)".
202    *
203    * @param out     the stream to write to
204    * @param t       the Tri to output
205    *
206    * @return  out after it has been written to
207    */
208   template< typename DATA_TYPE >
209   std::ostream& operator<<( std::ostream& out, const Tri<DATA_TYPE> &t )
210   {
211      out << t[0] << ", " << t[1] << ", " << t[2];
212      return out;
213   }
214
215   /**
216    * Outputs a string representation of the given Plane to the given output
217    * stream. The output is formatted such that
218    *    Plane<int>(
219    *       Vec<int, 3>(1,2,3),
220    *       4
221    *    )
222    * will appear as "(1, 2, 3), 4)".
223    *
224    * @param out     the stream to write to
225    * @param p       the Plane to output
226    *
227    * @return  out after it has been written to
228    */
229   template< typename DATA_TYPE >
230   std::ostream& operator<<( std::ostream& out, const Plane<DATA_TYPE> &p )
231   {
232      out << p.mNorm << ", " << p.mOffset;
233      return out;
234   }
235
236   /**
237    * Outputs a string representation of the given Sphere to the given output
238    * stream. The output is formatted such that
239    *    Sphere<int>(
240    *       Point<int, 3>(1,2,3),
241    *       4
242    *    )
243    * will appear as "(1, 2, 3), 4)".
244    *
245    * @param out     the stream to write to
246    * @param s       the Sphere to output
247    *
248    * @return  out after it has been written to
249    */
250   template< typename DATA_TYPE >
251   std::ostream& operator<<( std::ostream& out, const Sphere<DATA_TYPE> &s )
252   {
253      out << s.mCenter << ", " << s.mRadius;
254      return out;
255   }
256
257   /**
258    * Outputs a string representation of the given AABox to the given output
259    * stream. The output is formatted such that
260    *    AABox<int>(
261    *       Point<int, 3>(1,2,3),
262    *       Point<int, 3>(4,5,6)
263    *    )
264    * will appear as "(1,2,3) (4,5,6) false".
265    *
266    * @param out     the stream to write to
267    * @param b       the AABox to output
268    *
269    * @return  out after it has been written to
270    */
271   template< typename DATA_TYPE >
272   std::ostream& operator<<( std::ostream& out, const AABox<DATA_TYPE>& b)
273   {
274      out << b.mMin << " " << b.mMax << " ";
275      out << (b.mEmpty ? "true" : "false");
276      return out;
277   }
278
279   /**
280    * Outputs a string representation of the given Ray to the given output
281    * stream. The output is formatted such that
282    *    Ray<int>(
283    *       Point<int>(1,2,3),
284    *       Vec<int>(4,5,6)
285    *    )
286    * will appear as "(1,2,3) (4,5,6)".
287    *
288    * @param out     the stream to write to
289    * @param b       the Ray to output
290    *
291    * @return  out after it has been written to
292    */
293   template< typename DATA_TYPE >
294   std::ostream& operator<<( std::ostream& out, const Ray<DATA_TYPE>& b )
295   {
296      out << b.getOrigin() << " " << b.getDir();
297      return out;
298   }
299
300   /**
301    * Outputs a string representation of the given LineSeg to the given output
302    * stream. The output is formatted such that
303    *    LineSeg<int>(
304    *       Point<int>(1,2,3),
305    *       Vec<int>(4,5,6)
306    *    )
307    * will appear as "(1,2,3) (4,5,6)".
308    *
309    * @param out     the stream to write to
310    * @param b       the LineSeg to output
311    *
312    * @return  out after it has been written to
313    */
314   template< typename DATA_TYPE >
315   std::ostream& operator<<( std::ostream& out, const LineSeg<DATA_TYPE>& b )
316   {
317      out << b.getOrigin() << " " << b.getDir();
318      return out;
319   }
320
321   template< typename POS_TYPE, typename ROT_TYPE>
322   std::ostream& operator<<( std::ostream& out, const Coord<POS_TYPE,ROT_TYPE>& c)
323   {
324      out << "p:" << c.getPos() << " r:" << c.getRot();
325      return out;
326   }
327   //@}
328
329} // end namespace gmtl
330
331#endif
Note: See TracBrowser for help on using the repository browser.