Eigen-unsupported  3.4.90 (git rev 9589cc4e7fd8e4538bedef80dd36c7738977a8be)
 
Loading...
Searching...
No Matches
AlignedVector3
1// This file is part of Eigen, a lightweight C++ template library
2// for linear algebra.
3//
4// Copyright (C) 2009 Gael Guennebaud <g.gael@free.fr>
5//
6// This Source Code Form is subject to the terms of the Mozilla
7// Public License v. 2.0. If a copy of the MPL was not distributed
8// with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
9
10#ifndef EIGEN_ALIGNED_VECTOR3_MODULE_H
11#define EIGEN_ALIGNED_VECTOR3_MODULE_H
12
13#include "../../Eigen/Geometry"
14
15#include "../../Eigen/src/Core/util/DisableStupidWarnings.h"
16
17namespace Eigen {
18
27
38// TODO specialize Cwise
39template <typename Scalar_>
40class AlignedVector3;
41
42namespace internal {
43template <typename Scalar_>
44struct traits<AlignedVector3<Scalar_> > : traits<Matrix<Scalar_, 3, 1, 0, 4, 1> > {};
45} // namespace internal
46
47template <typename Scalar_>
48class AlignedVector3 : public MatrixBase<AlignedVector3<Scalar_> > {
49 typedef Matrix<Scalar_, 4, 1> CoeffType;
50 CoeffType m_coeffs;
51
52 public:
54 EIGEN_DENSE_PUBLIC_INTERFACE(AlignedVector3)
55 using Base::operator*;
56
57 inline Index rows() const { return 3; }
58 inline Index cols() const { return 1; }
59
60 Scalar* data() { return m_coeffs.data(); }
61 const Scalar* data() const { return m_coeffs.data(); }
62 Index innerStride() const { return 1; }
63 Index outerStride() const { return 3; }
64
65 inline const Scalar& coeff(Index row, Index col) const { return m_coeffs.coeff(row, col); }
66
67 inline Scalar& coeffRef(Index row, Index col) { return m_coeffs.coeffRef(row, col); }
68
69 inline const Scalar& coeff(Index index) const { return m_coeffs.coeff(index); }
70
71 inline Scalar& coeffRef(Index index) { return m_coeffs.coeffRef(index); }
72
73 inline AlignedVector3() {}
74
75 inline AlignedVector3(const Scalar& x, const Scalar& y, const Scalar& z) : m_coeffs(x, y, z, Scalar(0)) {}
76
77 inline AlignedVector3(const AlignedVector3& other) : Base(), m_coeffs(other.m_coeffs) {}
78
79 template <typename XprType, int Size = XprType::SizeAtCompileTime>
80 struct generic_assign_selector {};
81
82 template <typename XprType>
83 struct generic_assign_selector<XprType, 4> {
84 inline static void run(AlignedVector3& dest, const XprType& src) { dest.m_coeffs = src; }
85 };
86
87 template <typename XprType>
88 struct generic_assign_selector<XprType, 3> {
89 inline static void run(AlignedVector3& dest, const XprType& src) {
90 dest.m_coeffs.template head<3>() = src;
91 dest.m_coeffs.w() = Scalar(0);
92 }
93 };
94
95 template <typename Derived>
96 inline AlignedVector3(const MatrixBase<Derived>& other) {
97 generic_assign_selector<Derived>::run(*this, other.derived());
98 }
99
100 inline AlignedVector3& operator=(const AlignedVector3& other) {
101 m_coeffs = other.m_coeffs;
102 return *this;
103 }
104
105 template <typename Derived>
106 inline AlignedVector3& operator=(const MatrixBase<Derived>& other) {
107 generic_assign_selector<Derived>::run(*this, other.derived());
108 return *this;
109 }
110
111 inline AlignedVector3 operator+(const AlignedVector3& other) const {
112 return AlignedVector3(m_coeffs + other.m_coeffs);
113 }
114
115 inline AlignedVector3& operator+=(const AlignedVector3& other) {
116 m_coeffs += other.m_coeffs;
117 return *this;
118 }
119
120 inline AlignedVector3 operator-(const AlignedVector3& other) const {
121 return AlignedVector3(m_coeffs - other.m_coeffs);
122 }
123
124 inline AlignedVector3 operator-() const { return AlignedVector3(-m_coeffs); }
125
126 inline AlignedVector3 operator-=(const AlignedVector3& other) {
127 m_coeffs -= other.m_coeffs;
128 return *this;
129 }
130
131 inline AlignedVector3 operator*(const Scalar& s) const { return AlignedVector3(m_coeffs * s); }
132
133 inline friend AlignedVector3 operator*(const Scalar& s, const AlignedVector3& vec) {
134 return AlignedVector3(s * vec.m_coeffs);
135 }
136
137 inline AlignedVector3& operator*=(const Scalar& s) {
138 m_coeffs *= s;
139 return *this;
140 }
141
142 inline AlignedVector3 operator/(const Scalar& s) const { return AlignedVector3(m_coeffs / s); }
143
144 inline AlignedVector3& operator/=(const Scalar& s) {
145 m_coeffs /= s;
146 return *this;
147 }
148
149 inline Scalar dot(const AlignedVector3& other) const {
150 eigen_assert(m_coeffs.w() == Scalar(0));
151 eigen_assert(other.m_coeffs.w() == Scalar(0));
152 return m_coeffs.dot(other.m_coeffs);
153 }
154
155 inline void normalize() { m_coeffs /= norm(); }
156
157 inline AlignedVector3 normalized() const { return AlignedVector3(m_coeffs / norm()); }
158
159 inline Scalar sum() const {
160 eigen_assert(m_coeffs.w() == Scalar(0));
161 return m_coeffs.sum();
162 }
163
164 inline Scalar squaredNorm() const {
165 eigen_assert(m_coeffs.w() == Scalar(0));
166 return m_coeffs.squaredNorm();
167 }
168
169 inline Scalar norm() const {
170 using std::sqrt;
171 return sqrt(squaredNorm());
172 }
173
174 inline AlignedVector3 cross(const AlignedVector3& other) const {
175 return AlignedVector3(m_coeffs.cross3(other.m_coeffs));
176 }
177
178 template <typename Derived>
179 inline bool isApprox(const MatrixBase<Derived>& other,
180 const RealScalar& eps = NumTraits<Scalar>::dummy_precision()) const {
181 return m_coeffs.template head<3>().isApprox(other, eps);
182 }
183
184 CoeffType& coeffs() { return m_coeffs; }
185 const CoeffType& coeffs() const { return m_coeffs; }
186};
187
188namespace internal {
189
190template <typename Scalar_>
191struct eval<AlignedVector3<Scalar_>, Dense> {
192 typedef const AlignedVector3<Scalar_>& type;
193};
194
195template <typename Scalar>
196struct evaluator<AlignedVector3<Scalar> > : evaluator<Matrix<Scalar, 4, 1> > {
197 typedef AlignedVector3<Scalar> XprType;
198 typedef evaluator<Matrix<Scalar, 4, 1> > Base;
199
200 evaluator(const XprType& m) : Base(m.coeffs()) {}
201};
202
203} // namespace internal
204
206
207} // namespace Eigen
208
209#include "../../Eigen/src/Core/util/ReenableStupidWarnings.h"
210
211#endif // EIGEN_ALIGNED_VECTOR3_MODULE_H
A vectorization friendly 3D vector.
Definition AlignedVector3:48
FixedSegmentReturnType< N >::Type head(Index n=N)
internal::traits< Derived >::Scalar Scalar
const MatrixSquareRootReturnValue< Derived > sqrt() const
Namespace containing all symbols from the Eigen library.
EIGEN_DEFAULT_DENSE_INDEX_TYPE Index