Commit d82f78583f0990449019f4b225b2c236f535f95a
1 parent
9b563709
fixed excess files
Showing
9 changed files
with
0 additions
and
1298 deletions
Show diff stats
stim/math/.vec3.h.swp deleted
No preview for this file type
stim/math/.vec3_BASE_62876.h.swp deleted
No preview for this file type
stim/math/.vec3_LOCAL_62876.h.swp deleted
No preview for this file type
stim/math/.vec3_REMOTE_62876.h.swp deleted
No preview for this file type
stim/math/vec3.h.orig deleted
1 | -#ifndef STIM_VEC3_H | ||
2 | -#define STIM_VEC3_H | ||
3 | - | ||
4 | - | ||
5 | -#include <stim/cuda/cudatools/callable.h> | ||
6 | -#include <cmath> | ||
7 | - | ||
8 | - | ||
9 | -namespace stim{ | ||
10 | - | ||
11 | - | ||
12 | -/// A class designed to act as a 3D vector with CUDA compatibility | ||
13 | -template<typename T> | ||
14 | -class vec3{ | ||
15 | - | ||
16 | -protected: | ||
17 | - T ptr[3]; | ||
18 | - | ||
19 | -public: | ||
20 | - | ||
21 | - CUDA_CALLABLE vec3(){} | ||
22 | - | ||
23 | - CUDA_CALLABLE vec3(T v){ | ||
24 | - ptr[0] = ptr[1] = ptr[2] = v; | ||
25 | - } | ||
26 | - | ||
27 | - CUDA_CALLABLE vec3(T x, T y, T z){ | ||
28 | - ptr[0] = x; | ||
29 | - ptr[1] = y; | ||
30 | - ptr[2] = z; | ||
31 | - } | ||
32 | - | ||
33 | - //copy constructor | ||
34 | - CUDA_CALLABLE vec3( const vec3<T>& other){ | ||
35 | - ptr[0] = other.ptr[0]; | ||
36 | - ptr[1] = other.ptr[1]; | ||
37 | - ptr[2] = other.ptr[2]; | ||
38 | - } | ||
39 | - | ||
40 | - //access an element using an index | ||
41 | - CUDA_CALLABLE T& operator[](size_t idx){ | ||
42 | - return ptr[idx]; | ||
43 | - } | ||
44 | - | ||
45 | - CUDA_CALLABLE T* data(){ | ||
46 | - return ptr; | ||
47 | - } | ||
48 | - | ||
49 | -/// Casting operator. Creates a new vector with a new type U. | ||
50 | - template< typename U > | ||
51 | - CUDA_CALLABLE operator vec3<U>(){ | ||
52 | - vec3<U> result; | ||
53 | - result.ptr[0] = (U)ptr[0]; | ||
54 | - result.ptr[1] = (U)ptr[1]; | ||
55 | - result.ptr[2] = (U)ptr[2]; | ||
56 | - | ||
57 | - return result; | ||
58 | - } | ||
59 | - | ||
60 | - // computes the squared Euclidean length (useful for several operations where only >, =, or < matter) | ||
61 | - CUDA_CALLABLE T len_sq() const{ | ||
62 | - return ptr[0] * ptr[0] + ptr[1] * ptr[1] + ptr[2] * ptr[2]; | ||
63 | - } | ||
64 | - | ||
65 | - /// computes the Euclidean length of the vector | ||
66 | - CUDA_CALLABLE T len() const{ | ||
67 | - return sqrt(len_sq()); | ||
68 | - } | ||
69 | - | ||
70 | - | ||
71 | - /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi]) | ||
72 | - CUDA_CALLABLE vec3<T> cart2sph() const{ | ||
73 | - vec3<T> sph; | ||
74 | - sph.ptr[0] = len(); | ||
75 | - sph.ptr[1] = std::atan2(ptr[1], ptr[0]); | ||
76 | - if(sph.ptr[0] == 0) | ||
77 | - sph.ptr[2] = 0; | ||
78 | - else | ||
79 | - sph.ptr[2] = std::acos(ptr[2] / sph.ptr[0]); | ||
80 | - return sph; | ||
81 | - } | ||
82 | - | ||
83 | - /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | ||
84 | - CUDA_CALLABLE vec3<T> sph2cart() const{ | ||
85 | - vec3<T> cart; | ||
86 | - cart.ptr[0] = ptr[0] * std::cos(ptr[1]) * std::sin(ptr[2]); | ||
87 | - cart.ptr[1] = ptr[0] * std::sin(ptr[1]) * std::sin(ptr[2]); | ||
88 | - cart.ptr[2] = ptr[0] * std::cos(ptr[2]); | ||
89 | - | ||
90 | - return cart; | ||
91 | - } | ||
92 | - | ||
93 | - /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | ||
94 | - CUDA_CALLABLE vec3<T> norm() const{ | ||
95 | - vec3<T> result; | ||
96 | - T l = len(); //compute the vector length | ||
97 | - return (*this) / l; | ||
98 | - } | ||
99 | - | ||
100 | - /// Computes the cross product of a 3-dimensional vector | ||
101 | - CUDA_CALLABLE vec3<T> cross(const vec3<T> rhs) const{ | ||
102 | - | ||
103 | - vec3<T> result; | ||
104 | - | ||
105 | - result[0] = (ptr[1] * rhs.ptr[2] - ptr[2] * rhs.ptr[1]); | ||
106 | - result[1] = (ptr[2] * rhs.ptr[0] - ptr[0] * rhs.ptr[2]); | ||
107 | - result[2] = (ptr[0] * rhs.ptr[1] - ptr[1] * rhs.ptr[0]); | ||
108 | - | ||
109 | - return result; | ||
110 | - } | ||
111 | - | ||
112 | - /// Compute the Euclidean inner (dot) product | ||
113 | - CUDA_CALLABLE T dot(vec3<T> rhs) const{ | ||
114 | - return ptr[0] * rhs.ptr[0] + ptr[1] * rhs.ptr[1] + ptr[2] * rhs.ptr[2]; | ||
115 | - } | ||
116 | - | ||
117 | - /// Arithmetic addition operator | ||
118 | - | ||
119 | - /// @param rhs is the right-hand-side operator for the addition | ||
120 | - CUDA_CALLABLE vec3<T> operator+(vec3<T> rhs) const{ | ||
121 | - vec3<T> result; | ||
122 | - result.ptr[0] = ptr[0] + rhs[0]; | ||
123 | - result.ptr[1] = ptr[1] + rhs[1]; | ||
124 | - result.ptr[2] = ptr[2] + rhs[2]; | ||
125 | - return result; | ||
126 | - } | ||
127 | - | ||
128 | - /// Arithmetic addition to a scalar | ||
129 | - | ||
130 | - /// @param rhs is the right-hand-side operator for the addition | ||
131 | - CUDA_CALLABLE vec3<T> operator+(T rhs) const{ | ||
132 | - vec3<T> result; | ||
133 | - result.ptr[0] = ptr[0] + rhs; | ||
134 | - result.ptr[1] = ptr[1] + rhs; | ||
135 | - result.ptr[2] = ptr[2] + rhs; | ||
136 | - return result; | ||
137 | - } | ||
138 | - | ||
139 | - /// Arithmetic subtraction operator | ||
140 | - | ||
141 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
142 | - CUDA_CALLABLE vec3<T> operator-(vec3<T> rhs) const{ | ||
143 | - vec3<T> result; | ||
144 | - result.ptr[0] = ptr[0] - rhs[0]; | ||
145 | - result.ptr[1] = ptr[1] - rhs[1]; | ||
146 | - result.ptr[2] = ptr[2] - rhs[2]; | ||
147 | - return result; | ||
148 | - } | ||
149 | - /// Arithmetic subtraction to a scalar | ||
150 | - | ||
151 | - /// @param rhs is the right-hand-side operator for the addition | ||
152 | - CUDA_CALLABLE vec3<T> operator-(T rhs) const{ | ||
153 | - vec3<T> result; | ||
154 | - result.ptr[0] = ptr[0] - rhs; | ||
155 | - result.ptr[1] = ptr[1] - rhs; | ||
156 | - result.ptr[2] = ptr[2] - rhs; | ||
157 | - return result; | ||
158 | - } | ||
159 | - | ||
160 | - /// Arithmetic scalar multiplication operator | ||
161 | - | ||
162 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
163 | - CUDA_CALLABLE vec3<T> operator*(T rhs) const{ | ||
164 | - vec3<T> result; | ||
165 | - result.ptr[0] = ptr[0] * rhs; | ||
166 | - result.ptr[1] = ptr[1] * rhs; | ||
167 | - result.ptr[2] = ptr[2] * rhs; | ||
168 | - return result; | ||
169 | - } | ||
170 | - | ||
171 | - /// Arithmetic scalar division operator | ||
172 | - | ||
173 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
174 | - CUDA_CALLABLE vec3<T> operator/(T rhs) const{ | ||
175 | - return (*this) * ((T)1.0/rhs); | ||
176 | - } | ||
177 | - | ||
178 | - /// Multiplication by a scalar, followed by assignment | ||
179 | - CUDA_CALLABLE vec3<T> operator*=(T rhs){ | ||
180 | - ptr[0] = ptr[0] * rhs; | ||
181 | - ptr[1] = ptr[1] * rhs; | ||
182 | - ptr[2] = ptr[2] * rhs; | ||
183 | - return *this; | ||
184 | - } | ||
185 | - | ||
186 | - /// Addition and assignment | ||
187 | - CUDA_CALLABLE vec3<T> operator+=(vec3<T> rhs){ | ||
188 | - ptr[0] = ptr[0] + rhs; | ||
189 | - ptr[1] = ptr[1] + rhs; | ||
190 | - ptr[2] = ptr[2] + rhs; | ||
191 | - return *this; | ||
192 | - } | ||
193 | - | ||
194 | - /// Assign a scalar to all values | ||
195 | - CUDA_CALLABLE vec3<T> & operator=(T rhs){ | ||
196 | - ptr[0] = ptr[0] = rhs; | ||
197 | - ptr[1] = ptr[1] = rhs; | ||
198 | - ptr[2] = ptr[2] = rhs; | ||
199 | - return *this; | ||
200 | - } | ||
201 | - | ||
202 | - /// Casting and assignment | ||
203 | - template<typename Y> | ||
204 | - CUDA_CALLABLE vec3<T> & operator=(vec3<Y> rhs){ | ||
205 | - ptr[0] = (T)rhs.ptr[0]; | ||
206 | - ptr[1] = (T)rhs.ptr[1]; | ||
207 | - ptr[2] = (T)rhs.ptr[2]; | ||
208 | - return *this; | ||
209 | - } | ||
210 | - | ||
211 | - /// Unary minus (returns the negative of the vector) | ||
212 | - CUDA_CALLABLE vec3<T> operator-() const{ | ||
213 | - vec3<T> result; | ||
214 | - result.ptr[0] = -ptr[0]; | ||
215 | - result.ptr[1] = -ptr[1]; | ||
216 | - result.ptr[2] = -ptr[2]; | ||
217 | - return result; | ||
218 | - } | ||
219 | - | ||
220 | -<<<<<<< HEAD | ||
221 | -//#ifndef __NVCC__ | ||
222 | -======= | ||
223 | ->>>>>>> 9f5c0d4a055a2a19e69a97db1441aa617f96180c | ||
224 | - /// Outputs the vector as a string | ||
225 | - std::string str() const{ | ||
226 | - std::stringstream ss; | ||
227 | - | ||
228 | - const size_t N = 3; | ||
229 | - | ||
230 | - ss<<"["; | ||
231 | - for(size_t i=0; i<N; i++) | ||
232 | - { | ||
233 | - ss<<ptr[i]; | ||
234 | - if(i != N-1) | ||
235 | - ss<<", "; | ||
236 | - } | ||
237 | - ss<<"]"; | ||
238 | - | ||
239 | - return ss.str(); | ||
240 | - } | ||
241 | -<<<<<<< HEAD | ||
242 | -//#endif | ||
243 | -======= | ||
244 | ->>>>>>> 9f5c0d4a055a2a19e69a97db1441aa617f96180c | ||
245 | - | ||
246 | - size_t size(){ return 3; } | ||
247 | - | ||
248 | - }; //end class vec3 | ||
249 | -} //end namespace stim | ||
250 | - | ||
251 | -/// Multiply a vector by a constant when the vector is on the right hand side | ||
252 | -template <typename T> | ||
253 | -stim::vec3<T> operator*(T lhs, stim::vec3<T> rhs){ | ||
254 | - return rhs * lhs; | ||
255 | -} | ||
256 | - | ||
257 | -//stream operator | ||
258 | -template<typename T> | ||
259 | -std::ostream& operator<<(std::ostream& os, stim::vec3<T> const& rhs){ | ||
260 | - os<<rhs.str(); | ||
261 | - return os; | ||
262 | -} | ||
263 | - | ||
264 | -#endif |
stim/math/vec3_BACKUP_62876.h deleted
1 | -#ifndef STIM_VEC3_H | ||
2 | -#define STIM_VEC3_H | ||
3 | - | ||
4 | - | ||
5 | -#include <stim/cuda/cudatools/callable.h> | ||
6 | -#include <cmath> | ||
7 | - | ||
8 | - | ||
9 | -namespace stim{ | ||
10 | - | ||
11 | - | ||
12 | -/// A class designed to act as a 3D vector with CUDA compatibility | ||
13 | -template<typename T> | ||
14 | -class vec3{ | ||
15 | - | ||
16 | -protected: | ||
17 | - T ptr[3]; | ||
18 | - | ||
19 | -public: | ||
20 | - | ||
21 | - CUDA_CALLABLE vec3(){} | ||
22 | - | ||
23 | - CUDA_CALLABLE vec3(T v){ | ||
24 | - ptr[0] = ptr[1] = ptr[2] = v; | ||
25 | - } | ||
26 | - | ||
27 | - CUDA_CALLABLE vec3(T x, T y, T z){ | ||
28 | - ptr[0] = x; | ||
29 | - ptr[1] = y; | ||
30 | - ptr[2] = z; | ||
31 | - } | ||
32 | - | ||
33 | - //copy constructor | ||
34 | - CUDA_CALLABLE vec3( const vec3<T>& other){ | ||
35 | - ptr[0] = other.ptr[0]; | ||
36 | - ptr[1] = other.ptr[1]; | ||
37 | - ptr[2] = other.ptr[2]; | ||
38 | - } | ||
39 | - | ||
40 | - //access an element using an index | ||
41 | - CUDA_CALLABLE T& operator[](size_t idx){ | ||
42 | - return ptr[idx]; | ||
43 | - } | ||
44 | - | ||
45 | - CUDA_CALLABLE T* data(){ | ||
46 | - return ptr; | ||
47 | - } | ||
48 | - | ||
49 | -/// Casting operator. Creates a new vector with a new type U. | ||
50 | - template< typename U > | ||
51 | - CUDA_CALLABLE operator vec3<U>(){ | ||
52 | - vec3<U> result; | ||
53 | - result.ptr[0] = (U)ptr[0]; | ||
54 | - result.ptr[1] = (U)ptr[1]; | ||
55 | - result.ptr[2] = (U)ptr[2]; | ||
56 | - | ||
57 | - return result; | ||
58 | - } | ||
59 | - | ||
60 | - // computes the squared Euclidean length (useful for several operations where only >, =, or < matter) | ||
61 | - CUDA_CALLABLE T len_sq() const{ | ||
62 | - return ptr[0] * ptr[0] + ptr[1] * ptr[1] + ptr[2] * ptr[2]; | ||
63 | - } | ||
64 | - | ||
65 | - /// computes the Euclidean length of the vector | ||
66 | - CUDA_CALLABLE T len() const{ | ||
67 | - return sqrt(len_sq()); | ||
68 | - } | ||
69 | - | ||
70 | - | ||
71 | - /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi]) | ||
72 | - CUDA_CALLABLE vec3<T> cart2sph() const{ | ||
73 | - vec3<T> sph; | ||
74 | - sph.ptr[0] = len(); | ||
75 | - sph.ptr[1] = std::atan2(ptr[1], ptr[0]); | ||
76 | - if(sph.ptr[0] == 0) | ||
77 | - sph.ptr[2] = 0; | ||
78 | - else | ||
79 | - sph.ptr[2] = std::acos(ptr[2] / sph.ptr[0]); | ||
80 | - return sph; | ||
81 | - } | ||
82 | - | ||
83 | - /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | ||
84 | - CUDA_CALLABLE vec3<T> sph2cart() const{ | ||
85 | - vec3<T> cart; | ||
86 | - cart.ptr[0] = ptr[0] * std::cos(ptr[1]) * std::sin(ptr[2]); | ||
87 | - cart.ptr[1] = ptr[0] * std::sin(ptr[1]) * std::sin(ptr[2]); | ||
88 | - cart.ptr[2] = ptr[0] * std::cos(ptr[2]); | ||
89 | - | ||
90 | - return cart; | ||
91 | - } | ||
92 | - | ||
93 | - /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | ||
94 | - CUDA_CALLABLE vec3<T> norm() const{ | ||
95 | - vec3<T> result; | ||
96 | - T l = len(); //compute the vector length | ||
97 | - return (*this) / l; | ||
98 | - } | ||
99 | - | ||
100 | - /// Computes the cross product of a 3-dimensional vector | ||
101 | - CUDA_CALLABLE vec3<T> cross(const vec3<T> rhs) const{ | ||
102 | - | ||
103 | - vec3<T> result; | ||
104 | - | ||
105 | - result[0] = (ptr[1] * rhs.ptr[2] - ptr[2] * rhs.ptr[1]); | ||
106 | - result[1] = (ptr[2] * rhs.ptr[0] - ptr[0] * rhs.ptr[2]); | ||
107 | - result[2] = (ptr[0] * rhs.ptr[1] - ptr[1] * rhs.ptr[0]); | ||
108 | - | ||
109 | - return result; | ||
110 | - } | ||
111 | - | ||
112 | - /// Compute the Euclidean inner (dot) product | ||
113 | - CUDA_CALLABLE T dot(vec3<T> rhs) const{ | ||
114 | - return ptr[0] * rhs.ptr[0] + ptr[1] * rhs.ptr[1] + ptr[2] * rhs.ptr[2]; | ||
115 | - } | ||
116 | - | ||
117 | - /// Arithmetic addition operator | ||
118 | - | ||
119 | - /// @param rhs is the right-hand-side operator for the addition | ||
120 | - CUDA_CALLABLE vec3<T> operator+(vec3<T> rhs) const{ | ||
121 | - vec3<T> result; | ||
122 | - result.ptr[0] = ptr[0] + rhs[0]; | ||
123 | - result.ptr[1] = ptr[1] + rhs[1]; | ||
124 | - result.ptr[2] = ptr[2] + rhs[2]; | ||
125 | - return result; | ||
126 | - } | ||
127 | - | ||
128 | - /// Arithmetic addition to a scalar | ||
129 | - | ||
130 | - /// @param rhs is the right-hand-side operator for the addition | ||
131 | - CUDA_CALLABLE vec3<T> operator+(T rhs) const{ | ||
132 | - vec3<T> result; | ||
133 | - result.ptr[0] = ptr[0] + rhs; | ||
134 | - result.ptr[1] = ptr[1] + rhs; | ||
135 | - result.ptr[2] = ptr[2] + rhs; | ||
136 | - return result; | ||
137 | - } | ||
138 | - | ||
139 | - /// Arithmetic subtraction operator | ||
140 | - | ||
141 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
142 | - CUDA_CALLABLE vec3<T> operator-(vec3<T> rhs) const{ | ||
143 | - vec3<T> result; | ||
144 | - result.ptr[0] = ptr[0] - rhs[0]; | ||
145 | - result.ptr[1] = ptr[1] - rhs[1]; | ||
146 | - result.ptr[2] = ptr[2] - rhs[2]; | ||
147 | - return result; | ||
148 | - } | ||
149 | - /// Arithmetic subtraction to a scalar | ||
150 | - | ||
151 | - /// @param rhs is the right-hand-side operator for the addition | ||
152 | - CUDA_CALLABLE vec3<T> operator-(T rhs) const{ | ||
153 | - vec3<T> result; | ||
154 | - result.ptr[0] = ptr[0] - rhs; | ||
155 | - result.ptr[1] = ptr[1] - rhs; | ||
156 | - result.ptr[2] = ptr[2] - rhs; | ||
157 | - return result; | ||
158 | - } | ||
159 | - | ||
160 | - /// Arithmetic scalar multiplication operator | ||
161 | - | ||
162 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
163 | - CUDA_CALLABLE vec3<T> operator*(T rhs) const{ | ||
164 | - vec3<T> result; | ||
165 | - result.ptr[0] = ptr[0] * rhs; | ||
166 | - result.ptr[1] = ptr[1] * rhs; | ||
167 | - result.ptr[2] = ptr[2] * rhs; | ||
168 | - return result; | ||
169 | - } | ||
170 | - | ||
171 | - /// Arithmetic scalar division operator | ||
172 | - | ||
173 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
174 | - CUDA_CALLABLE vec3<T> operator/(T rhs) const{ | ||
175 | - return (*this) * ((T)1.0/rhs); | ||
176 | - } | ||
177 | - | ||
178 | - /// Multiplication by a scalar, followed by assignment | ||
179 | - CUDA_CALLABLE vec3<T> operator*=(T rhs){ | ||
180 | - ptr[0] = ptr[0] * rhs; | ||
181 | - ptr[1] = ptr[1] * rhs; | ||
182 | - ptr[2] = ptr[2] * rhs; | ||
183 | - return *this; | ||
184 | - } | ||
185 | - | ||
186 | - /// Addition and assignment | ||
187 | - CUDA_CALLABLE vec3<T> operator+=(vec3<T> rhs){ | ||
188 | - ptr[0] = ptr[0] + rhs; | ||
189 | - ptr[1] = ptr[1] + rhs; | ||
190 | - ptr[2] = ptr[2] + rhs; | ||
191 | - return *this; | ||
192 | - } | ||
193 | - | ||
194 | - /// Assign a scalar to all values | ||
195 | - CUDA_CALLABLE vec3<T> & operator=(T rhs){ | ||
196 | - ptr[0] = ptr[0] = rhs; | ||
197 | - ptr[1] = ptr[1] = rhs; | ||
198 | - ptr[2] = ptr[2] = rhs; | ||
199 | - return *this; | ||
200 | - } | ||
201 | - | ||
202 | - /// Casting and assignment | ||
203 | - template<typename Y> | ||
204 | - CUDA_CALLABLE vec3<T> & operator=(vec3<Y> rhs){ | ||
205 | - ptr[0] = (T)rhs.ptr[0]; | ||
206 | - ptr[1] = (T)rhs.ptr[1]; | ||
207 | - ptr[2] = (T)rhs.ptr[2]; | ||
208 | - return *this; | ||
209 | - } | ||
210 | - | ||
211 | - /// Unary minus (returns the negative of the vector) | ||
212 | - CUDA_CALLABLE vec3<T> operator-() const{ | ||
213 | - vec3<T> result; | ||
214 | - result.ptr[0] = -ptr[0]; | ||
215 | - result.ptr[1] = -ptr[1]; | ||
216 | - result.ptr[2] = -ptr[2]; | ||
217 | - return result; | ||
218 | - } | ||
219 | - | ||
220 | -<<<<<<< HEAD | ||
221 | -//#ifndef __NVCC__ | ||
222 | -======= | ||
223 | ->>>>>>> 9f5c0d4a055a2a19e69a97db1441aa617f96180c | ||
224 | - /// Outputs the vector as a string | ||
225 | - std::string str() const{ | ||
226 | - std::stringstream ss; | ||
227 | - | ||
228 | - const size_t N = 3; | ||
229 | - | ||
230 | - ss<<"["; | ||
231 | - for(size_t i=0; i<N; i++) | ||
232 | - { | ||
233 | - ss<<ptr[i]; | ||
234 | - if(i != N-1) | ||
235 | - ss<<", "; | ||
236 | - } | ||
237 | - ss<<"]"; | ||
238 | - | ||
239 | - return ss.str(); | ||
240 | - } | ||
241 | -<<<<<<< HEAD | ||
242 | -//#endif | ||
243 | -======= | ||
244 | ->>>>>>> 9f5c0d4a055a2a19e69a97db1441aa617f96180c | ||
245 | - | ||
246 | - size_t size(){ return 3; } | ||
247 | - | ||
248 | - }; //end class vec3 | ||
249 | -} //end namespace stim | ||
250 | - | ||
251 | -/// Multiply a vector by a constant when the vector is on the right hand side | ||
252 | -template <typename T> | ||
253 | -stim::vec3<T> operator*(T lhs, stim::vec3<T> rhs){ | ||
254 | - return rhs * lhs; | ||
255 | -} | ||
256 | - | ||
257 | -//stream operator | ||
258 | -template<typename T> | ||
259 | -std::ostream& operator<<(std::ostream& os, stim::vec3<T> const& rhs){ | ||
260 | - os<<rhs.str(); | ||
261 | - return os; | ||
262 | -} | ||
263 | - | ||
264 | -#endif |
stim/math/vec3_BASE_62876.h deleted
1 | -#ifndef STIM_VEC3_H | ||
2 | -#define STIM_VEC3_H | ||
3 | - | ||
4 | - | ||
5 | -#include <stim/cuda/cudatools/callable.h> | ||
6 | - | ||
7 | - | ||
8 | -namespace stim{ | ||
9 | - | ||
10 | - | ||
11 | -/// A class designed to act as a 3D vector with CUDA compatibility | ||
12 | -template<typename T> | ||
13 | -class vec3{ | ||
14 | - | ||
15 | -protected: | ||
16 | - T ptr[3]; | ||
17 | - | ||
18 | -public: | ||
19 | - | ||
20 | - CUDA_CALLABLE vec3(){} | ||
21 | - | ||
22 | - CUDA_CALLABLE vec3(T v){ | ||
23 | - ptr[0] = ptr[1] = ptr[2] = v; | ||
24 | - } | ||
25 | - | ||
26 | - CUDA_CALLABLE vec3(T x, T y, T z){ | ||
27 | - ptr[0] = x; | ||
28 | - ptr[1] = y; | ||
29 | - ptr[2] = z; | ||
30 | - } | ||
31 | - | ||
32 | - //copy constructor | ||
33 | - CUDA_CALLABLE vec3( const vec3<T>& other){ | ||
34 | - ptr[0] = other.ptr[0]; | ||
35 | - ptr[1] = other.ptr[1]; | ||
36 | - ptr[2] = other.ptr[2]; | ||
37 | - } | ||
38 | - | ||
39 | - //access an element using an index | ||
40 | - CUDA_CALLABLE T& operator[](size_t idx){ | ||
41 | - return ptr[idx]; | ||
42 | - } | ||
43 | - | ||
44 | - CUDA_CALLABLE T* data(){ | ||
45 | - return ptr; | ||
46 | - } | ||
47 | - | ||
48 | -/// Casting operator. Creates a new vector with a new type U. | ||
49 | - template< typename U > | ||
50 | - CUDA_CALLABLE operator vec3<U>(){ | ||
51 | - vec3<U> result; | ||
52 | - result.ptr[0] = (U)ptr[0]; | ||
53 | - result.ptr[1] = (U)ptr[1]; | ||
54 | - result.ptr[2] = (U)ptr[2]; | ||
55 | - | ||
56 | - return result; | ||
57 | - } | ||
58 | - | ||
59 | - // computes the squared Euclidean length (useful for several operations where only >, =, or < matter) | ||
60 | - CUDA_CALLABLE T len_sq() const{ | ||
61 | - return ptr[0] * ptr[0] + ptr[1] * ptr[1] + ptr[2] * ptr[2]; | ||
62 | - } | ||
63 | - | ||
64 | - /// computes the Euclidean length of the vector | ||
65 | - CUDA_CALLABLE T len() const{ | ||
66 | - return sqrt(len_sq()); | ||
67 | - } | ||
68 | - | ||
69 | - | ||
70 | - /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi]) | ||
71 | - CUDA_CALLABLE vec3<T> cart2sph() const{ | ||
72 | - vec3<T> sph; | ||
73 | - sph.ptr[0] = len(); | ||
74 | - sph.ptr[1] = std::atan2(ptr[1], ptr[0]); | ||
75 | - if(sph.ptr[0] == 0) | ||
76 | - sph.ptr[2] = 0; | ||
77 | - else | ||
78 | - sph.ptr[2] = std::acos(ptr[2] / sph.ptr[0]); | ||
79 | - return sph; | ||
80 | - } | ||
81 | - | ||
82 | - /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | ||
83 | - CUDA_CALLABLE vec3<T> sph2cart() const{ | ||
84 | - vec3<T> cart; | ||
85 | - cart.ptr[0] = ptr[0] * std::cos(ptr[1]) * std::sin(ptr[2]); | ||
86 | - cart.ptr[1] = ptr[0] * std::sin(ptr[1]) * std::sin(ptr[2]); | ||
87 | - cart.ptr[2] = ptr[0] * std::cos(ptr[2]); | ||
88 | - | ||
89 | - return cart; | ||
90 | - } | ||
91 | - | ||
92 | - /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | ||
93 | - CUDA_CALLABLE vec3<T> norm() const{ | ||
94 | - vec3<T> result; | ||
95 | - T l = len(); //compute the vector length | ||
96 | - return (*this) / l; | ||
97 | - } | ||
98 | - | ||
99 | - /// Computes the cross product of a 3-dimensional vector | ||
100 | - CUDA_CALLABLE vec3<T> cross(const vec3<T> rhs) const{ | ||
101 | - | ||
102 | - vec3<T> result; | ||
103 | - | ||
104 | - result[0] = (ptr[1] * rhs.ptr[2] - ptr[2] * rhs.ptr[1]); | ||
105 | - result[1] = (ptr[2] * rhs.ptr[0] - ptr[0] * rhs.ptr[2]); | ||
106 | - result[2] = (ptr[0] * rhs.ptr[1] - ptr[1] * rhs.ptr[0]); | ||
107 | - | ||
108 | - return result; | ||
109 | - } | ||
110 | - | ||
111 | - /// Compute the Euclidean inner (dot) product | ||
112 | - CUDA_CALLABLE T dot(vec3<T> rhs) const{ | ||
113 | - return ptr[0] * rhs.ptr[0] + ptr[1] * rhs.ptr[1] + ptr[2] * rhs.ptr[2]; | ||
114 | - } | ||
115 | - | ||
116 | - /// Arithmetic addition operator | ||
117 | - | ||
118 | - /// @param rhs is the right-hand-side operator for the addition | ||
119 | - CUDA_CALLABLE vec3<T> operator+(vec3<T> rhs) const{ | ||
120 | - vec3<T> result; | ||
121 | - result.ptr[0] = ptr[0] + rhs[0]; | ||
122 | - result.ptr[1] = ptr[1] + rhs[1]; | ||
123 | - result.ptr[2] = ptr[2] + rhs[2]; | ||
124 | - return result; | ||
125 | - } | ||
126 | - | ||
127 | - /// Arithmetic addition to a scalar | ||
128 | - | ||
129 | - /// @param rhs is the right-hand-side operator for the addition | ||
130 | - CUDA_CALLABLE vec3<T> operator+(T rhs) const{ | ||
131 | - vec3<T> result; | ||
132 | - result.ptr[0] = ptr[0] + rhs; | ||
133 | - result.ptr[1] = ptr[1] + rhs; | ||
134 | - result.ptr[2] = ptr[2] + rhs; | ||
135 | - return result; | ||
136 | - } | ||
137 | - | ||
138 | - /// Arithmetic subtraction operator | ||
139 | - | ||
140 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
141 | - CUDA_CALLABLE vec3<T> operator-(vec3<T> rhs) const{ | ||
142 | - vec3<T> result; | ||
143 | - result.ptr[0] = ptr[0] - rhs[0]; | ||
144 | - result.ptr[1] = ptr[1] - rhs[1]; | ||
145 | - result.ptr[2] = ptr[2] - rhs[2]; | ||
146 | - return result; | ||
147 | - } | ||
148 | - /// Arithmetic subtraction to a scalar | ||
149 | - | ||
150 | - /// @param rhs is the right-hand-side operator for the addition | ||
151 | - CUDA_CALLABLE vec3<T> operator-(T rhs) const{ | ||
152 | - vec3<T> result; | ||
153 | - result.ptr[0] = ptr[0] - rhs; | ||
154 | - result.ptr[1] = ptr[1] - rhs; | ||
155 | - result.ptr[2] = ptr[2] - rhs; | ||
156 | - return result; | ||
157 | - } | ||
158 | - | ||
159 | - /// Arithmetic scalar multiplication operator | ||
160 | - | ||
161 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
162 | - CUDA_CALLABLE vec3<T> operator*(T rhs) const{ | ||
163 | - vec3<T> result; | ||
164 | - result.ptr[0] = ptr[0] * rhs; | ||
165 | - result.ptr[1] = ptr[1] * rhs; | ||
166 | - result.ptr[2] = ptr[2] * rhs; | ||
167 | - return result; | ||
168 | - } | ||
169 | - | ||
170 | - /// Arithmetic scalar division operator | ||
171 | - | ||
172 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
173 | - CUDA_CALLABLE vec3<T> operator/(T rhs) const{ | ||
174 | - return (*this) * ((T)1.0/rhs); | ||
175 | - } | ||
176 | - | ||
177 | - /// Multiplication by a scalar, followed by assignment | ||
178 | - CUDA_CALLABLE vec3<T> operator*=(T rhs){ | ||
179 | - ptr[0] = ptr[0] * rhs; | ||
180 | - ptr[1] = ptr[1] * rhs; | ||
181 | - ptr[2] = ptr[2] * rhs; | ||
182 | - return *this; | ||
183 | - } | ||
184 | - | ||
185 | - /// Addition and assignment | ||
186 | - CUDA_CALLABLE vec3<T> operator+=(vec3<T> rhs){ | ||
187 | - ptr[0] = ptr[0] + rhs; | ||
188 | - ptr[1] = ptr[1] + rhs; | ||
189 | - ptr[2] = ptr[2] + rhs; | ||
190 | - return *this; | ||
191 | - } | ||
192 | - | ||
193 | - /// Assign a scalar to all values | ||
194 | - CUDA_CALLABLE vec3<T> & operator=(T rhs){ | ||
195 | - ptr[0] = ptr[0] = rhs; | ||
196 | - ptr[1] = ptr[1] = rhs; | ||
197 | - ptr[2] = ptr[2] = rhs; | ||
198 | - return *this; | ||
199 | - } | ||
200 | - | ||
201 | - /// Casting and assignment | ||
202 | - template<typename Y> | ||
203 | - CUDA_CALLABLE vec3<T> & operator=(vec3<Y> rhs){ | ||
204 | - ptr[0] = (T)rhs.ptr[0]; | ||
205 | - ptr[1] = (T)rhs.ptr[1]; | ||
206 | - ptr[2] = (T)rhs.ptr[2]; | ||
207 | - return *this; | ||
208 | - } | ||
209 | - | ||
210 | - /// Unary minus (returns the negative of the vector) | ||
211 | - CUDA_CALLABLE vec3<T> operator-() const{ | ||
212 | - vec3<T> result; | ||
213 | - result.ptr[0] = -ptr[0]; | ||
214 | - result.ptr[1] = -ptr[1]; | ||
215 | - result.ptr[2] = -ptr[2]; | ||
216 | - return result; | ||
217 | - } | ||
218 | - | ||
219 | -#ifndef __NVCC__ | ||
220 | - /// Outputs the vector as a string | ||
221 | - std::string str() const{ | ||
222 | - std::stringstream ss; | ||
223 | - | ||
224 | - const size_t N = 3; | ||
225 | - | ||
226 | - ss<<"["; | ||
227 | - for(size_t i=0; i<N; i++) | ||
228 | - { | ||
229 | - ss<<ptr[i]; | ||
230 | - if(i != N-1) | ||
231 | - ss<<", "; | ||
232 | - } | ||
233 | - ss<<"]"; | ||
234 | - | ||
235 | - return ss.str(); | ||
236 | - } | ||
237 | -#endif | ||
238 | - | ||
239 | - size_t size(){ return 3; } | ||
240 | - | ||
241 | - }; //end class vec3 | ||
242 | -} //end namespace stim | ||
243 | - | ||
244 | -/// Multiply a vector by a constant when the vector is on the right hand side | ||
245 | -template <typename T> | ||
246 | -stim::vec3<T> operator*(T lhs, stim::vec3<T> rhs){ | ||
247 | - return rhs * lhs; | ||
248 | -} | ||
249 | - | ||
250 | -//stream operator | ||
251 | -template<typename T> | ||
252 | -std::ostream& operator<<(std::ostream& os, stim::vec3<T> const& rhs){ | ||
253 | - os<<rhs.str(); | ||
254 | - return os; | ||
255 | -} | ||
256 | - | ||
257 | -#endif |
stim/math/vec3_LOCAL_62876.h deleted
1 | -#ifndef STIM_VEC3_H | ||
2 | -#define STIM_VEC3_H | ||
3 | - | ||
4 | - | ||
5 | -#include <stim/cuda/cudatools/callable.h> | ||
6 | - | ||
7 | - | ||
8 | -namespace stim{ | ||
9 | - | ||
10 | - | ||
11 | -/// A class designed to act as a 3D vector with CUDA compatibility | ||
12 | -template<typename T> | ||
13 | -class vec3{ | ||
14 | - | ||
15 | -protected: | ||
16 | - T ptr[3]; | ||
17 | - | ||
18 | -public: | ||
19 | - | ||
20 | - CUDA_CALLABLE vec3(){} | ||
21 | - | ||
22 | - CUDA_CALLABLE vec3(T v){ | ||
23 | - ptr[0] = ptr[1] = ptr[2] = v; | ||
24 | - } | ||
25 | - | ||
26 | - CUDA_CALLABLE vec3(T x, T y, T z){ | ||
27 | - ptr[0] = x; | ||
28 | - ptr[1] = y; | ||
29 | - ptr[2] = z; | ||
30 | - } | ||
31 | - | ||
32 | - //copy constructor | ||
33 | - CUDA_CALLABLE vec3( const vec3<T>& other){ | ||
34 | - ptr[0] = other.ptr[0]; | ||
35 | - ptr[1] = other.ptr[1]; | ||
36 | - ptr[2] = other.ptr[2]; | ||
37 | - } | ||
38 | - | ||
39 | - //access an element using an index | ||
40 | - CUDA_CALLABLE T& operator[](size_t idx){ | ||
41 | - return ptr[idx]; | ||
42 | - } | ||
43 | - | ||
44 | - CUDA_CALLABLE T* data(){ | ||
45 | - return ptr; | ||
46 | - } | ||
47 | - | ||
48 | -/// Casting operator. Creates a new vector with a new type U. | ||
49 | - template< typename U > | ||
50 | - CUDA_CALLABLE operator vec3<U>(){ | ||
51 | - vec3<U> result; | ||
52 | - result.ptr[0] = (U)ptr[0]; | ||
53 | - result.ptr[1] = (U)ptr[1]; | ||
54 | - result.ptr[2] = (U)ptr[2]; | ||
55 | - | ||
56 | - return result; | ||
57 | - } | ||
58 | - | ||
59 | - // computes the squared Euclidean length (useful for several operations where only >, =, or < matter) | ||
60 | - CUDA_CALLABLE T len_sq() const{ | ||
61 | - return ptr[0] * ptr[0] + ptr[1] * ptr[1] + ptr[2] * ptr[2]; | ||
62 | - } | ||
63 | - | ||
64 | - /// computes the Euclidean length of the vector | ||
65 | - CUDA_CALLABLE T len() const{ | ||
66 | - return sqrt(len_sq()); | ||
67 | - } | ||
68 | - | ||
69 | - | ||
70 | - /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi]) | ||
71 | - CUDA_CALLABLE vec3<T> cart2sph() const{ | ||
72 | - vec3<T> sph; | ||
73 | - sph.ptr[0] = len(); | ||
74 | - sph.ptr[1] = std::atan2(ptr[1], ptr[0]); | ||
75 | - if(sph.ptr[0] == 0) | ||
76 | - sph.ptr[2] = 0; | ||
77 | - else | ||
78 | - sph.ptr[2] = std::acos(ptr[2] / sph.ptr[0]); | ||
79 | - return sph; | ||
80 | - } | ||
81 | - | ||
82 | - /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | ||
83 | - CUDA_CALLABLE vec3<T> sph2cart() const{ | ||
84 | - vec3<T> cart; | ||
85 | - cart.ptr[0] = ptr[0] * std::cos(ptr[1]) * std::sin(ptr[2]); | ||
86 | - cart.ptr[1] = ptr[0] * std::sin(ptr[1]) * std::sin(ptr[2]); | ||
87 | - cart.ptr[2] = ptr[0] * std::cos(ptr[2]); | ||
88 | - | ||
89 | - return cart; | ||
90 | - } | ||
91 | - | ||
92 | - /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | ||
93 | - CUDA_CALLABLE vec3<T> norm() const{ | ||
94 | - vec3<T> result; | ||
95 | - T l = len(); //compute the vector length | ||
96 | - return (*this) / l; | ||
97 | - } | ||
98 | - | ||
99 | - /// Computes the cross product of a 3-dimensional vector | ||
100 | - CUDA_CALLABLE vec3<T> cross(const vec3<T> rhs) const{ | ||
101 | - | ||
102 | - vec3<T> result; | ||
103 | - | ||
104 | - result[0] = (ptr[1] * rhs.ptr[2] - ptr[2] * rhs.ptr[1]); | ||
105 | - result[1] = (ptr[2] * rhs.ptr[0] - ptr[0] * rhs.ptr[2]); | ||
106 | - result[2] = (ptr[0] * rhs.ptr[1] - ptr[1] * rhs.ptr[0]); | ||
107 | - | ||
108 | - return result; | ||
109 | - } | ||
110 | - | ||
111 | - /// Compute the Euclidean inner (dot) product | ||
112 | - CUDA_CALLABLE T dot(vec3<T> rhs) const{ | ||
113 | - return ptr[0] * rhs.ptr[0] + ptr[1] * rhs.ptr[1] + ptr[2] * rhs.ptr[2]; | ||
114 | - } | ||
115 | - | ||
116 | - /// Arithmetic addition operator | ||
117 | - | ||
118 | - /// @param rhs is the right-hand-side operator for the addition | ||
119 | - CUDA_CALLABLE vec3<T> operator+(vec3<T> rhs) const{ | ||
120 | - vec3<T> result; | ||
121 | - result.ptr[0] = ptr[0] + rhs[0]; | ||
122 | - result.ptr[1] = ptr[1] + rhs[1]; | ||
123 | - result.ptr[2] = ptr[2] + rhs[2]; | ||
124 | - return result; | ||
125 | - } | ||
126 | - | ||
127 | - /// Arithmetic addition to a scalar | ||
128 | - | ||
129 | - /// @param rhs is the right-hand-side operator for the addition | ||
130 | - CUDA_CALLABLE vec3<T> operator+(T rhs) const{ | ||
131 | - vec3<T> result; | ||
132 | - result.ptr[0] = ptr[0] + rhs; | ||
133 | - result.ptr[1] = ptr[1] + rhs; | ||
134 | - result.ptr[2] = ptr[2] + rhs; | ||
135 | - return result; | ||
136 | - } | ||
137 | - | ||
138 | - /// Arithmetic subtraction operator | ||
139 | - | ||
140 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
141 | - CUDA_CALLABLE vec3<T> operator-(vec3<T> rhs) const{ | ||
142 | - vec3<T> result; | ||
143 | - result.ptr[0] = ptr[0] - rhs[0]; | ||
144 | - result.ptr[1] = ptr[1] - rhs[1]; | ||
145 | - result.ptr[2] = ptr[2] - rhs[2]; | ||
146 | - return result; | ||
147 | - } | ||
148 | - /// Arithmetic subtraction to a scalar | ||
149 | - | ||
150 | - /// @param rhs is the right-hand-side operator for the addition | ||
151 | - CUDA_CALLABLE vec3<T> operator-(T rhs) const{ | ||
152 | - vec3<T> result; | ||
153 | - result.ptr[0] = ptr[0] - rhs; | ||
154 | - result.ptr[1] = ptr[1] - rhs; | ||
155 | - result.ptr[2] = ptr[2] - rhs; | ||
156 | - return result; | ||
157 | - } | ||
158 | - | ||
159 | - /// Arithmetic scalar multiplication operator | ||
160 | - | ||
161 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
162 | - CUDA_CALLABLE vec3<T> operator*(T rhs) const{ | ||
163 | - vec3<T> result; | ||
164 | - result.ptr[0] = ptr[0] * rhs; | ||
165 | - result.ptr[1] = ptr[1] * rhs; | ||
166 | - result.ptr[2] = ptr[2] * rhs; | ||
167 | - return result; | ||
168 | - } | ||
169 | - | ||
170 | - /// Arithmetic scalar division operator | ||
171 | - | ||
172 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
173 | - CUDA_CALLABLE vec3<T> operator/(T rhs) const{ | ||
174 | - return (*this) * ((T)1.0/rhs); | ||
175 | - } | ||
176 | - | ||
177 | - /// Multiplication by a scalar, followed by assignment | ||
178 | - CUDA_CALLABLE vec3<T> operator*=(T rhs){ | ||
179 | - ptr[0] = ptr[0] * rhs; | ||
180 | - ptr[1] = ptr[1] * rhs; | ||
181 | - ptr[2] = ptr[2] * rhs; | ||
182 | - return *this; | ||
183 | - } | ||
184 | - | ||
185 | - /// Addition and assignment | ||
186 | - CUDA_CALLABLE vec3<T> operator+=(vec3<T> rhs){ | ||
187 | - ptr[0] = ptr[0] + rhs; | ||
188 | - ptr[1] = ptr[1] + rhs; | ||
189 | - ptr[2] = ptr[2] + rhs; | ||
190 | - return *this; | ||
191 | - } | ||
192 | - | ||
193 | - /// Assign a scalar to all values | ||
194 | - CUDA_CALLABLE vec3<T> & operator=(T rhs){ | ||
195 | - ptr[0] = ptr[0] = rhs; | ||
196 | - ptr[1] = ptr[1] = rhs; | ||
197 | - ptr[2] = ptr[2] = rhs; | ||
198 | - return *this; | ||
199 | - } | ||
200 | - | ||
201 | - /// Casting and assignment | ||
202 | - template<typename Y> | ||
203 | - CUDA_CALLABLE vec3<T> & operator=(vec3<Y> rhs){ | ||
204 | - ptr[0] = (T)rhs.ptr[0]; | ||
205 | - ptr[1] = (T)rhs.ptr[1]; | ||
206 | - ptr[2] = (T)rhs.ptr[2]; | ||
207 | - return *this; | ||
208 | - } | ||
209 | - | ||
210 | - /// Unary minus (returns the negative of the vector) | ||
211 | - CUDA_CALLABLE vec3<T> operator-() const{ | ||
212 | - vec3<T> result; | ||
213 | - result.ptr[0] = -ptr[0]; | ||
214 | - result.ptr[1] = -ptr[1]; | ||
215 | - result.ptr[2] = -ptr[2]; | ||
216 | - return result; | ||
217 | - } | ||
218 | - | ||
219 | -//#ifndef __NVCC__ | ||
220 | - /// Outputs the vector as a string | ||
221 | - std::string str() const{ | ||
222 | - std::stringstream ss; | ||
223 | - | ||
224 | - const size_t N = 3; | ||
225 | - | ||
226 | - ss<<"["; | ||
227 | - for(size_t i=0; i<N; i++) | ||
228 | - { | ||
229 | - ss<<ptr[i]; | ||
230 | - if(i != N-1) | ||
231 | - ss<<", "; | ||
232 | - } | ||
233 | - ss<<"]"; | ||
234 | - | ||
235 | - return ss.str(); | ||
236 | - } | ||
237 | -//#endif | ||
238 | - | ||
239 | - size_t size(){ return 3; } | ||
240 | - | ||
241 | - }; //end class vec3 | ||
242 | -} //end namespace stim | ||
243 | - | ||
244 | -/// Multiply a vector by a constant when the vector is on the right hand side | ||
245 | -template <typename T> | ||
246 | -stim::vec3<T> operator*(T lhs, stim::vec3<T> rhs){ | ||
247 | - return rhs * lhs; | ||
248 | -} | ||
249 | - | ||
250 | -//stream operator | ||
251 | -template<typename T> | ||
252 | -std::ostream& operator<<(std::ostream& os, stim::vec3<T> const& rhs){ | ||
253 | - os<<rhs.str(); | ||
254 | - return os; | ||
255 | -} | ||
256 | - | ||
257 | -#endif |
stim/math/vec3_REMOTE_62876.h deleted
1 | -#ifndef STIM_VEC3_H | ||
2 | -#define STIM_VEC3_H | ||
3 | - | ||
4 | - | ||
5 | -#include <stim/cuda/cudatools/callable.h> | ||
6 | -#include <cmath> | ||
7 | - | ||
8 | - | ||
9 | -namespace stim{ | ||
10 | - | ||
11 | - | ||
12 | -/// A class designed to act as a 3D vector with CUDA compatibility | ||
13 | -template<typename T> | ||
14 | -class vec3{ | ||
15 | - | ||
16 | -protected: | ||
17 | - T ptr[3]; | ||
18 | - | ||
19 | -public: | ||
20 | - | ||
21 | - CUDA_CALLABLE vec3(){} | ||
22 | - | ||
23 | - CUDA_CALLABLE vec3(T v){ | ||
24 | - ptr[0] = ptr[1] = ptr[2] = v; | ||
25 | - } | ||
26 | - | ||
27 | - CUDA_CALLABLE vec3(T x, T y, T z){ | ||
28 | - ptr[0] = x; | ||
29 | - ptr[1] = y; | ||
30 | - ptr[2] = z; | ||
31 | - } | ||
32 | - | ||
33 | - //copy constructor | ||
34 | - CUDA_CALLABLE vec3( const vec3<T>& other){ | ||
35 | - ptr[0] = other.ptr[0]; | ||
36 | - ptr[1] = other.ptr[1]; | ||
37 | - ptr[2] = other.ptr[2]; | ||
38 | - } | ||
39 | - | ||
40 | - //access an element using an index | ||
41 | - CUDA_CALLABLE T& operator[](size_t idx){ | ||
42 | - return ptr[idx]; | ||
43 | - } | ||
44 | - | ||
45 | - CUDA_CALLABLE T* data(){ | ||
46 | - return ptr; | ||
47 | - } | ||
48 | - | ||
49 | -/// Casting operator. Creates a new vector with a new type U. | ||
50 | - template< typename U > | ||
51 | - CUDA_CALLABLE operator vec3<U>(){ | ||
52 | - vec3<U> result; | ||
53 | - result.ptr[0] = (U)ptr[0]; | ||
54 | - result.ptr[1] = (U)ptr[1]; | ||
55 | - result.ptr[2] = (U)ptr[2]; | ||
56 | - | ||
57 | - return result; | ||
58 | - } | ||
59 | - | ||
60 | - // computes the squared Euclidean length (useful for several operations where only >, =, or < matter) | ||
61 | - CUDA_CALLABLE T len_sq() const{ | ||
62 | - return ptr[0] * ptr[0] + ptr[1] * ptr[1] + ptr[2] * ptr[2]; | ||
63 | - } | ||
64 | - | ||
65 | - /// computes the Euclidean length of the vector | ||
66 | - CUDA_CALLABLE T len() const{ | ||
67 | - return sqrt(len_sq()); | ||
68 | - } | ||
69 | - | ||
70 | - | ||
71 | - /// Convert the vector from cartesian to spherical coordinates (x, y, z -> r, theta, phi where theta = [0, 2*pi]) | ||
72 | - CUDA_CALLABLE vec3<T> cart2sph() const{ | ||
73 | - vec3<T> sph; | ||
74 | - sph.ptr[0] = len(); | ||
75 | - sph.ptr[1] = std::atan2(ptr[1], ptr[0]); | ||
76 | - if(sph.ptr[0] == 0) | ||
77 | - sph.ptr[2] = 0; | ||
78 | - else | ||
79 | - sph.ptr[2] = std::acos(ptr[2] / sph.ptr[0]); | ||
80 | - return sph; | ||
81 | - } | ||
82 | - | ||
83 | - /// Convert the vector from cartesian to spherical coordinates (r, theta, phi -> x, y, z where theta = [0, 2*pi]) | ||
84 | - CUDA_CALLABLE vec3<T> sph2cart() const{ | ||
85 | - vec3<T> cart; | ||
86 | - cart.ptr[0] = ptr[0] * std::cos(ptr[1]) * std::sin(ptr[2]); | ||
87 | - cart.ptr[1] = ptr[0] * std::sin(ptr[1]) * std::sin(ptr[2]); | ||
88 | - cart.ptr[2] = ptr[0] * std::cos(ptr[2]); | ||
89 | - | ||
90 | - return cart; | ||
91 | - } | ||
92 | - | ||
93 | - /// Computes the normalized vector (where each coordinate is divided by the L2 norm) | ||
94 | - CUDA_CALLABLE vec3<T> norm() const{ | ||
95 | - vec3<T> result; | ||
96 | - T l = len(); //compute the vector length | ||
97 | - return (*this) / l; | ||
98 | - } | ||
99 | - | ||
100 | - /// Computes the cross product of a 3-dimensional vector | ||
101 | - CUDA_CALLABLE vec3<T> cross(const vec3<T> rhs) const{ | ||
102 | - | ||
103 | - vec3<T> result; | ||
104 | - | ||
105 | - result[0] = (ptr[1] * rhs.ptr[2] - ptr[2] * rhs.ptr[1]); | ||
106 | - result[1] = (ptr[2] * rhs.ptr[0] - ptr[0] * rhs.ptr[2]); | ||
107 | - result[2] = (ptr[0] * rhs.ptr[1] - ptr[1] * rhs.ptr[0]); | ||
108 | - | ||
109 | - return result; | ||
110 | - } | ||
111 | - | ||
112 | - /// Compute the Euclidean inner (dot) product | ||
113 | - CUDA_CALLABLE T dot(vec3<T> rhs) const{ | ||
114 | - return ptr[0] * rhs.ptr[0] + ptr[1] * rhs.ptr[1] + ptr[2] * rhs.ptr[2]; | ||
115 | - } | ||
116 | - | ||
117 | - /// Arithmetic addition operator | ||
118 | - | ||
119 | - /// @param rhs is the right-hand-side operator for the addition | ||
120 | - CUDA_CALLABLE vec3<T> operator+(vec3<T> rhs) const{ | ||
121 | - vec3<T> result; | ||
122 | - result.ptr[0] = ptr[0] + rhs[0]; | ||
123 | - result.ptr[1] = ptr[1] + rhs[1]; | ||
124 | - result.ptr[2] = ptr[2] + rhs[2]; | ||
125 | - return result; | ||
126 | - } | ||
127 | - | ||
128 | - /// Arithmetic addition to a scalar | ||
129 | - | ||
130 | - /// @param rhs is the right-hand-side operator for the addition | ||
131 | - CUDA_CALLABLE vec3<T> operator+(T rhs) const{ | ||
132 | - vec3<T> result; | ||
133 | - result.ptr[0] = ptr[0] + rhs; | ||
134 | - result.ptr[1] = ptr[1] + rhs; | ||
135 | - result.ptr[2] = ptr[2] + rhs; | ||
136 | - return result; | ||
137 | - } | ||
138 | - | ||
139 | - /// Arithmetic subtraction operator | ||
140 | - | ||
141 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
142 | - CUDA_CALLABLE vec3<T> operator-(vec3<T> rhs) const{ | ||
143 | - vec3<T> result; | ||
144 | - result.ptr[0] = ptr[0] - rhs[0]; | ||
145 | - result.ptr[1] = ptr[1] - rhs[1]; | ||
146 | - result.ptr[2] = ptr[2] - rhs[2]; | ||
147 | - return result; | ||
148 | - } | ||
149 | - /// Arithmetic subtraction to a scalar | ||
150 | - | ||
151 | - /// @param rhs is the right-hand-side operator for the addition | ||
152 | - CUDA_CALLABLE vec3<T> operator-(T rhs) const{ | ||
153 | - vec3<T> result; | ||
154 | - result.ptr[0] = ptr[0] - rhs; | ||
155 | - result.ptr[1] = ptr[1] - rhs; | ||
156 | - result.ptr[2] = ptr[2] - rhs; | ||
157 | - return result; | ||
158 | - } | ||
159 | - | ||
160 | - /// Arithmetic scalar multiplication operator | ||
161 | - | ||
162 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
163 | - CUDA_CALLABLE vec3<T> operator*(T rhs) const{ | ||
164 | - vec3<T> result; | ||
165 | - result.ptr[0] = ptr[0] * rhs; | ||
166 | - result.ptr[1] = ptr[1] * rhs; | ||
167 | - result.ptr[2] = ptr[2] * rhs; | ||
168 | - return result; | ||
169 | - } | ||
170 | - | ||
171 | - /// Arithmetic scalar division operator | ||
172 | - | ||
173 | - /// @param rhs is the right-hand-side operator for the subtraction | ||
174 | - CUDA_CALLABLE vec3<T> operator/(T rhs) const{ | ||
175 | - return (*this) * ((T)1.0/rhs); | ||
176 | - } | ||
177 | - | ||
178 | - /// Multiplication by a scalar, followed by assignment | ||
179 | - CUDA_CALLABLE vec3<T> operator*=(T rhs){ | ||
180 | - ptr[0] = ptr[0] * rhs; | ||
181 | - ptr[1] = ptr[1] * rhs; | ||
182 | - ptr[2] = ptr[2] * rhs; | ||
183 | - return *this; | ||
184 | - } | ||
185 | - | ||
186 | - /// Addition and assignment | ||
187 | - CUDA_CALLABLE vec3<T> operator+=(vec3<T> rhs){ | ||
188 | - ptr[0] = ptr[0] + rhs; | ||
189 | - ptr[1] = ptr[1] + rhs; | ||
190 | - ptr[2] = ptr[2] + rhs; | ||
191 | - return *this; | ||
192 | - } | ||
193 | - | ||
194 | - /// Assign a scalar to all values | ||
195 | - CUDA_CALLABLE vec3<T> & operator=(T rhs){ | ||
196 | - ptr[0] = ptr[0] = rhs; | ||
197 | - ptr[1] = ptr[1] = rhs; | ||
198 | - ptr[2] = ptr[2] = rhs; | ||
199 | - return *this; | ||
200 | - } | ||
201 | - | ||
202 | - /// Casting and assignment | ||
203 | - template<typename Y> | ||
204 | - CUDA_CALLABLE vec3<T> & operator=(vec3<Y> rhs){ | ||
205 | - ptr[0] = (T)rhs.ptr[0]; | ||
206 | - ptr[1] = (T)rhs.ptr[1]; | ||
207 | - ptr[2] = (T)rhs.ptr[2]; | ||
208 | - return *this; | ||
209 | - } | ||
210 | - | ||
211 | - /// Unary minus (returns the negative of the vector) | ||
212 | - CUDA_CALLABLE vec3<T> operator-() const{ | ||
213 | - vec3<T> result; | ||
214 | - result.ptr[0] = -ptr[0]; | ||
215 | - result.ptr[1] = -ptr[1]; | ||
216 | - result.ptr[2] = -ptr[2]; | ||
217 | - return result; | ||
218 | - } | ||
219 | - | ||
220 | - /// Outputs the vector as a string | ||
221 | - std::string str() const{ | ||
222 | - std::stringstream ss; | ||
223 | - | ||
224 | - const size_t N = 3; | ||
225 | - | ||
226 | - ss<<"["; | ||
227 | - for(size_t i=0; i<N; i++) | ||
228 | - { | ||
229 | - ss<<ptr[i]; | ||
230 | - if(i != N-1) | ||
231 | - ss<<", "; | ||
232 | - } | ||
233 | - ss<<"]"; | ||
234 | - | ||
235 | - return ss.str(); | ||
236 | - } | ||
237 | - | ||
238 | - size_t size(){ return 3; } | ||
239 | - | ||
240 | - }; //end class vec3 | ||
241 | -} //end namespace stim | ||
242 | - | ||
243 | -/// Multiply a vector by a constant when the vector is on the right hand side | ||
244 | -template <typename T> | ||
245 | -stim::vec3<T> operator*(T lhs, stim::vec3<T> rhs){ | ||
246 | - return rhs * lhs; | ||
247 | -} | ||
248 | - | ||
249 | -//stream operator | ||
250 | -template<typename T> | ||
251 | -std::ostream& operator<<(std::ostream& os, stim::vec3<T> const& rhs){ | ||
252 | - os<<rhs.str(); | ||
253 | - return os; | ||
254 | -} | ||
255 | - | ||
256 | -#endif |