Exemplo n.º 1
0
/////////////////////////////////////
// put_visibility()
/////////////////////////////////////
void
HatchingGroupFixed::put_visibility(TAGformat &d) const
{
   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::put_visibility()"); 

   BMESHptr m = _patch->mesh();
   LMESHptr lm = dynamic_pointer_cast<LMESH>(m);
   if (lm)
      m = lm->cur_mesh();

   Bface_list::size_type k;
   vector<int> indices;
   CBface_list& faces = m->faces();
        
   for (k=0; k< faces.size(); k++) {
      HatchingSimplexDataFixed *hsdf = HatchingSimplexDataFixed::find(faces[k]);
      if (hsdf) {
         if (hsdf->exists(this))
            indices.push_back(faces[k]->index());
      }
   }
   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::put_visibility() - Stored %d tri indices.", indices.size());

   d.id();
   *d << indices;
   d.end_id();
}
Exemplo n.º 2
0
/////////////////////////////////////
// get_visibility()
/////////////////////////////////////
void
HatchingGroupFixed::get_visibility(TAGformat &d)
{
   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::get_visibility()"); 

   BMESHptr m = _patch->mesh();
   LMESHptr lm = dynamic_pointer_cast<LMESH>(m);
   if (lm)
      m = lm->cur_mesh();

   vector<int>::size_type k;
   int ctr=0;
   vector<int> indices;
   CBface_list& faces = m->faces();

   *d >> indices;

   for (k=0; k<indices.size(); k++) {
      HatchingSimplexDataFixed *hsdf =
         HatchingSimplexDataFixed::find(faces[indices[k]]);
      if (!hsdf) {
         hsdf = new HatchingSimplexDataFixed(faces[indices[k]]);
         ctr++;
      }
      hsdf->add(this);
   }

   err_mesg(ERR_LEV_SPAM, "HatchingGroupFixed::get_visibility() - Flagged %d tris and added %d new simplex data.", indices.size(), ctr);
}
Exemplo n.º 3
0
void
TriStrip::get_strips(
   Bface* start,
   vector<TriStrip*>& strips
   ) 
{
   // if starting face was visited already, stop
   if (!is_cleared(start))
      return;

   // stack is used to record faces adjacent to
   // the current strip, in order to build additional
   // strips that align with the current one
   static Bface_list stack(1024);
   stack.clear();
   stack.push_back(start);

   BMESHptr mesh = start->mesh();

   while (!stack.empty()) {
      start = stack.back();
      stack.pop_back();
      if (is_cleared(start)) {
         TriStrip* strip = mesh->new_tri_strip();
         strip->build(start, stack);
         strips.push_back(strip);
      }
   }
}
Exemplo n.º 4
0
bool
BaseJOTapp::load_sm_file(Cstr_ptr &file)
{
   // read an .sm file

   BMESHptr mesh = new_mesh();
   if (!mesh)
      return false;

   mesh->read_file(**file);
   return create_mesh(mesh, file);
}
Exemplo n.º 5
0
int 
main(int argc, char *argv[])
{
   if (argc != 1) {
      err_msg("Usage: %s < input.sm", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work
   mesh->print();

   return 0;
}
Exemplo n.º 6
0
bool
OVERSKETCH::find_matching_sil(CGESTUREptr& g)
{
   err_adv(debug, "OVERSKETCH::find_matching_sil");

   const size_t MIN_GEST_PTS = 10;
   if (!(g && g->pts().size() >= MIN_GEST_PTS))
      return false;

   if (BMESH::_freeze_sils)
      return false;

   VisRefImage *vis_ref = VisRefImage::lookup(VIEW::peek());
   if (!vis_ref)
      return false;

   // 1. see if the gesture runs along a silhouette
   //    of a single mesh.

   SilEdgeFilter sil_filter;
   const  PIXEL_list& pts = g->pts();
   BMESHptr mesh = nullptr;
   for (PIXEL_list::size_type i=0; i<pts.size(); i++) {
      Bedge* e = (Bedge*)
         vis_ref->find_near_simplex(pts[i], SIL_SEARCH_RAD, sil_filter);
      if (!(e && e->mesh())) {
         err_adv(debug, "   gesture too far from silhouette");
         return false;
      }
      if (mesh && mesh != e->mesh()) {
         err_adv(debug, "   found a second mesh, rejecting");
         return false;
      }
      mesh = e->mesh();
   }
   if (!dynamic_pointer_cast<LMESH>(mesh)) {
      err_adv(debug, "   found non-LMESH, rejecting");
      return false;
   }

   err_adv(debug, "   gesture aligns with silhouette");
   err_adv(debug, "   mesh level %d", mesh->subdiv_level());

   // 2. extract the portion of the silhouette that matches
   //    the gesture, store in _selected_sils

   return find_matching_sil(pts, mesh->sil_strip());
}
Exemplo n.º 7
0
/////////////////////////////////////
// notify_change()
/////////////////////////////////////
void
HatchingHatchFixed::notify_change(BMESHptr m, BMESH::change_t chg)
{
   assert(chg == BMESH::VERT_POSITIONS_CHANGED);

   vector<HatchingFixedVertex>::size_type k;

   if (_verts.size() > 0) {
      //Sanity check
      assert(_verts.size() == _pts.size());
      assert(_verts.size() == _norms.size());

      for (k=0; k < _verts.size(); k++) {
         Bface *f = m->bf(_verts[k].ind);
         assert(f);
         f->bc2pos(_verts[k].bar,_pts[k]);
         f->bc2norm_blend(_verts[k].bar,_norms[k]);
      }

      //Clear these cached values so they regenerate
      _real_pts.clear();      
      _real_norms.clear();
      _real_good.clear();

   }
   else
   {
      err_mesg(ERR_LEV_WARN, "HatchingHatchFixed::notify_change() - Verts changed, but we can't update fixed hatches!!!"); 
   }

}
Exemplo n.º 8
0
int 
main(int argc, char *argv[])
{
   if (argc != 1)
   {
      err_msg("Usage: %s < mesh.sm > mesh.iv", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   // Write it out
   write_mesh(*mesh, cout);
   return 0;
}
Exemplo n.º 9
0
inline double
compute_yardstick(CBedge_list& edges, bool debug=false)
{
   double ret = 0.6 * edges.strong_edges().avg_len();

   BMESHptr mk = edges.mesh();
   BMESHptr m0 = get_top_level(edges.get_faces()).mesh();

   int    lk = 0;       // mesh level of edges
   int    l0 = 0;       // mesh level of edges' control region
   double  s = 1;       // scaling factor
   if (mk && m0) {
      lk = mk->subdiv_level();
      l0 = m0->subdiv_level();
      s = (1 << (lk - l0));
   }
   err_adv(debug, "lk: %d, l0: %d, scaling: %f", lk, l0, s);
   return s * ret;
}
Exemplo n.º 10
0
int 
main(int argc, char *argv[])
{
   if (argc != 1) {
      cerr << "Usage: " << argv[0] << " < input.sm > output.sm" << endl;
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   Wtransf xf = compute_xf(mesh->verts().pts());

   MOD::tick();
   mesh->transform(xf, MOD());

   mesh->write_stream(cout);

   return 0;
}
Exemplo n.º 11
0
int 
main(int argc, char *argv[])
{
   // -s option writes "simple" format, meaning faces are written as:
   //
   //   f 1 3 2
   //
   // instead of:
   //
   //   f 1//1 3//3 2//2

   bool do_simple = false;
   if (argc == 2 && string(argv[1]) == "-s") {
      do_simple = true;
   } else if (argc != 1) {
      err_msg("Usage: %s [ -s ] < input.sm > output.sm", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   if (Config::get_var_bool("JOT_RECENTER"))
      mesh->recenter();

   if (Config::get_var_bool("JOT_PRINT_MESH"))
      mesh->print();

   // write verts
   write_verts(*mesh, cout);

   // write faces
   write_faces(*mesh, cout, do_simple);

   return 0;
}
Exemplo n.º 12
0
int 
main(int argc, char *argv[])
{
   // See note above about -c option:
   bool do_components = false;
   if (argc == 2 && string(argv[1]) == string("-c")) {
      do_components = true;
   } else if (argc != 1) {
      err_msg("Usage: %s [ -c ] < input.sm > output.sm", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   if (do_components) {
      // Reverse separate components as needed:
      bool changed = false;
      vector<Bface_list> components = mesh->get_components();
      for (auto & component : components) {
         if (component.volume() < 0) {
            err_msg("reversing component: %d faces", component.size());
            reverse_faces(component);
            changed = true;
         }
      }
      if (changed) {
         mesh->changed();
      } else {
         err_msg("%s: nothing changed", argv[0]);
      }
   } else {
      // Do the whole thing
      mesh->reverse();
   }

   mesh->write_stream(cout);

   return 0;
}
Exemplo n.º 13
0
int 
main(int argc, char *argv[])
{
   if (argc != 1) {
      err_msg("Usage: %s < input.sm > output.sm", argv[0]);
      return 1;
   }

   BMESHptr mesh = BMESH::read_jot_stream(cin);
   if (!mesh || mesh->empty())
      return 1; // didn't work

   // Remove duplicate vertices
   mesh->remove_duplicate_vertices(false); // don't keep the bastards

   if (Config::get_var_bool("JOT_PRINT_MESH"))
      mesh->print();

   color_verts(mesh->verts());

   mesh->write_stream(cout);

   return 0;
}
Exemplo n.º 14
0
Patch*
SKY_BOX::get_patch()
{
   BMESHptr mesh = dynamic_pointer_cast<BMESH>(_body);
   return (mesh && mesh->npatches() > 0) ? mesh->patch(0) : nullptr;
}
Exemplo n.º 15
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;
}