Commit 66d1c0ff25344b0baaf4ad4a5a41bdc8b40c9c07

Authored by Pavel Govyadinov
1 parent 3b14b0f5

fixed some cuda compilation errors regarding operator<< & operator>> for edge and vertex classes.

Showing 1 changed file with 56 additions and 33 deletions   Show diff stats
stim/biomodels/network.h
... ... @@ -12,10 +12,9 @@
12 12 #include <stim/visualization/obj.h>
13 13 #include <stim/visualization/swc.h>
14 14 #include <stim/visualization/cylinder.h>
15   -#include <stim/structures/kdtree.cuh>
16 15 #include <stim/cuda/cudatools/timer.h>
17 16 #include <stim/cuda/cudatools/callable.h>
18   -
  17 +#include <stim/structures/kdtree.cuh>
19 18 //********************help function********************
20 19 // gaussian_function
21 20 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{
64 63 class edge : public cylinder<T>
65 64 {
66 65 public:
67   - unsigned v[2]; //unique id's designating the starting and ending
  66 + unsigned int v[2]; //unique id's designating the starting and ending
68 67 // default constructor
69 68 edge() : cylinder<T>() {
70 69 v[1] = (unsigned)(-1); v[0] = (unsigned)(-1);
71 70 }
72 71 /// Constructor - creates an edge from a list of points by calling the stim::fiber constructor
73   -
  72 +/*
74 73 ///@param v0, the starting index.
75 74 ///@param v1, the ending index.
76 75 ///@param sz, the number of point in the fiber.
... ... @@ -78,7 +77,7 @@ class network{
78 77 {
79 78  
80 79 }
81   -
  80 +*/
82 81 ///@param p is an array of positions in space
83 82 edge(stim::centerline<T> p) : cylinder<T>(p){}
84 83  
... ... @@ -114,11 +113,11 @@ class network{
114 113 return E;
115 114 }
116 115 /// operator for writing the edge information into a binary .nwt file.
117   - std::ofstream& operator<<(std::ofstream& out, const edge<T>& e)
  116 + friend std::ofstream& operator<<(std::ofstream& out, const edge& e)
118 117 {
119 118 out.write(reinterpret_cast<const char*>(&e.v[0]), sizeof(unsigned int)); ///write the starting point.
120 119 out.write(reinterpret_cast<const char*>(&e.v[1]), sizeof(unsigned int)); ///write the ending point.
121   - unsigned int sz = size(); ///write the number of point in the edge.
  120 + unsigned int sz = e.size(); ///write the number of point in the edge.
122 121 out.write(reinterpret_cast<const char*>(&sz), sizeof(unsigned int));
123 122 for(int i = 0; i < sz; i++) ///write each point
124 123 {
... ... @@ -133,25 +132,26 @@ class network{
133 132 }
134 133  
135 134 /// operator for reading an edge from a binary .nwt file.
136   - std::ofstream& operator>>(std::ofstream& in, edge<T>& e)
  135 + friend std::ifstream& operator>>(std::ifstream& in, edge& e)
137 136 {
138   - unsigned int v0, v1, sz;
139   - in.read((reinterpret_cast<const char*>(&v[0]), sizeof(unsigned int)); //read the staring point.
140   - in.read((reinterpret_cast<const char*>(&v[1]), sizeof(unsigned int)); //read the ending point
141   - in.read((reinterpret_cast<const char*>(&sz), sizeof(unsigned int)); //read the number of points in the edge
142   - stim::centerline temp = stim::centerline(sz) //allocate the new edge
  137 +// unsigned int v0, v1, sz;
  138 + unsigned int sz;
  139 + in.read(reinterpret_cast<char*>(&e.v[0]), sizeof(unsigned int)); //read the staring point.
  140 + in.read(reinterpret_cast<char*>(&e.v[1]), sizeof(unsigned int)); //read the ending point
  141 + in.read(reinterpret_cast<char*>(&sz), sizeof(unsigned int)); //read the number of points in the edge
  142 + stim::centerline<T> temp = stim::centerline<T>(sz); //allocate the new edge
143 143 e = edge(temp);
144 144 for(int i = 0; i < sz; i++) //set the points and radii to the newly read values
145 145 {
146 146 stim::vec3<T> point;
147   - in.read((reinterpret_cast<const char*>(&point[0]) 3*sizeof(T));
  147 + in.read(reinterpret_cast<char*>(&point[0]), 3*sizeof(T));
148 148 e[i] = point;
149 149 T mag;
150   -// for(int j = 0; j < nmags(); j++) ///future code for mags
151   -// {
152   - in.read(reinterpret_cast<const char*>(&mag), sizeof(T));
  150 + // for(int j = 0; j < nmags(); j++) ///future code for mags
  151 + // {
  152 + in.read(reinterpret_cast<char*>(&mag), sizeof(T));
153 153 set_r(0, mag);
154   -// }
  154 + // }
155 155 }
156 156 return in;
157 157 }
... ... @@ -169,7 +169,8 @@ class network{
169 169 vertex(stim::vec3<T> p) : stim::vec3<T>(p){}
170 170  
171 171 /// Output the vertex information as a string
172   - std::string str(){
  172 + std::string
  173 + str(){
173 174 std::stringstream ss;
174 175 ss<<"\t(x, y, z) = "<<stim::vec3<T>::str();
175 176  
... ... @@ -187,31 +188,35 @@ class network{
187 188 return ss.str();
188 189 }
189 190 ///operator for writing the edge into the stream;
190   - std::ofstream& operator<<(std::ofstream& out, const vertex& v)
  191 + friend std::ofstream& operator<<(std::ofstream& out, const vertex& v)
191 192 {
  193 + unsigned int s0, s1;
  194 + s0 = v.e[0].size();
  195 + s1 = v.e[1].size();
192 196 out.write(reinterpret_cast<const char*>(&v[0]), 3*sizeof(T));
193   - out.write(reinterpret_cast<const char*>(&v.e[0].size()), sizeof(unsigned int));
194   - out.write(reinterpret_cast<const char*>(&v.e[1].size()), sizeof(unsigned int));
  197 + out.write(reinterpret_cast<const char*>(&s0), sizeof(unsigned int));
  198 + out.write(reinterpret_cast<const char*>(&s1), sizeof(unsigned int));
195 199 out.write(reinterpret_cast<const char*>(&v.e[0][0]), sizeof(unsigned int)*v.e[0].size());
196 200 out.write(reinterpret_cast<const char*>(&v.e[1][0]), sizeof(unsigned int)*v.e[1].size());
197 201 return out;
198 202 }
199 203  
200 204 ///operator for reading the edge out of the stream;
201   - std::ofstream& operator<<(std::ofstream& in, vertex& v)
  205 + friend std::ifstream& operator>>(std::ifstream& in, vertex& v)
202 206 {
203   - in.read(reinterpret_cast<const char*>(&v[0]), 3*sizeof(T))
  207 + in.read(reinterpret_cast<char*>(&v[0]), 3*sizeof(T));
204 208 unsigned int s[2];
205   - in.read(reinterpret_cast<const char*>(&s[0]), 2*sizeof(unsigned int));
  209 + in.read(reinterpret_cast<char*>(&s[0]), 2*sizeof(unsigned int));
206 210  
207 211 std::vector<unsigned int> one(s[0]);
208 212 std::vector<unsigned int> two(s[1]);
209 213 v.e[0] = one;
210 214 v.e[1] = two;
211   - in.read(reinterpret_cast<const char*>(&v.e[0][0]),s[0]*sizeof(unsigned int));
212   - in.read(reinterpret_cast<const char*>(&v.e[1][0]),s[1]*sizeof(unsigned int));
  215 + in.read(reinterpret_cast<char*>(&v.e[0][0]),s[0]*sizeof(unsigned int));
  216 + in.read(reinterpret_cast<char*>(&v.e[1][0]),s[1]*sizeof(unsigned int));
213 217 return in;
214 218 }
  219 +
215 220 };
216 221  
217 222 protected:
... ... @@ -519,27 +524,45 @@ public:
519 524  
520 525 }
521 526 }
  527 +
522 528 ///loads a .nwt file. Reads the header and loads the data into the network according to the header.
523   -/* void
  529 + void
524 530 loadNwt(std::string filename)
525 531 {
526 532  
527 533 }
528 534  
529 535 ///saves a .nwt file. Writes the header in raw text format, then saves the network as a binary file.
530   - ///
531 536 void
532 537 saveNwt(std::string filename)
533 538 {
534   -
  539 + std::ofstream file;
  540 + file.open(filename, std::ios::out | std::ios::binary);
  541 + for(int i = 0; i < V.size(); i++)
  542 + {
  543 + file << V[i];
  544 + }
  545 + for(int i = 0; i < E.size(); i++)
  546 + {
  547 + file << E[i];
  548 + }
535 549 }
536 550  
  551 +
  552 + ///Writes the header information to a .nwt file.
537 553 void
538 554 writeHeader(std::string filename)
539 555 {
540 556  
541 557 }
542   -*/
  558 +
  559 + ///Reads the header information from a .nwt file.
  560 + void
  561 + readHeader(std::string filename, unsigned int &dims)
  562 + {
  563 +
  564 + }
  565 +
543 566 //load a network from an SWC file
544 567 void load_swc(std::string filename) {
545 568 stim::swc<T> S; // create swc variable
... ... @@ -819,7 +842,7 @@ public:
819 842 T* query = new T[3 * n];
820 843 T* m1 = new T[n];
821 844 T* dists = new T[n];
822   - size* nnIdx = new size_t[n];
  845 + size_t* nnIdx = new size_t[n];
823 846  
824 847 edge2array(query, R.E[e]);
825 848  
... ... @@ -1097,7 +1120,7 @@ public:
1097 1120 stim::vec3<T> p0, p1;
1098 1121 T* queryPt = new T[3];
1099 1122  
1100   - for(unsigned e = 0; e < R.E.size(); e++){ // for each edge in A
  1123 + for(unsigned int e = 0; e < R.E.size(); e++){ // for each edge in A
1101 1124 T M; // the sum of metrics of current edge
1102 1125 for(unsigned p = 0; p < R.E[e].size(); p++)
1103 1126 M += A.E[e].r(p);
... ...