From 58ee2b2161d82073123935023a6026ec7e79e7f3 Mon Sep 17 00:00:00 2001 From: David Date: Fri, 5 Feb 2016 17:23:22 -0600 Subject: [PATCH] incorporated stim::cylinder into stim::network, replacing stim::fiber --- stim/biomodels/network.h | 22 ++++++++++------------ stim/visualization/cylinder.h | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 76 insertions(+), 12 deletions(-) diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index eada0c4..898c56b 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -10,7 +10,7 @@ #include #include #include -#include +#include #include #include @@ -28,23 +28,23 @@ class network{ ///Each edge is a fiber with two nodes. ///Each node is an in index to the endpoint of the fiber in the nodes array. - class edge : public fiber + class edge : public cylinder { public: unsigned v[2]; //unique id's designating the starting and ending // default constructor - edge() : fiber(){v[1] = -1; v[0] = -1;} + edge() : cylinder(){v[1] = -1; v[0] = -1;} /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor ///@param p is an array of positions in space - edge(std::vector< stim::vec > p) : fiber(p){} + edge(std::vector< stim::vec > p) : cylinder(p){} /// Copy constructor creates an edge from a fiber - edge(stim::fiber f) : fiber(f) {} + edge(stim::cylinder f) : cylinder(f) {} /// Resamples an edge by calling the fiber resampling function edge resample(T spacing){ - edge e(fiber::resample(spacing)); //call the fiber->edge constructor + edge e(cylinder::resample(spacing)); //call the fiber->edge constructor e.v[0] = v[0]; //copy the vertex data e.v[1] = v[1]; @@ -54,7 +54,7 @@ class network{ /// Output the edge information as a string std::string str(){ std::stringstream ss; - ss<<"("<::N<<")\tl = "<::size()<<")\tl = "< get_fiber(unsigned f){ + stim::cylinder get_cylinder(unsigned f){ return E[f]; //return the specified edge (casting it to a fiber) } @@ -130,6 +130,7 @@ class network{ O.getLine(l, c); //get the fiber centerline edge new_edge = c; //create an edge from the given centerline + unsigned int I = new_edge.size(); //calculate the number of points on the centerline //get the first and last vertex IDs for the line std::vector< unsigned > id; //create an array to store the centerline point IDs @@ -158,7 +159,7 @@ class network{ it = find(id2vert.begin(), id2vert.end(), i[1]); //look for the second ID it_idx = std::distance(id2vert.begin(), it); if(it == id2vert.end()){ //if i[1] hasn't already been used - vertex new_vertex = new_edge.back(); //create a new vertex, assign it a position + vertex new_vertex = new_edge[I-1]; //create a new vertex, assign it a position new_vertex.e[1].push_back(E.size()); //add the current edge as incoming new_edge.v[1] = V.size(); V.push_back(new_vertex); //add the new vertex to the vertex list @@ -193,7 +194,6 @@ class network{ /// This function resamples all fibers in a network given a desired minimum spacing stim::network resample(T spacing){ - std::cout<<"network::resample()"< n; //create a new network that will be an exact copy, with resampled fibers n.V = V; //copy all vertices @@ -201,9 +201,7 @@ class network{ //copy all fibers, resampling them in the process for(unsigned e = 0; e < edges(); e++){ //for each edge in the edge list - std::cout<<"edge: "< > inP){ + std::vector< stim::vec > inM; //create an array of arbitrary magnitudes + inM.resize(inP.size(), 0); //initialize the magnitude values to zero + init(inP, inM); + } + + + ///Returns the number of points on the cylinder centerline + + unsigned int size(){ + return pos.size(); + } + ///Returns a position vector at the given p-value (p value ranges from 0 to 1). ///interpolates the position along the line. @@ -189,6 +206,55 @@ class cylinder return points; } } + + /// Allows a point on the centerline to be accessed using bracket notation + + vec operator[](unsigned int i){ + + return pos[i]; + + } + + /// Returns the total length of the cylinder centerline + T length(){ + return L.back(); + } + + /// Resamples the cylinder to provide a maximum distance of "spacing" between centerline points. All current + /// centerline points are guaranteed to exist in the new cylinder + /// @param spacing is the maximum spacing allowed between sample points + cylinder resample(T spacing){ + + std::vector< vec > result; + + vec p0 = pos[0]; //initialize p0 to the first point on the centerline + vec p1; + unsigned N = size(); //number of points in the current centerline + + //for each line segment on the centerline + for(unsigned int i = 1; i < N; i++){ + p1 = pos[i]; //get the second point in the line segment + + vec v = p1 - p0; //calculate the vector between these two points + T d = v.len(); //calculate the distance between these two points (length of the line segment) + + unsigned nsteps = d / spacing; //calculate the number of steps to take along the segment to meet the spacing criteria + T stepsize = 1.0 / nsteps; //calculate the parametric step size between new centerline points + + //for each step along the line segment + for(unsigned s = 0; s < nsteps; s++){ + T alpha = stepsize * s; //calculate the fraction of the distance along the line segment covered + result.push_back(p0 + alpha * v); //push the point at alpha position along the line segment + } + + p0 = p1; //shift the points to move to the next line segment + } + + result.push_back(pos[size() - 1]); //push the last point in the centerline + + return cylinder(result); + + } }; -- libgit2 0.21.4