1 #ifndef OPENMESH_PYTHON_VECTOR_HH 2 #define OPENMESH_PYTHON_VECTOR_HH 9 template <
class Vector,
class Scalar>
10 void set_item(
Vector& _vec,
int _index, Scalar _value) {
12 _index += _vec.
size();
15 if ((
size_t)_index < _vec.
size()) {
16 _vec[_index] = _value;
19 PyErr_SetString(PyExc_IndexError,
"Index out of range.");
20 throw_error_already_set();
24 template <
class Vector,
class Scalar>
25 Scalar get_item(
Vector& _vec,
int _index) {
27 _index += _vec.
size();
30 if ((
size_t)_index < _vec.
size()) {
34 PyErr_SetString(PyExc_IndexError,
"Index out of range.");
35 throw_error_already_set();
42 template<
class Scalar>
48 static Vector2 *vec2_default() {
49 return new Vector2(Scalar(), Scalar());
51 static Vector2 *vec2_user_defined(
const Scalar& _v0,
const Scalar& _v1) {
52 return new Vector2(_v0, _v1);
54 static Vector3 *vec3_default() {
55 return new Vector3(Scalar(), Scalar(), Scalar());
57 static Vector3 *vec3_user_defined(
const Scalar& _v0,
const Scalar& _v1,
const Scalar& _v2) {
58 return new Vector3(_v0, _v1, _v2);
60 static Vector4 *vec4_default() {
61 return new Vector4(Scalar(), Scalar(), Scalar(), Scalar());
63 static Vector4 *vec4_user_defined(
const Scalar& _v0,
const Scalar& _v1,
const Scalar& _v2,
const Scalar& _v3) {
64 return new Vector4(_v0, _v1, _v2, _v3);
69 template<
class Scalar,
class Vector>
72 .def(
"__init__", make_constructor(&Factory<Scalar>::vec2_default))
73 .def(
"__init__", make_constructor(&Factory<Scalar>::vec2_user_defined))
77 template<
class Scalar,
class Vector>
81 .def(
"__init__", make_constructor(&Factory<Scalar>::vec3_default))
82 .def(
"__init__", make_constructor(&Factory<Scalar>::vec3_user_defined))
83 .def(
"__mod__",
cross)
88 template<
class Scalar,
class Vector>
91 .def(
"__init__", make_constructor(&Factory<Scalar>::vec4_default))
92 .def(
"__init__", make_constructor(&Factory<Scalar>::vec4_user_defined))
109 template<
class Scalar,
int N>
119 Scalar (Vector::*
dot )(
const Vector&)
const = &Vector::operator|;
126 #if (_MSC_VER >= 1900 || __cplusplus > 199711L || defined(__GXX_EXPERIMENTAL_CXX0X__)) && !defined(OPENMESH_VECTOR_LEGACY) 132 class_<Vector> classVector = class_<Vector>(_name);
135 .def(
"__setitem__", &set_item<Vector, Scalar>)
136 .def(
"__getitem__", &get_item<Vector, Scalar>)
139 .def(
self *= Scalar())
140 .def(
self /= Scalar())
141 .def(
self * Scalar())
142 .def(Scalar() *
self)
143 .def(
self / Scalar())
159 .def(
"length", length)
160 .def(
"sqrnorm", sqrnorm)
161 .def(
"normalized", normalized)
162 .def(
"normalize", normalize, return_internal_reference<>())
163 .def(
"normalize_cond", normalize_cond, return_internal_reference<>())
168 .def(
"max", max_void)
170 .def(
"min", min_void)
178 .def(
"min", min_vector)
179 .def(
"max", max_vector)
182 .staticmethod(
"size")
184 .staticmethod(
"vectorized")
187 defInitMod<Scalar, Vector>(classVector);
auto length() const -> decltype(std::declval< VectorT< S, DIM >>().norm())
compute squared euclidean norm
static constexpr size_t size()
returns dimension of the vector
ACG::Vec4d Vector4
Standard Type for 4d Vector used for scripting.
Scalar l8_norm() const
compute l8_norm
Scalar min() const
return the minimal component
auto normalized() const -> decltype(*this/std::declval< VectorT< S, DIM >>().norm())
void expose_vec(const char *_name)
Scalar max_abs() const
return the maximal absolute component
vector_type & maximize(const vector_type &_rhs)
maximize values: same as *this = max(*this, _rhs), but faster
bool maximized(const vector_type &_rhs)
maximize values and signalize coordinate maximization
bool minimized(const vector_type &_rhs)
minimize values and signalize coordinate minimization
Scalar min_abs() const
return the minimal absolute component
Scalar mean() const
return arithmetic mean
ACG::Vec3d Vector
Standard Type for 3d Vector used for scripting.
Scalar mean_abs() const
return absolute arithmetic mean
auto normalize() -> decltype(*this/=std::declval< VectorT< S, DIM >>().norm())
static vector_type vectorized(const Scalar &_s)
store the same value in each component
auto norm() const -> decltype(std::sqrt(std::declval< VectorT< S, DIM >>().sqrnorm()))
compute euclidean norm
decltype(std::declval< S >()*std::declval< S >()) sqrnorm() const
compute squared euclidean norm
osg::Vec3f::ValueType dot(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
osg::Vec3f cross(const osg::Vec3f &_v1, const osg::Vec3f &_v2)
Adapter for osg vector member computing a scalar product.
Scalar max() const
return the maximal component
vector_type & vectorize(const Scalar &_s)
store the same value in each component (e.g. to clear all entries)
vector_type &::type normalize_cond()
compute squared euclidean norm
vector_type & minimize(const vector_type &_rhs)
minimize values: same as *this = min(*this, _rhs), but faster
Scalar l1_norm() const
compute L1 (Manhattan) norm