cgv
Loading...
Searching...
No Matches
fvec.h
1#pragma once
2
3// Make sure this is the first thing the compiler sees, while preventing warnings if
4// it happened to already be defined by something else including this header
5#ifndef _USE_MATH_DEFINES
6 #define _USE_MATH_DEFINES 1
7#endif
8#include <algorithm>
9#include <array>
10#include <cmath>
11#include <cstdint>
12#include <cstring>
13#include <iostream>
14#include <limits>
15#include <sstream>
16#include <cgv/type/standard_types.h>
17#include <cgv/math/functions.h>
18
19namespace cgv {
20namespace math {
21
22template <typename T> class vec;
23
25template <typename T, cgv::type::uint32_type N>
26class fvec
27{
28protected:
29 //elements of vector
30 T v[N];
31public:
32 //@name type definitions
34
35 typedef T value_type;
37 typedef T& reference;
39 typedef const T& const_reference;
41 typedef std::size_t size_type;
43 typedef std::ptrdiff_t difference_type;
45 typedef T* pointer;
47 typedef const T* const_pointer;
49 typedef T* iterator;
51 typedef const T* const_iterator;
53 typedef std::reverse_iterator<iterator> reverse_iterator;
55 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
57
59 enum { dims = N };
60
61 //@name iterator generation
63
64 iterator begin() { return v; }
66 iterator end() { return v+N; }
68 const_iterator begin() const { return v; }
70 const_iterator end() const { return v+N; }
72 reverse_iterator rbegin() { return reverse_iterator(end()); }
74 reverse_iterator rend() { return reverse_iterator(begin()); }
76 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
78 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
80
81 //@name construction and assignment
83
84 fvec() {}
86 fvec(const T &a) { std::fill(v, v+N, a); }
88 fvec(const T &x, const T &y) { set(x,y); }
90 fvec(const T &x, const T &y, const T &z) { set(x,y,z); }
92 fvec(const T &x, const T &y, const T &z,const T &w) { set(x,y,z,w); }
95 cgv::type::uint32_type i, min_n = n < N ? n : N;
96 memmove(v, a, min_n*sizeof(T)); //std::copy(a, a+min_n, v);
97 for (i = min_n; i < N; ++i) v[i] = T(0);
98 }
100 template <typename S>
102 cgv::type::uint32_type i, min_n = n < N ? n : N;
103 for (i=0; i<min_n; ++i) v[i] = (T)a[i];
104 for (; i < N; ++i) v[i] = T(0);
105 }
107 fvec(const fvec<T,N> &rhs) { if (this != &rhs) std::copy(rhs.v, rhs.v+N, v); }
109 template <typename S>
110 fvec(const fvec<S,N>& fv) { for (unsigned i=0; i<N; ++i) v[i] = (T)fv(i); }
112 template <typename S1, typename S2>
113 fvec(const fvec<S1, N - 1>& fv, S2 w) { for (unsigned i = 0; i < N - 1; ++i) v[i] = (T)fv(i); v[N - 1] = (T)w; }
115 template <typename S>
116 fvec(const fvec<S, N + 1>& fv) { for (unsigned i = 0; i < N; ++i) v[i] = (T)fv(i); }
118 fvec(const std::array<T, N>& arr) : fvec(N, arr.data()) {}
120 fvec & operator = (const fvec<T,N> &rhs) { if (this != &rhs) std::copy(rhs.v, rhs.v+N, v); return *this; }
122 fvec & operator = (const T &a) { std::fill(v, v+N, a); return *this; }
124 void assign(const std::array<T, N>& arr) { std::copy(arr.cbegin(), arr.cend(), v); }
126 void set(const T &x, const T &y) { v[0] = x; v[1] = y; }
128 void set(const T &x, const T &y, const T &z) { v[0] = x; v[1] = y; v[2] = z; }
130 void set(const T &x, const T &y, const T &z, const T &w) { v[0] = x; v[1] = y; v[2] = z; v[3] = w; }
132 void fill(const T& a) { std::fill(v, v+N, a); }
134 void zeros() { fill((T)0); }
136 void zerosh() { std::fill(v, v+N-1, (T)0); v[N-1] = (T)1; }
138 void ones() { fill((T)1); }
140 fvec<T,N+1> lift() const { fvec<T,N+1> h_v; (fvec<T,N>&)h_v=*this; h_v(N) = 1; return h_v; }
142 static fvec<T,N> zeroh() {
143 fvec<T,N> r;
144 std::fill(r.v, r.v+N-1, (T)0); r.v[N-1] = (T)1;
145 return r;
146 }
148 vec<T> to_vec() const;
150 static fvec<T, N> from_vec(const vec<T>&);
152
153 //@name access to components
155
156 T& x() { return v[0]; }
158 const T& x() const { return v[0]; }
160 T& y() { return v[1]; }
162 const T& y() const { return v[1]; }
164 T& z() { return v[2]; }
166 const T& z() const { return v[2]; }
168 T& w() { return v[3]; }
170 const T& w() const { return v[3]; }
172 T& operator()(const int i) { return v[i]; }
174 const T & operator()(const int i) const { return v[i]; }
176 T& operator[](const int i) { return v[i]; }
178 const T & operator[](const int i) const { return v[i]; }
180 static cgv::type::uint32_type size() { return N; }
182 T* data() { return v; }
184 const T* data() const { return v; }
186
187 //@name operators
189
190 fvec<T,N>& operator += (const T& s) { for (unsigned i=0;i<N;++i) v[i] += s; return *this; }
192 fvec<T,N>& operator -= (const T& s) { for (unsigned i=0;i<N;++i) v[i] -= s; return *this; }
194 fvec<T,N>& operator *= (const T& s) { for (unsigned i=0;i<N;++i) v[i] *= s; return *this; }
196 fvec<T,N>& operator /= (const T& s) { for (unsigned i=0;i<N;++i) v[i] /= s; return *this; }
198 template <typename S>
199 fvec<T,N>& operator += (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] += T(_v(i)); return *this; }
201 template <typename S>
202 fvec<T,N>& operator -= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] -= T(_v(i)); return *this; }
204 template <typename S>
205 fvec<T,N>& operator *= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] *= T(_v(i)); return *this; }
207 template <typename S>
208 fvec<T,N>& operator /= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] /= T(_v(i)); return *this; }
210 template <typename S>
211 fvec<T,N> operator + (const fvec<S,N>& v) const { fvec<T,N> r = *this; r += v; return r; }
213 fvec<T,N> operator + (const T& s) const { fvec<T,N> r = *this; r += s; return r; }
215 fvec<T,N> operator - (const T& s) const { fvec<T,N> r = *this; r -= s; return r; }
217 template <typename S>
218 fvec<T,N> operator - (const fvec<S,N>& v) const { fvec<T,N> r = *this; r -= v; return r; }
220 template <typename S>
221 fvec<T,N> operator * (const fvec<S,N>& v) const { fvec<T,N> r = *this; r *= v; return r; }
223 template <typename S>
224 fvec<T,N> operator / (const fvec<S,N>& v) const { fvec<T,N> r = *this; r /= v; return r; }
226 fvec<T,N> operator-(void) const { fvec<T,N> r; for (unsigned i=0; i<N; ++i) r(i) = -v[i]; return r; }
228 fvec<T,N> operator * (const T& s) const { fvec<T,N> r = *this; r *= s; return r; }
230 fvec<T,N> operator / (const T& s) const { fvec<T,N> r = *this; r /= s; return r; }
232 template <typename S>
233 bool operator == (const fvec<S,N>& v) const {
234 for (unsigned i=0;i<N;++i)
235 if(operator()(i) != (T)v(i)) return false;
236 return true;
237 }
239 template <typename S>
240 bool operator != (const fvec<S,N>& v) const {
241 for (unsigned i=0;i<N;++i)
242 if(operator()(i) != (T)v(i)) return true;
243 return false;
244 }
246
247 //@name functions
249
250 T length() const
251 {
252 return (T)std::sqrt((double)sqr_length());
253 }
254
256 void sign() {
257 for (unsigned i = 0; i < N; i++)
258 v[i] = cgv::math::sign(v[i]);
259 }
260
262 void step(const fvec<T, N>& r) {
263 for (unsigned i = 0; i < N; i++)
264 v[i] = cgv::math::step(v[i], r[i]);
265 }
266
268 void abs() {
269 if(std::numeric_limits<T>::is_signed) {
270 for(unsigned i = 0; i < N;i++)
271 v[i]=(T)std::abs((double)v[i]);
272 }
273 }
274
276 void ceil() {
277 for(unsigned i = 0; i < N;i++)
278 v[i]=(T)::ceil((double)v[i]);
279 }
280
282 void floor() {
283 for(unsigned i = 0; i < N;i++)
284 v[i]=(T)::floor((double)v[i]);
285 }
286
288 void round() {
289 for(unsigned i = 0; i < N;i++)
290 v[i]=(T)::floor((double)v[i]+0.5);
291 }
292
293
295 T sqr_length() const {
296 T l=0;
297 for(unsigned i = 0; i!=N;i++)
298 l+= operator()(i)*operator()(i);
299 return l;
300 }
301
304 T l = length();
305 T inv_l = (T)1.0/l;
306 for(unsigned i = 0; i<N; i++)
307 operator()(i)=inv_l*operator()(i);
308 return l;
309 }
310
313 T l = length();
314 if(std::abs(l) < std::numeric_limits<T>::epsilon())
315 return (T)0;
316 T inv_l = (T)1.0 / l;
317 for(unsigned i = 0; i < N; i++)
318 operator()(i) = inv_l * operator()(i);
319 return l;
320 }
322};
323
325#define CGV_MATH_FVEC_DECLARED
326
328template<typename T, cgv::type::uint32_type N>
329fvec<T,N> normalize(const fvec<T,N>& v) { fvec<T,N> w(v); w.normalize(); return w; }
330
332template<typename T, cgv::type::uint32_type N>
333fvec<T, N> safe_normalize(const fvec<T, N>& v) { fvec<T, N> w(v); w.safe_normalize(); return w; }
334
336template<typename T, cgv::type::uint32_type N>
337std::ostream& operator<<(std::ostream& out, const fvec<T,N>& v)
338{
339 for (unsigned i=0;i<N-1;++i)
340 out << v(i)<<" ";
341 out << v(N-1);
342 return out;
343
344}
345
347template<typename T, cgv::type::uint32_type N>
348std::istream& operator>>(std::istream& in, fvec<T,N>& v)
349{
350 for (unsigned i = 0; i < N; ++i) {
351 in >> v(i);
352 if (in.fail() && i == 1) {
353 for (unsigned i = 1; i < N; ++i)
354 v(i) = v(0);
355 break;
356 }
357 }
358 return in;
359}
360
362template<typename T, cgv::type::uint32_type N>
363std::string to_string(const fvec<T, N>& v)
364{
365 std::ostringstream ss;
366 ss << v;//.rdbuf();
367 return ss.str();
368}
369
371template<typename T, cgv::type::uint32_type N>
372bool from_string(const std::string& s, fvec<T, N>& v)
373{
374 std::istringstream iss(s);
375 iss >> v;
376 return !iss.fail();
377}
378
380template <typename T, cgv::type::uint32_type N>
381fvec<T,N> operator * (const T& s, const fvec<T,N>& v) { fvec<T,N> r = v; r *= s; return r; }
382
384template <typename T, cgv::type::uint32_type N>
385fvec<T,N> operator / (const T& s, const fvec<T,N>& v)
386{
387 fvec<T,N> r;
388 for (unsigned i=0;i<N;++i)
389 r(i) = s/v(i);
390 return r;
391}
392
394template <typename T, typename S, cgv::type::uint32_type N>
395inline T dot(const fvec<T,N>& v, const fvec<S,N>& w)
396{
397 T r = 0;
398 for (unsigned i=0;i<N;++i)
399 r += T(v(i)*w(i));
400 return r;
401}
402
405template <typename T, typename S, cgv::type::uint32_type N>
406inline S dot_pos(const fvec<T,N>& v, const fvec<S,N+1>& w)
407{
408 T r = 0;
409 for (unsigned i=0;i<N;++i)
410 r += v(i)*w(i);
411 return r+w(N);
412}
415template <typename T, typename S, cgv::type::uint32_type N>
416inline S dot_pos(const fvec<T,N+1>& v, const fvec<S,N>& w)
417{
418 T r = 0;
419 for (unsigned i=0;i<N;++i)
420 r += v(i)*w(i);
421 return r+v(N);
422}
423
426template <typename T, typename S, cgv::type::uint32_type N>
427inline S dot_dir(const fvec<T,N>& v, const fvec<S,N+1>& w)
428{
429 T r = 0;
430 for (unsigned i=0;i<N;++i)
431 r += v(i)*w(i);
432 return r;
433}
436template <typename T, typename S, cgv::type::uint32_type N>
437inline S dot_dir(const fvec<T,N+1>& v, const fvec<S,N>& w)
438{
439 T r = 0;
440 for (unsigned i=0;i<N;++i)
441 r += v(i)*w(i);
442 return r;
443}
444
446template <typename T, cgv::type::uint32_type N>
447inline T length(const fvec<T, N>& v) { return std::sqrt(dot(v, v)); }
448
450template <typename T, cgv::type::uint32_type N>
451inline fvec<T, N> sign(const fvec<T, N>& v) { fvec<T, N> r(v); r.sign(); return r; }
452
454template <typename T, cgv::type::uint32_type N>
455inline fvec<T, N> step(const fvec<T, N>& a, const fvec<T, N>& b) { fvec<T, N> r(a); r.step(b); return r; }
456
458template <typename T, cgv::type::uint32_type N>
459inline fvec<T, N> abs(const fvec<T, N>& v) { fvec<T, N> r(v); r.abs(); return r; }
460
462template <typename T, cgv::type::uint32_type N>
463inline fvec<T, N> round(const fvec<T, N>& v) { fvec<T, N> r(v); r.round(); return r; }
464
466template <typename T, cgv::type::uint32_type N>
467inline fvec<T, N> floor(const fvec<T, N>& v) { fvec<T, N> r(v); r.floor(); return r; }
468
470template <typename T, cgv::type::uint32_type N>
471inline fvec<T, N> ceil(const fvec<T, N>& v) { fvec<T, N> r(v); r.ceil(); return r; }
472
474template <typename T, cgv::type::uint32_type N>
475inline T sqr_length(const fvec<T,N>& v)
476{
477 return dot(v,v);
478}
479
481template < typename T, cgv::type::uint32_type N>
482inline fvec<T,N> cross(const fvec<T,N>& v, const fvec<T,N>& w)
483{
484 fvec<T,N> r(3);
485 r(0)= v(1)*w(2) - v(2)*w(1);
486 r(1)= v(2)*w(0) - v(0)*w(2);
487 r(2)= v(0)*w(1) - v(1)*w(0);
488 return r;
489}
490
492template < typename T, cgv::type::uint32_type N>
493inline fvec<T,N+1> hom(const fvec<T,N>& v)
494{
495 fvec<T,N+1> h;
496 for (unsigned i = 0; i<N; ++i)
497 h(i) = v(i);
498 h(N) = 1;
499 return h;
500}
501
503template < typename T, cgv::type::uint32_type N>
504T min_value(const fvec<T,N> &v)
505{
506 return *(std::min_element(&v(0),&v(N-1)+1));
507}
508
510template < typename T, cgv::type::uint32_type N>
511unsigned min_index(const fvec<T,N> &v)
512{
513 return (unsigned) (std::min_element(&v(0),&v(N-1)+1)-&v(0));
514}
515
517template < typename T, cgv::type::uint32_type N>
518unsigned max_index(const fvec<T,N> &v)
519{
520 return (unsigned) (std::max_element(&v(0),&v(N-1)+1)-&v(0));
521}
522
524template < typename T, cgv::type::uint32_type N>
525T max_value(const fvec<T,N> &v)
526{
527 return *(std::max_element(&v(0),&v(N-1)+1));
528}
529
531template <typename T, cgv::type::uint32_type N>
532const fvec<T, N> lerp(const fvec<T, N>& v1, const fvec<T, N>& v2, T t)
533{
534 return ((T)1 - t)*v1 + t * v2;
535}
536
538template <typename T, cgv::type::uint32_type N>
539const fvec<T, N> lerp(const fvec<T, N>& v1, const fvec<T, N>& v2, const fvec<T, N>& t)
540{
541 return (fvec<T, N>(1) - t)*v1 + t * v2;
542}
543
545template <typename T, cgv::type::uint32_type N>
546const fvec<T, N> slerp(const fvec<T, N> &v0, const fvec<T, N> &v1, T t) {
547 T dotv0v1 = dot(v0, v1);
548 // clamp between [-1,1]
549 if (dotv0v1 < -1)
550 dotv0v1 = -1;
551
552 if (dotv0v1 > 1)
553 dotv0v1 = 1;
554
555 T theta = acos(dotv0v1) * t;
556 auto v2 = normalize(v1 - (dotv0v1)*v0);
557 return T(cos(theta)) * v0 + T(sin(theta)) * v2;
558}
559
561template <typename T, cgv::type::uint32_type N>
562const fvec<T, N> min(const fvec<T, N>& v, T t) {
563 fvec<T, N> c;
564 for(unsigned i = 0; i < N; ++i)
565 c(i) = std::min(v(i), t);
566 return c;
567}
568
570template <typename T, cgv::type::uint32_type N>
571const fvec<T, N> min(const fvec<T, N>& v, const fvec<T, N>& t) {
572 fvec<T, N> c;
573 for(unsigned i = 0; i < N; ++i)
574 c(i) = std::min(v(i), t(i));
575 return c;
576}
577
579template <typename T, cgv::type::uint32_type N>
580const fvec<T, N> max(const fvec<T, N>& v, T t) {
581 fvec<T, N> c;
582 for(unsigned i = 0; i < N; ++i)
583 c(i) = std::max(v(i), t);
584 return c;
585}
586
588template <typename T, cgv::type::uint32_type N>
589const fvec<T, N> max(const fvec<T, N>& v, const fvec<T, N>& t) {
590 fvec<T, N> c;
591 for(unsigned i = 0; i < N; ++i)
592 c(i) = std::max(v(i), t(i));
593 return c;
594}
595
597template <typename T, cgv::type::uint32_type N>
598const fvec<T, N> clamp(const fvec<T, N>& v, T l, T r) {
599 fvec<T, N> c;
600 for(unsigned i = 0; i < N; ++i)
601 c(i) = cgv::math::clamp(v(i), l, r);
602 return c;
603}
604
606template <typename T, cgv::type::uint32_type N>
607const fvec<T, N> clamp(const fvec<T, N>& v, const fvec<T, N>& vl, const fvec<T, N>& vr)
608{
609 fvec<T, N> c;
610 for(unsigned i = 0; i < N; ++i)
611 c(i) = cgv::math::clamp(v(i), vl(i), vr(i));
612 return c;
613}
614
616template <typename T, cgv::type::uint32_type N>
617const fvec<T, N> saturate(const fvec<T, N>& v) {
618 return clamp(v, T(0), T(1));
619}
620
622template <typename T, cgv::type::uint32_type N>
623const fvec<T, N> pow(const fvec<T, N>& v, T e) {
624 fvec<T, N> c;
625 for(unsigned i = 0; i < N; ++i)
626 c(i) = std::pow(v(i), e);
627 return c;
628}
629
631template <typename T, cgv::type::uint32_type N>
632const fvec<T, N> pow(const fvec<T, N>& v, const fvec<T, N>& e) {
633 fvec<T, N> c;
634 for(unsigned i = 0; i < N; ++i)
635 c(i) = std::pow(v(i), e(i));
636 return c;
637}
638
640template <typename T, cgv::type::uint32_type N>
641fvec<T, N> ortho(const fvec<T, N>& v) = delete;
642
644template <typename T>
645fvec<T, 2> ortho(const fvec<T, 2>& v) {
646 return fvec<T, 2>(-v.y(), v.x());
647}
648
650template <typename T>
651fvec<T, 3> ortho(const fvec<T, 3>& v) {
652 return std::abs(v.x()) > std::abs(v.z()) ? fvec<T, 3>(-v.y(), v.x(), T(0)) : fvec<T, 3>(T(0), -v.z(), v.y());
653}
654
655} // namespace math
656
659
666
673
680
693
706
719
721
722} // namespace cgv
723
724#include "vec.h"
725
726namespace cgv {
727namespace math {
728
730template <typename T, cgv::type::uint32_type N>
732 vec<T> r;
733 r.set_extern_data(N,const_cast<T*>(v));
734 return r;
735}
736
738template <typename T, cgv::type::uint32_type N>
740{
741 return fvec<T, N>(std::min(N, v.dim()), &v[0]);
742}
743
744} // namespace math
745} // namespace cgv
746
747
748/*
749#include <cgv/utils/convert_string.h>
750#include <cgv/type/info/type_name.h>
751
752namespace cgv {
753 namespace type {
754 namespace info {
755
756template <typename T, cgv::type::uint32_type N>
757struct type_name<cgv::math::fvec<T,N> >
758{
759 static const char* get_name() {
760 static std::string name;
761 if (name.empty()) {
762 name = "fvec<";
763 name += type_name<T>::get_name();
764 name += ',';
765 name += cgv::utils::to_string(N);
766 name += '>';
767 }
768 return name.c_str();
769 }
770};
771 }
772 }
773}
774*/
complete implementation of method actions that only call one method when entering a node
Definition action.h:113
A vector with zero based index.
Definition fvec.h:27
T & z()
third element
Definition fvec.h:164
T & y()
second element
Definition fvec.h:160
fvec(const T &x, const T &y, const T &z, const T &w)
construct and init first four coordinates to the given values
Definition fvec.h:92
T safe_normalize()
normalize the vector if length is not zero using the L2-Norm and return the length
Definition fvec.h:312
fvec(cgv::type::uint32_type n, const S *a)
creates a column vector initialized to array of a different type with zeros filled to not copied comp...
Definition fvec.h:101
T normalize()
normalize the vector using the L2-Norm and return the length
Definition fvec.h:303
fvec(const T &x, const T &y, const T &z)
construct and init first three coordinates to the given values
Definition fvec.h:90
static fvec< T, N > zeroh()
creates a homogeneous zero-vector (yields same result as calling fvec<T,N-1>(0).lift() but is faster)
Definition fvec.h:142
void round()
round componentwise
Definition fvec.h:288
fvec< T, N+1 > lift() const
convert to homogeneous version by adding a 1
Definition fvec.h:140
const T & z() const
third element of const vector
Definition fvec.h:166
bool operator==(const fvec< S, N > &v) const
test for equality
Definition fvec.h:233
fvec< T, N > & operator*=(const T &s)
in place multiplication with s
Definition fvec.h:194
fvec< T, N > operator*(const fvec< S, N > &v) const
componentwise vector multiplication
Definition fvec.h:221
fvec< T, N > operator-(void) const
negates the vector
Definition fvec.h:226
fvec< T, N > & operator-=(const T &s)
in place subtraction by scalar s
Definition fvec.h:192
fvec< T, N > & operator/=(const T &s)
in place division by scalar s
Definition fvec.h:196
void sign()
componentwise sign values
Definition fvec.h:256
T & operator()(const int i)
access i'th element
Definition fvec.h:172
T * data()
cast into array. This allows calls like glVertex<N><T>v(p.data()) instead of glVertex<N><T,...
Definition fvec.h:182
T sqr_length() const
square length of vector
Definition fvec.h:295
void ones()
fill the vector with ones
Definition fvec.h:138
void set(const T &x, const T &y, const T &z)
set the first three components
Definition fvec.h:128
T length() const
length of the vector L2-Norm
Definition fvec.h:250
void floor()
floor componentwise
Definition fvec.h:282
static fvec< T, N > from_vec(const vec< T > &)
conversion from vector
Definition fvec.h:739
fvec(cgv::type::uint32_type n, const T *a)
creates a vector from a n-element array a, if n < N remaining N-n elements are set to zero
Definition fvec.h:94
fvec< T, N > operator+(const fvec< S, N > &v) const
vector addition
Definition fvec.h:211
void assign(const std::array< T, N > &arr)
set to the contents of the given std::array with same size
Definition fvec.h:124
fvec< T, N > & operator+=(const T &s)
in place addition of a scalar s
Definition fvec.h:190
fvec & operator=(const fvec< T, N > &rhs)
assign vector rhs, if vector and rhs have different sizes, vector has been resized to match the size ...
Definition fvec.h:120
fvec< T, N > operator/(const fvec< S, N > &v) const
componentwise vector division
Definition fvec.h:224
bool operator!=(const fvec< S, N > &v) const
test for inequality
Definition fvec.h:240
fvec(const fvec< T, N > &rhs)
copy constructor
Definition fvec.h:107
fvec(const fvec< S, N+1 > &fv)
construct from vector of one dimension higher by cutting of the highest dimension
Definition fvec.h:116
fvec(const fvec< S1, N - 1 > &fv, S2 w)
construct from vector of one dimension less plus a scalar
Definition fvec.h:113
vec< T > to_vec() const
conversion to vector type
Definition fvec.h:731
fvec(const fvec< S, N > &fv)
copies a column vector of a different type
Definition fvec.h:110
const_reverse_iterator rend() const
reverse iterator pointing to the end of reverse iteration
Definition fvec.h:78
void set(const T &x, const T &y, const T &z, const T &w)
set the first four components
Definition fvec.h:130
void zerosh()
fill the vector with zeros except for the last component, which will be set to one
Definition fvec.h:136
fvec(const T &x, const T &y)
construct and init first two coordinates to the given values
Definition fvec.h:88
void set(const T &x, const T &y)
set the first two components
Definition fvec.h:126
const T & y() const
second element of const vector
Definition fvec.h:162
fvec(const std::array< T, N > &arr)
construct from std::array of same size
Definition fvec.h:118
fvec()
creates a vector not initialized
Definition fvec.h:84
const T & operator[](const int i) const
access i'th element of const vector
Definition fvec.h:178
const T & w() const
fourth element of const vector
Definition fvec.h:170
T & x()
first element
Definition fvec.h:156
void abs()
componentwise absolute values
Definition fvec.h:268
const T & operator()(const int i) const
access i'th element of const vector
Definition fvec.h:174
T & operator[](const int i)
access i'th element
Definition fvec.h:176
const T & x() const
first element of const vector
Definition fvec.h:158
void ceil()
ceil componentwise
Definition fvec.h:276
T & w()
fourth element
Definition fvec.h:168
void zeros()
fill the vector with zeros
Definition fvec.h:134
fvec(const T &a)
creates a vector, where all N components are initialized to the constant value a
Definition fvec.h:86
void fill(const T &a)
fill elements of vector with scalar v
Definition fvec.h:132
void step(const fvec< T, N > &r)
componentwise sign values
Definition fvec.h:262
const T * data() const
cast into const array
Definition fvec.h:184
static cgv::type::uint32_type size()
return number of elements
Definition fvec.h:180
A column vector class.
Definition vec.h:28
void set_extern_data(unsigned dim, T *data)
set data pointer to an external data array
Definition vec.h:168
unsigned dim() const
number of elements
Definition vec.h:61
std::string to_string(const std::string &v, unsigned int w, unsigned int p, bool)
specialization of conversion from string to strings
bool from_string(std::string &v, const std::string &s)
specialization to extract string value from string
T min_value(ForwardIt first, ForwardIt last, T fallback)
Find the minimum value in the range [first, last) or return fallback if the range is empty.
Definition algorithm.h:59
T max_value(ForwardIt first, ForwardIt last, T fallback)
Find the maximum value in the range [first, last) or return fallback if the range is empty.
Definition algorithm.h:91
the cgv namespace
Definition print.h:11
cgv::math::fvec< int64_t, 2 > lvec2
declare type of 2d 64 bit integer vectors
Definition fvec.h:708
cgv::math::fvec< uint16_t, 4 > usvec4
declare type of 4d 16 bit unsigned integer vectors
Definition fvec.h:692
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:672
cgv::math::fvec< uint64_t, 4 > ulvec4
declare type of 4d 64 bit unsigned integer vectors
Definition fvec.h:718
cgv::math::fvec< double, 4 > dvec4
declare type of 4d double precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:679
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors
Definition fvec.h:677
cgv::math::fvec< uint32_t, 3 > uvec3
declare type of 3d 32 bit unsigned integer vectors
Definition fvec.h:703
cgv::math::fvec< int32_t, 3 > ivec3
declare type of 3d 32 bit integer vectors
Definition fvec.h:697
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:699
cgv::math::fvec< uint32_t, 4 > uvec4
declare type of 4d 32 bit unsigned integer vectors
Definition fvec.h:705
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
Definition fvec.h:695
cgv::math::fvec< int16_t, 3 > svec3
declare type of 3d 16 bit integer vectors
Definition fvec.h:684
cgv::math::fvec< uint16_t, 3 > usvec3
declare type of 3d 16 bit unsigned integer vectors
Definition fvec.h:690
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:668
cgv::math::fvec< int64_t, 3 > lvec3
declare type of 3d 64 bit integer vectors
Definition fvec.h:710
cgv::math::fvec< bool, 4 > bvec4
declare type of 4d boolean vectors
Definition fvec.h:665
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:670
cgv::math::fvec< double, 2 > dvec2
declare type of 2d double precision floating point vectors
Definition fvec.h:675
cgv::math::fvec< uint16_t, 2 > usvec2
declare type of 2d 16 bit unsigned integer vectors
Definition fvec.h:688
cgv::math::fvec< uint32_t, 2 > uvec2
declare type of 2d 32 bit unsigned integer vectors
Definition fvec.h:701
cgv::math::fvec< int16_t, 2 > svec2
declare type of 2d 16 bit integer vectors
Definition fvec.h:682
cgv::math::fvec< uint64_t, 3 > ulvec3
declare type of 3d 64 bit unsigned integer vectors
Definition fvec.h:716
cgv::math::fvec< int64_t, 4 > lvec4
declare type of 4d 64 bit integer vectors
Definition fvec.h:712
cgv::math::fvec< bool, 3 > bvec3
declare type of 3d boolean vectors
Definition fvec.h:663
cgv::math::fvec< int16_t, 4 > svec4
declare type of 4d 16 bit integer vectors
Definition fvec.h:686
cgv::math::fvec< bool, 2 > bvec2
declare type of 2d boolean vectors
Definition fvec.h:661
cgv::math::fvec< uint64_t, 2 > ulvec2
declare type of 2d 64 bit unsigned integer vectors
Definition fvec.h:714
the vr namespace for virtual reality support
std::ostream & operator<<(std::ostream &os, const vr_device_info &di)
stream out operator for device infos
Definition vr_info.cxx:10