3 #define _USE_MATH_DEFINES
8 #include <cgv/type/standard_types.h>
13 template <
typename T>
class vec;
16 template <
typename T, cgv::type::u
int32_type N>
30 typedef const T& const_reference;
32 typedef std::size_t size_type;
34 typedef std::ptrdiff_t difference_type;
38 typedef const T* const_pointer;
42 typedef const T* const_iterator;
44 typedef std::reverse_iterator<iterator> reverse_iterator;
46 typedef std::reverse_iterator<const_iterator> const_reverse_iterator;
51 iterator begin() {
return v; }
54 iterator end() {
return v+N; }
56 const_iterator begin()
const {
return v; }
58 const_iterator end()
const {
return v+N; }
60 reverse_iterator rbegin() {
return reverse_iterator(end()); }
62 reverse_iterator rend() {
return reverse_iterator(begin()); }
64 const_reverse_iterator rbegin()
const {
return const_reverse_iterator(end()); }
66 const_reverse_iterator
rend()
const {
return const_reverse_iterator(begin()); }
74 fvec(
const T &a) { std::fill(v, v+N, a); }
84 std::copy(a, a+min_n, v);
85 for (i = min_n; i < N; ++i) v[i] = T(0);
91 for (i=0; i<min_n; ++i) v[i] = (T)a[i];
92 for (; i < N; ++i) v[i] = T(0);
95 fvec(
const fvec<T,N> &rhs) {
if (
this != &rhs) std::copy(rhs.v, rhs.v+N, v); }
98 fvec(
const fvec<S,N>& fv) {
for (
unsigned i=0; i<N; ++i) v[i] = (T)fv(i); }
100 template <
typename S1,
typename S2>
107 void set(
const T &
x,
const T &
y) { v[0] =
x; v[1] =
y; }
109 void set(
const T &
x,
const T &
y,
const T &
z) { v[0] =
x; v[1] =
y; v[2] =
z; }
111 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; }
113 void fill(
const T& a) { std::fill(v, v+N, a); }
128 T&
x() {
return v[0]; }
131 const T&
x()
const {
return v[0]; }
133 T&
y() {
return v[1]; }
135 const T&
y()
const {
return v[1]; }
137 T&
z() {
return v[2]; }
139 const T&
z()
const {
return v[2]; }
141 T&
w() {
return v[3]; }
143 const T&
w()
const {
return v[3]; }
151 operator T*() {
return v; }
153 operator const T*()
const {
return v; }
167 template <
typename S>
170 template <
typename S>
173 template <
typename S>
176 template <
typename S>
179 template <
typename S>
186 template <
typename S>
189 template <
typename S>
192 template <
typename S>
201 template <
typename S>
203 for (
unsigned i=0;i<N;++i)
204 if(
operator()(i) != (T)v(i))
return false;
208 template <
typename S>
210 for (
unsigned i=0;i<N;++i)
211 if(
operator()(i) != (T)v(i))
return true;
226 if(std::numeric_limits<T>::is_signed) {
227 for(
unsigned i = 0; i < N;i++)
228 v[i]=(T)std::abs((
double)v[i]);
234 for(
unsigned i = 0; i < N;i++)
235 v[i]=(T)
::ceil((
double)v[i]);
240 for(
unsigned i = 0; i < N;i++)
246 for(
unsigned i = 0; i < N;i++)
247 v[i]=(T)
::floor((
double)v[i]+0.5);
254 for(
unsigned i = 0; i!=N;i++)
255 l+=
operator()(i)*
operator()(i);
263 for(
unsigned i = 0; i<N; i++)
264 operator()(i)=inv_l*
operator()(i);
271 template<
typename T, cgv::type::u
int32_type N>
275 template<
typename T, cgv::type::u
int32_type N>
278 for (
unsigned i=0;i<N-1;++i)
286 template<
typename T, cgv::type::u
int32_type N>
289 for (
unsigned i=0;i<N;++i)
295 template <
typename T, cgv::type::u
int32_type N>
299 template <
typename T, cgv::type::u
int32_type N>
303 for (
unsigned i=0;i<N;++i)
309 template <
typename T, cgv::type::u
int32_type N>
313 template <
typename T, cgv::type::u
int32_type N>
317 template <
typename T, cgv::type::u
int32_type N>
321 template <
typename T, cgv::type::u
int32_type N>
325 template <
typename T, cgv::type::u
int32_type N>
329 template <
typename T, cgv::type::u
int32_type N>
337 template <
typename T, cgv::type::u
int32_type N>
341 r(0)= v(1)*w(2) - v(2)*w(1);
342 r(1)= v(2)*w(0) - v(0)*w(2);
343 r(2)= v(0)*w(1) - v(1)*w(0);
348 template <
typename T, cgv::type::u
int32_type N>
352 for (
unsigned i = 0; i<N; ++i)
359 template <
typename T, cgv::type::u
int32_type N>
362 return *(std::min_element(&v(0),&v(N-1)+1));
366 template <
typename T, cgv::type::u
int32_type N>
369 return (
unsigned) (std::min_element(&v(0),&v(N-1)+1)-&v(0));
373 template <
typename T, cgv::type::u
int32_type N>
376 return (
unsigned) (std::max_element(&v(0),&v(N-1)+1)-&v(0));
380 template <
typename T, cgv::type::u
int32_type N>
383 return *(std::max_element(&v(0),&v(N-1)+1));
387 template <
typename T, cgv::type::u
int32_type N>
390 return ((T)1 - t)*v1 + t * v2;
394 template <
typename T, cgv::type::u
int32_type N>
410 template <
typename T, cgv::type::u
int32_type N>
418 template <
typename T, cgv::type::u
int32_type N>
421 return fvec<T, N>(std::min(N, v.dim()), &v[0]);
const_reverse_iterator rend() const
reverse iterator pointing to the end of reverse iteration
Definition: fvec.h:66
fvec< T, N > & operator-=(const T &s)
in place subtraction by scalar s
Definition: fvec.h:161
double normalize()
normalize the vector using the L2-Norm and return the length
Definition: fvec.h:260
fvec(const T &x, const T &y, const T &z)
construct and init first three coordinates to the given values
Definition: fvec.h:78
fvec(const fvec< T, N > &rhs)
copy constructor
Definition: fvec.h:95
const T & z() const
third element of const vector
Definition: fvec.h:139
T length() const
length of the vector L2-Norm
Definition: fvec.h:219
const T & w() const
fourth element of const vector
Definition: fvec.h:143
fvec< T, N > & operator+=(const T &s)
in place addition of a scalar s
Definition: fvec.h:159
T & y()
second element
Definition: fvec.h:133
fvec< T, N > cross(const fvec< T, N > &v, const fvec< T, N > &w)
returns the cross product of vector v and w
Definition: fvec.h:338
void round()
round componentwise
Definition: fvec.h:245
fvec< T, N > round(const fvec< T, N > &v)
apply round function component wise to vector
Definition: fvec.h:318
void zeros()
fill the vector with zeros
Definition: fvec.h:115
const T & y() const
second element of const vector
Definition: fvec.h:135
void abs()
componentwise absolute values
Definition: fvec.h:225
void set_extern_data(unsigned dim, T *data)
set data pointer to an external data array
Definition: vec.h:232
void floor()
floor componentwise
Definition: fvec.h:239
A column vector class.
Definition: fvec.h:13
bool operator!=(const fvec< S, N > &v) const
test for inequality
Definition: fvec.h:209
void set(const T &x, const T &y, const T &z, const T &w)
set the first four components
Definition: fvec.h:111
bool operator==(const fvec< S, N > &v) const
test for equality
Definition: fvec.h:202
T & operator()(const int i)
access i'th element
Definition: fvec.h:145
T & w()
fourth element
Definition: fvec.h:141
fvec< T, N > & operator*=(const T &s)
in place multiplication with s
Definition: fvec.h:163
fvec< T, N > floor(const fvec< T, N > &v)
apply floor function component wise to vector
Definition: fvec.h:322
fvec(const fvec< S1, N - 1 > &fv, S2 w)
construct from vector of one dimension less plus a scalar
Definition: fvec.h:101
void set(const T &x, const T &y)
set the first two components
Definition: fvec.h:107
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:82
std::ostream & operator<<(std::ostream &out, const diag_mat< T > &m)
output of a diagonal matrix onto an ostream
Definition: diag_mat.h:442
fvec(const T &a)
creates a vector, where all N components are initialized to the constant value a
Definition: fvec.h:74
unsigned max_index(const fvec< T, N > &v)
return the index of the largest entry
Definition: fvec.h:374
fvec< T, N > abs(const fvec< T, N > &v)
apply abs function component wise to vector
Definition: fvec.h:314
T sqr_length() const
square length of vector
Definition: fvec.h:252
vec< T > to_vec() const
conversion to vector type
Definition: fvec.h:411
T & x()
first element
Definition: fvec.h:129
const fmat< T, N, M > lerp(const fmat< T, N, M > &m1, const fmat< T, N, M > &m2, T t)
linear interpolation returns (1-t)*m1 + t*m2
Definition: fmat.h:259
void ceil()
ceil componentwise
Definition: fvec.h:233
T min_value(const fvec< T, N > &v)
returns the minimal entry
Definition: fvec.h:360
const T & x() const
first element of const vector
Definition: fvec.h:131
fvec< T, N > ceil(const fvec< T, N > &v)
apply ceil function component wise to vector
Definition: fvec.h:326
static cgv::type::uint32_type size()
return number of elements
Definition: fvec.h:149
T sqr_length(const fvec< T, N > &v)
returns the squared length of vector v
Definition: fvec.h:330
fvec()
creates a vector not initialized
Definition: fvec.h:72
fvec< T, N > operator-(void) const
negates the vector
Definition: fvec.h:195
void fill(const T &a)
fill elements of vector with scalar v
Definition: fvec.h:113
fvec< T, N > operator/(const fvec< S, N > &v) const
componentwise vector division
Definition: fvec.h:193
std::istream & operator>>(std::istream &in, diag_mat< T > &m)
input of a diagonal matrix from an istream
Definition: diag_mat.h:453
T max_value(const fvec< T, N > &v)
return the value of the largest entry
Definition: fvec.h:381
unsigned int uint32_type
this type provides an 32 bit unsigned integer type
Definition: standard_types.h:20
static fvec< T, N > from_vec(const vec< T > &)
conversion from vector
Definition: fvec.h:419
fvec< T, N+1 > hom(const fvec< T, N > &v)
returns the cross product of vector v and w
Definition: fvec.h:349
void set(const T &x, const T &y, const T &z)
set the first three components
Definition: fvec.h:109
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:103
T dot(const fvec< T, N > &v, const fvec< T, N > &w)
returns the dot product of vector v and w
Definition: fvec.h:300
fvec(const fvec< S, N > &fv)
copies a column vector of a different type
Definition: fvec.h:98
void ones()
fill the vector with ones
Definition: fvec.h:117
const T & operator()(const int i) const
access i'th element of const vector
Definition: fvec.h:147
fvec< T, N > operator+(const fvec< S, N > &v) const
vector addition
Definition: fvec.h:180
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:89
T & z()
third element
Definition: fvec.h:137
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:80
fvec< T, N+1 > lift() const
convert to homogeneous version by adding a 1
Definition: fvec.h:119
fvec(const T &x, const T &y)
construct and init first two coordinates to the given values
Definition: fvec.h:76
the cgv namespace
Definition: vr_calib.cxx:9
unsigned min_index(const fvec< T, N > &v)
returns the index of the smallest value
Definition: fvec.h:367
fvec< T, N > normalize(const fvec< T, N > &v)
return normalized vector
Definition: fvec.h:272
fvec< T, N > operator*(const fvec< S, N > &v) const
componentwise vector multiplication
Definition: fvec.h:190
T length(const fvec< T, N > &v)
returns the length of vector v
Definition: fvec.h:310
fvec< T, N > & operator/=(const T &s)
in place division by scalar s
Definition: fvec.h:165