Authored by David Mayerich
1 parent 814eb271

fixed class compatibility with stim::vec3

Showing 9 changed files with 142 additions and 127 deletions
stim/biomodels/network.h

 ... ... @@ -8,7 +8,7 @@ 8 8 #include 9 9 #include 10 10 #include 11 -#include 11 +#include 12 12 #include 13 13 #include 14 14 #include ... ... @@ -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 > p) : cylinder(p){} 40 + edge(std::vector< stim::vec3 > p) : cylinder(p){} 41 41 42 42 /// Copy constructor creates an edge from a fiber 43 43 edge(stim::cylinder f) : cylinder(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 64 + class vertex : public stim::vec3 65 65 { 66 66 public: 67 67 //std::vector edges; //indices of edges connected to this node. 68 68 std::vector e[2]; //indices of edges going out (e[0]) and coming in (e[1]) 69 - //stim::vec p; //position of this node in physical space. 69 + //stim::vec3 p; //position of this node in physical space. 70 70 71 71 //constructor takes a stim::vec 72 - vertex(stim::vec p) : stim::vec(p){} 72 + vertex(stim::vec3 p) : stim::vec3(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) = "<::str(); 77 + ss<<"\t(x, y, z) = "<::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 > 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 > 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 b){ 229 + void stim2ann(ANNpoint &a, stim::vec3 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 p0, p1; 282 - float m0, m1; 285 + stim::vec3 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 Y; 20 + stim::vec3 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() 49 49 { 50 50 init(); 51 - center(stim::vec(0,0,z_pos)); 51 + center(stim::vec3(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 c, vec n = vec(0,0,1)) : plane() 59 + circle(vec3 c, vec3 n = vec3(0,0,1)) : plane() 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 c, T s, vec n = vec(0,0,1)) : plane() 71 + circle(vec3 c, T s, vec3 n = vec3(0,0,1)) : plane() 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 c, T s, vec n = vec(0,0,1), vec u = vec(1, 0, 0)) : plane() 85 + circle(vec3 c, T s, vec3 n = vec3(0,0,1), vec3 u = vec3(1, 0, 0)) : plane() 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 n) 106 + normal(vec3 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 p) 115 - { 113 + CUDA_CALLABLE void 114 + center(vec3 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 p(T a, T b) 129 + CUDA_CALLABLE stim::vec3 p(T a, T b) 131 130 { 132 - stim::vec result; 131 + stim::vec3 result; 133 132 134 - vec A = this->P - this->U * (T)0.5 - Y * (T)0.5; 133 + vec3 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 operator()(T a, T b) 139 + CUDA_CALLABLE stim::vec3 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 > 147 + std::vector > 149 148 getPoints(int n) 150 149 { 151 - std::vector > result; 152 - stim::vec point; 150 + std::vector > result; 151 + stim::vec3 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 166 + stim::vec3 168 167 p(T theta) 169 168 { 170 169 T x,y; ... ...
stim/math/matrix.h

 ... ... @@ -5,6 +5,7 @@ 5 5 #include 6 6 #include 7 7 #include 8 +#include 8 9 #include 9 10 10 11 namespace stim{ ... ... @@ -54,7 +55,7 @@ struct matrix 54 55 vec operator*(vec rhs){ 55 56 unsigned int N = rhs.size(); 56 57 57 - vec result; 58 + vec3Y> result; 58 59 result.resize(N); 59 60 60 61 for(int r=0; r
stim/math/plane.h

 ... ... @@ -2,7 +2,7 @@ 2 2 #define STIM_PLANE_H 3 3 4 4 #include 5 -#include 5 +#include 6 6 #include 7 7 #include 8 8 ... ... @@ -22,17 +22,17 @@ template <typename T> 22 22 class plane 23 23 { 24 24 protected: 25 - stim::vec P; 26 - stim::vec N; 27 - stim::vec U; 25 + stim::vec3 P; 26 + stim::vec3 N; 27 + stim::vec3 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(0, 0, 0); 34 - N = stim::vec(0, 0, 1); 35 - U = stim::vec(1, 0, 0); 33 + P = stim::vec3(0, 0, 0); 34 + N = stim::vec3(0, 0, 1); 35 + U = stim::vec3(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 n, vec p = vec(0, 0, 0)) 45 + CUDA_CALLABLE plane(vec3 n, vec3 p = vec3(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 a, vec b, vec c) 59 + CUDA_CALLABLE plane(vec3 a, vec3 b, vec3 c) 60 60 { 61 61 init(); 62 62 P = c; 63 - stim::vec n = (c - a).cross(b - a); 63 + stim::vec3 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 n() 87 + CUDA_CALLABLE vec3 n() 88 88 { 89 89 return N; 90 90 } 91 91 92 - CUDA_CALLABLE vec p() 92 + CUDA_CALLABLE vec3 p() 93 93 { 94 94 return P; 95 95 } 96 96 97 - CUDA_CALLABLE vec u() 97 + CUDA_CALLABLE vec3 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 v){ 110 + CUDA_CALLABLE int face(vec3 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 p){ 124 + CUDA_CALLABLE int side(vec3 p){ 125 125 126 - vec v = p - P; //get the vector from P to the query point p 126 + vec3 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 perpendicular(vec v){ 132 + CUDA_CALLABLE vec3 perpendicular(vec3 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 parallel(vec v){ 137 + CUDA_CALLABLE vec3 parallel(vec3 v){ 138 138 return v - perpendicular(v); 139 139 } 140 140 141 - CUDA_CALLABLE void setU(vec v) 141 + CUDA_CALLABLE void setU(vec3 v) 142 142 { 143 143 U = (parallel(v.norm())).norm(); 144 144 } 145 145 146 - CUDA_CALLABLE void decompose(vec v, vec& para, vec& perp){ 146 + CUDA_CALLABLE void decompose(vec3 v, vec3& para, vec3& 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 v, vec &v_par, vec &v_perp){ 152 + CUDA_CALLABLE void project(vec3 v, vec3 &v_par, vec3 &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 reflect(vec v){ 159 + CUDA_CALLABLE vec3 reflect(vec3 v){ 160 160 161 161 //compute the reflection using N_prime as the plane normal 162 - vec par = parallel(v); 163 - vec r = (-v) + par * 2; 162 + vec3 par = parallel(v); 163 + vec3 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 n) 187 + CUDA_CALLABLE void rotate(vec3 n) 188 188 { 189 189 quaternion 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 n, vec &Y) 197 + CUDA_CALLABLE void rotate(vec3 n, vec3 &Y) 198 198 { 199 199 quaternion 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 n, vec &X, vec &Y) 208 + CUDA_CALLABLE void rotate(vec3 n, vec3 &X, vec3 &Y) 209 209 { 210 210 quaternion 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
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(){ 322 + vec3 r; 323 + size_t N = std::min(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 322 331 vec & operator=(vec 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 A; //minimum point in the bounding box 14 - stim::vec B; //maximum point in the bounding box 13 + stim::vec3 A; //minimum point in the bounding box 14 + stim::vec3 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 p){ 24 + bool test(stim::vec3 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 p){ 36 + void expand(stim::vec3 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 center(){ 50 + stim::vec3 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 size(){ 55 + stim::vec3 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 d; //direction that the camera is pointing 15 - vec p; //position of the camera 16 - vec up; //"up" direction 14 + vec3 d; //direction that the camera is pointing 15 + vec3 p; //position of the camera 16 + vec3 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 side = up.cross(d); 23 + vec3 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 pos) 30 + void setPosition(vec3 pos) 31 31 { 32 32 p = pos; 33 33 } 34 - void setPosition(float x, float y, float z){setPosition(vec(x, y, z));} 34 + void setPosition(float x, float y, float z){setPosition(vec3(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 pos) 39 + void LookAt(vec3 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(px, py, pz));} 51 - void LookAt(vec pos, vec new_up){up = new_up; LookAt(pos);} 52 - void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(vec(px, py, pz), vec(ux, uy, uz));} 50 + void LookAt(float px, float py, float pz){LookAt(vec3(px, py, pz));} 51 + void LookAt(vec3 pos, vec3 new_up){up = new_up; LookAt(pos);} 52 + void LookAt(float px, float py, float pz, float ux, float uy, float uz){LookAt(vec3(px, py, pz), vec3(ux, uy, uz));} 53 53 void LookAtDolly(float lx, float ly, float lz) 54 54 { 55 55 //find the current focus point 56 - vec f = p + focus*d; 57 - vec T = vec(lx, ly, lz) - f; 56 + vec3 f = p + focus*d; 57 + vec3 T = vec3(lx, ly, lz) - f; 58 58 p = p + T; 59 59 } 60 60 61 - void Dolly(vec direction) 61 + void Dolly(vec3 direction) 62 62 { 63 63 p = p+direction; 64 64 } 65 - void Dolly(float x, float y, float z){Dolly(vec(x, y, z));} 65 + void Dolly(float x, float y, float z){Dolly(vec3(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 side = up.cross(d); 83 + vec3 side = up.cross(d); 84 84 quaternion 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 focal_point = p + focus*d; 121 + vec3 focal_point = p + focus*d; 122 122 123 123 //center the coordinate system on the focal point 124 - vec centered = p - (focal_point - vec(0, 0, 0)); 124 + vec3 centered = p - (focal_point - vec3(0, 0, 0)); 125 125 126 126 //create the x rotation (around the up vector) 127 127 quaternion qx; 128 128 qx.CreateRotation(theta_x, up[0], up[1], up[2]); 129 - centered = vec(0, 0, 0) + qx.toMatrix3()*(centered - vec(0, 0, 0)); 129 + centered = vec3(0, 0, 0) + qx.toMatrix3()*(centered - vec3(0, 0, 0)); 130 130 131 131 //get a side vector for theta_y rotation 132 - vec side = up.cross((vec(0, 0, 0) - centered).norm()); 132 + vec3 side = up.cross((vec3(0, 0, 0) - centered).norm()); 133 133 134 134 quaternion qy; 135 135 qy.CreateRotation(theta_y, side[0], side[1], side[2]); 136 - centered = vec(0, 0, 0) + qy.toMatrix3()*(centered - vec(0, 0, 0)); 136 + centered = vec3(0, 0, 0) + qy.toMatrix3()*(centered - vec3(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(0, 0, 0)); 142 + p = centered + (focal_point - vec3(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 V = up.norm(); 155 - vec U = up.cross(d).norm(); 154 + vec3 V = up.norm(); 155 + vec3 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 getPosition(){return p;} 162 - vec getUp(){return up;} 163 - vec getDirection(){return d;} 164 - vec getLookAt(){return p + focus*d;} 161 + vec3 getPosition(){return p;} 162 + vec3 getUp(){return up;} 163 + vec3 getDirection(){return d;} 164 + vec3 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(0, 0, 0); 186 - d = vec(0, 0, 1); 187 - up = vec(0, 1, 0); 185 + p = vec3(0, 0, 0); 186 + d = vec3(0, 0, 1); 187 + up = vec3(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 4 4 #include 5 -#include 5 +#include 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 > inP, std::vector > inM) 28 + init(std::vector > inP, std::vector > inM) 29 29 { 30 30 mags = inM; 31 - stim::vec v1; 32 - stim::vec v2; 31 + stim::vec3 v1; 32 + stim::vec3 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 dr = (inP[1] - inP[0]).norm(); 48 - s = stim::circle(inP[0], inM[0][0], dr, stim::vec(1,0,0)); 47 + stim::vec3 dr = (inP[1] - inP[0]).norm(); 48 + s = stim::circle(inP[0], inM[0][0], dr, stim::vec3(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 70 + stim::vec3 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 v1 = (e[idx].P-e[idx-1].P).norm(); 85 - stim::vec v2 = (e[idx+1].P-e[idx].P).norm(); 84 + stim::vec3 v1 = (e[idx].P-e[idx-1].P).norm(); 85 + stim::vec3 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 92 + stim::vec3 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 > inP, std::vector > inM){ 147 + cylinder(std::vector > inP, std::vector > 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 > inP){ 153 + cylinder(std::vector< stim::vec3 > inP){ 154 154 std::vector< stim::vec > inM; //create an array of arbitrary magnitudes 155 155 156 156 stim::vec 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 174 + stim::vec3 175 175 p(T pvalue) 176 176 { 177 177 if(pvalue < 0.0 || pvalue > 1.0) 178 178 { 179 - return stim::vec(-1,-1,-1); 179 + return stim::vec3(-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 191 + stim::vec3 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 255 + stim::vec3 256 256 surf(T pvalue, T theta) 257 257 { 258 258 if(pvalue < 0.0 || pvalue > 1.0) 259 259 { 260 - return stim::vec(-1,-1,-1); 260 + return stim::vec3(-1,-1,-1); 261 261 } else { 262 262 T l = pvalue*L[L.size()-1]; 263 263 int idx = findIdx(l); 264 - stim::vec ps = p(l, idx); 264 + stim::vec3 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 > > 276 + std::vector > > 277 277 getPoints(int sides) 278 278 { 279 - std::vector > > points; 279 + std::vector > > 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 operator[](unsigned int i){ 296 + vec3 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 p0, p1; //allocate space for both points in a single segment 312 + //vec3 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 resample(T spacing){ 347 347 348 - std::vector< vec > result; 348 + std::vector< vec3 > result; 349 349 350 - vec p0 = e[0].P; //initialize p0 to the first point on the centerline 351 - vec p1; 350 + vec3 p0 = e[0].P; //initialize p0 to the first point on the centerline 351 + vec3 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 v = p1 - p0; //calculate the vector between these two points 358 + vec3 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++){ ... ...