Example #1
0
bool
BvertGrid::build(
   CBvert_list& bottom,         // bottom row
   CBvert_list& top,            // top row
   CBvert_list& left,           // left column
   CBvert_list& right           // right column
   )
{
   // Vertices of bottom and top run left to right.
   // On the left and right they run bottom to top.

   // Check everything is righteous:
   if (bottom.size() < 2                ||
       bottom.size() != top.size()      ||
       left.size() < 2                  ||
       left.size() != right.size()      ||
       bottom.front() != left.front()   ||
       bottom.back()  != right.front()  ||
       top.front()    != left.back()    ||
       top.back()     != right.back()   ||
       !bottom.same_mesh()              ||
       !top.same_mesh()                 ||
       !left.same_mesh()                ||
       !right.same_mesh()               ||
       bottom.mesh() == nullptr) {
      err_msg("BvertGrid::build: can't deal with CRAP input");

      std::ostream_iterator<Bvert*> err_it (std::cerr, ", ");

      cerr << "bottom: ";
      std::copy(bottom.begin(), bottom.end(), err_it);
      cerr << endl;

      cerr << "top:    ";
      std::copy(top.begin(), top.end(), err_it);
      cerr << endl;

      cerr << "left:   ";
      std::copy(left.begin(), left.end(), err_it);
      cerr << endl;

      cerr << "right:  ";
      std::copy(right.begin(), right.end(), err_it);
      cerr << endl;

      return false;
   }

   // Wipe the old:
   clear();

   // Build the new...
   //   bottom row:
   _grid.push_back(bottom);

   BMESHptr m = bottom.mesh();    assert(m);

   // Internal rows:
   for (Bvert_list::size_type j=1; j<left.size()-1; j++) {
      Bvert_list row;                    // vertices for row j
      row.push_back(left[j]);            // add first vertex for row j
      for (Bvert_list::size_type i=1; i<bottom.size()-1; i++)
         row.push_back(m->add_vertex()); // add internal vertices
      row.push_back(right[j]);           // add last vertex for row j
      _grid.push_back(row);
   }

   // top row:
   _grid.push_back(top);

   // Now compute cached values:
   cache();

   return true;
}