diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index 483274f..fbc2607 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -71,6 +71,14 @@ class network{ } /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor + ///@param v0, the starting index. + ///@param v1, the ending index. + ///@param sz, the number of point in the fiber. + edge(unsigned int v0, unsigned int v1, unsigned int sz) : cylinder( + { + + } + ///@param p is an array of positions in space edge(stim::centerline p) : cylinder(p){} @@ -105,7 +113,48 @@ class network{ } return E; } + /// operator for writing the edge information into a binary .nwt file. + std::ofstream& operator<<(std::ofstream& out, const edge& e) + { + out.write(reinterpret_cast(&e.v[0]), sizeof(unsigned int)); ///write the starting point. + out.write(reinterpret_cast(&e.v[1]), sizeof(unsigned int)); ///write the ending point. + unsigned int sz = size(); ///write the number of point in the edge. + out.write(reinterpret_cast(&sz), sizeof(unsigned int)); + for(int i = 0; i < sz; i++) ///write each point + { + stim::vec3 point = e[i]; + out.write(reinterpret_cast(point[0]), 3*sizeof(T)); + // for(int j = 0; j < nmags(); j++) //future code for multiple mags + // { + out.write(reinterpret_cast(e[i].R[0]), sizeof(T)); ///write the radius + // } + } + return out; //return stream + } + /// operator for reading an edge from a binary .nwt file. + std::ofstream& operator>>(std::ofstream& in, edge& e) + { + unsigned int v0, v1, sz; + in.read((reinterpret_cast(&v[0]), sizeof(unsigned int)); //read the staring point. + in.read((reinterpret_cast(&v[1]), 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); + 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; + T mag; +// for(int j = 0; j < nmags(); j++) ///future code for mags +// { + in.read(reinterpret_cast(&mag), sizeof(T)); + set_r(0, mag); +// } + } + return in; + } }; ///Node class that stores the physical position of the node as well as the edges it is connected to (edges that connect to it), As well as any additional data necessary. @@ -137,6 +186,32 @@ class network{ return ss.str(); } + ///operator for writing the edge into the stream; + std::ofstream& operator<<(std::ofstream& out, const vertex& v) + { + out.write(reinterpret_cast(&v[0]), 3*sizeof(T)); + out.write(reinterpret_cast(&v.e[0].size()), sizeof(unsigned int)); + out.write(reinterpret_cast(&v.e[1].size()), sizeof(unsigned int)); + out.write(reinterpret_cast(&v.e[0][0]), sizeof(unsigned int)*v.e[0].size()); + out.write(reinterpret_cast(&v.e[1][0]), sizeof(unsigned int)*v.e[1].size()); + return out; + } + + ///operator for reading the edge out of the stream; + std::ofstream& operator<<(std::ofstream& in, vertex& v) + { + in.read(reinterpret_cast(&v[0]), 3*sizeof(T)) + unsigned int s[2]; + in.read(reinterpret_cast(&s[0]), 2*sizeof(unsigned int)); + + std::vector one(s[0]); + std::vector two(s[1]); + v.e[0] = one; + v.e[1] = two; + in.read(reinterpret_cast(&v.e[0][0]),s[0]*sizeof(unsigned int)); + in.read(reinterpret_cast(&v.e[1][0]),s[1]*sizeof(unsigned int)); + return in; + } }; protected: @@ -444,7 +519,27 @@ public: } } + ///loads a .nwt file. Reads the header and loads the data into the network according to the header. +/* void + loadNwt(std::string filename) + { + } + + ///saves a .nwt file. Writes the header in raw text format, then saves the network as a binary file. + /// + void + saveNwt(std::string filename) + { + + } + + void + writeHeader(std::string filename) + { + + } +*/ //load a network from an SWC file void load_swc(std::string filename) { stim::swc S; // create swc variable @@ -1136,4 +1231,4 @@ public: } }; //end stim::network class }; //end stim namespace -#endif \ No newline at end of file +#endif diff --git a/stim/visualization/cylinder.h b/stim/visualization/cylinder.h index 9c218cf..db8aaaa 100644 --- a/stim/visualization/cylinder.h +++ b/stim/visualization/cylinder.h @@ -46,7 +46,7 @@ public: cylinder(centerlinec) : centerline(c) { init(); } - + //cylinder(centerlinec, T r) : centerline(c) { // init(); // //add_mag(r); @@ -711,4 +711,4 @@ public: }; } -#endif \ No newline at end of file +#endif -- libgit2 0.21.4