| OpenMesh

EigenVectorT.hh
1 /* ========================================================================= *
2 * *
3 * OpenMesh *
4 * Copyright (c) 2001-2015, RWTH-Aachen University *
5 * Department of Computer Graphics and Multimedia *
6 * All rights reserved. *
7 * www.openmesh.org *
8 * *
9 *---------------------------------------------------------------------------*
10 * This file is part of OpenMesh. *
11 *---------------------------------------------------------------------------*
12 * *
13 * Redistribution and use in source and binary forms, with or without *
14 * modification, are permitted provided that the following conditions *
15 * are met: *
16 * *
17 * 1. Redistributions of source code must retain the above copyright notice, *
18 * this list of conditions and the following disclaimer. *
19 * *
20 * 2. Redistributions in binary form must reproduce the above copyright *
21 * notice, this list of conditions and the following disclaimer in the *
22 * documentation and/or other materials provided with the distribution. *
23 * *
24 * 3. Neither the name of the copyright holder nor the names of its *
25 * contributors may be used to endorse or promote products derived from *
26 * this software without specific prior written permission. *
27 * *
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
30 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
31 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
33 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
34 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
35 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
36 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
37 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
38 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
39 * *
40 * ========================================================================= */
41
45 #pragma once
46
47 #include <Eigen/Core>
48 #include <Eigen/Dense>
49 #include <Eigen/Geometry>
50
51
52 namespace OpenMesh {
53 template <typename _Scalar, int _Rows, int _Cols, int _Options>
54 struct vector_traits<Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>> {
55 static_assert(_Rows != Eigen::Dynamic && _Cols != Eigen::Dynamic,
56 "Should not use dynamic vectors.");
57 static_assert(_Rows == 1 || _Cols == 1, "Should not use matrices.");
58
59 using vector_type = Eigen::Matrix<_Scalar, _Rows, _Cols, _Options>;
60 using value_type = _Scalar;
61 static const size_t size_ = _Rows * _Cols;
62 static size_t size() { return size_; }
63 };
64
65 } // namespace OpenMesh
66
67 namespace Eigen {
68
69 template <typename Derived>
70 typename Derived::Scalar dot(const MatrixBase<Derived> &x,
71 const MatrixBase<Derived> &y) {
72 return x.dot(y);
73 }
74
75 template <typename Derived>
76 typename MatrixBase< Derived >::PlainObject cross(const MatrixBase<Derived> &x, const MatrixBase<Derived> &y) {
77 return x.cross(y);
78 }
79
80 template <typename Derived>
81 typename Derived::Scalar norm(const MatrixBase<Derived> &x) {
82 return x.norm();
83 }
84
85 template <typename Derived>
86 typename Derived::Scalar sqrnorm(const MatrixBase<Derived> &x) {
87 return x.dot(x);
88 }
89
90 template <typename Derived>
91 MatrixBase<Derived> &normalize(MatrixBase<Derived> &x) {
92 x /= x.norm();
93 return x;
94 }
95
96 template <typename Derived>
97 MatrixBase<Derived> &vectorize(MatrixBase<Derived> &x,
98 typename Derived::Scalar const &val) {
99 x.fill(val);
100 return x;
101 }
102
103 } // namespace Eigen
104
OpenMesh::vector_traits
Helper class providing information about a vector type.
Definition: vector_traits.hh:88
OpenMesh::dot
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:176
Eigen
Definition: EigenVectorT.hh:67
OpenMesh::cross
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Definition: VectorAdapter.hh:191
OpenMesh::vector_traits::size_
static const size_t size_
size/dimension of the vector
Definition: vector_traits.hh:97
OpenMesh::vector_traits::size
static size_t size()
size/dimension of the vector
Definition: vector_traits.hh:100
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition: MeshItems.hh:59