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