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
stim/math/plane.h
... ... @@ -6,11 +6,22 @@
6 6 #include <stim/cuda/cudatools/callable.h>
7 7 #include <stim/math/quaternion.h>
8 8  
  9 +
9 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 25 stim::vec<T> P;
15 26 stim::vec<T> N;
16 27 stim::vec<T> U;
... ... @@ -31,17 +42,11 @@ template &lt;typename T&gt; class plane
31 42 init();
32 43 }
33 44  
34   - CUDA_CALLABLE plane(vec<T> p)
35   - {
36   - init();
37   - P = p;
38   - }
39   -
40 45 CUDA_CALLABLE plane(vec<T> n, vec<T> p = vec<T>(0, 0, 0))
41 46 {
42 47 init();
43 48 P = p;
44   - rotate(N, n.norm());
  49 + rotate(n.norm());
45 50 }
46 51  
47 52 CUDA_CALLABLE plane(T z_pos)
... ... @@ -60,13 +65,15 @@ template &lt;typename T&gt; class plane
60 65 {
61 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 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 79 template< typename U >
... ... @@ -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 89 return N;
83 90 }
... ... @@ -160,7 +167,7 @@ template &lt;typename T&gt; class plane
160 167  
161 168 CUDA_CALLABLE stim::plane<T> operator-()
162 169 {
163   - rts::plane<T> p = *this;
  170 + stim::plane<T> p = *this;
164 171  
165 172 //negate the normal vector
166 173 p.N = -p.N;
... ... @@ -172,7 +179,7 @@ template &lt;typename T&gt; class plane
172 179 std::stringstream ss;
173 180 ss<<"P: "<<P<<std::endl;
174 181 ss<<"N: "<<N<<std::endl;
175   - ss<<"D: "<<D;
  182 + ss<<"U: "<<U;
176 183 return ss.str();
177 184 }
178 185  
... ...
stim/math/rect.h
1 1 #ifndef STIM_RECT_H
2 2 #define STIM_RECT_H
3 3  
  4 +
4 5 //enable CUDA_CALLABLE macro
5 6 #include <stim/cuda/cudatools/callable.h>
6 7 #include <stim/math/plane.h>
... ... @@ -9,12 +10,13 @@
9 10 #include <iostream>
10 11 #include <iomanip>
11 12 #include <algorithm>
  13 +#include <assert.h>
12 14  
13 15 namespace stim{
14 16  
15 17 //template for a rectangle class in ND space
16 18 template <typename T>
17   -class rect : public plane <T>
  19 +class rect : plane <T>
18 20 {
19 21 /*
20 22 ^ O
... ... @@ -40,6 +42,12 @@ private:
40 42  
41 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 51 ///base constructor.
44 52 CUDA_CALLABLE rect()
45 53 : plane<T>()
... ... @@ -84,7 +92,7 @@ public:
84 92 ///@param directionX: u,v,w direction of the X vector.
85 93 ///@param directionY: u,v,w direction of the Y vector.
86 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 97 X = directionX;
90 98 Y = directionY;
... ... @@ -96,7 +104,7 @@ public:
96 104 ///@param directionX: u,v,w direction of the X vector.
97 105 ///@param directionY: u,v,w direction of the Y vector.
98 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 109 X = directionX;
102 110 Y = directionY;
... ... @@ -108,8 +116,8 @@ public:
108 116 ///@param center: x,y,z location of the center.
109 117 ///@param directionX: u,v,w direction of the X vector.
110 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 122 X = directionX;
115 123 Y = directionY;
... ... @@ -136,7 +144,6 @@ public:
136 144 ///general init method that sets a general rectangle.
137 145 CUDA_CALLABLE void init()
138 146 {
139   - P = vec<T>(0, 0, 0);
140 147 X = vec<T>(1, 0, 0);
141 148 Y = vec<T>(0, 1, 0);
142 149 }
... ... @@ -156,7 +163,7 @@ public:
156 163 {
157 164 stim::vec<T> result;
158 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 167 result = A + X * a + Y * b;
161 168  
162 169 return result;
... ... @@ -217,7 +224,7 @@ public:
217 224  
218 225 CUDA_CALLABLE T center(vec<T> p)
219 226 {
220   - C = p;
  227 + this->P = p;
221 228 }
222 229  
223 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 71 vec( const vec<T>& other){
72 72 unsigned int N = other.size();
73 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 79 //I'm not sure what these were doing here.
... ...