From 49061f1d0af4ff037778f14a5b34f03ed6d1f734 Mon Sep 17 00:00:00 2001 From: Pavel Govyadinov Date: Thu, 27 Jul 2017 15:39:49 -0500 Subject: [PATCH] Modified centerline, cylinder and network to have std::vector constructors --- stim/biomodels/centerline.h | 36 +++++++++++++++++++++--------------- stim/biomodels/network.h | 19 ++++++++++++------- stim/parser/table.h | 3 ++- stim/visualization/cylinder.h | 40 +++++++++++++++++++++++++++------------- 4 files changed, 62 insertions(+), 36 deletions(-) diff --git a/stim/biomodels/centerline.h b/stim/biomodels/centerline.h index c122f5d..90ba645 100644 --- a/stim/biomodels/centerline.h +++ b/stim/biomodels/centerline.h @@ -32,6 +32,21 @@ protected: return ab.norm(); } + //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) + void update_L(size_t start = 0) { + L.resize(size()); //allocate space for the L array + if (start == 0) { + L[0] = 0; //initialize the length value for the first point to zero (0) + start++; + } + + stim::vec3 d; + for (size_t i = start; i < size(); i++) { //for each line segment in the centerline + d = at(i) - at(i - 1); + L[i] = L[i - 1] + d.len(); //calculate the running length total + } + } + void init() { if (size() == 0) return; //return if there aren't any points update_L(); @@ -93,7 +108,12 @@ public: centerline(size_t n) : std::vector< stim::vec3 >(n){ init(); } - + centerline(std::vector > pos) : + std::vector > (pos) + { + init(); + } + //overload the push_back function to update the length vector void push_back(stim::vec3 p) { std::vector< stim::vec3 >::push_back(p); @@ -121,20 +141,6 @@ public: return L.back(); } - //initializes the integrated length vector to make parameterization easier, starting with index idx (all previous indices are assumed to be correct) - void update_L(size_t start = 0) { - L.resize(size()); //allocate space for the L array - if (start == 0) { - L[0] = 0; //initialize the length value for the first point to zero (0) - start++; - } - - stim::vec3 d; - for (size_t i = start; i < size(); i++) { //for each line segment in the centerline - d = at(i) - at(i - 1); - L[i] = L[i - 1] + d.len(); //calculate the running length total - } - } /// stitch two centerlines ///@param c1, c2: two centerlines diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index 814f649..aeeead0 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -79,6 +79,10 @@ class network{ } */ + edge(std::vector p, std::vector s) + : cylinder(p,s) + { + } ///@param p is an array of positions in space edge(stim::centerline p) : cylinder(p){} @@ -141,24 +145,25 @@ class network{ in.read(reinterpret_cast(&v0), sizeof(unsigned int)); //read the staring point. in.read(reinterpret_cast(&v1), sizeof(unsigned int)); //read the ending point in.read(reinterpret_cast(&sz), sizeof(unsigned int)); //read the number of points in the edge - stim::centerline temp = stim::centerline(sz); //allocate the new edge - e = edge(temp); - e.v[0] = v0; e.v[1] = v1; +// stim::centerline temp = stim::centerline(sz); //allocate the new edge +// e = edge(temp); + std::vector > p(sz); + std::vector r(sz); for(int i = 0; i < sz; i++) //set the points and radii to the newly read values { stim::vec3 point; in.read(reinterpret_cast(&point[0]), 3*sizeof(T)); - e[i] = point; + p[i] = point; T mag; // for(int j = 0; j < nmags(); j++) ///future code for mags // { in.read(reinterpret_cast(&mag), sizeof(T)); - e.set_r(i, mag); + r[i] = mag; //std::cout << point.str() << " " << mag << std::endl; // } } - e.init(); - e.update(); + e = edge(p,r); + e.v[0] = v0; e.v[1] = v1; return in; } }; diff --git a/stim/parser/table.h b/stim/parser/table.h index 9042951..678f854 100644 --- a/stim/parser/table.h +++ b/stim/parser/table.h @@ -1,6 +1,7 @@ #ifndef STIM_CSV_H #define STIM_CSV_H +#include #include #include #include @@ -105,4 +106,4 @@ namespace stim{ }; -#endif \ No newline at end of file +#endif diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index 7def9d2..5945611 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -18,6 +18,20 @@ protected: std::vector< T > R; //stores a list of magnitudes for each point in the centerline (assuming mags[0] is the radius) using stim::centerline::findIdx; + + void init() { + U.resize(size()); //allocate space for the frenet frame vectors +// if (R.size() != 0) + R.resize(size()); + + stim::circle c; //create a circle + stim::vec3 d0, d1; + for (size_t i = 0; i < size() - 1; i++) { //for each line segment in the centerline + c.rotate(d(i)); //rotate the circle to match that normal + U[i] = c.U; //save the U vector from the circle + } + U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector + } //calculates the U values for each point to initialize the frenet frame // this function assumes that the centerline has already been set @@ -34,6 +48,19 @@ public: cylinder(centerlinec) : centerline(c) { init(); } + + cylinder(std::vector > p, std::vector s) + : centerline(p) + { + R = s; + init(); + { + + cylinder(stim::centerline p, std::vector s) + { + d = s; + init(); + { //cylinder(centerlinec, T r) : centerline(c) { // init(); @@ -82,19 +109,6 @@ public: return R[i]; } - void init() { - U.resize(size()); //allocate space for the frenet frame vectors -// if (R.size() != 0) - R.resize(size()); - - stim::circle c; //create a circle - stim::vec3 d0, d1; - for (size_t i = 0; i < size() - 1; i++) { //for each line segment in the centerline - c.rotate(d(i)); //rotate the circle to match that normal - U[i] = c.U; //save the U vector from the circle - } - U[size() - 1] = c.U; //for the last point, duplicate the final frenet frame vector - } ///adds a magnitude to each point in the cylinder /*void add_mag(V val = 0) { -- libgit2 0.21.4