Commit 308a743caefd505141563c2434cf1002b978f202
1 parent
814eb271
fixed class compatibility with stim::vec3
Showing
9 changed files
with
142 additions
and
127 deletions
Show diff stats
stim/biomodels/network.h
... | ... | @@ -8,7 +8,7 @@ |
8 | 8 | #include <algorithm> |
9 | 9 | #include <string.h> |
10 | 10 | #include <math.h> |
11 | -#include <stim/math/vector.h> | |
11 | +#include <stim/math/vec3.h> | |
12 | 12 | #include <stim/visualization/obj.h> |
13 | 13 | #include <stim/visualization/cylinder.h> |
14 | 14 | #include <ANN/ANN.h> |
... | ... | @@ -37,7 +37,7 @@ class network{ |
37 | 37 | /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor |
38 | 38 | |
39 | 39 | ///@param p is an array of positions in space |
40 | - edge(std::vector< stim::vec<T> > p) : cylinder<T>(p){} | |
40 | + edge(std::vector< stim::vec3<T> > p) : cylinder<T>(p){} | |
41 | 41 | |
42 | 42 | /// Copy constructor creates an edge from a fiber |
43 | 43 | edge(stim::cylinder<T> f) : cylinder<T>(f) {} |
... | ... | @@ -61,20 +61,20 @@ class network{ |
61 | 61 | }; |
62 | 62 | |
63 | 63 | ///Node class that stores the physical position of the node as well as the edges it is connected to (edges that connect to it), As well as any additional data necessary. |
64 | - class vertex : public stim::vec<T> | |
64 | + class vertex : public stim::vec3<T> | |
65 | 65 | { |
66 | 66 | public: |
67 | 67 | //std::vector<unsigned int> edges; //indices of edges connected to this node. |
68 | 68 | std::vector<unsigned int> e[2]; //indices of edges going out (e[0]) and coming in (e[1]) |
69 | - //stim::vec<T> p; //position of this node in physical space. | |
69 | + //stim::vec3<T> p; //position of this node in physical space. | |
70 | 70 | |
71 | 71 | //constructor takes a stim::vec |
72 | - vertex(stim::vec<T> p) : stim::vec<T>(p){} | |
72 | + vertex(stim::vec3<T> p) : stim::vec3<T>(p){} | |
73 | 73 | |
74 | 74 | /// Output the vertex information as a string |
75 | 75 | std::string str(){ |
76 | 76 | std::stringstream ss; |
77 | - ss<<"\t(x, y, z) = "<<stim::vec<T>::str(); | |
77 | + ss<<"\t(x, y, z) = "<<stim::vec3<T>::str(); | |
78 | 78 | |
79 | 79 | if(e[0].size() > 0){ |
80 | 80 | ss<<"\t> "; |
... | ... | @@ -129,7 +129,11 @@ public: |
129 | 129 | std::vector< stim::vec<T> > c; //allocate an array of points for the vessel centerline |
130 | 130 | O.getLine(l, c); //get the fiber centerline |
131 | 131 | |
132 | - edge new_edge = c; //create an edge from the given centerline | |
132 | + std::vector< stim::vec3<T> > c3(c.size()); | |
133 | + for(size_t j = 0; j < c.size(); j++) | |
134 | + c3[j] = c[j]; | |
135 | + | |
136 | + edge new_edge = c3; //create an edge from the given centerline | |
133 | 137 | unsigned int I = new_edge.size(); //calculate the number of points on the centerline |
134 | 138 | |
135 | 139 | //get the first and last vertex IDs for the line |
... | ... | @@ -222,7 +226,7 @@ public: |
222 | 226 | float gaussianFunction(float x, float std=25){ return exp(-x/(2*std*std));} // by default std = 25 |
223 | 227 | |
224 | 228 | // stim 3d vector to annpoint of 3 dimensions |
225 | - void stim2ann(ANNpoint &a, stim::vec<T> b){ | |
229 | + void stim2ann(ANNpoint &a, stim::vec3<T> b){ | |
226 | 230 | a[0] = b[0]; |
227 | 231 | a[1] = b[1]; |
228 | 232 | a[2] = b[2]; |
... | ... | @@ -278,10 +282,9 @@ public: |
278 | 282 | ANNdistArray dists = new ANNdist[1]; // near neighbor distances |
279 | 283 | ANNidxArray nnIdx = new ANNidx[1]; // near neighbor indices // allocate near neigh indices |
280 | 284 | |
281 | - stim::vec<T> p0, p1; | |
282 | - float m0, m1; | |
285 | + stim::vec3<T> p0, p1; | |
286 | + float m1; | |
283 | 287 | float M = 0; //stores the total metric value |
284 | - float l; //stores the segment length | |
285 | 288 | float L = 0; //stores the total network length |
286 | 289 | ANNpoint queryPt = annAllocPt(3); |
287 | 290 | for(unsigned e = 0; e < R.E.size(); e++){ //for each edge in A |
... | ... | @@ -292,7 +295,7 @@ public: |
292 | 295 | p1 = R.E[e][p]; //get the next point in the edge |
293 | 296 | stim2ann(queryPt, p1); |
294 | 297 | kdt->annkSearch( queryPt, 1, nnIdx, dists, eps); //find the distance between A and the current network |
295 | - m1 = 1.0f - gaussianFunction(dists[0], sigma); //calculate the metric value based on the distance | |
298 | + m1 = 1.0f - gaussianFunction((float)dists[0], sigma); //calculate the metric value based on the distance | |
296 | 299 | R.E[e].set_mag(m1, p, 1); //set the error for the second point in the segment |
297 | 300 | |
298 | 301 | } | ... | ... |
stim/math/circle.h
... | ... | @@ -17,7 +17,7 @@ class circle : plane<T> |
17 | 17 | |
18 | 18 | private: |
19 | 19 | |
20 | - stim::vec<T> Y; | |
20 | + stim::vec3<T> Y; | |
21 | 21 | |
22 | 22 | CUDA_CALLABLE void |
23 | 23 | init() |
... | ... | @@ -48,7 +48,7 @@ public: |
48 | 48 | circle(T size, T z_pos = (T)0) : plane<T>() |
49 | 49 | { |
50 | 50 | init(); |
51 | - center(stim::vec<T>(0,0,z_pos)); | |
51 | + center(stim::vec3<T>(0,0,z_pos)); | |
52 | 52 | scale(size); |
53 | 53 | } |
54 | 54 | |
... | ... | @@ -56,7 +56,7 @@ public: |
56 | 56 | ///@param c: x,y,z location of the center. |
57 | 57 | ///@param n: x,y,z direction of the normal. |
58 | 58 | CUDA_CALLABLE |
59 | - circle(vec<T> c, vec<T> n = vec<T>(0,0,1)) : plane<T>() | |
59 | + circle(vec3<T> c, vec3<T> n = vec3<T>(0,0,1)) : plane<T>() | |
60 | 60 | { |
61 | 61 | center(c); |
62 | 62 | normal(n); |
... | ... | @@ -68,7 +68,7 @@ public: |
68 | 68 | ///@param s: size of the rectangle. |
69 | 69 | ///@param n: x,y,z direction of the normal. |
70 | 70 | CUDA_CALLABLE |
71 | - circle(vec<T> c, T s, vec<T> n = vec<T>(0,0,1)) : plane<T>() | |
71 | + circle(vec3<T> c, T s, vec3<T> n = vec3<T>(0,0,1)) : plane<T>() | |
72 | 72 | { |
73 | 73 | init(); |
74 | 74 | center(c); |
... | ... | @@ -82,7 +82,7 @@ public: |
82 | 82 | ///@param n: x,y,z direction of the normal. |
83 | 83 | ///@param u: x,y,z direction for the zero vector (from where the rotation starts) |
84 | 84 | CUDA_CALLABLE |
85 | - circle(vec<T> c, T s, vec<T> n = vec<T>(0,0,1), vec<T> u = vec<T>(1, 0, 0)) : plane<T>() | |
85 | + circle(vec3<T> c, T s, vec3<T> n = vec3<T>(0,0,1), vec3<T> u = vec3<T>(1, 0, 0)) : plane<T>() | |
86 | 86 | { |
87 | 87 | init(); |
88 | 88 | setU(u); |
... | ... | @@ -103,16 +103,15 @@ public: |
103 | 103 | ///sets the normal for the cirlce |
104 | 104 | ///@param n: x,y,z direction of the normal. |
105 | 105 | CUDA_CALLABLE void |
106 | - normal(vec<T> n) | |
106 | + normal(vec3<T> n) | |
107 | 107 | { |
108 | 108 | rotate(n, Y); |
109 | 109 | } |
110 | 110 | |
111 | 111 | ///sets the center of the circle. |
112 | 112 | ///@param n: x,y,z location of the center. |
113 | - CUDA_CALLABLE T | |
114 | - center(vec<T> p) | |
115 | - { | |
113 | + CUDA_CALLABLE void | |
114 | + center(vec3<T> p){ | |
116 | 115 | this->P = p; |
117 | 116 | } |
118 | 117 | |
... | ... | @@ -127,17 +126,17 @@ public: |
127 | 126 | } |
128 | 127 | |
129 | 128 | ///get the world space value given the planar coordinates a, b in [0, 1] |
130 | - CUDA_CALLABLE stim::vec<T> p(T a, T b) | |
129 | + CUDA_CALLABLE stim::vec3<T> p(T a, T b) | |
131 | 130 | { |
132 | - stim::vec<T> result; | |
131 | + stim::vec3<T> result; | |
133 | 132 | |
134 | - vec<T> A = this->P - this->U * (T)0.5 - Y * (T)0.5; | |
133 | + vec3<T> A = this->P - this->U * (T)0.5 - Y * (T)0.5; | |
135 | 134 | result = A + this->U * a + Y * b; |
136 | 135 | return result; |
137 | 136 | } |
138 | 137 | |
139 | 138 | ///parenthesis operator returns the world space given rectangular coordinates a and b in [0 1] |
140 | - CUDA_CALLABLE stim::vec<T> operator()(T a, T b) | |
139 | + CUDA_CALLABLE stim::vec3<T> operator()(T a, T b) | |
141 | 140 | { |
142 | 141 | return p(a,b); |
143 | 142 | } |
... | ... | @@ -145,11 +144,11 @@ public: |
145 | 144 | ///returns a vector with the points on the initialized circle. |
146 | 145 | ///connecting the points results in a circle. |
147 | 146 | ///@param n: integer for the number of points representing the circle. |
148 | - std::vector<stim::vec<T> > | |
147 | + std::vector<stim::vec3<T> > | |
149 | 148 | getPoints(int n) |
150 | 149 | { |
151 | - std::vector<stim::vec<T> > result; | |
152 | - stim::vec<T> point; | |
150 | + std::vector<stim::vec3<T> > result; | |
151 | + stim::vec3<T> point; | |
153 | 152 | T x,y; |
154 | 153 | float step = 360.0/(float) n; |
155 | 154 | for(float j = 0; j <= 360.0; j += step) |
... | ... | @@ -164,7 +163,7 @@ public: |
164 | 163 | ///returns a vector with the points on the initialized circle. |
165 | 164 | ///connecting the points results in a circle. |
166 | 165 | ///@param n: integer for the number of points representing the circle. |
167 | - stim::vec<T> | |
166 | + stim::vec3<T> | |
168 | 167 | p(T theta) |
169 | 168 | { |
170 | 169 | T x,y; | ... | ... |
stim/math/matrix.h
... | ... | @@ -5,6 +5,7 @@ |
5 | 5 | #include <string.h> |
6 | 6 | #include <iostream> |
7 | 7 | #include <stim/math/vector.h> |
8 | +#include <stim/math/vec3.h> | |
8 | 9 | #include <stim/cuda/cudatools/callable.h> |
9 | 10 | |
10 | 11 | namespace stim{ |
... | ... | @@ -54,7 +55,7 @@ struct matrix |
54 | 55 | vec<Y> operator*(vec<Y> rhs){ |
55 | 56 | unsigned int N = rhs.size(); |
56 | 57 | |
57 | - vec<Y> result; | |
58 | + vec3Y> result; | |
58 | 59 | result.resize(N); |
59 | 60 | |
60 | 61 | for(int r=0; r<N; r++) | ... | ... |
stim/math/plane.h
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | #define STIM_PLANE_H |
3 | 3 | |
4 | 4 | #include <iostream> |
5 | -#include <stim/math/vector.h> | |
5 | +#include <stim/math/vec3.h> | |
6 | 6 | #include <stim/cuda/cudatools/callable.h> |
7 | 7 | #include <stim/math/quaternion.h> |
8 | 8 | |
... | ... | @@ -22,17 +22,17 @@ template <typename T> |
22 | 22 | class plane |
23 | 23 | { |
24 | 24 | protected: |
25 | - stim::vec<T> P; | |
26 | - stim::vec<T> N; | |
27 | - stim::vec<T> U; | |
25 | + stim::vec3<T> P; | |
26 | + stim::vec3<T> N; | |
27 | + stim::vec3<T> U; | |
28 | 28 | |
29 | 29 | ///Initializes the plane with standard coordinates. |
30 | 30 | /// |
31 | 31 | CUDA_CALLABLE void init() |
32 | 32 | { |
33 | - P = stim::vec<T>(0, 0, 0); | |
34 | - N = stim::vec<T>(0, 0, 1); | |
35 | - U = stim::vec<T>(1, 0, 0); | |
33 | + P = stim::vec3<T>(0, 0, 0); | |
34 | + N = stim::vec3<T>(0, 0, 1); | |
35 | + U = stim::vec3<T>(1, 0, 0); | |
36 | 36 | } |
37 | 37 | |
38 | 38 | public: |
... | ... | @@ -42,7 +42,7 @@ class plane |
42 | 42 | init(); |
43 | 43 | } |
44 | 44 | |
45 | - CUDA_CALLABLE plane(vec<T> n, vec<T> p = vec<T>(0, 0, 0)) | |
45 | + CUDA_CALLABLE plane(vec3<T> n, vec3<T> p = vec3<T>(0, 0, 0)) | |
46 | 46 | { |
47 | 47 | init(); |
48 | 48 | P = p; |
... | ... | @@ -56,11 +56,11 @@ class plane |
56 | 56 | } |
57 | 57 | |
58 | 58 | //create a plane from three points (a triangle) |
59 | - CUDA_CALLABLE plane(vec<T> a, vec<T> b, vec<T> c) | |
59 | + CUDA_CALLABLE plane(vec3<T> a, vec3<T> b, vec3<T> c) | |
60 | 60 | { |
61 | 61 | init(); |
62 | 62 | P = c; |
63 | - stim::vec<T> n = (c - a).cross(b - a); | |
63 | + stim::vec3<T> n = (c - a).cross(b - a); | |
64 | 64 | try |
65 | 65 | { |
66 | 66 | if(n.len() != 0) |
... | ... | @@ -84,17 +84,17 @@ class plane |
84 | 84 | |
85 | 85 | } |
86 | 86 | |
87 | - CUDA_CALLABLE vec<T> n() | |
87 | + CUDA_CALLABLE vec3<T> n() | |
88 | 88 | { |
89 | 89 | return N; |
90 | 90 | } |
91 | 91 | |
92 | - CUDA_CALLABLE vec<T> p() | |
92 | + CUDA_CALLABLE vec3<T> p() | |
93 | 93 | { |
94 | 94 | return P; |
95 | 95 | } |
96 | 96 | |
97 | - CUDA_CALLABLE vec<T> u() | |
97 | + CUDA_CALLABLE vec3<T> u() | |
98 | 98 | { |
99 | 99 | return U; |
100 | 100 | } |
... | ... | @@ -107,7 +107,7 @@ class plane |
107 | 107 | } |
108 | 108 | |
109 | 109 | //determines how a vector v intersects the plane (1 = intersects front, 0 = within plane, -1 = intersects back) |
110 | - CUDA_CALLABLE int face(vec<T> v){ | |
110 | + CUDA_CALLABLE int face(vec3<T> v){ | |
111 | 111 | |
112 | 112 | T dprod = v.dot(N); //get the dot product between v and N |
113 | 113 | |
... | ... | @@ -121,46 +121,46 @@ class plane |
121 | 121 | } |
122 | 122 | |
123 | 123 | //determine on which side of the plane a point lies (1 = front, 0 = on the plane, -1 = bac k) |
124 | - CUDA_CALLABLE int side(vec<T> p){ | |
124 | + CUDA_CALLABLE int side(vec3<T> p){ | |
125 | 125 | |
126 | - vec<T> v = p - P; //get the vector from P to the query point p | |
126 | + vec3<T> v = p - P; //get the vector from P to the query point p | |
127 | 127 | |
128 | 128 | return face(v); |
129 | 129 | } |
130 | 130 | |
131 | 131 | //compute the component of v that is perpendicular to the plane |
132 | - CUDA_CALLABLE vec<T> perpendicular(vec<T> v){ | |
132 | + CUDA_CALLABLE vec3<T> perpendicular(vec3<T> v){ | |
133 | 133 | return N * v.dot(N); |
134 | 134 | } |
135 | 135 | |
136 | 136 | //compute the projection of v in the plane |
137 | - CUDA_CALLABLE vec<T> parallel(vec<T> v){ | |
137 | + CUDA_CALLABLE vec3<T> parallel(vec3<T> v){ | |
138 | 138 | return v - perpendicular(v); |
139 | 139 | } |
140 | 140 | |
141 | - CUDA_CALLABLE void setU(vec<T> v) | |
141 | + CUDA_CALLABLE void setU(vec3<T> v) | |
142 | 142 | { |
143 | 143 | U = (parallel(v.norm())).norm(); |
144 | 144 | } |
145 | 145 | |
146 | - CUDA_CALLABLE void decompose(vec<T> v, vec<T>& para, vec<T>& perp){ | |
146 | + CUDA_CALLABLE void decompose(vec3<T> v, vec3<T>& para, vec3<T>& perp){ | |
147 | 147 | perp = N * v.dot(N); |
148 | 148 | para = v - perp; |
149 | 149 | } |
150 | 150 | |
151 | 151 | //get both the parallel and perpendicular components of a vector v w.r.t. the plane |
152 | - CUDA_CALLABLE void project(vec<T> v, vec<T> &v_par, vec<T> &v_perp){ | |
152 | + CUDA_CALLABLE void project(vec3<T> v, vec3<T> &v_par, vec3<T> &v_perp){ | |
153 | 153 | |
154 | 154 | v_perp = v.dot(N); |
155 | 155 | v_par = v - v_perp; |
156 | 156 | } |
157 | 157 | |
158 | 158 | //compute the reflection of v off of the plane |
159 | - CUDA_CALLABLE vec<T> reflect(vec<T> v){ | |
159 | + CUDA_CALLABLE vec3<T> reflect(vec3<T> v){ | |
160 | 160 | |
161 | 161 | //compute the reflection using N_prime as the plane normal |
162 | - vec<T> par = parallel(v); | |
163 | - vec<T> r = (-v) + par * 2; | |
162 | + vec3<T> par = parallel(v); | |
163 | + vec3<T> r = (-v) + par * 2; | |
164 | 164 | return r; |
165 | 165 | |
166 | 166 | } |
... | ... | @@ -184,7 +184,7 @@ class plane |
184 | 184 | } |
185 | 185 | |
186 | 186 | |
187 | - CUDA_CALLABLE void rotate(vec<T> n) | |
187 | + CUDA_CALLABLE void rotate(vec3<T> n) | |
188 | 188 | { |
189 | 189 | quaternion<T> q; |
190 | 190 | q.CreateRotation(N, n); |
... | ... | @@ -194,7 +194,7 @@ class plane |
194 | 194 | |
195 | 195 | } |
196 | 196 | |
197 | - CUDA_CALLABLE void rotate(vec<T> n, vec<T> &Y) | |
197 | + CUDA_CALLABLE void rotate(vec3<T> n, vec3<T> &Y) | |
198 | 198 | { |
199 | 199 | quaternion<T> q; |
200 | 200 | q.CreateRotation(N, n); |
... | ... | @@ -205,7 +205,7 @@ class plane |
205 | 205 | |
206 | 206 | } |
207 | 207 | |
208 | - CUDA_CALLABLE void rotate(vec<T> n, vec<T> &X, vec<T> &Y) | |
208 | + CUDA_CALLABLE void rotate(vec3<T> n, vec3<T> &X, vec3<T> &Y) | |
209 | 209 | { |
210 | 210 | quaternion<T> q; |
211 | 211 | q.CreateRotation(N, n); | ... | ... |
stim/math/vec3.h
... | ... | @@ -217,12 +217,12 @@ public: |
217 | 217 | std::string str() const{ |
218 | 218 | std::stringstream ss; |
219 | 219 | |
220 | - size_t N = size(); | |
220 | + const size_t N = 3; | |
221 | 221 | |
222 | 222 | ss<<"["; |
223 | 223 | for(size_t i=0; i<N; i++) |
224 | 224 | { |
225 | - ss<<at(i); | |
225 | + ss<<ptr[i]; | |
226 | 226 | if(i != N-1) |
227 | 227 | ss<<", "; |
228 | 228 | } |
... | ... | @@ -230,7 +230,10 @@ public: |
230 | 230 | |
231 | 231 | return ss.str(); |
232 | 232 | } |
233 | - }; //end class triple | |
233 | + | |
234 | + size_t size(){ return 3; } | |
235 | + | |
236 | + }; //end class vec3 | |
234 | 237 | } //end namespace stim |
235 | 238 | |
236 | 239 | /// Multiply a vector by a constant when the vector is on the right hand side | ... | ... |
stim/math/vector.h
... | ... | @@ -317,6 +317,15 @@ struct vec : public std::vector<T> |
317 | 317 | return *this; |
318 | 318 | } |
319 | 319 | |
320 | + /// Cast to a vec3 | |
321 | + operator vec3<T>(){ | |
322 | + vec3<T> r; | |
323 | + size_t N = std::min<size_t>(size(), 3); | |
324 | + for(size_t i = 0; i < N; i++) | |
325 | + r[i] = at(i); | |
326 | + return r; | |
327 | + } | |
328 | + | |
320 | 329 | /// Casting and assignment |
321 | 330 | template<typename Y> |
322 | 331 | vec<T> & operator=(vec<Y> rhs){ | ... | ... |
stim/visualization/aaboundingbox.h
... | ... | @@ -10,8 +10,8 @@ class aaboundingbox{ |
10 | 10 | |
11 | 11 | public: |
12 | 12 | bool set; //has the bounding box been set to include any points? |
13 | - stim::vec<T> A; //minimum point in the bounding box | |
14 | - stim::vec<T> B; //maximum point in the bounding box | |
13 | + stim::vec3<T> A; //minimum point in the bounding box | |
14 | + stim::vec3<T> B; //maximum point in the bounding box | |
15 | 15 | |
16 | 16 | aaboundingbox(){ //constructor generates an empty bounding box |
17 | 17 | set = false; |
... | ... | @@ -21,7 +21,7 @@ public: |
21 | 21 | /// Test if a point is inside of the bounding box and returns true if it is. |
22 | 22 | |
23 | 23 | /// @param p is the point to be tested |
24 | - bool test(stim::vec<T> p){ | |
24 | + bool test(stim::vec3<T> p){ | |
25 | 25 | |
26 | 26 | for(unsigned d = 0; d < p.size(); p++){ //for each dimension |
27 | 27 | if(p[d] < A[d]) return false; //if the point is less than the minimum bound, return false |
... | ... | @@ -33,7 +33,7 @@ public: |
33 | 33 | /// Expand the bounding box to include the specified point. |
34 | 34 | |
35 | 35 | /// @param p is the point to be included |
36 | - void expand(stim::vec<T> p){ | |
36 | + void expand(stim::vec3<T> p){ | |
37 | 37 | |
38 | 38 | if(!set){ //if the bounding box is empty, fill it with the current point |
39 | 39 | A = B = p; |
... | ... | @@ -47,12 +47,12 @@ public: |
47 | 47 | } |
48 | 48 | |
49 | 49 | /// Return the center point of the bounding box as a stim::vec |
50 | - stim::vec<T> center(){ | |
50 | + stim::vec3<T> center(){ | |
51 | 51 | return (B + A) * 0.5; |
52 | 52 | } |
53 | 53 | |
54 | 54 | /// Return the size of the bounding box as a stim::vec |
55 | - stim::vec<T> size(){ | |
55 | + stim::vec3<T> size(){ | |
56 | 56 | return (B - A); |
57 | 57 | } |
58 | 58 | ... | ... |
stim/visualization/camera.h
... | ... | @@ -11,32 +11,32 @@ namespace stim{ |
11 | 11 | |
12 | 12 | class camera |
13 | 13 | { |
14 | - vec<float> d; //direction that the camera is pointing | |
15 | - vec<float> p; //position of the camera | |
16 | - vec<float> up; //"up" direction | |
14 | + vec3<float> d; //direction that the camera is pointing | |
15 | + vec3<float> p; //position of the camera | |
16 | + vec3<float> up; //"up" direction | |
17 | 17 | float focus; //focal length of the camera |
18 | 18 | float fov; |
19 | 19 | |
20 | 20 | //private function makes sure that the up vector is orthogonal to the direction vector and both are normalized |
21 | 21 | void stabalize() |
22 | 22 | { |
23 | - vec<float> side = up.cross(d); | |
23 | + vec3<float> side = up.cross(d); | |
24 | 24 | up = d.cross(side); |
25 | 25 | up = up.norm(); |
26 | 26 | d = d.norm(); |
27 | 27 | } |
28 | 28 | |
29 | 29 | public: |
30 | - void setPosition(vec<float> pos) | |
30 | + void setPosition(vec3<float> pos) | |
31 | 31 | { |
32 | 32 | p = pos; |
33 | 33 | } |
34 | - void setPosition(float x, float y, float z){setPosition(vec<float>(x, y, z));} | |
34 | + void setPosition(float x, float y, float z){setPosition(vec3<float>(x, y, z));} | |
35 | 35 | |
36 | 36 | void setFocalDistance(float distance){focus = distance;} |
37 | 37 | void setFOV(float field_of_view){fov = field_of_view;} |
38 | 38 | |
39 | - void LookAt(vec<float> pos) | |
39 | + void LookAt(vec3<float> pos) | |
40 | 40 | { |
41 | 41 | //find the new direction |
42 | 42 | d = pos - p; |
... | ... | @@ -47,22 +47,22 @@ public: |
47 | 47 | //stabalize the camera |
48 | 48 | stabalize(); |
49 | 49 | } |
50 | - void LookAt(float px, float py, float pz){LookAt(vec<float>(px, py, pz));} | |
51 | - void LookAt(vec<float> pos, vec<float> new_up){up = new_up; LookAt(pos);} | |
52 | - void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(vec<float>(px, py, pz), vec<float>(ux, uy, uz));} | |
50 | + void LookAt(float px, float py, float pz){LookAt(vec3<float>(px, py, pz));} | |
51 | + void LookAt(vec3<float> pos, vec3<float> new_up){up = new_up; LookAt(pos);} | |
52 | + void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(vec3<float>(px, py, pz), vec3<float>(ux, uy, uz));} | |
53 | 53 | void LookAtDolly(float lx, float ly, float lz) |
54 | 54 | { |
55 | 55 | //find the current focus point |
56 | - vec<float> f = p + focus*d; | |
57 | - vec<float> T = vec<float>(lx, ly, lz) - f; | |
56 | + vec3<float> f = p + focus*d; | |
57 | + vec3<float> T = vec3<float>(lx, ly, lz) - f; | |
58 | 58 | p = p + T; |
59 | 59 | } |
60 | 60 | |
61 | - void Dolly(vec<float> direction) | |
61 | + void Dolly(vec3<float> direction) | |
62 | 62 | { |
63 | 63 | p = p+direction; |
64 | 64 | } |
65 | - void Dolly(float x, float y, float z){Dolly(vec<float>(x, y, z));} | |
65 | + void Dolly(float x, float y, float z){Dolly(vec3<float>(x, y, z));} | |
66 | 66 | void Push(float delta) |
67 | 67 | { |
68 | 68 | if(delta > focus) |
... | ... | @@ -80,7 +80,7 @@ public: |
80 | 80 | qx.CreateRotation(theta_x, up[0], up[1], up[2]); |
81 | 81 | |
82 | 82 | //y rotation is around the side axis |
83 | - vec<float> side = up.cross(d); | |
83 | + vec3<float> side = up.cross(d); | |
84 | 84 | quaternion<float> qy; |
85 | 85 | qy.CreateRotation(theta_y, side[0], side[1], side[2]); |
86 | 86 | |
... | ... | @@ -118,28 +118,28 @@ public: |
118 | 118 | void OrbitFocus(float theta_x, float theta_y) |
119 | 119 | { |
120 | 120 | //find the focal point |
121 | - vec<float> focal_point = p + focus*d; | |
121 | + vec3<float> focal_point = p + focus*d; | |
122 | 122 | |
123 | 123 | //center the coordinate system on the focal point |
124 | - vec<float> centered = p - (focal_point - vec<float>(0, 0, 0)); | |
124 | + vec3<float> centered = p - (focal_point - vec3<float>(0, 0, 0)); | |
125 | 125 | |
126 | 126 | //create the x rotation (around the up vector) |
127 | 127 | quaternion<float> qx; |
128 | 128 | qx.CreateRotation(theta_x, up[0], up[1], up[2]); |
129 | - centered = vec<float>(0, 0, 0) + qx.toMatrix3()*(centered - vec<float>(0, 0, 0)); | |
129 | + centered = vec3<float>(0, 0, 0) + qx.toMatrix3()*(centered - vec3<float>(0, 0, 0)); | |
130 | 130 | |
131 | 131 | //get a side vector for theta_y rotation |
132 | - vec<float> side = up.cross((vec<float>(0, 0, 0) - centered).norm()); | |
132 | + vec3<float> side = up.cross((vec3<float>(0, 0, 0) - centered).norm()); | |
133 | 133 | |
134 | 134 | quaternion<float> qy; |
135 | 135 | qy.CreateRotation(theta_y, side[0], side[1], side[2]); |
136 | - centered = vec<float>(0, 0, 0) + qy.toMatrix3()*(centered - vec<float>(0, 0, 0)); | |
136 | + centered = vec3<float>(0, 0, 0) + qy.toMatrix3()*(centered - vec3<float>(0, 0, 0)); | |
137 | 137 | |
138 | 138 | //perform the rotation on the centered camera position |
139 | 139 | //centered = final.toMatrix()*centered; |
140 | 140 | |
141 | 141 | //re-position the camera |
142 | - p = centered + (focal_point - vec<float>(0, 0, 0)); | |
142 | + p = centered + (focal_point - vec3<float>(0, 0, 0)); | |
143 | 143 | |
144 | 144 | //make sure we are looking at the focal point |
145 | 145 | LookAt(focal_point); |
... | ... | @@ -151,17 +151,17 @@ public: |
151 | 151 | |
152 | 152 | void Slide(float u, float v) |
153 | 153 | { |
154 | - vec<float> V = up.norm(); | |
155 | - vec<float> U = up.cross(d).norm(); | |
154 | + vec3<float> V = up.norm(); | |
155 | + vec3<float> U = up.cross(d).norm(); | |
156 | 156 | |
157 | 157 | p = p + (V * v) + (U * u); |
158 | 158 | } |
159 | 159 | |
160 | 160 | //accessor methods |
161 | - vec<float> getPosition(){return p;} | |
162 | - vec<float> getUp(){return up;} | |
163 | - vec<float> getDirection(){return d;} | |
164 | - vec<float> getLookAt(){return p + focus*d;} | |
161 | + vec3<float> getPosition(){return p;} | |
162 | + vec3<float> getUp(){return up;} | |
163 | + vec3<float> getDirection(){return d;} | |
164 | + vec3<float> getLookAt(){return p + focus*d;} | |
165 | 165 | float getFOV(){return fov;} |
166 | 166 | |
167 | 167 | //output the camera settings |
... | ... | @@ -182,9 +182,9 @@ public: |
182 | 182 | //constructor |
183 | 183 | camera() |
184 | 184 | { |
185 | - p = vec<float>(0, 0, 0); | |
186 | - d = vec<float>(0, 0, 1); | |
187 | - up = vec<float>(0, 1, 0); | |
185 | + p = vec3<float>(0, 0, 0); | |
186 | + d = vec3<float>(0, 0, 1); | |
187 | + up = vec3<float>(0, 1, 0); | |
188 | 188 | focus = 1; |
189 | 189 | |
190 | 190 | } | ... | ... |
stim/visualization/cylinder.h
... | ... | @@ -2,7 +2,7 @@ |
2 | 2 | #define STIM_CYLINDER_H |
3 | 3 | #include <iostream> |
4 | 4 | #include <stim/math/circle.h> |
5 | -#include <stim/math/vector.h> | |
5 | +#include <stim/math/vec3.h> | |
6 | 6 | |
7 | 7 | |
8 | 8 | namespace stim |
... | ... | @@ -25,11 +25,11 @@ class cylinder |
25 | 25 | |
26 | 26 | ///inits the cylinder from a list of points (inP) and radii (inM) |
27 | 27 | void |
28 | - init(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM) | |
28 | + init(std::vector<stim::vec3<T> > inP, std::vector<stim::vec<T> > inM) | |
29 | 29 | { |
30 | 30 | mags = inM; |
31 | - stim::vec<float> v1; | |
32 | - stim::vec<float> v2; | |
31 | + stim::vec3<float> v1; | |
32 | + stim::vec3<float> v2; | |
33 | 33 | e.resize(inP.size()); |
34 | 34 | if(inP.size() < 2) |
35 | 35 | return; |
... | ... | @@ -38,16 +38,16 @@ class cylinder |
38 | 38 | L.resize(inP.size()); |
39 | 39 | T temp = (T)0; |
40 | 40 | L[0] = 0; |
41 | - for(int i = 1; i < L.size(); i++) | |
41 | + for(size_t i = 1; i < L.size(); i++) | |
42 | 42 | { |
43 | 43 | temp += (inP[i-1] - inP[i]).len(); |
44 | 44 | L[i] = temp; |
45 | 45 | } |
46 | 46 | |
47 | - stim::vec<T> dr = (inP[1] - inP[0]).norm(); | |
48 | - s = stim::circle<T>(inP[0], inM[0][0], dr, stim::vec<T>(1,0,0)); | |
47 | + stim::vec3<T> dr = (inP[1] - inP[0]).norm(); | |
48 | + s = stim::circle<T>(inP[0], inM[0][0], dr, stim::vec3<T>(1,0,0)); | |
49 | 49 | e[0] = s; |
50 | - for(int i = 1; i < inP.size()-1; i++) | |
50 | + for(size_t i = 1; i < inP.size()-1; i++) | |
51 | 51 | { |
52 | 52 | s.center(inP[i]); |
53 | 53 | v1 = (inP[i] - inP[i-1]).norm(); |
... | ... | @@ -67,7 +67,7 @@ class cylinder |
67 | 67 | } |
68 | 68 | |
69 | 69 | ///returns the direction vector at point idx. |
70 | - stim::vec<T> | |
70 | + stim::vec3<T> | |
71 | 71 | d(int idx) |
72 | 72 | { |
73 | 73 | if(idx == 0) |
... | ... | @@ -81,15 +81,15 @@ class cylinder |
81 | 81 | else |
82 | 82 | { |
83 | 83 | // return (e[idx+1].P - e[idx].P).norm(); |
84 | - stim::vec<float> v1 = (e[idx].P-e[idx-1].P).norm(); | |
85 | - stim::vec<float> v2 = (e[idx+1].P-e[idx].P).norm(); | |
84 | + stim::vec3<float> v1 = (e[idx].P-e[idx-1].P).norm(); | |
85 | + stim::vec3<float> v2 = (e[idx+1].P-e[idx].P).norm(); | |
86 | 86 | return (v1+v2).norm(); |
87 | 87 | } |
88 | 88 | // return e[idx].N; |
89 | 89 | |
90 | 90 | } |
91 | 91 | |
92 | - stim::vec<T> | |
92 | + stim::vec3<T> | |
93 | 93 | d(T l, int idx) |
94 | 94 | { |
95 | 95 | if(idx == 0 || idx == e.size()-1) |
... | ... | @@ -144,13 +144,13 @@ class cylinder |
144 | 144 | ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. |
145 | 145 | ///@param inP: Vector of stim vecs composing the points of the centerline. |
146 | 146 | ///@param inM: Vector of stim vecs composing the radii of the centerline. |
147 | - cylinder(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM){ | |
147 | + cylinder(std::vector<stim::vec3<T> > inP, std::vector<stim::vec3<T> > inM){ | |
148 | 148 | init(inP, inM); |
149 | 149 | } |
150 | 150 | |
151 | 151 | ///Constructor defines a cylinder with centerline inP and magnitudes of zero |
152 | 152 | ///@param inP: Vector of stim vecs composing the points of the centerline |
153 | - cylinder(std::vector< stim::vec<T> > inP){ | |
153 | + cylinder(std::vector< stim::vec3<T> > inP){ | |
154 | 154 | std::vector< stim::vec<T> > inM; //create an array of arbitrary magnitudes |
155 | 155 | |
156 | 156 | stim::vec<T> zero; |
... | ... | @@ -171,12 +171,12 @@ class cylinder |
171 | 171 | ///Returns a position vector at the given p-value (p value ranges from 0 to 1). |
172 | 172 | ///interpolates the position along the line. |
173 | 173 | ///@param pvalue: the location of the in the cylinder, from 0 (beginning to 1). |
174 | - stim::vec<T> | |
174 | + stim::vec3<T> | |
175 | 175 | p(T pvalue) |
176 | 176 | { |
177 | 177 | if(pvalue < 0.0 || pvalue > 1.0) |
178 | 178 | { |
179 | - return stim::vec<float>(-1,-1,-1); | |
179 | + return stim::vec3<float>(-1,-1,-1); | |
180 | 180 | } |
181 | 181 | T l = pvalue*L[L.size()-1]; |
182 | 182 | int idx = findIdx(l); |
... | ... | @@ -188,7 +188,7 @@ class cylinder |
188 | 188 | ///Interpolates the radius along the line. |
189 | 189 | ///@param l: the location of the in the cylinder. |
190 | 190 | ///@param idx: integer location of the point closest to l but prior to it. |
191 | - stim::vec<T> | |
191 | + stim::vec3<T> | |
192 | 192 | p(T l, int idx) |
193 | 193 | { |
194 | 194 | T rat = (l-L[idx])/(L[idx+1]-L[idx]); |
... | ... | @@ -252,16 +252,16 @@ class cylinder |
252 | 252 | ///in x, y, z coordinates. Theta is in degrees from 0 to 360. |
253 | 253 | ///@param pvalue: the location of the in the cylinder, from 0 (beginning to 1). |
254 | 254 | ///@param theta: the angle to the point of a circle. |
255 | - stim::vec<T> | |
255 | + stim::vec3<T> | |
256 | 256 | surf(T pvalue, T theta) |
257 | 257 | { |
258 | 258 | if(pvalue < 0.0 || pvalue > 1.0) |
259 | 259 | { |
260 | - return stim::vec<float>(-1,-1,-1); | |
260 | + return stim::vec3<float>(-1,-1,-1); | |
261 | 261 | } else { |
262 | 262 | T l = pvalue*L[L.size()-1]; |
263 | 263 | int idx = findIdx(l); |
264 | - stim::vec<T> ps = p(l, idx); | |
264 | + stim::vec3<T> ps = p(l, idx); | |
265 | 265 | T m = r(l, idx); |
266 | 266 | s = e[idx]; |
267 | 267 | s.center(ps); |
... | ... | @@ -273,10 +273,10 @@ class cylinder |
273 | 273 | |
274 | 274 | ///returns a vector of points necessary to create a circle at every position in the fiber. |
275 | 275 | ///@param sides: the number of sides of each circle. |
276 | - std::vector<std::vector<vec<T> > > | |
276 | + std::vector<std::vector<vec3<T> > > | |
277 | 277 | getPoints(int sides) |
278 | 278 | { |
279 | - std::vector<std::vector <vec<T> > > points; | |
279 | + std::vector<std::vector <vec3<T> > > points; | |
280 | 280 | points.resize(e.size()); |
281 | 281 | for(int i = 0; i < e.size(); i++) |
282 | 282 | { |
... | ... | @@ -293,7 +293,7 @@ class cylinder |
293 | 293 | } |
294 | 294 | /// Allows a point on the centerline to be accessed using bracket notation |
295 | 295 | |
296 | - vec<T> operator[](unsigned int i){ | |
296 | + vec3<T> operator[](unsigned int i){ | |
297 | 297 | return e[i].P; |
298 | 298 | } |
299 | 299 | |
... | ... | @@ -309,7 +309,7 @@ class cylinder |
309 | 309 | T M = 0; //initialize the integral to zero |
310 | 310 | T m0, m1; //allocate space for both magnitudes in a single segment |
311 | 311 | |
312 | - //vec<T> p0, p1; //allocate space for both points in a single segment | |
312 | + //vec3<T> p0, p1; //allocate space for both points in a single segment | |
313 | 313 | |
314 | 314 | m0 = mags[0][m]; //initialize the first point and magnitude to the first point in the cylinder |
315 | 315 | //p0 = pos[0]; |
... | ... | @@ -325,7 +325,7 @@ class cylinder |
325 | 325 | if(p > 1) len = (L[p-1] - L[p-2]); //calculate the segment length using the L array |
326 | 326 | |
327 | 327 | //add the average magnitude, weighted by the segment length |
328 | - M += (m0 + m1)/2.0 * len; | |
328 | + M += (m0 + m1)/(T)2.0 * len; | |
329 | 329 | |
330 | 330 | m0 = m1; //move to the next segment by shifting points |
331 | 331 | } |
... | ... | @@ -345,21 +345,21 @@ class cylinder |
345 | 345 | /// @param spacing is the maximum spacing allowed between sample points |
346 | 346 | cylinder<T> resample(T spacing){ |
347 | 347 | |
348 | - std::vector< vec<T> > result; | |
348 | + std::vector< vec3<T> > result; | |
349 | 349 | |
350 | - vec<T> p0 = e[0].P; //initialize p0 to the first point on the centerline | |
351 | - vec<T> p1; | |
350 | + vec3<T> p0 = e[0].P; //initialize p0 to the first point on the centerline | |
351 | + vec3<T> p1; | |
352 | 352 | unsigned N = size(); //number of points in the current centerline |
353 | 353 | |
354 | 354 | //for each line segment on the centerline |
355 | 355 | for(unsigned int i = 1; i < N; i++){ |
356 | 356 | p1 = e[i].P; //get the second point in the line segment |
357 | 357 | |
358 | - vec<T> v = p1 - p0; //calculate the vector between these two points | |
358 | + vec3<T> v = p1 - p0; //calculate the vector between these two points | |
359 | 359 | T d = v.len(); //calculate the distance between these two points (length of the line segment) |
360 | 360 | |
361 | - unsigned nsteps = d / spacing+1; //calculate the number of steps to take along the segment to meet the spacing criteria | |
362 | - T stepsize = 1.0 / nsteps; //calculate the parametric step size between new centerline points | |
361 | + size_t nsteps = (size_t)std::ceil(d / spacing); //calculate the number of steps to take along the segment to meet the spacing criteria | |
362 | + T stepsize = (T)1.0 / nsteps; //calculate the parametric step size between new centerline points | |
363 | 363 | |
364 | 364 | //for each step along the line segment |
365 | 365 | for(unsigned s = 0; s < nsteps; s++){ | ... | ... |