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 <iostream>
13#include <limits>
14#include <sstream>
15#include <cgv/type/standard_types.h>
16#include <cgv/math/functions.h>
17
18namespace cgv {
19namespace math {
20
21template <typename T> class vec;
22
24template <typename T, cgv::type::uint32_type N>
25class fvec
26{
27protected:
28 //elements of vector
29 T v[N];
30public:
31 //@name type definitions
33
34 typedef T value_type;
36 typedef T& reference;
38 typedef const T& const_reference;
40 typedef std::size_t size_type;
42 typedef std::ptrdiff_t difference_type;
44 typedef T* pointer;
46 typedef const T* const_pointer;
48 typedef T* iterator;
50 typedef const T* const_iterator;
52 typedef std::reverse_iterator<iterator> reverse_iterator;
54 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
56
58 enum { dims = N };
59
60 //@name iterator generation
62
63 iterator begin() { return v; }
65 iterator end() { return v+N; }
67 const_iterator begin() const { return v; }
69 const_iterator end() const { return v+N; }
71 reverse_iterator rbegin() { return reverse_iterator(end()); }
73 reverse_iterator rend() { return reverse_iterator(begin()); }
75 const_reverse_iterator rbegin() const { return const_reverse_iterator(end()); }
77 const_reverse_iterator rend() const { return const_reverse_iterator(begin()); }
79
80 //@name construction and assignment
82
83 fvec() {}
85 fvec(const T &a) { std::fill(v, v+N, a); }
87 fvec(const T &x, const T &y) { set(x,y); }
89 fvec(const T &x, const T &y, const T &z) { set(x,y,z); }
91 fvec(const T &x, const T &y, const T &z,const T &w) { set(x,y,z,w); }
94 cgv::type::uint32_type i, min_n = n < N ? n : N;
95 std::copy(a, a+min_n, v);
96 for (i = min_n; i < N; ++i) v[i] = T(0);
97 }
99 template <typename S>
101 cgv::type::uint32_type i, min_n = n < N ? n : N;
102 for (i=0; i<min_n; ++i) v[i] = (T)a[i];
103 for (; i < N; ++i) v[i] = T(0);
104 }
106 fvec(const fvec<T,N> &rhs) { if (this != &rhs) std::copy(rhs.v, rhs.v+N, v); }
108 template <typename S>
109 fvec(const fvec<S,N>& fv) { for (unsigned i=0; i<N; ++i) v[i] = (T)fv(i); }
111 template <typename S1, typename S2>
112 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; }
114 template <typename S>
115 fvec(const fvec<S, N + 1>& fv) { for (unsigned i = 0; i < N; ++i) v[i] = (T)fv(i); }
117 fvec(const std::array<T, N>& arr) : fvec(N, arr.data()) {}
119 fvec & operator = (const fvec<T,N> &rhs) { if (this != &rhs) std::copy(rhs.v, rhs.v+N, v); return *this; }
121 fvec & operator = (const T &a) { std::fill(v, v+N, a); return *this; }
123 void assign(const std::array<T, N>& arr) { std::copy(arr.cbegin(), arr.cend(), v); }
125 void set(const T &x, const T &y) { v[0] = x; v[1] = y; }
127 void set(const T &x, const T &y, const T &z) { v[0] = x; v[1] = y; v[2] = z; }
129 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; }
131 void fill(const T& a) { std::fill(v, v+N, a); }
133 void zeros() { fill((T)0); }
135 void zerosh() { std::fill(v, v+N-1, (T)0); v[N-1] = (T)1; }
137 void ones() { fill((T)1); }
139 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; }
141 static fvec<T,N> zeroh() {
142 fvec<T,N> r;
143 std::fill(r.v, r.v+N-1, (T)0); r.v[N-1] = (T)1;
144 return r;
145 }
147 vec<T> to_vec() const;
149 static fvec<T, N> from_vec(const vec<T>&);
151
152 //@name access to components
154
155 T& x() { return v[0]; }
157 const T& x() const { return v[0]; }
159 T& y() { return v[1]; }
161 const T& y() const { return v[1]; }
163 T& z() { return v[2]; }
165 const T& z() const { return v[2]; }
167 T& w() { return v[3]; }
169 const T& w() const { return v[3]; }
171 T& operator()(const int i) { return v[i]; }
173 const T & operator()(const int i) const { return v[i]; }
175 T& operator[](const int i) { return v[i]; }
177 const T & operator[](const int i) const { return v[i]; }
179 static cgv::type::uint32_type size() { return N; }
181 T* data() { return v; }
183 const T* data() const { return v; }
185
186 //@name operators
188
189 fvec<T,N>& operator += (const T& s) { for (unsigned i=0;i<N;++i) v[i] += s; return *this; }
191 fvec<T,N>& operator -= (const T& s) { for (unsigned i=0;i<N;++i) v[i] -= s; return *this; }
193 fvec<T,N>& operator *= (const T& s) { for (unsigned i=0;i<N;++i) v[i] *= s; return *this; }
195 fvec<T,N>& operator /= (const T& s) { for (unsigned i=0;i<N;++i) v[i] /= s; return *this; }
197 template <typename S>
198 fvec<T,N>& operator += (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] += T(_v(i)); return *this; }
200 template <typename S>
201 fvec<T,N>& operator -= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] -= T(_v(i)); return *this; }
203 template <typename S>
204 fvec<T,N>& operator *= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] *= T(_v(i)); return *this; }
206 template <typename S>
207 fvec<T,N>& operator /= (const fvec<S,N>& _v) { for (unsigned i=0; i<N;++i) v[i] /= T(_v(i)); return *this; }
209 template <typename S>
210 fvec<T,N> operator + (const fvec<S,N>& v) const { fvec<T,N> r = *this; r += v; return r; }
212 fvec<T,N> operator + (const T& s) const { fvec<T,N> r = *this; r += s; return r; }
214 fvec<T,N> operator - (const T& s) const { fvec<T,N> r = *this; r -= s; return r; }
216 template <typename S>
217 fvec<T,N> operator - (const fvec<S,N>& v) const { fvec<T,N> r = *this; r -= v; return r; }
219 template <typename S>
220 fvec<T,N> operator * (const fvec<S,N>& v) const { fvec<T,N> r = *this; r *= v; return r; }
222 template <typename S>
223 fvec<T,N> operator / (const fvec<S,N>& v) const { fvec<T,N> r = *this; r /= v; return r; }
225 fvec<T,N> operator-(void) const { fvec<T,N> r; for (unsigned i=0; i<N; ++i) r(i) = -v[i]; return r; }
227 fvec<T,N> operator * (const T& s) const { fvec<T,N> r = *this; r *= s; return r; }
229 fvec<T,N> operator / (const T& s) const { fvec<T,N> r = *this; r /= s; return r; }
231 template <typename S>
232 bool operator == (const fvec<S,N>& v) const {
233 for (unsigned i=0;i<N;++i)
234 if(operator()(i) != (T)v(i)) return false;
235 return true;
236 }
238 template <typename S>
239 bool operator != (const fvec<S,N>& v) const {
240 for (unsigned i=0;i<N;++i)
241 if(operator()(i) != (T)v(i)) return true;
242 return false;
243 }
245
246 //@name functions
248
249 T length() const
250 {
251 return (T)std::sqrt((double)sqr_length());
252 }
253
255 void sign() {
256 for (unsigned i = 0; i < N; i++)
257 v[i] = cgv::math::sign(v[i]);
258 }
259
261 void step(const fvec<T, N>& r) {
262 for (unsigned i = 0; i < N; i++)
263 v[i] = cgv::math::step(v[i], r[i]);
264 }
265
267 void abs() {
268 if(std::numeric_limits<T>::is_signed) {
269 for(unsigned i = 0; i < N;i++)
270 v[i]=(T)std::abs((double)v[i]);
271 }
272 }
273
275 void ceil() {
276 for(unsigned i = 0; i < N;i++)
277 v[i]=(T)::ceil((double)v[i]);
278 }
279
281 void floor() {
282 for(unsigned i = 0; i < N;i++)
283 v[i]=(T)::floor((double)v[i]);
284 }
285
287 void round() {
288 for(unsigned i = 0; i < N;i++)
289 v[i]=(T)::floor((double)v[i]+0.5);
290 }
291
292
294 T sqr_length() const {
295 T l=0;
296 for(unsigned i = 0; i!=N;i++)
297 l+= operator()(i)*operator()(i);
298 return l;
299 }
300
303 T l = length();
304 T inv_l = (T)1.0/l;
305 for(unsigned i = 0; i<N; i++)
306 operator()(i)=inv_l*operator()(i);
307 return l;
308 }
309
312 T l = length();
313 if(std::abs(l) < std::numeric_limits<T>::epsilon())
314 return (T)0;
315 T inv_l = (T)1.0 / l;
316 for(unsigned i = 0; i < N; i++)
317 operator()(i) = inv_l * operator()(i);
318 return l;
319 }
321};
322
324#define CGV_MATH_FVEC_DECLARED
325
327template<typename T, cgv::type::uint32_type N>
328fvec<T,N> normalize(const fvec<T,N>& v) { fvec<T,N> w(v); w.normalize(); return w; }
329
331template<typename T, cgv::type::uint32_type N>
332fvec<T, N> safe_normalize(const fvec<T, N>& v) { fvec<T, N> w(v); w.safe_normalize(); return w; }
333
335template<typename T, cgv::type::uint32_type N>
336std::ostream& operator<<(std::ostream& out, const fvec<T,N>& v)
337{
338 for (unsigned i=0;i<N-1;++i)
339 out << v(i)<<" ";
340 out << v(N-1);
341 return out;
342
343}
344
346template<typename T, cgv::type::uint32_type N>
347std::istream& operator>>(std::istream& in, fvec<T,N>& v)
348{
349 for (unsigned i = 0; i < N; ++i) {
350 in >> v(i);
351 if (in.fail() && i == 1) {
352 for (unsigned i = 1; i < N; ++i)
353 v(i) = v(0);
354 break;
355 }
356 }
357 return in;
358}
359
361template<typename T, cgv::type::uint32_type N>
362std::string to_string(const fvec<T, N>& v)
363{
364 std::ostringstream ss;
365 ss << v;//.rdbuf();
366 return ss.str();
367}
368
370template<typename T, cgv::type::uint32_type N>
371bool from_string(const std::string& s, fvec<T, N>& v)
372{
373 std::istringstream iss(s);
374 iss >> v;
375 return !iss.fail();
376}
377
379template <typename T, cgv::type::uint32_type N>
380fvec<T,N> operator * (const T& s, const fvec<T,N>& v) { fvec<T,N> r = v; r *= s; return r; }
381
383template <typename T, cgv::type::uint32_type N>
384fvec<T,N> operator / (const T& s, const fvec<T,N>& v)
385{
386 fvec<T,N> r;
387 for (unsigned i=0;i<N;++i)
388 r(i) = s/v(i);
389 return r;
390}
391
393template <typename T, typename S, cgv::type::uint32_type N>
394inline T dot(const fvec<T,N>& v, const fvec<S,N>& w)
395{
396 T r = 0;
397 for (unsigned i=0;i<N;++i)
398 r += T(v(i)*w(i));
399 return r;
400}
401
404template <typename T, typename S, cgv::type::uint32_type N>
405inline S dot_pos(const fvec<T,N>& v, const fvec<S,N+1>& w)
406{
407 T r = 0;
408 for (unsigned i=0;i<N;++i)
409 r += v(i)*w(i);
410 return r+w(N);
411}
414template <typename T, typename S, cgv::type::uint32_type N>
415inline S dot_pos(const fvec<T,N+1>& v, const fvec<S,N>& w)
416{
417 T r = 0;
418 for (unsigned i=0;i<N;++i)
419 r += v(i)*w(i);
420 return r+v(N);
421}
422
425template <typename T, typename S, cgv::type::uint32_type N>
426inline S dot_dir(const fvec<T,N>& v, const fvec<S,N+1>& w)
427{
428 T r = 0;
429 for (unsigned i=0;i<N;++i)
430 r += v(i)*w(i);
431 return r;
432}
435template <typename T, typename S, cgv::type::uint32_type N>
436inline S dot_dir(const fvec<T,N+1>& v, const fvec<S,N>& w)
437{
438 T r = 0;
439 for (unsigned i=0;i<N;++i)
440 r += v(i)*w(i);
441 return r;
442}
443
445template <typename T, cgv::type::uint32_type N>
446inline T length(const fvec<T, N>& v) { return std::sqrt(dot(v, v)); }
447
449template <typename T, cgv::type::uint32_type N>
450inline fvec<T, N> sign(const fvec<T, N>& v) { fvec<T, N> r(v); r.sign(); return r; }
451
453template <typename T, cgv::type::uint32_type N>
454inline fvec<T, N> step(const fvec<T, N>& a, const fvec<T, N>& b) { fvec<T, N> r(a); r.step(b); return r; }
455
457template <typename T, cgv::type::uint32_type N>
458inline fvec<T, N> abs(const fvec<T, N>& v) { fvec<T, N> r(v); r.abs(); return r; }
459
461template <typename T, cgv::type::uint32_type N>
462inline fvec<T, N> round(const fvec<T, N>& v) { fvec<T, N> r(v); r.round(); return r; }
463
465template <typename T, cgv::type::uint32_type N>
466inline fvec<T, N> floor(const fvec<T, N>& v) { fvec<T, N> r(v); r.floor(); return r; }
467
469template <typename T, cgv::type::uint32_type N>
470inline fvec<T, N> ceil(const fvec<T, N>& v) { fvec<T, N> r(v); r.ceil(); return r; }
471
473template <typename T, cgv::type::uint32_type N>
474inline T sqr_length(const fvec<T,N>& v)
475{
476 return dot(v,v);
477}
478
480template < typename T, cgv::type::uint32_type N>
481inline fvec<T,N> cross(const fvec<T,N>& v, const fvec<T,N>& w)
482{
483 fvec<T,N> r(3);
484 r(0)= v(1)*w(2) - v(2)*w(1);
485 r(1)= v(2)*w(0) - v(0)*w(2);
486 r(2)= v(0)*w(1) - v(1)*w(0);
487 return r;
488}
489
491template < typename T, cgv::type::uint32_type N>
492inline fvec<T,N+1> hom(const fvec<T,N>& v)
493{
494 fvec<T,N+1> h;
495 for (unsigned i = 0; i<N; ++i)
496 h(i) = v(i);
497 h(N) = 1;
498 return h;
499}
500
502template < typename T, cgv::type::uint32_type N>
503T min_value(const fvec<T,N> &v)
504{
505 return *(std::min_element(&v(0),&v(N-1)+1));
506}
507
509template < typename T, cgv::type::uint32_type N>
510unsigned min_index(const fvec<T,N> &v)
511{
512 return (unsigned) (std::min_element(&v(0),&v(N-1)+1)-&v(0));
513}
514
516template < typename T, cgv::type::uint32_type N>
517unsigned max_index(const fvec<T,N> &v)
518{
519 return (unsigned) (std::max_element(&v(0),&v(N-1)+1)-&v(0));
520}
521
523template < typename T, cgv::type::uint32_type N>
524T max_value(const fvec<T,N> &v)
525{
526 return *(std::max_element(&v(0),&v(N-1)+1));
527}
528
530template <typename T, cgv::type::uint32_type N>
531const fvec<T, N> lerp(const fvec<T, N>& v1, const fvec<T, N>& v2, T t)
532{
533 return ((T)1 - t)*v1 + t * v2;
534}
535
537template <typename T, cgv::type::uint32_type N>
538const fvec<T, N> lerp(const fvec<T, N>& v1, const fvec<T, N>& v2, const fvec<T, N>& t)
539{
540 return (fvec<T, N>(1) - t)*v1 + t * v2;
541}
542
544template <typename T, cgv::type::uint32_type N>
545const fvec<T, N> slerp(const fvec<T, N> &v0, const fvec<T, N> &v1, T t) {
546 T dotv0v1 = dot(v0, v1);
547 // clamp between [-1,1]
548 if (dotv0v1 < -1)
549 dotv0v1 = -1;
550
551 if (dotv0v1 > 1)
552 dotv0v1 = 1;
553
554 T theta = acos(dotv0v1) * t;
555 auto v2 = normalize(v1 - (dotv0v1)*v0);
556 return T(cos(theta)) * v0 + T(sin(theta)) * v2;
557}
558
560template <typename T, cgv::type::uint32_type N>
561const fvec<T, N> min(const fvec<T, N>& v, T t) {
562 fvec<T, N> c;
563 for(unsigned i = 0; i < N; ++i)
564 c(i) = std::min(v(i), t);
565 return c;
566}
567
569template <typename T, cgv::type::uint32_type N>
570const fvec<T, N> min(const fvec<T, N>& v, const fvec<T, N>& t) {
571 fvec<T, N> c;
572 for(unsigned i = 0; i < N; ++i)
573 c(i) = std::min(v(i), t(i));
574 return c;
575}
576
578template <typename T, cgv::type::uint32_type N>
579const fvec<T, N> max(const fvec<T, N>& v, T t) {
580 fvec<T, N> c;
581 for(unsigned i = 0; i < N; ++i)
582 c(i) = std::max(v(i), t);
583 return c;
584}
585
587template <typename T, cgv::type::uint32_type N>
588const fvec<T, N> max(const fvec<T, N>& v, const fvec<T, N>& t) {
589 fvec<T, N> c;
590 for(unsigned i = 0; i < N; ++i)
591 c(i) = std::max(v(i), t(i));
592 return c;
593}
594
596template <typename T, cgv::type::uint32_type N>
597const fvec<T, N> clamp(const fvec<T, N>& v, T l, T r) {
598 fvec<T, N> c;
599 for(unsigned i = 0; i < N; ++i)
600 c(i) = cgv::math::clamp(v(i), l, r);
601 return c;
602}
603
605template <typename T, cgv::type::uint32_type N>
606const fvec<T, N> clamp(const fvec<T, N>& v, const fvec<T, N>& vl, const fvec<T, N>& vr)
607{
608 fvec<T, N> c;
609 for(unsigned i = 0; i < N; ++i)
610 c(i) = cgv::math::clamp(v(i), vl(i), vr(i));
611 return c;
612}
613
615template <typename T, cgv::type::uint32_type N>
616const fvec<T, N> saturate(const fvec<T, N>& v) {
617 return clamp(v, T(0), T(1));
618}
619
621template <typename T, cgv::type::uint32_type N>
622const fvec<T, N> pow(const fvec<T, N>& v, T e) {
623 fvec<T, N> c;
624 for(unsigned i = 0; i < N; ++i)
625 c(i) = std::pow(v(i), e);
626 return c;
627}
628
630template <typename T, cgv::type::uint32_type N>
631const fvec<T, N> pow(const fvec<T, N>& v, const fvec<T, N>& e) {
632 fvec<T, N> c;
633 for(unsigned i = 0; i < N; ++i)
634 c(i) = std::pow(v(i), e(i));
635 return c;
636}
637
639template <typename T, cgv::type::uint32_type N>
640fvec<T, N> ortho(const fvec<T, N>& v) = delete;
641
643template <typename T>
644fvec<T, 2> ortho(const fvec<T, 2>& v) {
645 return fvec<T, 2>(-v.y(), v.x());
646}
647
649template <typename T>
650fvec<T, 3> ortho(const fvec<T, 3>& v) {
651 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());
652}
653
654} // namespace math
655
658
665
672
679
692
705
718
720
721} // namespace cgv
722
723#include "vec.h"
724
725namespace cgv {
726namespace math {
727
729template <typename T, cgv::type::uint32_type N>
731 vec<T> r;
732 r.set_extern_data(N,const_cast<T*>(v));
733 return r;
734}
735
737template <typename T, cgv::type::uint32_type N>
739{
740 return fvec<T, N>(std::min(N, v.dim()), &v[0]);
741}
742
743} // namespace math
744} // namespace cgv
745
746/*
747#include <cgv/utils/convert_string.h>
748#include <cgv/type/info/type_name.h>
749
750namespace cgv {
751 namespace type {
752 namespace info {
753
754template <typename T, cgv::type::uint32_type N>
755struct type_name<cgv::math::fvec<T,N> >
756{
757 static const char* get_name() {
758 static std::string name;
759 if (name.empty()) {
760 name = "fvec<";
761 name += type_name<T>::get_name();
762 name += ',';
763 name += cgv::utils::to_string(N);
764 name += '>';
765 }
766 return name.c_str();
767 }
768};
769 }
770 }
771}
772*/
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:26
T & z()
third element
Definition fvec.h:163
T & y()
second element
Definition fvec.h:159
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:91
T safe_normalize()
normalize the vector if length is not zero using the L2-Norm and return the length
Definition fvec.h:311
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:100
T normalize()
normalize the vector using the L2-Norm and return the length
Definition fvec.h:302
fvec(const T &x, const T &y, const T &z)
construct and init first three coordinates to the given values
Definition fvec.h:89
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:141
void round()
round componentwise
Definition fvec.h:287
fvec< T, N+1 > lift() const
convert to homogeneous version by adding a 1
Definition fvec.h:139
const T & z() const
third element of const vector
Definition fvec.h:165
bool operator==(const fvec< S, N > &v) const
test for equality
Definition fvec.h:232
fvec< T, N > & operator*=(const T &s)
in place multiplication with s
Definition fvec.h:193
fvec< T, N > operator*(const fvec< S, N > &v) const
componentwise vector multiplication
Definition fvec.h:220
fvec< T, N > operator-(void) const
negates the vector
Definition fvec.h:225
fvec< T, N > & operator-=(const T &s)
in place subtraction by scalar s
Definition fvec.h:191
fvec< T, N > & operator/=(const T &s)
in place division by scalar s
Definition fvec.h:195
void sign()
componentwise sign values
Definition fvec.h:255
T & operator()(const int i)
access i'th element
Definition fvec.h:171
T * data()
cast into array. This allows calls like glVertex<N><T>v(p.data()) instead of glVertex<N><T,...
Definition fvec.h:181
T sqr_length() const
square length of vector
Definition fvec.h:294
void ones()
fill the vector with ones
Definition fvec.h:137
void set(const T &x, const T &y, const T &z)
set the first three components
Definition fvec.h:127
T length() const
length of the vector L2-Norm
Definition fvec.h:249
void floor()
floor componentwise
Definition fvec.h:281
static fvec< T, N > from_vec(const vec< T > &)
conversion from vector
Definition fvec.h:738
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:93
fvec< T, N > operator+(const fvec< S, N > &v) const
vector addition
Definition fvec.h:210
void assign(const std::array< T, N > &arr)
set to the contents of the given std::array with same size
Definition fvec.h:123
fvec< T, N > & operator+=(const T &s)
in place addition of a scalar s
Definition fvec.h:189
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:119
fvec< T, N > operator/(const fvec< S, N > &v) const
componentwise vector division
Definition fvec.h:223
bool operator!=(const fvec< S, N > &v) const
test for inequality
Definition fvec.h:239
fvec(const fvec< T, N > &rhs)
copy constructor
Definition fvec.h:106
fvec(const fvec< S, N+1 > &fv)
construct from vector of one dimension higher by cutting of the highest dimension
Definition fvec.h:115
fvec(const fvec< S1, N - 1 > &fv, S2 w)
construct from vector of one dimension less plus a scalar
Definition fvec.h:112
vec< T > to_vec() const
conversion to vector type
Definition fvec.h:730
fvec(const fvec< S, N > &fv)
copies a column vector of a different type
Definition fvec.h:109
const_reverse_iterator rend() const
reverse iterator pointing to the end of reverse iteration
Definition fvec.h:77
void set(const T &x, const T &y, const T &z, const T &w)
set the first four components
Definition fvec.h:129
void zerosh()
fill the vector with zeros except for the last component, which will be set to one
Definition fvec.h:135
fvec(const T &x, const T &y)
construct and init first two coordinates to the given values
Definition fvec.h:87
void set(const T &x, const T &y)
set the first two components
Definition fvec.h:125
const T & y() const
second element of const vector
Definition fvec.h:161
fvec(const std::array< T, N > &arr)
construct from std::array of same size
Definition fvec.h:117
fvec()
creates a vector not initialized
Definition fvec.h:83
const T & operator[](const int i) const
access i'th element of const vector
Definition fvec.h:177
const T & w() const
fourth element of const vector
Definition fvec.h:169
T & x()
first element
Definition fvec.h:155
void abs()
componentwise absolute values
Definition fvec.h:267
const T & operator()(const int i) const
access i'th element of const vector
Definition fvec.h:173
T & operator[](const int i)
access i'th element
Definition fvec.h:175
const T & x() const
first element of const vector
Definition fvec.h:157
void ceil()
ceil componentwise
Definition fvec.h:275
T & w()
fourth element
Definition fvec.h:167
void zeros()
fill the vector with zeros
Definition fvec.h:133
fvec(const T &a)
creates a vector, where all N components are initialized to the constant value a
Definition fvec.h:85
void fill(const T &a)
fill elements of vector with scalar v
Definition fvec.h:131
void step(const fvec< T, N > &r)
componentwise sign values
Definition fvec.h:261
const T * data() const
cast into const array
Definition fvec.h:183
static cgv::type::uint32_type size()
return number of elements
Definition fvec.h:179
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
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:707
cgv::math::fvec< uint16_t, 4 > usvec4
declare type of 4d 16 bit unsigned integer vectors
Definition fvec.h:691
cgv::math::fvec< float, 4 > vec4
declare type of 4d single precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:671
cgv::math::fvec< uint64_t, 4 > ulvec4
declare type of 4d 64 bit unsigned integer vectors
Definition fvec.h:717
cgv::math::fvec< double, 4 > dvec4
declare type of 4d double precision floating point vectors (used for homogeneous coordinates)
Definition fvec.h:678
cgv::math::fvec< double, 3 > dvec3
declare type of 3d double precision floating point vectors
Definition fvec.h:676
cgv::math::fvec< uint32_t, 3 > uvec3
declare type of 3d 32 bit unsigned integer vectors
Definition fvec.h:702
cgv::math::fvec< int32_t, 3 > ivec3
declare type of 3d 32 bit integer vectors
Definition fvec.h:696
cgv::math::fvec< int32_t, 4 > ivec4
declare type of 4d 32 bit integer vectors
Definition fvec.h:698
cgv::math::fvec< uint32_t, 4 > uvec4
declare type of 4d 32 bit unsigned integer vectors
Definition fvec.h:704
cgv::math::fvec< int32_t, 2 > ivec2
declare type of 2d 32 bit integer vectors
Definition fvec.h:694
cgv::math::fvec< int16_t, 3 > svec3
declare type of 3d 16 bit integer vectors
Definition fvec.h:683
cgv::math::fvec< uint16_t, 3 > usvec3
declare type of 3d 16 bit unsigned integer vectors
Definition fvec.h:689
cgv::math::fvec< float, 2 > vec2
declare type of 2d single precision floating point vectors
Definition fvec.h:667
cgv::math::fvec< int64_t, 3 > lvec3
declare type of 3d 64 bit integer vectors
Definition fvec.h:709
cgv::math::fvec< bool, 4 > bvec4
declare type of 4d boolean vectors
Definition fvec.h:664
cgv::math::fvec< float, 3 > vec3
declare type of 3d single precision floating point vectors
Definition fvec.h:669
cgv::math::fvec< double, 2 > dvec2
declare type of 2d double precision floating point vectors
Definition fvec.h:674
cgv::math::fvec< uint16_t, 2 > usvec2
declare type of 2d 16 bit unsigned integer vectors
Definition fvec.h:687
cgv::math::fvec< uint32_t, 2 > uvec2
declare type of 2d 32 bit unsigned integer vectors
Definition fvec.h:700
cgv::math::fvec< int16_t, 2 > svec2
declare type of 2d 16 bit integer vectors
Definition fvec.h:681
cgv::math::fvec< uint64_t, 3 > ulvec3
declare type of 3d 64 bit unsigned integer vectors
Definition fvec.h:715
cgv::math::fvec< int64_t, 4 > lvec4
declare type of 4d 64 bit integer vectors
Definition fvec.h:711
cgv::math::fvec< bool, 3 > bvec3
declare type of 3d boolean vectors
Definition fvec.h:662
cgv::math::fvec< int16_t, 4 > svec4
declare type of 4d 16 bit integer vectors
Definition fvec.h:685
cgv::math::fvec< bool, 2 > bvec2
declare type of 2d boolean vectors
Definition fvec.h:660
cgv::math::fvec< uint64_t, 2 > ulvec2
declare type of 2d 64 bit unsigned integer vectors
Definition fvec.h:713
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