36 #include <cugar/basic/types.h> 60 CUGAR_HOST_DEVICE
bool operator() (
const T t)
const {
return t ? true :
false; }
66 template <
typename T,
typename R>
70 typedef T argument_type;
71 typedef R result_type;
79 CUGAR_HOST_DEVICE R operator() (
const T op)
const {
return constant; }
86 template <
typename T,
typename R>
90 typedef T argument_type;
91 typedef R result_type;
93 CUGAR_HOST_DEVICE R operator() (
const T op)
const {
return R(1); }
102 typedef uint32 argument_type;
103 typedef uint32 result_type;
105 CUGAR_HOST_DEVICE uint32 operator() (
const uint32 op)
const 113 template <
typename T>
117 typedef T argument_type;
118 typedef T result_type;
120 CUGAR_HOST_DEVICE T operator() (
const T op)
const {
return !op; }
125 template <
typename T>
129 typedef T argument_type;
130 typedef T result_type;
132 CUGAR_HOST_DEVICE T operator() (
const T op)
const {
return op - T(1); }
137 template <
typename F,
typename C>
141 typedef typename F::first_argument_type argument_type;
142 typedef typename F::result_type result_type;
145 binder1st(
const F& f,
const C c) : functor(f), first(c) {}
147 CUGAR_HOST_DEVICE uint32 operator() (
const uint32 op)
const {
return functor( first, op ); }
155 template <
typename F,
typename C>
159 typedef typename F::second_argument_type argument_type;
160 typedef typename F::result_type result_type;
163 binder2nd(
const F& f,
const C c) : functor(f), second(c) {}
165 CUGAR_HOST_DEVICE uint32 operator() (
const uint32 op)
const {
return functor( op, second ); }
176 template <
typename Vector_type>
180 typedef Vector_type first_argument_type;
181 typedef uint32 second_argument_type;
182 typedef typename Vector_type::value_type result_type;
184 CUGAR_HOST_DEVICE result_type operator() (
const first_argument_type v,
const second_argument_type i)
const {
return v[i]; }
189 template <
typename T>
193 typedef T argument_type;
194 typedef T result_type;
196 CUGAR_HOST_DEVICE T operator() (
const T& v)
const {
return v*v; }
201 template <
typename T>
205 typedef T argument_type;
206 typedef bool result_type;
208 CUGAR_HOST_DEVICE
bool operator() (
const T& v)
const {
return v > 0; }
213 template <
typename T>
217 typedef T first_argument_type;
218 typedef T second_argument_type;
219 typedef bool result_type;
221 CUGAR_HOST_DEVICE
bool operator() (
const T& op1,
const T& op2)
const {
return op1 == op2; }
226 template <
typename T>
230 typedef T first_argument_type;
231 typedef T second_argument_type;
232 typedef bool result_type;
234 CUGAR_HOST_DEVICE
bool operator() (
const T& op1,
const T& op2)
const {
return op1 != op2; }
239 template <
typename T>
243 typedef T argument_type;
244 typedef bool result_type;
252 CUGAR_HOST_DEVICE
bool operator() (
const T& v)
const {
return v == m_c; }
260 template <
typename T>
264 typedef T argument_type;
265 typedef bool result_type;
273 CUGAR_HOST_DEVICE
bool operator() (
const T& v)
const {
return v != m_c; }
282 template <
typename T,
typename R>
286 typedef T argument_type;
287 typedef R result_type;
296 CUGAR_HOST_DEVICE R operator() (
const T& v)
const {
return v ? m_r_true : m_r_false; }
306 template <
typename T,
typename R>
310 typedef T argument_type;
311 typedef R result_type;
319 if_constant(
const T c,
const R r0,
const R r1) : m_c(c), m_r_true(r0), m_r_false(r1) {}
321 CUGAR_HOST_DEVICE R operator() (
const T& v)
const {
return v == m_c ? m_r_true : m_r_false; }
331 template <
typename F1,
typename F2>
335 typedef typename F2::first_argument_type argument_type;
336 typedef typename F1::result_type result_type;
339 compose_unary(
const F1 f1,
const F2 f2) : m_fun1(f1), m_fun2(f2) {}
341 CUGAR_HOST_DEVICE result_type operator() (
const argument_type& op)
const {
return m_fun1( m_fun2( op ) ); }
350 template <
typename F,
typename G1,
typename G2>
354 typedef typename G1::argument_type first_argument_type;
355 typedef typename G2::argument_type second_argument_type;
356 typedef typename F::result_type result_type;
359 compose_binary(
const F f,
const G1 g1,
const G2 g2) : m_f(f), m_g1(g1), m_g2(g2) {}
361 CUGAR_HOST_DEVICE result_type operator() (
362 const first_argument_type& op1,
363 const second_argument_type& op2)
const {
return m_f( m_g1( op1 ), m_g2( op2 ) ); }
373 template <
typename F1,
typename F2>
377 typedef typename F2::first_argument_type first_argument_type;
378 typedef typename F2::second_argument_type second_argument_type;
379 typedef typename F1::result_type result_type;
384 CUGAR_HOST_DEVICE result_type operator() (
385 const first_argument_type& op1,
386 const second_argument_type& op2)
const {
return m_fun1( m_fun2( op1, op2 ) ); }
393 template <
typename F1,
typename F2,
typename T1,
typename T2>
395 template <
typename F1,
typename F2>
397 template <
typename F1,
typename F2>
402 template <
typename F1,
typename F2>
409 template <
typename F,
typename G1,
typename G2>
418 template <
typename T>
421 typedef T first_argument_type;
422 typedef T second_argument_type;
423 typedef T result_type;
425 CUGAR_HOST_DEVICE T operator() (
const T a,
const T b)
const {
return a < b ? a : b; }
430 template <
typename T>
433 typedef T first_argument_type;
434 typedef T second_argument_type;
435 typedef T result_type;
437 CUGAR_HOST_DEVICE T operator() (
const T a,
const T b)
const {
return a > b ? a : b; }
443 template <
typename T>
446 typedef T first_argument_type;
447 typedef T second_argument_type;
448 typedef T result_type;
450 CUGAR_HOST_DEVICE T operator() (
const T op1,
const T op2)
const {
return op1 + op2; }
455 template <
typename T>
458 typedef T first_argument_type;
459 typedef T second_argument_type;
460 typedef T result_type;
462 CUGAR_HOST_DEVICE T operator() (
const T op1,
const T op2)
const {
return op1 | op2; }
467 template <
typename T>
470 typedef T first_argument_type;
471 typedef T second_argument_type;
472 typedef T result_type;
474 CUGAR_HOST_DEVICE T operator() (
const T op1,
const T op2)
const {
return op1 & op2; }
480 template <
typename T>
483 typedef T argument_type;
484 typedef T result_type;
489 CUGAR_HOST_DEVICE
mask_and(
const T mask) : m_mask( mask ) {}
491 CUGAR_HOST_DEVICE T operator() (
const T op)
const {
return op & m_mask; }
500 template <
typename T>
503 typedef T argument_type;
504 typedef T result_type;
509 CUGAR_HOST_DEVICE
mask_or(
const T mask) : m_mask( mask ) {}
511 CUGAR_HOST_DEVICE T operator() (
const T op)
const {
return op | m_mask; }
520 template <
typename T>
523 typedef T argument_type;
524 typedef T result_type;
531 CUGAR_HOST_DEVICE T operator() (
const T x)
const {
return x << m_bits; }
540 template <
typename T>
543 typedef T argument_type;
544 typedef T result_type;
551 CUGAR_HOST_DEVICE T operator() (
const T x)
const {
return x >> m_bits; }
561 template <
typename Vector_type>
564 typedef Vector_type argument_type;
565 typedef float result_type;
572 CUGAR_HOST_DEVICE
float operator() (
const Vector_type& dir)
const {
return max( dot( dir, m_normal ), 0.0f ); }
574 const Vector_type m_normal;
581 template <
typename Vector_type>
584 typedef Vector_type argument_type;
585 typedef float result_type;
592 CUGAR_HOST_DEVICE
float operator() (
const Vector_type& dir)
const {
return fabsf( dot( dir, m_normal ) ); }
594 const Vector_type m_normal;
600 template <
typename T>
604 typedef T first_argument_type;
605 typedef T second_argument_type;
606 typedef bool result_type;
608 CUGAR_HOST_DEVICE
bool operator() (
const T& op1,
const T& op2)
const {
return op1 < op2; }
613 template <
typename T>
617 typedef T first_argument_type;
618 typedef T second_argument_type;
619 typedef bool result_type;
621 CUGAR_HOST_DEVICE
bool operator() (
const T& op1,
const T& op2)
const {
return op1 > op2; }
627 template <
typename word_type>
630 typedef word_type argument_type;
631 typedef word_type result_type;
633 static const uint32 BITS = 8u *
sizeof(word_type);
637 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
642 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
643 result_type operator() (
const argument_type op)
const {
return op >> (BITS - n_bits); }
650 template <
typename word_type>
653 typedef word_type argument_type;
654 typedef word_type result_type;
658 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
663 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
664 result_type operator() (
const argument_type i)
const 667 return result_type(i) << shift;
675 template <
typename word_type>
678 typedef word_type argument_type;
679 typedef word_type result_type;
683 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
688 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
689 result_type operator() (
const argument_type i)
const 692 return result_type(i) >> shift;
700 template <
typename T,
typename U>
708 typedef uint32 argument_type;
709 typedef uint8 result_type;
711 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
712 result_type operator() (
const argument_type op)
const {
return result_type(op >> 24u); }
720 typedef uint32 argument_type;
721 typedef uint16 result_type;
723 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
724 result_type operator() (
const argument_type op)
const {
return result_type(op >> 16u); }
732 typedef uint32 argument_type;
733 typedef uint32 result_type;
735 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
736 result_type operator() (
const argument_type op)
const {
return result_type(op); }
744 typedef uint64 argument_type;
745 typedef uint32 result_type;
747 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
748 result_type operator() (
const argument_type op)
const {
return result_type(op >> 32); }
753 template <
typename T>
756 typedef T argument_type;
757 typedef bool result_type;
759 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
760 result_type operator() (
const T op)
const {
return op ? true :
false; }
765 template <
typename T>
768 typedef T argument_type;
769 typedef bool result_type;
771 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
772 result_type operator() (
const T op)
const {
return op ? false :
true; }
777 template <
typename Iterator,
typename index_type = u
int32>
780 typedef index_type argument_type;
781 typedef typename std::iterator_traits<Iterator>::value_type result_type;
783 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
786 CUGAR_FORCEINLINE CUGAR_HOST_DEVICE
787 result_type operator() (
const argument_type op)
const {
return m_perm[op]; }
791 template <
typename Iterator>
Definition: functors.h:48
Definition: functors.h:126
Definition: functors.h:261
Definition: functors.h:332
Definition: functors.h:521
Definition: functors.h:766
Definition: functors.h:651
Definition: functors.h:614
Definition: functors.h:456
CUGAR_HOST_DEVICE eq_constant(const T c)
Definition: functors.h:250
Definition: functors.h:501
Definition: functors.h:240
CUGAR_HOST_DEVICE clamped_cosine_functor(const Vector_type &normal)
Definition: functors.h:570
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE shift_right(const uint32 _shift)
Definition: functors.h:684
CUGAR_HOST_DEVICE if_true_functor(const R r0, const R r1)
Definition: functors.h:294
Definition: functors.h:541
Definition: functors.h:114
Definition: functors.h:419
Definition: functors.h:49
Definition: functors.h:701
Definition: functors.h:374
Definition: functors.h:99
Definition: functors.h:283
Definition: functors.h:444
CUGAR_HOST_DEVICE r_bit_shift(const T bits)
Definition: functors.h:549
Definition: functors.h:351
Definition: functors.h:468
Definition: functors.h:676
CUGAR_HOST_DEVICE mask_and(const T mask)
Definition: functors.h:489
CUGAR_HOST_DEVICE constant_functor(R c)
Definition: functors.h:77
CUGAR_HOST_DEVICE l_bit_shift(const T bits)
Definition: functors.h:529
Definition: functors.h:87
Definition: functors.h:394
Definition: functors.h:628
Definition: functors.h:227
Definition: functors.h:481
Definition: functors.h:177
Definition: functors.h:56
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE leading_bits(const uint32 n)
Definition: functors.h:638
CUGAR_HOST_DEVICE if_constant(const T c, const R r0, const R r1)
Definition: functors.h:319
CUGAR_HOST_DEVICE mask_or(const T mask)
Definition: functors.h:509
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_FORCEINLINE CUGAR_HOST_DEVICE shift_left(const uint32 _shift)
Definition: functors.h:659
Definition: functors.h:431
Definition: functors.h:202
Definition: functors.h:67
Definition: functors.h:562
Definition: functors.h:778
Definition: functors.h:156
composition_type< F1, F2, typename F1::function_tag, typename F2::function_tag >::type compose(const F1 f1, const F2 f2)
Definition: functors.h:403
CUGAR_HOST_DEVICE abs_cosine_functor(const Vector_type &normal)
Definition: functors.h:590
Definition: functors.h:307
CUGAR_HOST_DEVICE neq_constant(const T c)
Definition: functors.h:271
Definition: functors.h:138
Definition: functors.h:50
Definition: functors.h:190
Definition: functors.h:601
Definition: functors.h:582
Definition: functors.h:214
Definition: functors.h:754