From 66d1c0ff25344b0baaf4ad4a5a41bdc8b40c9c07 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 15 Jun 2017 18:51:42 -0500 Subject: [PATCH] fixed some cuda compilation errors regarding operator<< & operator>> for edge and vertex classes. --- stim/biomodels/network.h | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------------------------------- 1 file changed, 56 insertions(+), 33 deletions(-) diff --git a/stim/biomodels/network.h b/stim/biomodels/network.h index fbc2607..98a4f77 100644 --- a/stim/biomodels/network.h +++ b/stim/biomodels/network.h @@ -12,10 +12,9 @@ #include #include #include -#include #include #include - +#include //********************help function******************** // gaussian_function CUDA_CALLABLE float gaussianFunction(float x, float std = 25) { return exp(-x / (2 * std*std)); } // std default sigma value is 25 @@ -64,13 +63,13 @@ class network{ class edge : public cylinder { public: - unsigned v[2]; //unique id's designating the starting and ending + unsigned int v[2]; //unique id's designating the starting and ending // default constructor edge() : cylinder() { v[1] = (unsigned)(-1); v[0] = (unsigned)(-1); } /// 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. @@ -78,7 +77,7 @@ class network{ { } - +*/ ///@param p is an array of positions in space edge(stim::centerline p) : cylinder(p){} @@ -114,11 +113,11 @@ class network{ return E; } /// operator for writing the edge information into a binary .nwt file. - std::ofstream& operator<<(std::ofstream& out, const edge& e) + friend 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. + unsigned int sz = e.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 { @@ -133,25 +132,26 @@ class network{ } /// operator for reading an edge from a binary .nwt file. - std::ofstream& operator>>(std::ofstream& in, edge& e) + friend std::ifstream& operator>>(std::ifstream& 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 +// unsigned int v0, v1, sz; + unsigned int sz; + in.read(reinterpret_cast(&e.v[0]), sizeof(unsigned int)); //read the staring point. + in.read(reinterpret_cast(&e.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)); + 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)); + // for(int j = 0; j < nmags(); j++) ///future code for mags + // { + in.read(reinterpret_cast(&mag), sizeof(T)); set_r(0, mag); -// } + // } } return in; } @@ -169,7 +169,8 @@ class network{ vertex(stim::vec3 p) : stim::vec3(p){} /// Output the vertex information as a string - std::string str(){ + std::string + str(){ std::stringstream ss; ss<<"\t(x, y, z) = "<::str(); @@ -187,31 +188,35 @@ class network{ return ss.str(); } ///operator for writing the edge into the stream; - std::ofstream& operator<<(std::ofstream& out, const vertex& v) + friend std::ofstream& operator<<(std::ofstream& out, const vertex& v) { + unsigned int s0, s1; + s0 = v.e[0].size(); + s1 = v.e[1].size(); 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(&s0), sizeof(unsigned int)); + out.write(reinterpret_cast(&s1), 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) + friend std::ifstream& operator>>(std::ifstream& in, vertex& v) { - in.read(reinterpret_cast(&v[0]), 3*sizeof(T)) + in.read(reinterpret_cast(&v[0]), 3*sizeof(T)); unsigned int s[2]; - in.read(reinterpret_cast(&s[0]), 2*sizeof(unsigned int)); + 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)); + 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: @@ -519,27 +524,45 @@ public: } } + ///loads a .nwt file. Reads the header and loads the data into the network according to the header. -/* void + 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) { - + std::ofstream file; + file.open(filename, std::ios::out | std::ios::binary); + for(int i = 0; i < V.size(); i++) + { + file << V[i]; + } + for(int i = 0; i < E.size(); i++) + { + file << E[i]; + } } + + ///Writes the header information to a .nwt file. void writeHeader(std::string filename) { } -*/ + + ///Reads the header information from a .nwt file. + void + readHeader(std::string filename, unsigned int &dims) + { + + } + //load a network from an SWC file void load_swc(std::string filename) { stim::swc S; // create swc variable @@ -819,7 +842,7 @@ public: T* query = new T[3 * n]; T* m1 = new T[n]; T* dists = new T[n]; - size* nnIdx = new size_t[n]; + size_t* nnIdx = new size_t[n]; edge2array(query, R.E[e]); @@ -1097,7 +1120,7 @@ public: stim::vec3 p0, p1; T* queryPt = new T[3]; - for(unsigned e = 0; e < R.E.size(); e++){ // for each edge in A + for(unsigned int e = 0; e < R.E.size(); e++){ // for each edge in A T M; // the sum of metrics of current edge for(unsigned p = 0; p < R.E[e].size(); p++) M += A.E[e].r(p); -- libgit2 0.21.4