Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
SpatSupportStream.h
1// trax track library
2// AD 2015
3//
4// "There's a truth begging to be told"
5//
6// Powderfinger
7//
8// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
9// Copyright (c) 2019 Marc-Michael Horstmann
10//
11// Permission is hereby granted to any person obtaining a copy of this software
12// and associated source code (the "Software"), to use, view, and study the
13// Software for personal or internal business purposes, subject to the following
14// conditions:
15//
16// 1. Redistribution, modification, sublicensing, or commercial use of the
17// Software is NOT permitted without prior written consent from the copyright
18// holder.
19//
20// 2. The Software is provided "AS IS", without warranty of any kind, express
21// or implied.
22//
23// 3. All copies of the Software must retain this license notice.
24//
25// For further information, please contact: horstmann.marc@trendverlag.de
26
27#pragma once
28
29#include "common/support/CommonSupportStream.h"
30
31#include "spat/Box.h"
32#include "spat/Frame.h"
33#include "spat/Matrix.h"
34#include "spat/Rect.h"
35#include "spat/Sphere.h"
36
37#include <iostream>
38#include <iomanip>
39
40namespace spat{
41
45 template<typename Valtype>
46 std::ostream& operator << ( std::ostream& os, const Position<Valtype>& p );
47
48 template<typename Valtype>
49 std::istream& operator >> ( std::istream& is, Position<Valtype>& p );
50
51 template<typename Valtype>
52 std::ostream& operator << ( std::ostream& os, const Position2D<Valtype>& p );
53
54 template<typename Valtype>
55 std::istream& operator >> ( std::istream& is, Position2D<Valtype>& p );
56
57 template<typename Valtype>
58 std::ostream& operator << ( std::ostream& os, const PositionH<Valtype>& p );
59
60 template<typename Valtype>
61 std::istream& operator >> ( std::istream& is, PositionH<Valtype>& p );
62
63 template<typename Valtype>
64 std::ostream& operator << ( std::ostream& os, const Vector<Valtype>& v );
65
66 template<typename Valtype>
67 std::istream& operator >> ( std::istream& is, Vector<Valtype>& v );
68
69 template<typename Valtype>
70 std::ostream& operator << ( std::ostream& os, const Vector2D<Valtype>& v );
71
72 template<typename Valtype>
73 std::istream& operator >> ( std::istream& is, Vector2D<Valtype>& v );
74
75 template<typename Valtype,typename ValtypeT>
76 std::ostream& operator << ( std::ostream& os, const VectorBundle<Valtype,ValtypeT>& vb );
77
78 template<typename Valtype,typename ValtypeT>
79 std::istream& operator >> ( std::istream& is, VectorBundle<Valtype,ValtypeT>& vb );
80
81 template<typename Valtype,typename ValtypeT>
82 std::ostream& operator << ( std::ostream& os, const VectorBundle2<Valtype,ValtypeT>& vb );
83
84 template<typename Valtype,typename ValtypeT>
85 std::istream& operator >> ( std::istream& is, VectorBundle2<Valtype,ValtypeT>& vb );
86
87 template<typename Valtype,typename ValtypeT>
88 std::ostream& operator << ( std::ostream& os, const Frame<Valtype,ValtypeT>& f );
89
90 template<typename Valtype,typename ValtypeT>
91 std::istream& operator >> ( std::istream& is, Frame<Valtype,ValtypeT>& f );
92
93 template<typename Valtype>
94 std::ostream& operator << ( std::ostream& os, const Box<Valtype>& b );
95
96 template<typename Valtype>
97 std::istream& operator >> ( std::istream& is, Box<Valtype>& b );
98
99 template<typename Valtype>
100 std::ostream& operator << ( std::ostream& os, const Rect<Valtype>& r );
101
102 template<typename Valtype>
103 std::istream& operator >> ( std::istream& is, Rect<Valtype>& r );
104
105 template<typename Valtype>
106 std::ostream& operator << ( std::ostream& os, const Sphere<Valtype>& s );
107
108 template<typename Valtype>
109 std::istream& operator >> ( std::istream& is, Sphere<Valtype>& s );
110
111
112 template<typename Valtype,typename ValtypeT>
113 void OrthogonalityDump( std::ostream& os, const Frame<Valtype,ValtypeT>& f );
114
118 template< typename Valtype,
119 const unsigned short nCols,
120 const unsigned short nRows >
121 std::ostream& operator << ( std::ostream& os, const Matrix<Valtype,nCols,nRows>& m );
122
123 template< typename Valtype,
124 const unsigned short nCols,
125 const unsigned short nRows >
126 std::istream& operator >> ( std::istream& is, Matrix<Valtype,nCols,nRows>& m );
128
129
130template<typename Valtype>
131std::ostream& operator << ( std::ostream& os, const Position<Valtype>& p ){
132 os << "Position( " << p.x << ", " << p.y << ", " << p.z << " )";
133 return os;
134}
135
136template<typename Valtype>
137std::istream& operator >> ( std::istream& is, Position<Valtype>& p )
138{
139 common::StreamInHead( is, "Position" );
140
141 char c;
142 is >> p.x;
143 is >> c; assert( c == ',' );
144 is >> p.y;
145 is >> c; assert( c == ',' );
146 is >> p.z;
147 is >> c; assert( c == ')' );
148 return is;
149}
150
151template<typename Valtype>
152std::ostream& operator << ( std::ostream& os, const Position2D<Valtype>& p ){
153 os << "Position2D( " << p.x << ", " << p.y << " )";
154 return os;
155}
156
157template<typename Valtype>
158std::istream& operator >> ( std::istream& is, Position2D<Valtype>& p )
159{
160 common::StreamInHead( is, "Position2D" );
161
162 char c;
163 is >> p.x;
164 is >> c; assert( c == ',' );
165 is >> p.y;
166 is >> c; assert( c == ')' );
167 return is;
168}
169
170template<typename Valtype>
171std::ostream& operator<<( std::ostream& os, const PositionH<Valtype>& p ){
172 os << "PositionH( " << p.x << ", " << p.y << ", " << p.z << ", " << p.w << " )";
173 return os;
174}
175
176template<typename Valtype>
177std::istream& operator>>( std::istream& is, PositionH<Valtype>& p )
178{
179 common::StreamInHead( is, "PositionH" );
180
181 char c;
182 is >> p.x;
183 is >> c; assert( c == ',' );
184 is >> p.y;
185 is >> c; assert( c == ',' );
186 is >> p.z;
187 is >> c; assert( c == ',' );
188 is >> p.w;
189 is >> c; assert( c == ')' );
190 return is;
191}
192
193template<typename Valtype>
194std::ostream& operator << ( std::ostream& os, const Vector<Valtype>& v ){
195 os << "Vector( " << v.dx << ", " << v.dy << ", " << v.dz << " )";
196 return os;
197}
198
199template<typename Valtype>
200std::istream& operator >> ( std::istream& is, Vector<Valtype>& v )
201{
202 common::StreamInHead( is, "Vector" );
203
204 char c;
205 is >> v.dx;
206 is >> c; assert( c == ',' );
207 is >> v.dy;
208 is >> c; assert( c == ',' );
209 is >> v.dz;
210 is >> c; assert( c == ')' );
211 return is;
212}
213
214template<typename Valtype>
215std::ostream& operator << ( std::ostream& os, const Vector2D<Valtype>& v ){
216 os << "Vector2D( " << v.dx << ", " << v.dy << " )";
217 return os;
218}
219
220template<typename Valtype>
221std::istream& operator >> ( std::istream& is, Vector2D<Valtype>& v )
222{
223 common::StreamInHead( is, "Vector2D" );
224
225 char c;
226 is >> v.dx;
227 is >> c; assert( c == ',' );
228 is >> v.dy;
229 is >> c; assert( c == ')' );
230 return is;
231}
232
233template<typename Valtype,typename ValtypeT>
234std::ostream& operator << ( std::ostream& os, const VectorBundle<Valtype,ValtypeT>& vb ){
235 os << "VectorBundle( " << vb.P << ", " << vb.T << " )";
236 return os;
237}
238
239template<typename Valtype,typename ValtypeT>
240std::istream& operator >> ( std::istream& is, VectorBundle<Valtype,ValtypeT>& vb )
241{
242 common::StreamInHead( is, "VectorBundle" );
243
244 char c;
245 is >> vb.P;
246 is >> c; assert( c == ',' );
247 is >> vb.T;
248 is >> c; assert( c == ')' );
249 return is;
250}
251
252template<typename Valtype,typename ValtypeT>
253std::ostream& operator << ( std::ostream& os, const VectorBundle2<Valtype,ValtypeT>& vb ){
254 os << "VectorBundle2( " << vb.P << ", " << vb.T << ", " << vb.N << " )";
255 return os;
256}
257
258template<typename Valtype,typename ValtypeT>
259std::istream& operator >> ( std::istream& is, VectorBundle2<Valtype,ValtypeT>& vb )
260{
261 common::StreamInHead( is, "VectorBundle2" );
262
263 char c;
264 is >> vb.P;
265 is >> c; assert( c == ',' );
266 is >> vb.T;
267 is >> c; assert( c == ',' );
268 is >> vb.N;
269 is >> c; assert( c == ')' );
270 return is;
271}
272
273template<typename Valtype,typename ValtypeT>
274std::ostream& operator << ( std::ostream& os, const Frame<Valtype,ValtypeT>& f ){
275 os << "Frame( " << f.P << ", " << f.T << ", " << f.N << ", " << f.B << " )";
276 return os;
277}
278
279template<typename Valtype,typename ValtypeT>
280std::istream& operator >> ( std::istream& is, Frame<Valtype,ValtypeT>& f )
281{
282 common::StreamInHead( is, "Frame" );
283
284 char c;
285 is >> f.P;
286 is >> c; assert( c == ',' );
287 is >> f.T;
288 is >> c; assert( c == ',' );
289 is >> f.N;
290 is >> c; assert( c == ',' );
291 is >> f.B;
292 is >> c; assert( c == ')' );
293 return is;
294}
295
296template<typename Valtype>
297std::ostream& operator << ( std::ostream& os, const Box<Valtype>& b ){
298 os << "Box( " << b.m_WidthX << ", " << b.m_WidthY << ", " << b.m_WidthZ << " )";
299 return os;
300}
301
302template<typename Valtype>
303std::istream& operator >> ( std::istream& is, Box<Valtype>& b )
304{
305 common::StreamInHead( is, "Box" );
306
307 char c;
308 is >> b.m_WidthX;
309 is >> c; assert( c == ',' );
310 is >> b.m_WidthY;
311 is >> c; assert( c == ',' );
312 is >> b.m_WidthZ;
313 is >> c; assert( c == ')' );
314 return is;
315}
316
317template<typename Valtype>
318std::ostream& operator << ( std::ostream& os, const Rect<Valtype>& r ){
319 os << "Rect( " << r.m_Width << ", " << r.m_Height << " )";
320 return os;
321}
322
323template<typename Valtype>
324std::istream& operator >> ( std::istream& is, Rect<Valtype>& r )
325{
326 common::StreamInHead( is, "Rect" );
327
328 char c;
329 is >> r.m_Width;
330 is >> c; assert( c == ',' );
331 is >> r.m_Height;
332 is >> c; assert( c == ')' );
333 return is;
334}
335
336template<typename Valtype>
337std::ostream& operator << ( std::ostream& os, const Sphere<Valtype>& s ){
338 os << "Sphere( " << s.c << ", " << s.r << " )";
339 return os;
340}
341
342template<typename Valtype>
343std::istream& operator >> ( std::istream& is, Sphere<Valtype>& s )
344{
345 common::StreamInHead( is, "Sphere" );
346
347 char c;
348 is >> s.c;
349 is >> c; assert( c == ',' );
350 is >> s.r;
351 is >> c; assert( c == ')' );
352 return is;
353}
354
355template<typename Valtype,typename ValtypeT>
356void OrthogonalityDump( std::ostream& os, const Frame<Valtype,ValtypeT>& f ){
357 os << "T*T: " << f.T*f.T << ", T*N: " << f.T*f.N << ", T*B: " << f.T*f.B << std::endl;
358 os << "N*T: " << f.N*f.T << ", N*N: " << f.N*f.N << ", T*B: " << f.N*f.B << std::endl;
359 os << "B*T: " << f.B*f.T << ", B*N: " << f.B*f.N << ", B*B: " << f.B*f.B << std::endl;
360}
361
362template< typename Valtype,
363 const unsigned short nCols,
364 const unsigned short nRows >
365std::ostream& operator << ( std::ostream& os, const Matrix<Valtype,nCols,nRows>& matrix ){
366 os << "<Matrix";
367 for( unsigned short i = 0; i < nRows; ++i ){
368 os << "\n";
369 for( unsigned short j = 0; j < nCols; ++j ){
370 os << "(" << j << "," << i << ") = " << matrix( j, i ) << "\t";
371 }
372 }
373 os << "\n/>";
374 return os;
375}
376
377template< typename Valtype,
378 const unsigned short nCols,
379 const unsigned short nRows >
380std::istream& operator >> ( std::istream& is, Matrix<Valtype,nCols,nRows>& m ){
381 // this will need a parser to work properly ...
382 throw std::logic_error{ "Not implemented" };
383 return is;
384}
385
386}
Matrix template for arbitrary dimensions and value type.
Definition Matrix.h:63
The namespace provides classes and methods for spatial computations.
Definition Box.h:32
Axis aligned box.
Definition Box.h:41
A Frame ("TNBFrame") describes a location in 3d space and an orientation using a right handed coordin...
Definition Frame.h:52
Implements a 2D - position in cartesian coordinates.
Definition Position2D.h:45
Implements a 4D - position in homogenous coordinates.
Definition PositionH.h:41
Implements a 3D - position in cartesian coordinates.
Definition Position.h:46
Axis aligned rectangle.
Definition Rect.h:41
Sphere with center and radius.
Definition Sphere.h:39
Implements a 2D - vector in cartesian coordinates.
Definition Vector2D.h:46
Implements a tangential space bundle.
Definition VectorBundle2.h:43
Implements a Vector bundle.
Definition VectorBundle.h:42
Implements a 3D - vector in cartesian coordinates.
Definition Vector.h:48