MeshLib
 
Loading...
Searching...
No Matches
MRStreamOperators.h
Go to the documentation of this file.
1#pragma once
2#include "MRMeshFwd.h"
3#include "MRVector2.h"
4#include "MRVector3.h"
5#include "MRVector4.h"
6#include "MRMatrix3.h"
7#include "MRMatrix4.h"
8#include "MRPlane3.h"
9#include "MRBitSet.h"
10#include "MRTriPoint.h"
11#include "MRAffineXf3.h"
12#include "MRPointOnFace.h"
13
14
24namespace MR
25{
26 // =====================================================================
27 // Vector
28 template <typename T>
29 inline std::ostream& operator << ( std::ostream& s, const Vector2<T>& vec )
30 {
31 return s << vec.x << ' ' << vec.y;
32 }
33 template <typename T>
34 inline std::ostream& operator << ( std::ostream& s, const Vector3<T>& vec )
35 {
36 return s << vec.x << ' ' << vec.y << ' ' << vec.z;
37 }
38 template <typename T>
39 inline std::ostream& operator << ( std::ostream& s, const Vector4<T>& vec )
40 {
41 return s << vec.x << ' ' << vec.y << ' ' << vec.z << ' ' << vec.w;
42 }
43
44 template <typename T>
45 inline std::istream& operator >> ( std::istream& s, Vector2<T>& vec )
46 {
47 return s >> vec.x >> vec.y;
48 }
49 template <typename T>
50 inline std::istream& operator >> ( std::istream& s, Vector3<T>& vec )
51 {
52 return s >> vec.x >> vec.y >> vec.z;
53 }
54 template <typename T>
55 inline std::istream& operator >> ( std::istream& s, Vector4<T>& vec )
56 {
57 return s >> vec.x >> vec.y >> vec.z >> vec.w;
58 }
59
60 // =====================================================================
61 // Matrix3
62 template <typename T>
63 inline std::ostream& operator << ( std::ostream& s, const Matrix3<T>& mat )
64 {
65 return s << mat.x << '\n' << mat.y << '\n' << mat.z << '\n';
66 }
67
68 template <typename T>
69 inline std::istream& operator >> ( std::istream& s, Matrix3<T>& mat )
70 {
71 return s >> mat.x >> mat.y >> mat.z;
72 }
73
74 // =====================================================================
75 // Matrix4
76 template <typename T>
77 inline std::ostream& operator << ( std::ostream& s, const Matrix4<T>& mat )
78 {
79 return s << mat.x << '\n' << mat.y << '\n' << mat.z << '\n' << mat.w << '\n';
80 }
81
82 template <typename T>
83 inline std::istream& operator >> ( std::istream& s, Matrix4<T>& mat )
84 {
85 return s >> mat.x >> mat.y >> mat.z >> mat.w;
86 }
87
88 // =====================================================================
89 // Plane3
90 template <typename T>
91 inline std::ostream& operator << ( std::ostream& s, const Plane3<T>& pl )
92 {
93 return s << pl.n << '\n' << pl.d;
94 }
95
96 template <typename T>
97 inline std::istream& operator >> ( std::istream& s, Plane3<T>& pl )
98 {
99 return s >> pl.n >> pl.d;
100 }
101
102 // =====================================================================
103 // Line3
104 template <typename T>
105 inline std::ostream& operator << ( std::ostream& s, const Line3<T>& l )
106 {
107 return s << l.p << '\n' << l.d;
108 }
109
110 template <typename T>
111 inline std::istream& operator >> ( std::istream& s, Line3<T>& l )
112 {
113 return s >> l.p >> l.d;
114 }
115
116 // =====================================================================
117 // TriPoint
118 template <typename T>
119 inline std::ostream& operator << ( std::ostream& s, const TriPoint<T>& tp )
120 {
121 return s << tp.a << ' ' << tp.b;
122 }
123
124 template <typename T>
125 inline std::istream& operator >> ( std::istream& s, TriPoint<T>& tp )
126 {
127 s >> tp.a >> tp.b;
128 return s;
129 }
130
131 // =====================================================================
132 // AffineXf3
133 template <typename T>
134 inline std::ostream& operator << ( std::ostream& s, const AffineXf3<T>& xf )
135 {
136 return s << xf.A << xf.b;
137 }
138
139 template <typename T>
140 inline std::istream& operator >> ( std::istream& s, AffineXf3<T>& xf )
141 {
142 return s >> xf.A >> xf.b;
143 }
144
145 // =====================================================================
146 // PointOnFace
147 inline std::ostream& operator << ( std::ostream& s, const PointOnFace& pof )
148 {
149 return s << pof.face << '\n' << pof.point;
150 }
151
152 inline std::istream& operator >> ( std::istream& s, PointOnFace& pof )
153 {
154 int a;
155 s >> a >> pof.point;
156 pof.face = FaceId( a );
157 return s;
158 }
159
160
161 // =====================================================================
162 // Box
163 template<typename V>
164 inline std::ostream& operator << ( std::ostream& s, const Box<V>& box )
165 {
166 return s << box.min << '\n' << box.max;
167 }
168
169 template<typename V>
170 inline std::istream& operator >> ( std::istream& s, Box<V>& box )
171 {
172 return s >> box.min >> box.max;
173 }
174}
175
int FaceId
Definition MRDotNet/MRMeshFwd.h:53
Definition MRCameraOrientationPlugin.h:7
std::istream & operator>>(std::istream &s, Vector2< T > &vec)
Definition MRStreamOperators.h:45
std::ostream & operator<<(std::ostream &s, const Vector2< T > &vec)
Definition MRStreamOperators.h:29
Definition MRMesh/MRAffineXf.h:14
V b
Definition MRMesh/MRAffineXf.h:19
M A
Definition MRMesh/MRAffineXf.h:18
Box given by its min- and max- corners.
Definition MRMesh/MRBox.h:23
V max
Definition MRMesh/MRBox.h:27
V min
Definition MRMesh/MRBox.h:27
Definition MRLine.h:12
V d
Definition MRLine.h:15
V p
Definition MRLine.h:15
Definition MRMesh/MRMatrix3.h:13
Vector3< T > x
rows, identity matrix by default
Definition MRMesh/MRMatrix3.h:18
Vector3< T > y
Definition MRMesh/MRMatrix3.h:19
Vector3< T > z
Definition MRMesh/MRMatrix3.h:20
Definition MRMatrix4.h:14
Vector4< T > z
Definition MRMatrix4.h:21
Vector4< T > y
Definition MRMatrix4.h:20
Vector4< T > w
Definition MRMatrix4.h:22
Vector4< T > x
rows, identity matrix by default
Definition MRMatrix4.h:19
Definition MRPlane3.h:12
Vector3< T > n
Definition MRPlane3.h:13
T d
Definition MRPlane3.h:14
Definition MRPointOnFace.h:11
FaceId face
Definition MRPointOnFace.h:12
Vector3f point
Definition MRPointOnFace.h:13
encodes a point inside a triangle using barycentric coordinates
Definition MRTriPoint.h:14
T b
b in [0,1], b=0 => point is on [v0,v1] edge, b=1 => point is in v2
Definition MRTriPoint.h:18
T a
a in [0,1], a=0 => point is on [v2,v0] edge, a=1 => point is in v1
Definition MRTriPoint.h:17
Definition MRVector2.h:18
T x
Definition MRVector2.h:24
T y
Definition MRVector2.h:24
Definition MRMesh/MRVector3.h:19
T x
Definition MRMesh/MRVector3.h:25
T y
Definition MRMesh/MRVector3.h:25
T z
Definition MRMesh/MRVector3.h:25
Definition MRVector4.h:13
T y
Definition MRVector4.h:19
T z
Definition MRVector4.h:19
T x
Definition MRVector4.h:19
T w
Definition MRVector4.h:19