30 #include <cugar/basic/types.h> 31 #include <cugar/basic/numbers.h> 35 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER 38 #pragma warning(disable:4068) 53 template <
typename T, u
int32 DIM>
58 static const uint32 DIMENSION = DIM;
60 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
63 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
67 for (uint32 d = 0; d < DIM; ++d)
71 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
75 for (uint32 d = 0; d < DIM; ++d)
79 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
80 uint32 dimension()
const {
return DIM; }
82 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
83 const T& operator[] (
const uint32 i)
const {
return data[i]; }
85 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
86 T& operator[] (
const uint32 i) {
return data[i]; }
100 static const uint32 DIMENSION = 1;
102 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
105 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
111 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
112 uint32 dimension()
const {
return 1; }
114 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
115 const T& operator[] (
const uint32 i)
const {
return data; }
117 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
118 T& operator[] (
const uint32 i) {
return data; }
120 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
121 operator base_type()
const {
return data; }
129 template <
typename T>
133 typedef T value_type;
135 static const uint32 DIMENSION = 2;
137 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
140 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
143 base_type::x = base_type::y = v;
146 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
153 template <
typename U>
154 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
157 base_type::x = T(op[0]);
158 base_type::y = T(op[1]);
161 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
164 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
165 uint32 dimension()
const {
return 2; }
167 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
168 const T& operator[] (
const uint32 i)
const {
return (&this->base_type::x)[i]; }
170 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
171 T& operator[] (
const uint32 i) {
return (&this->base_type::x)[i]; }
176 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
179 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
186 template <
typename T>
190 typedef T value_type;
192 static const uint32 DIMENSION = 3;
194 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
197 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
200 base_type::x = base_type::y = base_type::z = v;
203 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
211 template <
typename U>
212 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
215 base_type::x = T(op[0]);
216 base_type::y = T(op[1]);
217 base_type::z = T(op[2]);
220 template <
typename U>
221 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
224 base_type::x = T(op[0]);
225 base_type::y = T(op[1]);
226 base_type::z = T(v2);
229 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
232 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
233 uint32 dimension()
const {
return 3; }
235 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
236 const T& operator[] (
const uint32 i)
const {
return (&this->base_type::x)[i]; }
238 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
239 T& operator[] (
const uint32 i) {
return (&this->base_type::x)[i]; }
241 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
244 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
247 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
250 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
253 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
263 template <
typename T>
267 typedef T value_type;
269 static const uint32 DIMENSION = 4;
271 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
274 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
277 base_type::x = base_type::y = base_type::z = base_type::w = v;
280 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
281 Vector<T,4>(
const T v0,
const T v1,
const T v2,
const T v3)
289 template <
typename U>
290 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
293 base_type::x = T(op[0]);
294 base_type::y = T(op[1]);
295 base_type::z = T(op[2]);
296 base_type::w = T(op[3]);
299 template <
typename U>
300 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
303 base_type::x = T(op[0]);
304 base_type::y = T(op[1]);
305 base_type::z = T(op[2]);
309 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
312 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
313 uint32 dimension()
const {
return 4; }
315 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
316 const T& operator[] (
const uint32 i)
const {
return (&this->base_type::x)[i]; }
318 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
319 T& operator[] (
const uint32 i) {
return (&this->base_type::x)[i]; }
321 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
324 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
327 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
330 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
333 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
340 template <
typename T,u
int32 DIM_T>
struct vector_traits<
Vector<T,DIM_T> > {
typedef T value_type;
const static uint32 DIM = DIM_T; };
345 template <
typename T, u
int32 DIM>
346 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
352 template <
typename T, u
int32 DIM>
353 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
359 template <
typename T, u
int32 DIM>
360 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
366 template <
typename T, u
int32 DIM>
367 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
373 template <
typename T, u
int32 DIM>
374 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
380 template <
typename T, u
int32 DIM>
381 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
387 template <
typename T, u
int32 DIM>
388 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
394 template <
typename T, u
int32 DIM>
395 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
401 template <
typename T, u
int32 DIM>
402 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
408 template <
typename T, u
int32 DIM>
409 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
415 template <
typename T, u
int32 DIM>
416 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
422 template <
typename T, u
int32 DIM>
423 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
429 template <
typename T, u
int32 DIM>
430 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
436 template <
typename T, u
int32 DIM>
437 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
443 template <
typename T, u
int32 DIM>
444 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
450 template <
typename T, u
int32 DIM>
451 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
457 template <
typename T, u
int32 DIM>
458 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
464 template <
typename T, u
int32 DIM>
465 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
471 template <
typename T, u
int32 DIM>
472 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
478 template <
typename T, u
int32 DIM>
479 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
485 template <
typename T, u
int32 DIM>
486 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
492 template <
typename T, u
int32 DIM>
493 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
499 template <
typename T, u
int32 DIM>
500 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
506 template <
typename T, u
int32 DIM>
507 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
513 template <
typename T, u
int32 DIM>
514 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
520 template <
typename T, u
int32 DIM>
521 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
522 bool operator< (const Vector<T,DIM>& op1,
const Vector<T,DIM>& op2);
527 template <
typename T, u
int32 DIM>
528 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
534 template <
typename T, u
int32 DIM>
535 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
536 bool operator<= (const Vector<T,DIM>& op1,
const Vector<T,DIM>& op2);
541 template <
typename T, u
int32 DIM>
542 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
548 template <
typename T, u
int32 DIM>
549 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
555 template <
typename T, u
int32 DIM>
556 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
562 template <
typename T, u
int32 DIM>
563 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
569 template <
typename T>
570 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
579 template <
typename T>
580 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
589 template <
typename T>
590 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
599 template <
typename T>
600 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
606 template <
typename T>
607 CUGAR_HOST_DEVICE CUGAR_FORCEINLINE
613 template <
typename T>
620 template <
typename T>
630 template <
typename T>
637 template <
typename T>
644 template <
typename T, u
int32 DIM>
645 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
651 template <
typename T, u
int32 DIM>
652 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
658 template <
typename T, u
int32 DIM>
659 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
665 template <
typename T, u
int32 DIM>
666 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
672 template <
typename T, u
int32 DIM>
673 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
679 template <
typename T, u
int32 DIM>
680 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
686 template <
typename T, u
int32 DIM, u
int32 p>
687 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
693 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
699 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
700 double L1_norm(
const double op);
705 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
711 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
712 double L2_norm(
const double op);
717 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
723 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
730 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
731 float L_norm(
const float op);
737 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
738 double L_norm(
const double op);
743 template <
typename T, u
int32 DIM>
744 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
750 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
756 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
757 double average(
const double op);
762 template <
typename T, u
int32 DIM>
763 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
769 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
770 float lerp(
const float op1,
const float op2,
const float u);
775 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
776 double lerp(
const double op1,
const double op2,
const double u);
796 #include <cugar/linalg/vector_inl.h> 798 #if (defined _WIN32 || defined _WIN64) && defined _MSC_VER CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > refract(const Vector< T, 3 > I, const Vector< T, 3 > N, const float eta)
Definition: vector_inl.h:368
CUGAR_HOST_DEVICE void orthonormal_basis(const Vector< T, 3 > normal, Vector< T, 3 > &tangent, Vector< T, 3 > &bitangent)
Definition: vector_inl.h:423
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T max_comp(const Vector< T, DIM > &op)
Definition: tensor_inl.h:425
CUGAR_HOST_DEVICE Vector< T, 3 > orthogonal(const Vector< T, 3 > v)
Definition: tensor_inl.h:362
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator-(const Vector< T, DIM > &op)
Definition: tensor_inl.h:45
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator-=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:85
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator+=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:66
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T min_comp(const Vector< T, DIM > &op)
Definition: tensor_inl.h:436
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator/=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:152
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:594
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator>(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:286
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator!=(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:252
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > min(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:180
Definition: numbers.h:463
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator==(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:241
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > refraction_normal(const Vector< T, 3 > I, const Vector< T, 3 > T, const float eta)
Definition: vector_inl.h:379
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T length(const Vector< T, DIM > &op)
Definition: tensor_inl.h:326
CUGAR_HOST_DEVICE Vector< T, 2 > unpack_vector(const uint32 u, const uint32 n_bits_comp)
Definition: tensor_inl.h:404
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3u > cross(const Vector< T, 3u > &op1, const Vector< T, 3u > &op2)
Definition: tensor_inl.h:341
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T dot(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:309
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator*(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:94
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator/(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:142
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool all(const Vector< T, DIM > &op)
Definition: tensor_inl.h:230
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool is_finite(const Vector< T, DIM > &op)
Definition: tensor_inl.h:458
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > faceforward(const Vector< T, 3 > N, const Vector< T, 3 > I)
Definition: tensor_inl.h:356
Definition: numbers.h:368
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > mod(const Vector< T, DIM > &op, const T m)
Definition: tensor_inl.h:414
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > operator+(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:56
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > & operator*=(Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:104
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool operator>=(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:298
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > lerp(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2, const T u)
Definition: vector_inl.h:723
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE bool any(const Vector< T, DIM > &op)
Definition: tensor_inl.h:220
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L1_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:560
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T average(const Vector< T, DIM > &op)
Definition: vector_inl.h:692
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > abs(const Vector< T, DIM > &op)
Definition: vector_inl.h:221
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > sqrt(const Vector< T, DIM > &op)
Definition: vector_inl.h:487
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > normalize(const Vector< T, DIM > &op)
Definition: tensor_inl.h:333
CUGAR_HOST_DEVICE CUGAR_FORCEINLINE Vector< T, 3 > reflect(const Vector< T, 3 > I, const Vector< T, 3 > N)
Definition: tensor_inl.h:350
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE Vector< T, DIM > max(const Vector< T, DIM > &op1, const Vector< T, DIM > &op2)
Definition: tensor_inl.h:190
CUGAR_HOST_DEVICE uint32 pack_vector(const Vector< T, 2 > v, const uint32 n_bits_comp)
Definition: tensor_inl.h:394
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L_inf_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:584
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE T L2_norm(const Vector< T, DIM > &op)
Definition: vector_inl.h:574