Commit a42c92ae8348d20f4389f4b848a41b385af82d0e

Authored by David Mayerich
2 parents 88088186 e24ed5a6

Merge branch 'glnetwork'

Showing 2 changed files with 161 additions and 6 deletions   Show diff stats
stim/math/circle.h 0 → 100644
  1 +#ifndef STIM_CIRCLE_H
  2 +#define STIM_CIRCLE_H
  3 +
  4 +//enable CUDA_CALLABLE macro
  5 +#include <stim/cuda/cudatools/callable.h>
  6 +#include <stim/math/vector.h>
  7 +#include <stim/math/triangle.h>
  8 +#include <stim/math/quaternion.h>
  9 +#include <stim/math/rect.h>
  10 +#include <iostream>
  11 +#include <iomanip>
  12 +#include <algorithm>
  13 +
  14 +namespace stim
  15 +{
  16 +
  17 +template <class T>
  18 +struct circle : rect<T>
  19 +{
  20 + private:
  21 + T theta;
  22 +
  23 + public:
  24 +
  25 + using stim::rect<T>::p;
  26 + using stim::rect<T>::normal;
  27 + using stim::rect<T>::center;
  28 + using stim::rect<T>::scale;
  29 + ///base constructor
  30 + ///@param th value of the angle of the starting point from 0 to 360.
  31 + CUDA_CALLABLE circle(float th = 0.0) : rect<T>()
  32 + {
  33 + theta = th;
  34 + }
  35 +
  36 + ///create a rectangle given a size and position in Z space.
  37 + ///@param size: size of the rectangle in ND space.
  38 + ///@param z_pos z coordinate of the rectangle.
  39 + ///@param th value of the angle of the starting point from 0 to 360.
  40 + CUDA_CALLABLE circle(T size, T zpos = (T)0, float th = 0.0) : rect<T>(size, zpos)
  41 + {
  42 + theta = th;
  43 + }
  44 +
  45 + ///create a rectangle from a center point, normal
  46 + ///@param c: x,y,z location of the center.
  47 + ///@param n: x,y,z direction of the normal.
  48 + ///@param th value of the angle of the starting point from 0 to 360.
  49 + CUDA_CALLABLE circle(vec<T> c, vec<T> n = vec<T>(0,0,1), float th = 0.0) : rect<T>(c, n)
  50 + {
  51 + theta = th;
  52 + }
  53 +
  54 + ///create a rectangle from a center point, normal, and size
  55 + ///@param c: x,y,z location of the center.
  56 + ///@param s: size of the rectangle.
  57 + ///@param n: x,y,z direction of the normal.
  58 + ///@param th value of the angle of the starting point from 0 to 360.
  59 + CUDA_CALLABLE circle(vec<T> c, T s, vec<T> n = vec<T>(0,0,1), float th = 0.0):rect<T>(c,s,n)
  60 + {
  61 + theta = th;
  62 + }
  63 +
  64 + ///creates a rectangle from a centerpoint and an X and Y direction vectors.
  65 + ///@param center: x,y,z location of the center.
  66 + ///@param directionX: u,v,w direction of the X vector.
  67 + ///@param directionY: u,v,w direction of the Y vector.
  68 + ///@param th value of the angle of the starting point from 0 to 360.
  69 + CUDA_CALLABLE circle(vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(center, directionX, directionY)
  70 + {
  71 + theta = th;
  72 + }
  73 +
  74 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  75 + ///@param size of the rectangle in ND space.
  76 + ///@param center: x,y,z location of the center.
  77 + ///@param directionX: u,v,w direction of the X vector.
  78 + ///@param directionY: u,v,w direction of the Y vector.
  79 + ///@param th value of the angle of the starting point from 0 to 360.
  80 + CUDA_CALLABLE circle(T size, vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(size, center, directionX, directionY)
  81 + {
  82 + theta = th;
  83 + }
  84 +
  85 + ///creates a rectangle from a size, centerpoint, X, and Y direction vectors.
  86 + ///@param size of the rectangle in ND space, size[0] = size in X, size[1] = size in Y.
  87 + ///@param center: x,y,z location of the center.
  88 + ///@param directionX: u,v,w direction of the X vector.
  89 + ///@param directionY: u,v,w direction of the Y vector.
  90 + ///@param th value of the angle of the starting point from 0 to 360.
  91 + CUDA_CALLABLE circle(vec<T> size, vec<T> center, vec<T> directionX, vec<T> directionY, float th = 0.0) : rect<T>(size, center, directionX, directionY)
  92 + {
  93 + theta = th;
  94 + }
  95 +
  96 + ///returns a vector with the points on the initialized circle.
  97 + ///connecting the points results in a circle.
  98 + ///@param n: integer for the number of points representing the circle.
  99 + std::vector<stim::vec<T> >
  100 + getPoints(int n)
  101 + {
  102 + std::vector<stim::vec<T> > result;
  103 + stim::vec<T> point;
  104 + T x,y;
  105 + float step = 360.0/(float) n;
  106 + for(float j = theta; j <= theta+360.0; j += step)
  107 + {
  108 + y = 0.5*cos(j*2.0*M_PI/360.0)+0.5;
  109 + x = 0.5*sin(j*2.0*M_PI/360.0)+0.5;
  110 + result.push_back(p(x,y));
  111 + }
  112 +
  113 + return result;
  114 + }
  115 +
  116 + ///returns a vector with the points on the initialized circle.
  117 + ///connecting the points results in a circle.
  118 + ///@param n: integer for the number of points representing the circle.
  119 + stim::vec<T>
  120 + p(T theta)
  121 + {
  122 + T x,y;
  123 + y = 0.5*cos(theta*2.0*M_PI/360.0)+0.5;
  124 + x = 0.5*sin(theta*2.0*M_PI/360.0)+0.5;
  125 + return p(x,y);
  126 + }
  127 +};
  128 +
  129 +}
  130 +
  131 +#endif
... ...
stim/visualization/cylinder.h
... ... @@ -11,22 +11,26 @@ template&lt;typename T&gt;
11 11 class cylinder
12 12 {
13 13 private:
14   - stim::circle<T> s;
15   - std::vector< stim::vec<T> > pos;
16   - std::vector< stim::vec<T> > mags;
17   - std::vector< T > L;
  14 + stim::circle<T> s; //an arbitrary circle
  15 + std::vector< stim::vec<T> > pos; //positions of the cylinder.
  16 + std::vector< stim::vec<T> > mags; //radii at each position
  17 + std::vector< T > L; //length of the cylinder at each position.
18 18  
  19 + ///default init
19 20 void
20 21 init()
21 22 {
22 23  
23 24 }
24 25  
  26 + ///inits the cylinder from a list of points (inP) and radii (inM)
25 27 void
26 28 init(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM)
27 29 {
28 30 pos = inP;
29 31 mags = inM;
  32 +
  33 + //calculate each L.
30 34 L.resize(pos.size()-1);
31 35 T temp = (T)0;
32 36 for(int i = 0; i < L.size()-1; i++)
... ... @@ -36,6 +40,7 @@ class cylinder
36 40 }
37 41 }
38 42  
  43 + ///returns the direction vector at point idx.
39 44 stim::vec<T>
40 45 d(int idx)
41 46 {
... ... @@ -43,6 +48,7 @@ class cylinder
43 48  
44 49 }
45 50  
  51 + ///returns the total length of the line at index j.
46 52 T
47 53 getl(int j)
48 54 {
... ... @@ -53,6 +59,8 @@ class cylinder
53 59 }
54 60 }
55 61  
  62 + ///finds the index of the point closest to the length l on the lower bound.
  63 + ///binary search.
56 64 int
57 65 findIdx(T l)
58 66 {
... ... @@ -76,13 +84,13 @@ class cylinder
76 84 }
77 85  
78 86 public:
  87 + ///default constructor
79 88 cylinder()
80 89 {
81 90  
82 91 }
83 92  
84 93 ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder.
85   - ///The higher the number of sides, the more rectangeles compose the surface of the cylinder.
86 94 ///@param inP: Vector of stim vecs composing the points of the centerline.
87 95 ///@param inM: Vector of stim vecs composing the radii of the centerline.
88 96 cylinder(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM)
... ... @@ -92,6 +100,8 @@ class cylinder
92 100  
93 101  
94 102 ///Returns a position vector at the given p-value (p value ranges from 0 to 1).
  103 + ///interpolates the position along the line.
  104 + ///@param pvalue: the location of the in the cylinder, from 0 (beginning to 1).
95 105 stim::vec<T>
96 106 p(T pvalue)
97 107 {
... ... @@ -102,6 +112,10 @@ class cylinder
102 112 return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
103 113 }
104 114  
  115 + ///Returns a position vector at the given length into the fiber (based on the pvalue).
  116 + ///Interpolates the radius along the line.
  117 + ///@param l: the location of the in the cylinder.
  118 + ///@param idx: integer location of the point closest to l but prior to it.
105 119 stim::vec<T>
106 120 p(T l, int idx)
107 121 {
... ... @@ -109,6 +123,8 @@ class cylinder
109 123 }
110 124  
111 125 ///Returns a radius at the given p-value (p value ranges from 0 to 1).
  126 + ///interpolates the radius along the line.
  127 + ///@param pvalue: the location of the in the cylinder, from 0 (beginning to 1).
112 128 T
113 129 r(T pvalue)
114 130 {
... ... @@ -119,6 +135,10 @@ class cylinder
119 135 return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
120 136 }
121 137  
  138 + ///Returns a radius at the given length into the fiber (based on the pvalue).
  139 + ///Interpolates the position along the line.
  140 + ///@param l: the location of the in the cylinder.
  141 + ///@param idx: integer location of the point closest to l but prior to it.
122 142 T
123 143 r(T l, int idx)
124 144 {
... ... @@ -127,7 +147,9 @@ class cylinder
127 147  
128 148  
129 149 ///returns the position of the point with a given pvalue and theta on the surface
130   - ///in x, y, z coordinates. Theta is in degrees from 0 to 360
  150 + ///in x, y, z coordinates. Theta is in degrees from 0 to 360.
  151 + ///@param pvalue: the location of the in the cylinder, from 0 (beginning to 1).
  152 + ///@param theta: the angle to the point of a circle.
131 153 stim::vec<T>
132 154 surf(T pvalue, T theta)
133 155 {
... ... @@ -142,6 +164,8 @@ class cylinder
142 164 return(s.p(theta));
143 165 }
144 166  
  167 + ///returns a vector of points necessary to create a circle at every position in the fiber.
  168 + ///@param sides: the number of sides of each circle.
145 169 std::vector<std::vector<vec<T> > >
146 170 getPoints(int sides)
147 171 {
... ...