Loading...
Searching...
No Matches
VectorT.hh
/* ========================================================================= *
* *
* OpenMesh *
* Copyright (c) 2001-2022, RWTH-Aachen University *
* Department of Computer Graphics and Multimedia *
* All rights reserved. *
* www.openmesh.org *
* *
*---------------------------------------------------------------------------*
* This file is part of OpenMesh. *
*---------------------------------------------------------------------------*
* *
* Redistribution and use in source and binary forms, with or without *
* modification, are permitted provided that the following conditions *
* are met: *
* *
* 1. Redistributions of source code must retain the above copyright notice, *
* this list of conditions and the following disclaimer. *
* *
* 2. Redistributions in binary form must reproduce the above copyright *
* notice, this list of conditions and the following disclaimer in the *
* documentation and/or other materials provided with the distribution. *
* *
* 3. Neither the name of the copyright holder nor the names of its *
* contributors may be used to endorse or promote products derived from *
* this software without specific prior written permission. *
* *
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS *
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED *
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A *
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER *
* OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, *
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, *
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR *
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF *
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING *
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS *
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. *
* *
* ========================================================================= */
//=============================================================================
//
// CLASS VectorT
//
//=============================================================================
// Don't parse this header file with doxygen since
// for some reason (obviously due to a bug in doxygen,
// bugreport: https://bugzilla.gnome.org/show_bug.cgi?id=629182)
// macro expansion and preprocessor defines
// don't work properly.
#if ((defined(_MSC_VER) && (_MSC_VER >= 1900)) || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY)
#include "Vector11T.hh"
#else
#ifndef DOXYGEN
#ifndef OPENMESH_VECTOR_HH
#define OPENMESH_VECTOR_HH
//== INCLUDES =================================================================
#include <OpenMesh/Core/System/config.h>
#include <ostream>
#include <cmath>
#include <cassert>
#include <cstring>
#if defined(__GNUC__) && defined(__SSE__)
#include <xmmintrin.h>
#endif
//== NAMESPACES ===============================================================
namespace OpenMesh {
//== CLASS DEFINITION =========================================================
template<typename Scalar, int N> class VectorDataT {
public:
Scalar values_[N];
};
#if defined(__GNUC__) && defined(__SSE__)
template<> class VectorDataT<float, 4> {
public:
union {
__m128 m128;
float values_[4];
};
};
#endif
//== CLASS DEFINITION =========================================================
#define DIM N
#define TEMPLATE_HEADER template <typename Scalar, int N>
#define CLASSNAME VectorT
#define DERIVED VectorDataT<Scalar,N>
#define unroll(expr) for (int i=0; i<N; ++i) expr(i)
#include "VectorT_inc.hh"
#undef DIM
#undef TEMPLATE_HEADER
#undef CLASSNAME
#undef DERIVED
#undef unroll
//== PARTIAL TEMPLATE SPECIALIZATIONS =========================================
#if OM_PARTIAL_SPECIALIZATION
#define TEMPLATE_HEADER template <typename Scalar>
#define CLASSNAME VectorT<Scalar,DIM>
#define DERIVED VectorDataT<Scalar,DIM>
#define DIM 2
#define unroll(expr) expr(0) expr(1)
#define unroll_comb(expr, op) expr(0) op expr(1)
#define unroll_csv(expr) expr(0), expr(1)
#include "VectorT_inc.hh"
#undef DIM
#undef unroll
#undef unroll_comb
#undef unroll_csv
#define DIM 3
#define unroll(expr) expr(0) expr(1) expr(2)
#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2)
#define unroll_csv(expr) expr(0), expr(1), expr(2)
#include "VectorT_inc.hh"
#undef DIM
#undef unroll
#undef unroll_comb
#undef unroll_csv
#define DIM 4
#define unroll(expr) expr(0) expr(1) expr(2) expr(3)
#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3)
#define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3)
#include "VectorT_inc.hh"
#undef DIM
#undef unroll
#undef unroll_comb
#undef unroll_csv
#define DIM 5
#define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4)
#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4)
#define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4)
#include "VectorT_inc.hh"
#undef DIM
#undef unroll
#undef unroll_comb
#undef unroll_csv
#define DIM 6
#define unroll(expr) expr(0) expr(1) expr(2) expr(3) expr(4) expr(5)
#define unroll_comb(expr, op) expr(0) op expr(1) op expr(2) op expr(3) op expr(4) op expr(5)
#define unroll_csv(expr) expr(0), expr(1), expr(2), expr(3), expr(4), expr(5)
#include "VectorT_inc.hh"
#undef DIM
#undef unroll
#undef unroll_comb
#undef unroll_csv
#undef TEMPLATE_HEADER
#undef CLASSNAME
#undef DERIVED
//== FULL TEMPLATE SPECIALIZATIONS ============================================
#else
template<>
inline VectorT<float,3>
VectorT<float,3>::operator%(const VectorT<float,3>& _rhs) const
{
return
VectorT<float,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
}
template<>
inline VectorT<double,3>
VectorT<double,3>::operator%(const VectorT<double,3>& _rhs) const
{
return
VectorT<double,3>(values_[1]*_rhs.values_[2]-values_[2]*_rhs.values_[1],
values_[2]*_rhs.values_[0]-values_[0]*_rhs.values_[2],
values_[0]*_rhs.values_[1]-values_[1]*_rhs.values_[0]);
}
#endif
//== GLOBAL FUNCTIONS =========================================================
template<typename Scalar1, typename Scalar2,int N>
inline VectorT<Scalar1,N> operator*(Scalar2 _s, const VectorT<Scalar1,N>& _v) {
return _v*_s;
}
template<typename Scalar, int N>
inline Scalar
dot(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
return (_v1 | _v2);
}
template<typename Scalar, int N>
inline VectorT<Scalar,N>
cross(const VectorT<Scalar,N>& _v1, const VectorT<Scalar,N>& _v2) {
return (_v1 % _v2);
}
template<typename Scalar, int DIM>
Scalar norm(const VectorT<Scalar, DIM>& _v) {
return _v.norm();
}
template<typename Scalar, int DIM>
Scalar sqrnorm(const VectorT<Scalar, DIM>& _v) {
return _v.sqrnorm();
}
template<typename Scalar, int DIM, typename OtherScalar>
VectorT<Scalar, DIM>& vectorize(VectorT<Scalar, DIM>& _v, OtherScalar const& _val) {
return _v.vectorize(_val);
}
template<typename Scalar, int DIM>
VectorT<Scalar, DIM>& normalize(VectorT<Scalar, DIM>& _v) {
return _v.normalize();
}
template<typename Scalar, int DIM>
VectorT<Scalar, DIM>& maximize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
return _v1.maximize(_v2);
}
template<typename Scalar, int DIM>
VectorT<Scalar, DIM>& minimize(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
return _v1.minimize(_v2);
}
template<typename Scalar, int DIM>
VectorT<Scalar, DIM> max(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
return VectorT<Scalar, DIM>(_v1).maximize(_v2);
}
template<typename Scalar, int DIM>
VectorT<Scalar, DIM> min(VectorT<Scalar, DIM>& _v1, VectorT<Scalar, DIM>& _v2) {
return VectorT<Scalar, DIM>(_v1).minimize(_v2);
}
//== TYPEDEFS =================================================================
typedef VectorT<signed char,1> Vec1c;
typedef VectorT<unsigned char,1> Vec1uc;
typedef VectorT<signed short int,1> Vec1s;
typedef VectorT<unsigned short int,1> Vec1us;
typedef VectorT<signed int,1> Vec1i;
typedef VectorT<unsigned int,1> Vec1ui;
typedef VectorT<float,1> Vec1f;
typedef VectorT<double,1> Vec1d;
typedef VectorT<signed char,2> Vec2c;
typedef VectorT<unsigned char,2> Vec2uc;
typedef VectorT<signed short int,2> Vec2s;
typedef VectorT<unsigned short int,2> Vec2us;
typedef VectorT<signed int,2> Vec2i;
typedef VectorT<unsigned int,2> Vec2ui;
typedef VectorT<float,2> Vec2f;
typedef VectorT<double,2> Vec2d;
typedef VectorT<signed char,3> Vec3c;
typedef VectorT<unsigned char,3> Vec3uc;
typedef VectorT<signed short int,3> Vec3s;
typedef VectorT<unsigned short int,3> Vec3us;
typedef VectorT<signed int,3> Vec3i;
typedef VectorT<unsigned int,3> Vec3ui;
typedef VectorT<float,3> Vec3f;
typedef VectorT<double,3> Vec3d;
typedef VectorT<bool,3> Vec3b;
typedef VectorT<signed char,4> Vec4c;
typedef VectorT<unsigned char,4> Vec4uc;
typedef VectorT<signed short int,4> Vec4s;
typedef VectorT<unsigned short int,4> Vec4us;
typedef VectorT<signed int,4> Vec4i;
typedef VectorT<unsigned int,4> Vec4ui;
typedef VectorT<float,4> Vec4f;
typedef VectorT<double,4> Vec4d;
typedef VectorT<signed char, 5> Vec5c;
typedef VectorT<unsigned char, 5> Vec5uc;
typedef VectorT<signed short int, 5> Vec5s;
typedef VectorT<unsigned short int, 5> Vec5us;
typedef VectorT<signed int, 5> Vec5i;
typedef VectorT<unsigned int, 5> Vec5ui;
typedef VectorT<float, 5> Vec5f;
typedef VectorT<double, 5> Vec5d;
typedef VectorT<signed char,6> Vec6c;
typedef VectorT<unsigned char,6> Vec6uc;
typedef VectorT<signed short int,6> Vec6s;
typedef VectorT<unsigned short int,6> Vec6us;
typedef VectorT<signed int,6> Vec6i;
typedef VectorT<unsigned int,6> Vec6ui;
typedef VectorT<float,6> Vec6f;
typedef VectorT<double,6> Vec6d;
//=============================================================================
} // namespace OpenMesh
//=============================================================================
#endif // OPENMESH_VECTOR_HH defined
//=============================================================================
#endif // DOXYGEN
#endif // C++11
OpenMesh
Contains all the mesh ingredients like the polygonal mesh, the triangle mesh, different mesh kernels ...
Definition MeshItems.hh:59
OpenMesh::Vec3c
VectorT< signed char, 3 > Vec3c
3-byte signed vector
Definition Vector11T.hh:838
OpenMesh::Vec3d
VectorT< double, 3 > Vec3d
3-double vector
Definition Vector11T.hh:852
OpenMesh::Vec1i
VectorT< signed int, 1 > Vec1i
1-int signed vector
Definition Vector11T.hh:812
OpenMesh::Vec5uc
VectorT< unsigned char, 5 > Vec5uc
5-byte unsigned vector
Definition Vector11T.hh:876
OpenMesh::Vec2ui
VectorT< unsigned int, 2 > Vec2ui
2-int unsigned vector
Definition Vector11T.hh:831
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
OpenMesh::Vec1d
VectorT< double, 1 > Vec1d
1-double vector
Definition Vector11T.hh:818
OpenMesh::Vec4d
VectorT< double, 4 > Vec4d
4-double vector
Definition Vector11T.hh:871
OpenMesh::Vec2f
VectorT< float, 2 > Vec2f
2-float vector
Definition Vector11T.hh:833
OpenMesh::Vec3s
VectorT< signed short int, 3 > Vec3s
3-short signed vector
Definition Vector11T.hh:842
OpenMesh::Vec2d
VectorT< double, 2 > Vec2d
2-double vector
Definition Vector11T.hh:835
OpenMesh::Vec5i
VectorT< signed int, 5 > Vec5i
5-int signed vector
Definition Vector11T.hh:882
OpenMesh::Vec4c
VectorT< signed char, 4 > Vec4c
4-byte signed vector
Definition Vector11T.hh:857
OpenMesh::Vec5c
VectorT< signed char, 5 > Vec5c
5-byte signed vector
Definition Vector11T.hh:874
OpenMesh::Vec5ui
VectorT< unsigned int, 5 > Vec5ui
5-int unsigned vector
Definition Vector11T.hh:884
OpenMesh::Vec5s
VectorT< signed short int, 5 > Vec5s
5-short signed vector
Definition Vector11T.hh:878
OpenMesh::Vec4ui
VectorT< unsigned int, 4 > Vec4ui
4-int unsigned vector
Definition Vector11T.hh:867
OpenMesh::Vec3us
VectorT< unsigned short int, 3 > Vec3us
3-short unsigned vector
Definition Vector11T.hh:844
OpenMesh::Vec3uc
VectorT< unsigned char, 3 > Vec3uc
3-byte unsigned vector
Definition Vector11T.hh:840
OpenMesh::Vec2s
VectorT< signed short int, 2 > Vec2s
2-short signed vector
Definition Vector11T.hh:825
OpenMesh::Vec2i
VectorT< signed int, 2 > Vec2i
2-int signed vector
Definition Vector11T.hh:829
OpenMesh::operator*
auto operator*(const OtherScalar &_s, const VectorT< Scalar, DIM > &rhs) -> decltype(rhs.operator*(_s))
Component wise multiplication from the left.
Definition Vector11T.hh:692
OpenMesh::Vec2c
VectorT< signed char, 2 > Vec2c
2-byte signed vector
Definition Vector11T.hh:821
OpenMesh::Vec2us
VectorT< unsigned short int, 2 > Vec2us
2-short unsigned vector
Definition Vector11T.hh:827
OpenMesh::Vec6c
VectorT< signed char, 6 > Vec6c
6-byte signed vector
Definition Vector11T.hh:891
OpenMesh::Vec6i
VectorT< signed int, 6 > Vec6i
6-int signed vector
Definition Vector11T.hh:899
OpenMesh::Vec4i
VectorT< signed int, 4 > Vec4i
4-int signed vector
Definition Vector11T.hh:865
OpenMesh::Vec4s
VectorT< signed short int, 4 > Vec4s
4-short signed vector
Definition Vector11T.hh:861
OpenMesh::Vec6uc
VectorT< unsigned char, 6 > Vec6uc
6-byte unsigned vector
Definition Vector11T.hh:893
OpenMesh::Vec6f
VectorT< float, 6 > Vec6f
6-float vector
Definition Vector11T.hh:903
OpenMesh::Vec5f
VectorT< float, 5 > Vec5f
5-float vector
Definition Vector11T.hh:886
OpenMesh::Vec2uc
VectorT< unsigned char, 2 > Vec2uc
2-byte unsigned vector
Definition Vector11T.hh:823
OpenMesh::Vec6ui
VectorT< unsigned int, 6 > Vec6ui
6-int unsigned vector
Definition Vector11T.hh:901
OpenMesh::Vec4f
VectorT< float, 4 > Vec4f
4-float vector
Definition Vector11T.hh:869
OpenMesh::Vec1uc
VectorT< unsigned char, 1 > Vec1uc
1-byte unsigned vector
Definition Vector11T.hh:806
OpenMesh::Vec4uc
VectorT< unsigned char, 4 > Vec4uc
4-byte unsigned vector
Definition Vector11T.hh:859
OpenMesh::Vec1us
VectorT< unsigned short int, 1 > Vec1us
1-short unsigned vector
Definition Vector11T.hh:810
OpenMesh::Vec1f
VectorT< float, 1 > Vec1f
1-float vector
Definition Vector11T.hh:816
OpenMesh::Vec6d
VectorT< double, 6 > Vec6d
6-double vector
Definition Vector11T.hh:905
OpenMesh::Vec1s
VectorT< signed short int, 1 > Vec1s
1-short signed vector
Definition Vector11T.hh:808
OpenMesh::Vec3b
VectorT< bool, 3 > Vec3b
3-bool vector
Definition Vector11T.hh:854
OpenMesh::Vec1ui
VectorT< unsigned int, 1 > Vec1ui
1-int unsigned vector
Definition Vector11T.hh:814
OpenMesh::Vec1c
VectorT< signed char, 1 > Vec1c
1-byte signed vector
Definition Vector11T.hh:804
OpenMesh::Vec5d
VectorT< double, 5 > Vec5d
5-double vector
Definition Vector11T.hh:888
OpenMesh::Vec4us
VectorT< unsigned short int, 4 > Vec4us
4-short unsigned vector
Definition Vector11T.hh:863
OpenMesh::Vec3ui
VectorT< unsigned int, 3 > Vec3ui
3-int unsigned vector
Definition Vector11T.hh:848
OpenMesh::Vec6us
VectorT< unsigned short int, 6 > Vec6us
6-short unsigned vector
Definition Vector11T.hh:897
OpenMesh::Vec5us
VectorT< unsigned short int, 5 > Vec5us
5-short unsigned vector
Definition Vector11T.hh:880
OpenMesh::Vec3f
VectorT< float, 3 > Vec3f
3-float vector
Definition Vector11T.hh:850
OpenMesh::Vec6s
VectorT< signed short int, 6 > Vec6s
6-short signed vector
Definition Vector11T.hh:895
OpenMesh::Vec3i
VectorT< signed int, 3 > Vec3i
3-int signed vector
Definition Vector11T.hh:846
OpenMesh::VectorT::operator%
auto operator%(const VectorT< OtherScalar, DIM > &_rhs) const -> typename std::enable_if< DIM==3, VectorT< decltype((*this)[0] *_rhs[0] -(*this)[0] *_rhs[0]), DIM > >::type
cross product: only defined for Vec3* as specialization
Definition Vector11T.hh:374
VectorT
Definition VectorT_inc.hh:68
VectorT::maximize
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
Definition VectorT_inc.hh:564
VectorT::norm
Scalar norm() const
compute euclidean norm
Definition VectorT_inc.hh:410
VectorT::vectorize
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
Definition VectorT_inc.hh:605
VectorT::sqrnorm
Scalar sqrnorm() const
compute squared euclidean norm
Definition VectorT_inc.hh:414
VectorT::normalize
vector_type & normalize()
normalize vector, return normalized vector
Definition VectorT_inc.hh:432
VectorT::minimize
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Definition VectorT_inc.hh:547