Commit 5b6c317a030d29508f72cf54cd27a08b4dfcabe7
1 parent
591f04ec
implemented the cylinder with accordance with the plane/rect/circle implementati…
…on. Fixed minor bugs in other classes
Showing
2 changed files
with
79 additions
and
4 deletions
Show diff stats
stim/math/rect.h
... | ... | @@ -33,10 +33,6 @@ private: |
33 | 33 | stim::vec<T> X; |
34 | 34 | stim::vec<T> Y; |
35 | 35 | |
36 | - CUDA_CALLABLE void scale(T factor){ | |
37 | - X *= factor; | |
38 | - Y *= factor; | |
39 | - } | |
40 | 36 | |
41 | 37 | |
42 | 38 | |
... | ... | @@ -126,6 +122,11 @@ public: |
126 | 122 | scale(size[0], size[1]); |
127 | 123 | } |
128 | 124 | |
125 | + CUDA_CALLABLE void scale(T factor){ | |
126 | + X *= factor; | |
127 | + Y *= factor; | |
128 | + } | |
129 | + | |
129 | 130 | ///scales a rectangle in ND space. |
130 | 131 | ///@param factor1: size of the scale in the X-direction. |
131 | 132 | ///@param factor2: size of the scale in the Y-direction. | ... | ... |
1 | +#ifndef STIM_CYLINDER_H | |
2 | +#define STIM_CYLINDER_H | |
3 | +#include <iostream> | |
4 | +#include <stim/math/circle.h> | |
5 | +#include <stim/math/vector.h> | |
6 | + | |
7 | + | |
8 | +namespace stim | |
9 | +{ | |
10 | +template<typename T> | |
11 | +class cylinder | |
12 | +{ | |
13 | + private: | |
14 | + stim::circle<T> s; | |
15 | + std::vector< stim::vec<T> > pos; | |
16 | + std::vector< stim::vec<T> > mags; | |
17 | + | |
18 | + void | |
19 | + init() | |
20 | + { | |
21 | + | |
22 | + } | |
23 | + | |
24 | + void | |
25 | + init(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM) | |
26 | + { | |
27 | + pos = inP; | |
28 | + mags = inM; | |
29 | + } | |
30 | + | |
31 | + | |
32 | + public: | |
33 | + cylinder() | |
34 | + { | |
35 | + | |
36 | + } | |
37 | + | |
38 | + ///constructor to create a cylinder from a set of points, radii, and the number of sides for the cylinder. | |
39 | + ///The higher the number of sides, the more rectangeles compose the surface of the cylinder. | |
40 | + ///@param inP: Vector of stim vecs composing the points of the centerline. | |
41 | + ///@param inM: Vector of stim vecs composing the radii of the centerline. | |
42 | + cylinder(std::vector<stim::vec<T> > &inP, std::vector<stim::vec<T> > &inM) | |
43 | + { | |
44 | + init(inP, inM); | |
45 | + } | |
46 | + | |
47 | + std::vector<std::vector<vec<T> > > | |
48 | + getPoints(int sides) | |
49 | + { | |
50 | + if(pos.size() < 2) | |
51 | + { | |
52 | + return; | |
53 | + } else { | |
54 | + std::vector<std::vector <vec<T> > > points; | |
55 | + points.resize(pos.size()); | |
56 | + stim::vec<T> d = (pos[0] - pos[1]).norm(); | |
57 | + s = stim::circle<T>(pos[0], mags[0][0], d); | |
58 | + points[0] = s.getPoints(sides); | |
59 | + for(int i = 1; i < pos.size(); i++) | |
60 | + { | |
61 | + d = (pos[i] - pos[i-1]).norm(); | |
62 | + s.center(pos[i]); | |
63 | + s.normal(d); | |
64 | + s.scale(mags[i][0]/mags[i-1][0], mags[i][0]/mags[i-1][0]); | |
65 | + points[i] = s.getPoints(sides); | |
66 | + } | |
67 | + return points; | |
68 | + } | |
69 | + } | |
70 | + | |
71 | +}; | |
72 | + | |
73 | +} | |
74 | +#endif | ... | ... |