Commit 5bccf89d07af8ec102d3e351ccb7455841b1c1ad

Authored by David Mayerich
1 parent 2f365fd5

fixed some errors with loading networks as OBJ files

stim/biomodels/fiber.h
@@ -430,7 +430,7 @@ public: @@ -430,7 +430,7 @@ public:
430 ////resample a fiber in the network 430 ////resample a fiber in the network
431 stim::fiber<T> resample(T spacing) 431 stim::fiber<T> resample(T spacing)
432 { 432 {
433 - 433 + std::cout<<"fiber::resample()"<<std::endl;
434 434
435 std::vector<T> v(3); //v-direction vector of the segment 435 std::vector<T> v(3); //v-direction vector of the segment
436 stim::vec<T> p(3); //- intermediate point to be added 436 stim::vec<T> p(3); //- intermediate point to be added
stim/biomodels/network.h
@@ -193,6 +193,7 @@ class network{ @@ -193,6 +193,7 @@ class network{
193 193
194 /// This function resamples all fibers in a network given a desired minimum spacing 194 /// This function resamples all fibers in a network given a desired minimum spacing
195 stim::network<T> resample(T spacing){ 195 stim::network<T> resample(T spacing){
  196 + std::cout<<"network::resample()"<<std::endl;
196 stim::network<T> n; //create a new network that will be an exact copy, with resampled fibers 197 stim::network<T> n; //create a new network that will be an exact copy, with resampled fibers
197 n.V = V; //copy all vertices 198 n.V = V; //copy all vertices
198 199
@@ -200,7 +201,9 @@ class network{ @@ -200,7 +201,9 @@ class network{
200 201
201 //copy all fibers, resampling them in the process 202 //copy all fibers, resampling them in the process
202 for(unsigned e = 0; e < edges(); e++){ //for each edge in the edge list 203 for(unsigned e = 0; e < edges(); e++){ //for each edge in the edge list
  204 + std::cout<<"edge: "<<e<<std::endl;
203 n.E[e] = E[e].resample(spacing); //resample the edge and copy it to the new network 205 n.E[e] = E[e].resample(spacing); //resample the edge and copy it to the new network
  206 + std::cout<<"resampled"<<std::endl;
204 } 207 }
205 208
206 return n; //return the resampled network 209 return n; //return the resampled network
stim/visualization/obj.h
@@ -9,6 +9,8 @@ @@ -9,6 +9,8 @@
9 #include <stim/math/vector.h> 9 #include <stim/math/vector.h>
10 #include <algorithm> 10 #include <algorithm>
11 11
  12 +#include <time.h>
  13 +
12 namespace stim{ 14 namespace stim{
13 15
14 /** This class provides an interface for loading, saving, and working with Wavefront OBJ files. 16 /** This class provides an interface for loading, saving, and working with Wavefront OBJ files.
@@ -92,6 +94,9 @@ protected: @@ -92,6 +94,9 @@ protected:
92 94
93 //triplet used to specify geometric vertices consisting of a position vertex, texture vertex, and normal 95 //triplet used to specify geometric vertices consisting of a position vertex, texture vertex, and normal
94 struct triplet : public std::vector<unsigned int>{ 96 struct triplet : public std::vector<unsigned int>{
  97 +
  98 + //default constructor, empty triplet
  99 + triplet(){}
95 100
96 //create a triplet given a parameter list (OBJ indices start at 1, so 0 can be used to indicate no value) 101 //create a triplet given a parameter list (OBJ indices start at 1, so 0 can be used to indicate no value)
97 triplet(unsigned int v, unsigned int vt = 0, unsigned int vn = 0){ 102 triplet(unsigned int v, unsigned int vt = 0, unsigned int vn = 0){
@@ -162,10 +167,12 @@ protected: @@ -162,10 +167,12 @@ protected:
162 //create a temporary vector used to store string tokens 167 //create a temporary vector used to store string tokens
163 std::vector<std::string> tokens = stim::parser::split(line, ' '); 168 std::vector<std::string> tokens = stim::parser::split(line, ' ');
164 169
  170 + resize(tokens.size() - 1); //set the geometry size based on the number of tokens
165 //for each triplet in the line 171 //for each triplet in the line
166 for(unsigned int i = 1; i < tokens.size(); i++){ 172 for(unsigned int i = 1; i < tokens.size(); i++){
167 //construct the triplet and push it to the geometry 173 //construct the triplet and push it to the geometry
168 - push_back( triplet(tokens[i]) ); 174 + //push_back( triplet(tokens[i]) );
  175 + at(i-1) = triplet(tokens[i]);
169 } 176 }
170 177
171 } 178 }
@@ -173,14 +180,15 @@ protected: @@ -173,14 +180,15 @@ protected:
173 //returns a vector containing the vertex indices for the geometry 180 //returns a vector containing the vertex indices for the geometry
174 void get_v(std::vector<unsigned>& v){ 181 void get_v(std::vector<unsigned>& v){
175 v.resize(size()); //resize the vector to match the number of vertices 182 v.resize(size()); //resize the vector to match the number of vertices
176 - for(unsigned int i = 0; i<size(); i++) //for each vertex  
177 - v[i] = at(i)[0]; //copy the vertex index 183 + for(unsigned int i = 0; i<size(); i++){ //for each vertex
  184 + v[i] = at(i)[0]; //copy the vertex index (1st element of triplet)
  185 + }
178 } 186 }
179 187
180 void get_vt(std::vector<unsigned>& vt){ 188 void get_vt(std::vector<unsigned>& vt){
181 vt.resize(size()); //resize the vector to match the number of vertices 189 vt.resize(size()); //resize the vector to match the number of vertices
182 for(unsigned int i = 0; i<size(); i++) //for each vertex 190 for(unsigned int i = 0; i<size(); i++) //for each vertex
183 - vt[i] = at(i)[1]; //copy the vertex index 191 + vt[i] = at(i)[1]; //copy the vertex texture index (2nd element of triplet)
184 } 192 }
185 193
186 void get_vn(std::vector<unsigned>& vn){ 194 void get_vn(std::vector<unsigned>& vn){
@@ -492,9 +500,10 @@ public: @@ -492,9 +500,10 @@ public:
492 500
493 std::string line; 501 std::string line;
494 getline(infile, line); //get the first line 502 getline(infile, line); //get the first line
  503 + unsigned int l = 0;
495 while(infile){ 504 while(infile){
496 -  
497 - 505 + l++;
  506 + //unsigned int t = time(NULL);
498 507
499 //get the token representing the first parameter 508 //get the token representing the first parameter
500 token_type token = get_token(line); 509 token_type token = get_token(line);
@@ -521,16 +530,17 @@ public: @@ -521,16 +530,17 @@ public:
521 break; 530 break;
522 531
523 case OBJ_L: 532 case OBJ_L:
  533 +
524 L.push_back(geometry(line)); 534 L.push_back(geometry(line));
525 break; 535 break;
526 536
527 }; 537 };
528 538
  539 +
529 //get the next line 540 //get the next line
530 getline(infile, line); 541 getline(infile, line);
531 - }  
532 -  
533 542
  543 + }
534 544
535 //close the file 545 //close the file
536 infile.close(); 546 infile.close();