Commit 1a31ffa04223d3a05e8569ae701023fab615c73d

Authored by David Mayerich
1 parent 8478bb2b

implemented OBJ_TRIANGLE_STRIP

Showing 1 changed file with 31 additions and 1 deletions   Show diff stats
stim/visualization/obj.h
... ... @@ -29,7 +29,7 @@ namespace stim{
29 29 * geometry class - contains a list of triplets used to define a geometric structure, such as a face or line
30 30 */
31 31  
32   -enum obj_type { OBJ_NONE, OBJ_LINE, OBJ_FACE, OBJ_POINTS };
  32 +enum obj_type { OBJ_NONE, OBJ_LINE, OBJ_FACE, OBJ_POINTS, OBJ_TRIANGLE_STRIP };
33 33  
34 34 template <typename T>
35 35 class obj{
... ... @@ -353,6 +353,30 @@ public:
353 353 current_type = t;
354 354 }
355 355  
  356 + //generates a list of faces from a list of points, assuming the input list forms a triangle strip
  357 + std::vector<geometry> genTriangleStrip(geometry s) {
  358 + if (s.size() < 3) return std::vector<geometry>(); //return an empty list if there aren't enough points to form a triangle
  359 + size_t nt = s.size() - 2; //calculate the number of triangles in the strip
  360 + std::vector<geometry> r(nt); //create a list of geometry objects, where the number of faces = the number of triangles in the strip
  361 +
  362 + r[0].push_back(s[0]);
  363 + r[0].push_back(s[1]);
  364 + r[0].push_back(s[2]);
  365 + for (size_t i = 1; i < nt; i++) {
  366 + if (i % 2) {
  367 + r[i].push_back(s[i + 1]);
  368 + r[i].push_back(s[i + 0]);
  369 + r[i].push_back(s[i + 2]);
  370 + }
  371 + else {
  372 + r[i].push_back(s[i + 0]);
  373 + r[i].push_back(s[i + 1]);
  374 + r[i].push_back(s[i + 2]);
  375 + }
  376 + }
  377 + return r;
  378 + }
  379 +
356 380 /// This function terminates drawing of a primitive object, such as a line, face, or point set
357 381 void End(){
358 382 //copy the current object to the appropriate list
... ... @@ -374,6 +398,12 @@ public:
374 398  
375 399 case OBJ_FACE:
376 400 F.push_back(current_geo);
  401 + break;
  402 +
  403 + case OBJ_TRIANGLE_STRIP:
  404 + std::vector<geometry> tstrip = genTriangleStrip(current_geo); //generate a list of faces from the current geometry
  405 + F.insert(F.begin(), tstrip.begin(), tstrip.end()); //insert all of the triangles into the face list
  406 + break;
377 407 }
378 408 }
379 409 //clear everything
... ...