View on GitHub

Vistle

Distributed Data-parallel Scientific Visualization in VR

vector.h
Go to the documentation of this file.
1#ifndef VISTLE_VECTOR_H
2#define VISTLE_VECTOR_H
3
4#include "scalar.h"
5#include <cmath>
6#include <vistle/util/math.h>
7
8#include <eigen3/Eigen/Core>
9#include <eigen3/Eigen/Geometry>
10#include <eigen3/Eigen/StdVector>
11
12namespace vistle {
13
14typedef Eigen::Quaternion<vistle::Scalar> Quaternion;
15typedef Eigen::AngleAxis<vistle::Scalar> AngleAxis;
16
17template<class T, int d>
18using VistleVector = Eigen::Matrix<T, d, 1>;
19template<int d>
21template<int d>
23template<int d>
25
26template<int d>
28 typedef Eigen::Matrix<Scalar, d, 1> type;
29};
30
31typedef Eigen::Matrix<Scalar, 1, 1> Vector1;
32typedef Eigen::Matrix<Scalar, 2, 1> Vector2;
33typedef Eigen::Matrix<Scalar, 3, 1> Vector3;
34typedef Eigen::Matrix<Scalar, 4, 1> Vector4;
35
37
38typedef Eigen::Matrix<Scalar, 2, 3> Matrix2x3;
39typedef Eigen::Matrix<Scalar, 3, 2> Matrix3x2;
40
41typedef Eigen::Matrix<Scalar, 1, 1> Matrix1;
42typedef Eigen::Matrix<Scalar, 2, 2> Matrix2;
43typedef Eigen::Matrix<Scalar, 3, 3> Matrix3;
44typedef Eigen::Matrix<Scalar, 4, 4> Matrix4;
45
46
47typedef Eigen::Matrix<double, 1, 1> DoubleVector1;
48typedef Eigen::Matrix<double, 2, 1> DoubleVector2;
49typedef Eigen::Matrix<double, 3, 1> DoubleVector3;
50typedef Eigen::Matrix<double, 4, 1> DoubleVector4;
51
52typedef Eigen::Matrix<double, 2, 3> DoubleMatrix2x3;
53typedef Eigen::Matrix<double, 3, 2> DoubleMatrix3x2;
54
55typedef Eigen::Matrix<double, 1, 1> DoubleMatrix1;
56typedef Eigen::Matrix<double, 2, 2> DoubleMatrix2;
57typedef Eigen::Matrix<double, 3, 3> DoubleMatrix3;
58typedef Eigen::Matrix<double, 4, 4> DoubleMatrix4;
59
60template<class Archive, class M>
61void serializeMatrix(Archive &ar, M &m, const unsigned int version)
62{
63 for (int j = 0; j < m.rows(); ++j) {
64 for (int i = 0; i < m.cols(); ++i) {
65 ar &m(j, i);
66 }
67 }
68}
69
70template<class FourColMat>
71Vector3 transformPoint(const FourColMat &t, const Vector3 &v)
72{
73 Vector4 v4;
74 v4 << v, 1;
75 v4 = t * v4;
76 return v4.block<3, 1>(0, 0) / v4[3];
77}
78
79inline Vector3 cross(const Vector &a, const Vector &b)
80{
81 return Vector3(difference_of_products(a[1], b[2], a[2], b[1]), difference_of_products(a[2], b[0], a[0], b[2]),
82 difference_of_products(a[0], b[1], a[1], b[0]));
83}
84
85} // namespace vistle
86
87EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Vector1)
88EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Vector2)
89EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Vector3)
90EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Vector4)
91
92EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix2x3)
93EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix3x2)
94
95//EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix1)
96EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix2)
97EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix3)
98EIGEN_DEFINE_STL_VECTOR_SPECIALIZATION(vistle::Matrix4)
99
100
101namespace boost {
102namespace serialization {
103
104template<class Archive>
105void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
106{
107 vistle::serializeMatrix(ar, v, version);
108}
109
110template<class Archive>
111void serialize(Archive &ar, vistle::Vector2 &v, const unsigned int version)
112{
113 vistle::serializeMatrix(ar, v, version);
114}
115
116template<class Archive>
117void serialize(Archive &ar, vistle::Vector3 &v, const unsigned int version)
118{
119 vistle::serializeMatrix(ar, v, version);
120}
121
122template<class Archive>
123void serialize(Archive &ar, vistle::Vector4 &v, const unsigned int version)
124{
125 vistle::serializeMatrix(ar, v, version);
126}
127
128template<class Archive>
129void serialize(Archive &ar, vistle::Matrix4 &m, const unsigned int version)
130{
131 vistle::serializeMatrix(ar, m, version);
132}
133
134} // namespace serialization
135} // namespace boost
136
137#endif
void serialize(Archive &ar, vistle::Vector1 &v, const unsigned int version)
Definition: vector.h:105
Definition: serialize.h:35
Definition: allobjects.cpp:30
Eigen::Matrix< double, 3, 1 > DoubleVector3
Definition: vector.h:49
Eigen::Matrix< double, 4, 1 > DoubleVector4
Definition: vector.h:50
Eigen::Matrix< Scalar, 3, 2 > Matrix3x2
Definition: vector.h:39
Eigen::Matrix< double, 4, 4 > DoubleMatrix4
Definition: vector.h:58
Eigen::Matrix< Scalar, 2, 3 > Matrix2x3
Definition: vector.h:38
Eigen::Matrix< T, d, 1 > VistleVector
Definition: vector.h:18
Eigen::AngleAxis< vistle::Scalar > AngleAxis
Definition: vector.h:15
Eigen::Matrix< Scalar, 3, 1 > Vector3
Definition: vector.h:33
Eigen::Matrix< double, 1, 1 > DoubleMatrix1
Definition: vector.h:55
Vector3 transformPoint(const FourColMat &t, const Vector3 &v)
Definition: vector.h:71
S difference_of_products(S a, S b, S c, S d)
Definition: math.h:22
Eigen::Matrix< Scalar, 2, 2 > Matrix2
Definition: vector.h:42
Eigen::Matrix< Scalar, 1, 1 > Matrix1
Definition: vector.h:41
void serializeMatrix(Archive &ar, M &m, const unsigned int version)
Definition: vector.h:61
VistleVector< double, d > DoubleVector
Definition: vector.h:22
VistleVector< Scalar, d > ScalarVector
Definition: vector.h:20
Vector3 Vector
Definition: vector.h:36
Eigen::Matrix< Scalar, 3, 3 > Matrix3
Definition: vector.h:43
VistleVector< float, d > FloatVector
Definition: vector.h:24
Eigen::Matrix< double, 2, 3 > DoubleMatrix2x3
Definition: vector.h:52
Eigen::Matrix< Scalar, 4, 1 > Vector4
Definition: vector.h:34
Eigen::Matrix< Scalar, d, 1 > type
Definition: vector.h:28
Eigen::Matrix< double, 2, 1 > DoubleVector2
Definition: vector.h:48
Eigen::Matrix< double, 3, 2 > DoubleMatrix3x2
Definition: vector.h:53
Eigen::Quaternion< vistle::Scalar > Quaternion
Definition: vector.h:14
Eigen::Matrix< double, 3, 3 > DoubleMatrix3
Definition: vector.h:57
Eigen::Matrix< double, 2, 2 > DoubleMatrix2
Definition: vector.h:56
Eigen::Matrix< Scalar, 4, 4 > Matrix4
Definition: vector.h:44
Eigen::Matrix< double, 1, 1 > DoubleVector1
Definition: vector.h:47
Vector3 cross(const Vector &a, const Vector &b)
Definition: vector.h:79
Eigen::Matrix< Scalar, 1, 1 > Vector1
Definition: vector.h:31
Eigen::Matrix< Scalar, 2, 1 > Vector2
Definition: vector.h:32
Definition: vector.h:27