OSG  3.4.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
io_utils.h
Go to the documentation of this file.
1 /* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2  *
3  * This library is open source and may be redistributed and/or modified under
4  * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5  * (at your option) any later version. The full license is in LICENSE file
6  * included with this distribution, and on the openscenegraph.org website.
7  *
8  * This library is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * OpenSceneGraph Public License for more details.
12 */
13 
14 #ifndef OSG_IO_UTILS
15 #define OSG_IO_UTILS 1
16 
17 #include <ostream>
18 #include <istream>
19 
20 #include <osg/Vec4d>
21 #include <osg/Vec4ub>
22 #include <osg/Vec2b>
23 #include <osg/Vec3b>
24 #include <osg/Vec4b>
25 #include <osg/Vec2s>
26 #include <osg/Vec3s>
27 #include <osg/Vec4s>
28 #include <osg/Vec2i>
29 #include <osg/Vec3i>
30 #include <osg/Vec4i>
31 #include <osg/Matrixf>
32 #include <osg/Matrixd>
33 #include <osg/Plane>
34 
35 namespace osg {
36 
37 
39 // Vec2f streaming operators
40 inline std::ostream& operator << (std::ostream& output, const Vec2f& vec)
41 {
42  output << vec._v[0] << " " << vec._v[1];
43  return output; // to enable cascading
44 }
45 
46 inline std::istream& operator >> (std::istream& input, Vec2f& vec)
47 {
48  input >> vec._v[0] >> std::ws >> vec._v[1];
49  return input;
50 }
51 
53 // Vec2d steaming operators.
54 inline std::ostream& operator << (std::ostream& output, const Vec2d& vec)
55 {
56  output << vec._v[0] << " " << vec._v[1];
57  return output; // to enable cascading
58 }
59 
60 inline std::istream& operator >> (std::istream& input, Vec2d& vec)
61 {
62  input >> vec._v[0] >> std::ws >> vec._v[1];
63  return input;
64 }
65 
67 // Vec3f steaming operators.
68 inline std::ostream& operator << (std::ostream& output, const Vec3f& vec)
69 {
70  output << vec._v[0] << " "
71  << vec._v[1] << " "
72  << vec._v[2];
73  return output; // to enable cascading
74 }
75 
76 inline std::istream& operator >> (std::istream& input, Vec3f& vec)
77 {
78  input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
79  return input;
80 }
81 
82 
84 // Vec3d steaming operators.
85 inline std::ostream& operator << (std::ostream& output, const Vec3d& vec)
86 {
87  output << vec._v[0] << " "
88  << vec._v[1] << " "
89  << vec._v[2];
90  return output; // to enable cascading
91 }
92 
93 inline std::istream& operator >> (std::istream& input, Vec3d& vec)
94 {
95  input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
96  return input;
97 }
98 
99 
101 // Vec3f steaming operators.
102 inline std::ostream& operator << (std::ostream& output, const Vec4f& vec)
103 {
104  output << vec._v[0] << " "
105  << vec._v[1] << " "
106  << vec._v[2] << " "
107  << vec._v[3];
108  return output; // to enable cascading
109 }
110 
111 inline std::istream& operator >> (std::istream& input, Vec4f& vec)
112 {
113  input >> vec._v[0] >> std::ws
114  >> vec._v[1] >> std::ws
115  >> vec._v[2] >> std::ws
116  >> vec._v[3];
117  return input;
118 }
119 
120 
121 
123 // Vec4d steaming operators.
124 inline std::ostream& operator << (std::ostream& output, const Vec4d& vec)
125 {
126  output << vec._v[0] << " "
127  << vec._v[1] << " "
128  << vec._v[2] << " "
129  << vec._v[3];
130  return output; // to enable cascading
131 }
132 inline std::istream& operator >> (std::istream& input, Vec4d& vec)
133 {
134  input >> vec._v[0] >> std::ws
135  >> vec._v[1] >> std::ws
136  >> vec._v[2] >> std::ws
137  >> vec._v[3];
138  return input;
139 }
140 
141 
143 // Vec2b steaming operators.
144 inline std::ostream& operator << (std::ostream& output, const Vec2b& vec)
145 {
146  output << (int)vec._v[0] << " "
147  << (int)vec._v[1];
148  return output; // to enable cascading
149 }
150 
151 inline std::istream& operator >> (std::istream& input, Vec2b& vec)
152 {
153  input >> vec._v[0] >> std::ws >> vec._v[1];
154  return input;
155 }
156 
158 // Vec3b steaming operators.
159 inline std::ostream& operator << (std::ostream& output, const Vec3b& vec)
160 {
161  output << (int)vec._v[0] << " "
162  << (int)vec._v[1] << " "
163  << (int)vec._v[2];
164  return output; // to enable cascading
165 }
166 
167 inline std::istream& operator >> (std::istream& input, Vec3b& vec)
168 {
169  input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
170  return input;
171 }
172 
174 // Vec4b steaming operators.
175 inline std::ostream& operator << (std::ostream& output, const Vec4b& vec)
176 {
177  output << (int)vec._v[0] << " "
178  << (int)vec._v[1] << " "
179  << (int)vec._v[2] << " "
180  << (int)vec._v[3];
181  return output; // to enable cascading
182 }
183 
184 inline std::istream& operator >> (std::istream& input, Vec4b& vec)
185 {
186  input >> vec._v[0] >> std::ws
187  >> vec._v[1] >> std::ws
188  >> vec._v[2] >> std::ws
189  >> vec._v[3];
190  return input;
191 }
192 
193 
195 // Vec2s steaming operators.
196 inline std::ostream& operator << (std::ostream& output, const Vec2s& vec)
197 {
198  output << (int)vec._v[0] << " "
199  << (int)vec._v[1];
200  return output; // to enable cascading
201 }
202 
203 inline std::istream& operator >> (std::istream& input, Vec2s& vec)
204 {
205  input >> vec._v[0] >> std::ws >> vec._v[1];
206  return input;
207 }
208 
210 // Vec3s steaming operators.
211 inline std::ostream& operator << (std::ostream& output, const Vec3s& vec)
212 {
213  output << (int)vec._v[0] << " "
214  << (int)vec._v[1] << " "
215  << (int)vec._v[2];
216  return output; // to enable cascading
217 }
218 
219 inline std::istream& operator >> (std::istream& input, Vec3s& vec)
220 {
221  input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
222  return input;
223 }
224 
226 // Vec4s steaming operators.
227 inline std::ostream& operator << (std::ostream& output, const Vec4s& vec)
228 {
229  output << (int)vec._v[0] << " "
230  << (int)vec._v[1] << " "
231  << (int)vec._v[2] << " "
232  << (int)vec._v[3];
233  return output; // to enable cascading
234 }
235 
236 inline std::istream& operator >> (std::istream& input, Vec4s& vec)
237 {
238  input >> vec._v[0] >> std::ws
239  >> vec._v[1] >> std::ws
240  >> vec._v[2] >> std::ws
241  >> vec._v[3];
242  return input;
243 }
244 
245 
246 
248 // Vec2i steaming operators.
249 inline std::ostream& operator << (std::ostream& output, const Vec2i& vec)
250 {
251  output << vec._v[0] << " "
252  << vec._v[1];
253  return output; // to enable cascading
254 }
255 
256 inline std::istream& operator >> (std::istream& input, Vec2i& vec)
257 {
258  input >> vec._v[0] >> std::ws >> vec._v[1];
259  return input;
260 }
261 
263 // Vec3i steaming operators.
264 inline std::ostream& operator << (std::ostream& output, const Vec3i& vec)
265 {
266  output << vec._v[0] << " "
267  << vec._v[1] << " "
268  << vec._v[2];
269  return output; // to enable cascading
270 }
271 
272 inline std::istream& operator >> (std::istream& input, Vec3i& vec)
273 {
274  input >> vec._v[0] >> std::ws >> vec._v[1] >> std::ws >> vec._v[2];
275  return input;
276 }
277 
279 // Vec4i steaming operators.
280 inline std::ostream& operator << (std::ostream& output, const Vec4i& vec)
281 {
282  output << vec._v[0] << " "
283  << vec._v[1] << " "
284  << vec._v[2] << " "
285  << vec._v[3];
286  return output; // to enable cascading
287 }
288 
289 inline std::istream& operator >> (std::istream& input, Vec4i& vec)
290 {
291  input >> vec._v[0] >> std::ws
292  >> vec._v[1] >> std::ws
293  >> vec._v[2] >> std::ws
294  >> vec._v[3];
295  return input;
296 }
297 
298 
300 // Matrixf steaming operators.
301 inline std::ostream& operator<< (std::ostream& os, const Matrixf& m )
302 {
303  os << "{"<<std::endl;
304  for(int row=0; row<4; ++row) {
305  os << "\t";
306  for(int col=0; col<4; ++col)
307  os << m(row,col) << " ";
308  os << std::endl;
309  }
310  os << "}" << std::endl;
311  return os;
312 }
313 
314 
316 // Matrixd steaming operators.
317 inline std::ostream& operator<< (std::ostream& os, const Matrixd& m )
318 {
319  os << "{"<<std::endl;
320  for(int row=0; row<4; ++row) {
321  os << "\t";
322  for(int col=0; col<4; ++col)
323  os << m(row,col) << " ";
324  os << std::endl;
325  }
326  os << "}" << std::endl;
327  return os;
328 }
329 
331 // Vec4ub steaming operators.
332 inline std::ostream& operator << (std::ostream& output, const Vec4ub& vec)
333 {
334  output << (int)vec._v[0] << " "
335  << (int)vec._v[1] << " "
336  << (int)vec._v[2] << " "
337  << (int)vec._v[3];
338  return output; // to enable cascading
339 }
340 
341 inline std::istream& operator >> (std::istream& input, Vec4ub& vec)
342 {
343  input >> vec._v[0] >> std::ws
344  >> vec._v[1] >> std::ws
345  >> vec._v[2] >> std::ws
346  >> vec._v[3];
347  return input;
348 }
349 
350 
352 // Quat steaming operators.
353 inline std::ostream& operator << (std::ostream& output, const Quat& vec)
354 {
355  output << vec._v[0] << " "
356  << vec._v[1] << " "
357  << vec._v[2] << " "
358  << vec._v[3];
359  return output; // to enable cascading
360 }
361 
362 inline std::istream& operator >> (std::istream& input, Quat& vec)
363 {
364  input >> vec._v[0] >> std::ws
365  >> vec._v[1] >> std::ws
366  >> vec._v[2] >> std::ws
367  >> vec._v[3];
368  return input;
369 }
370 
371 
372 
374 // Plane steaming operators.
375 inline std::ostream& operator << (std::ostream& output, const Plane& pl)
376 {
377  output << pl[0] << " "
378  << pl[1] << " "
379  << pl[2] << " "
380  << pl[3];
381  return output; // to enable cascading
382 }
383 
384 inline std::istream& operator >> (std::istream& input, Plane& vec)
385 {
386  input >> vec[0] >> std::ws
387  >> vec[1] >> std::ws
388  >> vec[2] >> std::ws
389  >> vec[3];
390  return input;
391 }
392 
393 } // end of namespace osg
394 #endif
value_type _v[4]
Definition: Vec4i.h:32
value_type _v[3]
Definition: Vec3b.h:35
value_type _v[2]
Definition: Vec2d.h:38
value_type _v[4]
Definition: Vec4b.h:35
value_type _v[2]
Definition: Vec2i.h:32
value_type _v[4]
Definition: Vec4d.h:38
value_type _v[4]
Definition: Vec4f.h:38
value_type _v[2]
Definition: Vec2f.h:39
value_type _v[3]
Definition: Vec3f.h:38
value_type _v[3]
Definition: Vec3i.h:32
value_type _v[3]
Definition: Vec3d.h:39
value_type _v[3]
Definition: Vec3s.h:29
std::ostream & operator<<(std::ostream &output, const Vec2f &vec)
Definition: io_utils.h:40
A plane class. It can be used to represent an infinite plane.
Definition: Plane.h:33
value_type _v[2]
Definition: Vec2b.h:38
std::istream & operator>>(std::istream &input, Vec2f &vec)
Definition: io_utils.h:46
value_type _v[4]
Definition: Vec4ub.h:38
Definition: AlphaFunc.h:19
value_type _v[2]
Definition: Vec2s.h:29
value_type _v[4]
Definition: Vec4s.h:36
Definition: Quat.h:29
value_type _v[4]
Definition: Quat.h:36