5b6c317a
Pavel Govyadinov
implemented the c...
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
|
#ifndef STIM_CYLINDER_H
#define STIM_CYLINDER_H
#include <iostream>
#include <stim/math/circle.h>
#include <stim/math/vector.h>
namespace stim
{
template<typename T>
class cylinder
{
private:
stim::circle<T> s;
std::vector< stim::vec<T> > pos;
std::vector< stim::vec<T> > mags;
|
10654a1f
Pavel Govyadinov
added the necessa...
|
17
|
std::vector< T > L;
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
18
19
20
21
|
void
init()
{
|
10654a1f
Pavel Govyadinov
added the necessa...
|
22
|
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
23
24
25
|
}
void
|
10654a1f
Pavel Govyadinov
added the necessa...
|
26
|
init(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM)
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
27
28
29
|
{
pos = inP;
mags = inM;
|
10654a1f
Pavel Govyadinov
added the necessa...
|
30
|
L.resize(pos.size()-1);
|
66fe63f3
Pavel Govyadinov
fixed minor typo
|
31
|
for(int i = 0; i < L.size(); i++)
|
10654a1f
Pavel Govyadinov
added the necessa...
|
32
33
34
|
{
L[i] += (pos[i] - pos[i+1]).len();
}
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
35
36
|
}
|
10654a1f
Pavel Govyadinov
added the necessa...
|
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
|
stim::vec<T>
d(int idx)
{
return (pos[idx] - pos[idx+1]).norm();
}
T
getl(int j)
{
for(int i = 0; i < j-1; ++i)
{
L += (pos[i] -pos[i+1]).len();
}
}
int
findIdx(T l)
{
int i = pos.size()/2;
while(1)
{
if(L[i] < l)
{
i = i/2;
}
else if(L[i] < l && L[i+1] > l)
{
break;
}
else
{
i = i+i/2;
}
}
return i;
}
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
74
75
76
77
78
79
80
81
82
83
84
|
public:
cylinder()
{
}
///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder.
///The higher the number of sides, the more rectangeles compose the surface of the cylinder.
///@param inP: Vector of stim vecs composing the points of the centerline.
///@param inM: Vector of stim vecs composing the radii of the centerline.
|
10654a1f
Pavel Govyadinov
added the necessa...
|
85
|
cylinder(std::vector<stim::vec<T> > inP, std::vector<stim::vec<T> > inM)
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
86
87
88
89
|
{
init(inP, inM);
}
|
10654a1f
Pavel Govyadinov
added the necessa...
|
90
91
92
93
94
95
96
|
///Returns a position vector at the given p-value (p value ranges from 0 to 1).
stim::vec<T>
p(T pvalue)
{
T l = pvalue*L[L.size()-1];
int idx = findIdx(l);
|
66fe63f3
Pavel Govyadinov
fixed minor typo
|
97
|
return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
|
10654a1f
Pavel Govyadinov
added the necessa...
|
98
99
100
101
102
|
}
stim::vec<T>
p(T l, int idx)
{
|
66fe63f3
Pavel Govyadinov
fixed minor typo
|
103
|
return (pos[idx] + (pos[idx+1]-pos[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
|
10654a1f
Pavel Govyadinov
added the necessa...
|
104
105
106
107
108
109
110
111
|
}
///Returns a radius at the given p-value (p value ranges from 0 to 1).
T
r(T pvalue)
{
T l = pvalue*L[L.size()-1];
int idx = findIdx(l);
|
66fe63f3
Pavel Govyadinov
fixed minor typo
|
112
113
|
return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
}
|
10654a1f
Pavel Govyadinov
added the necessa...
|
114
115
116
117
|
T
r(T l, int idx)
{
|
66fe63f3
Pavel Govyadinov
fixed minor typo
|
118
119
|
return (mags[idx] + (mags[idx+1]-mags[idx])*((l-L[idx])/(L[idx+1]- L[idx])));
}
|
10654a1f
Pavel Govyadinov
added the necessa...
|
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
|
///returns the position of the point with a given pvalue and theta on the surface
///in x, y, z coordinates. Theta is in degrees from 0 to 360
stim::vec<T>
surf(T pvalue, T theta)
{
T l = pvalue*L[L.size()-1];
int idx = findIdx(l);
stim::vec<T> ps = p(l, idx);
T m = r(l, idx);
stim::vec<T> dr = d(idx);
s = stim::circle<T>(ps, m, dr);
return(s.p(theta));
}
|
5b6c317a
Pavel Govyadinov
implemented the c...
|
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
|
std::vector<std::vector<vec<T> > >
getPoints(int sides)
{
if(pos.size() < 2)
{
return;
} else {
std::vector<std::vector <vec<T> > > points;
points.resize(pos.size());
stim::vec<T> d = (pos[0] - pos[1]).norm();
s = stim::circle<T>(pos[0], mags[0][0], d);
points[0] = s.getPoints(sides);
for(int i = 1; i < pos.size(); i++)
{
d = (pos[i] - pos[i-1]).norm();
s.center(pos[i]);
s.normal(d);
s.scale(mags[i][0]/mags[i-1][0], mags[i][0]/mags[i-1][0]);
points[i] = s.getPoints(sides);
}
return points;
}
}
};
}
#endif
|