Commit d03b807e8084446bf7f205f717b2af0e0626eeab

Authored by Pavel Govyadinov
1 parent 2137d771

fixed all the bugs and issue in the plane, rect, and circle classes. Fully funct…

…ional, but needs cleanup
Showing 3 changed files with 41 additions and 26 deletions   Show diff stats
@@ -6,11 +6,22 @@ @@ -6,11 +6,22 @@
6 #include <stim/cuda/cudatools/callable.h> 6 #include <stim/cuda/cudatools/callable.h>
7 #include <stim/math/quaternion.h> 7 #include <stim/math/quaternion.h>
8 8
  9 +
9 namespace stim 10 namespace stim
10 { 11 {
11 -template <typename T> class plane 12 +template<typename T> class plane;
  13 +}
  14 +
  15 +template<typename T>
  16 +CUDA_CALLABLE stim::plane<T> operator-(stim::plane<T> v);
  17 +
  18 +namespace stim
  19 +{
  20 +
  21 +template <typename T>
  22 +class plane
12 { 23 {
13 - private: 24 + protected:
14 stim::vec<T> P; 25 stim::vec<T> P;
15 stim::vec<T> N; 26 stim::vec<T> N;
16 stim::vec<T> U; 27 stim::vec<T> U;
@@ -31,17 +42,11 @@ template &lt;typename T&gt; class plane @@ -31,17 +42,11 @@ template &lt;typename T&gt; class plane
31 init(); 42 init();
32 } 43 }
33 44
34 - CUDA_CALLABLE plane(vec<T> p)  
35 - {  
36 - init();  
37 - P = p;  
38 - }  
39 -  
40 CUDA_CALLABLE plane(vec<T> n, vec<T> p = vec<T>(0, 0, 0)) 45 CUDA_CALLABLE plane(vec<T> n, vec<T> p = vec<T>(0, 0, 0))
41 { 46 {
42 init(); 47 init();
43 P = p; 48 P = p;
44 - rotate(N, n.norm()); 49 + rotate(n.norm());
45 } 50 }
46 51
47 CUDA_CALLABLE plane(T z_pos) 52 CUDA_CALLABLE plane(T z_pos)
@@ -60,13 +65,15 @@ template &lt;typename T&gt; class plane @@ -60,13 +65,15 @@ template &lt;typename T&gt; class plane
60 { 65 {
61 if(n.len() != 0) 66 if(n.len() != 0)
62 { 67 {
63 - rotate(N, n.norm()); 68 + rotate(n.norm());
  69 + } else {
  70 + throw 42;
64 } 71 }
65 } 72 }
66 - catch  
67 - { 73 + catch(int i)
  74 + {
68 std::cerr << "No plane can be creates as all points a,b,c lie on a straight line" << std::endl; 75 std::cerr << "No plane can be creates as all points a,b,c lie on a straight line" << std::endl;
69 - } 76 + }
70 } 77 }
71 78
72 template< typename U > 79 template< typename U >
@@ -77,7 +84,7 @@ template &lt;typename T&gt; class plane @@ -77,7 +84,7 @@ template &lt;typename T&gt; class plane
77 84
78 } 85 }
79 86
80 - CUDA_CALLABLE vec<T> norm() 87 + CUDA_CALLABLE vec<T> n()
81 { 88 {
82 return N; 89 return N;
83 } 90 }
@@ -160,7 +167,7 @@ template &lt;typename T&gt; class plane @@ -160,7 +167,7 @@ template &lt;typename T&gt; class plane
160 167
161 CUDA_CALLABLE stim::plane<T> operator-() 168 CUDA_CALLABLE stim::plane<T> operator-()
162 { 169 {
163 - rts::plane<T> p = *this; 170 + stim::plane<T> p = *this;
164 171
165 //negate the normal vector 172 //negate the normal vector
166 p.N = -p.N; 173 p.N = -p.N;
@@ -172,7 +179,7 @@ template &lt;typename T&gt; class plane @@ -172,7 +179,7 @@ template &lt;typename T&gt; class plane
172 std::stringstream ss; 179 std::stringstream ss;
173 ss<<"P: "<<P<<std::endl; 180 ss<<"P: "<<P<<std::endl;
174 ss<<"N: "<<N<<std::endl; 181 ss<<"N: "<<N<<std::endl;
175 - ss<<"D: "<<D; 182 + ss<<"U: "<<U;
176 return ss.str(); 183 return ss.str();
177 } 184 }
178 185
1 #ifndef STIM_RECT_H 1 #ifndef STIM_RECT_H
2 #define STIM_RECT_H 2 #define STIM_RECT_H
3 3
  4 +
4 //enable CUDA_CALLABLE macro 5 //enable CUDA_CALLABLE macro
5 #include <stim/cuda/cudatools/callable.h> 6 #include <stim/cuda/cudatools/callable.h>
6 #include <stim/math/plane.h> 7 #include <stim/math/plane.h>
@@ -9,12 +10,13 @@ @@ -9,12 +10,13 @@
9 #include <iostream> 10 #include <iostream>
10 #include <iomanip> 11 #include <iomanip>
11 #include <algorithm> 12 #include <algorithm>
  13 +#include <assert.h>
12 14
13 namespace stim{ 15 namespace stim{
14 16
15 //template for a rectangle class in ND space 17 //template for a rectangle class in ND space
16 template <typename T> 18 template <typename T>
17 -class rect : public plane <T> 19 +class rect : plane <T>
18 { 20 {
19 /* 21 /*
20 ^ O 22 ^ O
@@ -40,6 +42,12 @@ private: @@ -40,6 +42,12 @@ private:
40 42
41 public: 43 public:
42 44
  45 + using stim::plane<T>::n;
  46 + using stim::plane<T>::P;
  47 + using stim::plane<T>::N;
  48 + using stim::plane<T>::U;
  49 + using stim::plane<T>::rotate;
  50 +
43 ///base constructor. 51 ///base constructor.
44 CUDA_CALLABLE rect() 52 CUDA_CALLABLE rect()
45 : plane<T>() 53 : plane<T>()
@@ -84,7 +92,7 @@ public: @@ -84,7 +92,7 @@ public:
84 ///@param directionX: u,v,w direction of the X vector. 92 ///@param directionX: u,v,w direction of the X vector.
85 ///@param directionY: u,v,w direction of the Y vector. 93 ///@param directionY: u,v,w direction of the Y vector.
86 CUDA_CALLABLE rect(vec<T> center, vec<T> directionX, vec<T> directionY ) 94 CUDA_CALLABLE rect(vec<T> center, vec<T> directionX, vec<T> directionY )
87 - : plane<T>(p) 95 + : plane<T>((directionX.cross(directionY)).norm(),center)
88 { 96 {
89 X = directionX; 97 X = directionX;
90 Y = directionY; 98 Y = directionY;
@@ -96,7 +104,7 @@ public: @@ -96,7 +104,7 @@ public:
96 ///@param directionX: u,v,w direction of the X vector. 104 ///@param directionX: u,v,w direction of the X vector.
97 ///@param directionY: u,v,w direction of the Y vector. 105 ///@param directionY: u,v,w direction of the Y vector.
98 CUDA_CALLABLE rect(T size, vec<T> center, vec<T> directionX, vec<T> directionY ) 106 CUDA_CALLABLE rect(T size, vec<T> center, vec<T> directionX, vec<T> directionY )
99 - : plane<T>(p) 107 + : plane<T>((directionX.cross(directionY)).norm(),center)
100 { 108 {
101 X = directionX; 109 X = directionX;
102 Y = directionY; 110 Y = directionY;
@@ -108,8 +116,8 @@ public: @@ -108,8 +116,8 @@ public:
108 ///@param center: x,y,z location of the center. 116 ///@param center: x,y,z location of the center.
109 ///@param directionX: u,v,w direction of the X vector. 117 ///@param directionX: u,v,w direction of the X vector.
110 ///@param directionY: u,v,w direction of the Y vector. 118 ///@param directionY: u,v,w direction of the Y vector.
111 - CUDA_CALLABLE rect(vec<T> size, vec<T> center, vec<T> directionX, vec<T> directionY )  
112 - : plane<T>(p) 119 + CUDA_CALLABLE rect(vec<T> size, vec<T> center, vec<T> directionX, vec<T> directionY)
  120 + : plane<T>((directionX.cross(directionY)).norm(), center)
113 { 121 {
114 X = directionX; 122 X = directionX;
115 Y = directionY; 123 Y = directionY;
@@ -136,7 +144,6 @@ public: @@ -136,7 +144,6 @@ public:
136 ///general init method that sets a general rectangle. 144 ///general init method that sets a general rectangle.
137 CUDA_CALLABLE void init() 145 CUDA_CALLABLE void init()
138 { 146 {
139 - P = vec<T>(0, 0, 0);  
140 X = vec<T>(1, 0, 0); 147 X = vec<T>(1, 0, 0);
141 Y = vec<T>(0, 1, 0); 148 Y = vec<T>(0, 1, 0);
142 } 149 }
@@ -156,7 +163,7 @@ public: @@ -156,7 +163,7 @@ public:
156 { 163 {
157 stim::vec<T> result; 164 stim::vec<T> result;
158 //given the two parameters a, b = [0 1], returns the position in world space 165 //given the two parameters a, b = [0 1], returns the position in world space
159 - vec<T> A = P - X * (T)0.5 - Y * (T)0.5; 166 + vec<T> A = this->P - X * (T)0.5 - Y * (T)0.5;
160 result = A + X * a + Y * b; 167 result = A + X * a + Y * b;
161 168
162 return result; 169 return result;
@@ -217,7 +224,7 @@ public: @@ -217,7 +224,7 @@ public:
217 224
218 CUDA_CALLABLE T center(vec<T> p) 225 CUDA_CALLABLE T center(vec<T> p)
219 { 226 {
220 - C = p; 227 + this->P = p;
221 } 228 }
222 229
223 ///Returns the maximum distance of the rectangle from a point p to the sides of the rectangle. 230 ///Returns the maximum distance of the rectangle from a point p to the sides of the rectangle.
stim/math/vector.h
@@ -71,8 +71,9 @@ struct vec : public std::vector&lt;T&gt; @@ -71,8 +71,9 @@ struct vec : public std::vector&lt;T&gt;
71 vec( const vec<T>& other){ 71 vec( const vec<T>& other){
72 unsigned int N = other.size(); 72 unsigned int N = other.size();
73 resize(N); //resize the current vector to match the copy 73 resize(N); //resize the current vector to match the copy
74 - for(unsigned int i=0; i<N; i++) //copy each element  
75 - at(i) = other[i]; 74 + for(unsigned int i=0; i<N; i++){ //copy each element
  75 + at(i) = other[i];
  76 + }
76 } 77 }
77 78
78 //I'm not sure what these were doing here. 79 //I'm not sure what these were doing here.