Fermat
cp_rotations.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010-2018, NVIDIA Corporation
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  * * Redistributions of source code must retain the above copyright
8  * notice, this list of conditions and the following disclaimer.
9  * * Redistributions in binary form must reproduce the above copyright
10  * notice, this list of conditions and the following disclaimer in the
11  * documentation and/or other materials provided with the distribution.
12  * * Neither the name of NVIDIA Corporation nor the
13  * names of its contributors may be used to endorse or promote products
14  * derived from this software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19  * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  */
27 
32 #pragma once
33 
34 #include <cugar/basic/numbers.h>
35 
36 namespace cugar {
37 
55 template <typename Generator, typename Iterator = const float*>
67 struct CP_rotator
68 {
75  CUGAR_HOST_DEVICE CP_rotator(Generator& gen, Iterator rot, uint32 size, uint32 dim = 0) :
76  m_gen( gen ), m_rot( rot ), m_size( size ), m_dim( dim ) {}
77 
80  inline CUGAR_HOST_DEVICE float next()
81  {
82  return cugar::mod( m_gen.next() + m_rot[m_dim++ & (m_size-1)], 1.0f );
83  }
87  inline CUGAR_HOST_DEVICE float density(const float x) const
88  {
89  return 1.0f;
90  }
91 
92  Generator& m_gen;
93  Iterator m_rot;
94  uint32 m_size;
95  uint32 m_dim;
96 };
97 
102 template <typename Sample_sequence, typename Iterator = const float*>
104 {
106 
113  CUGAR_HOST_DEVICE CP_rotated_sequence(Sample_sequence& sequence, const uint32 dims, Iterator rot, uint32 size) :
114  m_sequence( sequence ), m_rot( rot ), m_size( size ), m_dims( dims ) {}
115 
120  Sampler_type CUGAR_HOST_DEVICE instance(const uint32 index, const uint32 copy) const
121  {
122  return Sampler_type( m_sequence.instance( index, copy ), m_rot, m_dims * m_size, copy * m_dims );
123  }
124 
125  Sample_sequence& m_sequence;
126  Iterator m_rot;
127  uint32 m_size;
128  uint32 m_dims;
129 };
130 
134 } // namespace cugar
CUGAR_HOST_DEVICE CP_rotator(Generator &gen, Iterator rot, uint32 size, uint32 dim=0)
Definition: cp_rotations.h:75
float CUGAR_HOST_DEVICE mod(const float x, const float m)
Definition: numbers.h:606
CUGAR_HOST_DEVICE CP_rotated_sequence(Sample_sequence &sequence, const uint32 dims, Iterator rot, uint32 size)
Definition: cp_rotations.h:113
Definition: cp_rotations.h:103
Sampler_type CUGAR_HOST_DEVICE instance(const uint32 index, const uint32 copy) const
Definition: cp_rotations.h:120
Define a vector_view POD type and plain_view() for std::vector.
Definition: diff.h:38
CUGAR_HOST_DEVICE float next()
Definition: cp_rotations.h:80
Definition: cp_rotations.h:67
CUGAR_HOST_DEVICE float density(const float x) const
Definition: cp_rotations.h:87