From 5b6c317a030d29508f72cf54cd27a08b4dfcabe7 Mon Sep 17 00:00:00 2001 From: pgovyadi Date: Sun, 31 Jan 2016 19:12:33 -0600 Subject: [PATCH] implemented the cylinder with accordance with the plane/rect/circle implementation. Fixed minor bugs in other classes --- stim/math/rect.h | 9 +++++---- stim/visualization/cylinder.h | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+), 4 deletions(-) create mode 100644 stim/visualization/cylinder.h diff --git a/stim/math/rect.h b/stim/math/rect.h index ee49845..969f88b 100644 --- a/stim/math/rect.h +++ b/stim/math/rect.h @@ -33,10 +33,6 @@ private: stim::vec X; stim::vec Y; - CUDA_CALLABLE void scale(T factor){ - X *= factor; - Y *= factor; - } @@ -126,6 +122,11 @@ public: scale(size[0], size[1]); } + CUDA_CALLABLE void scale(T factor){ + X *= factor; + Y *= factor; + } + ///scales a rectangle in ND space. ///@param factor1: size of the scale in the X-direction. ///@param factor2: size of the scale in the Y-direction. diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h new file mode 100644 index 0000000..50cc1d1 --- /dev/null +++ b/stim/visualization/cylinder.h @@ -0,0 +1,74 @@ +#ifndef STIM_CYLINDER_H +#define STIM_CYLINDER_H +#include +#include +#include + + +namespace stim +{ +template +class cylinder +{ + private: + stim::circle s; + std::vector< stim::vec > pos; + std::vector< stim::vec > mags; + + void + init() + { + + } + + void + init(std::vector > &inP, std::vector > &inM) + { + pos = inP; + mags = inM; + } + + + 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. + cylinder(std::vector > &inP, std::vector > &inM) + { + init(inP, inM); + } + + std::vector > > + getPoints(int sides) + { + if(pos.size() < 2) + { + return; + } else { + std::vector > > points; + points.resize(pos.size()); + stim::vec d = (pos[0] - pos[1]).norm(); + s = stim::circle(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 -- libgit2 0.21.4