Esempio n. 1
0
/******************************************************************************
Main program.
******************************************************************************/
int
main(int argc, char *argv[])
{
   char *s;
   char *progname;

   progname = argv[0];

   while (--argc > 0 && (*++argv)[0]=='-') {
      for (s = argv[0]+1; *s; s++)
         switch (*s) {
          default:
            usage (progname);
            exit (-1);
            break;
         }
   }

   err_adv(debug, "reading ply file...");
   read_file();
   err_adv(debug, "done\n");

   write_sm();

   return 0;
}
Esempio n. 2
0
int
XformPen::tap_cb(CGESTUREptr& tap, DrawState*& s)
{
   assert(tap);
   if (tap->is_double_tap()) {
      // should never happen given order of arcs in XformPen constructor
      cerr << "XformPen::tap_cb: error: gesture is double tap"
           << endl;
      return 0;
   }

   // tap on cursor?
   BMESHray ray(tap->center());
   _view->intersect(ray);
   Cursor3D* c = Cursor3D::upcast(ray.geom());
   if (c) {
      err_adv(debug, "XformPen::tap_cb: hit axis");
      c->handle_gesture(tap);
      return 0;
   }

   // tap on mesh?
   _mesh = 0;
   Bface* f = cur_face();
   if (!f) {
      err_adv(debug, "XformPen::tap_cb: missed face");
      return cancel_cb(tap, s);
   }
   BMESH* m = f->mesh();
   if (!m) {
      err_adv(debug, "XformPen::tap_cb: hit face, no mesh");
      return cancel_cb(tap, s);
   }
   GEOMptr g = bmesh_to_geom(m);
   if (!g) {
      err_adv(debug, "XformPen::tap_cb: hit mesh, no geom");
      return cancel_cb(tap, s);
   }
   // skip floor:
   if (FLOOR::isa(g)) {
      err_adv(debug, "XformPen::tap_cb: hit floor, skipping...");
      return cancel_cb(tap, s);
   }

   // tap on ordinary mesh (not floor):
   _mesh = m;
   assert(_mesh);
   BMESH::set_focus(_mesh, f->patch());
   FLOOR::show();
   FLOOR::realign(_mesh,0); // 0 = no undo command

   Cursor3D::attach(g);

   return 0;
}
Esempio n. 3
0
OctreeNode*
sps_real(CBface_list& input_faces,
         CBBOX& box,
         int height,
         double regularity,
         double min_dist,
         Bface_list& flist,
         ARRAY<Wvec>& blist,
         double& spacing
   ) 
{
   clock_t start, end;
   double duration; 
   flist.clear();
   blist.clear();

   OctreeNode* root = new OctreeNode(box.min(), box.max(), 1, NULL);
   if (height == 1) {
      root->set_leaf(true);
      root->set_disp(true);
   }
   root->intersects() = input_faces;

   start = clock();
   root->build_octree(height);
   end = clock();   
  
   duration = (double)(end - start) / CLOCKS_PER_SEC;
   err_adv(debug, "step 1 time: %f", duration); 
  
   start = clock();
   visit(root, regularity, flist, blist);
   end = clock();
   duration = (double)(end - start) / CLOCKS_PER_SEC;
   err_adv(debug, "step 2 time: %f", duration);

   // remove bad samples
   start = clock();
   double dist = min_dist * box.dim().length() / (1<<(height-1));
   spacing = dist;
   root->set_neibors();

   root->set_terms();

   remove_nodes(flist, blist, dist, root->terms());
   end = clock();
   duration = (double)(end - start) / CLOCKS_PER_SEC;
   err_adv(debug, "step 3 time: %f", duration);   
   err_adv(debug, "no of points: %d", flist.num());

   return root;
}
Esempio n. 4
0
bool
SkinMeme::compute_delt()
{
   static bool debug = ::debug || Config::get_var_bool("DEBUG_SKIN_MEMES",false);

   _delt = Wvec::null();

   if (is_frozen())
      return false;

   if (!is_tracking()) {
      err_msg("SkinMeme::compute_delt: not tracking, can't proceed");
      return false;
   }

   if (!is_boss()) {
      err_adv(debug, "SkinMeme::compute_delt: non-boss; bailing...");
      track_to_target(loc());
      return false;
   }

   Wpt cur = loc();
   Wpt centroid = vert()->qr_centroid();

   static const double bw = Config::get_var_dbl("SKIN_SMOOTH_CENTROID_WEIGHT",0.5);
   Wpt target = interp(cur, centroid, bw);

   // Target is where we want to be, but we'll settle for
   // somewhere on the skeleton surface that is as close as
   // possible.
   Wpt tp;
   if (track_to_target(target, tp)) {
//      double d = target.dist(tp);
//      Wpt new_loc = target + norm() * (fabs(_h) - d);
//      Wpt new_loc = tp + ((target - tp).normalized() * fabs(_h));

      // XXX - hack
      // can we figure this out, one day, soon??
      Wpt new_loc;
      if (is_border(track_simplex())) {
         new_loc = tp + track_norm()*_h;
      } else {
         new_loc = tp + ((target - tp).normalized() * fabs(_h));
      }

      _delt = new_loc - cur;
      return true;
   }

   err_adv(debug, "SkinMeme::compute_delt: track to target failed");
   return false;
}
Esempio n. 5
0
/*****************************************************************
 * UTILITIES 
 *****************************************************************/
inline LMESHptr 
lookup_mesh(int mesh_num)
{
   TEXBODY* tx = TEXBODY::cur_tex_body();
   if (!tx) {
      err_adv(debug, "lookup_mesh: error: can't get TEXBODY");
      return nullptr;
   }
   if (!tx->meshes().valid_index(mesh_num)) {
      err_adv(debug, "lookup_mesh: error: invalid mesh num");
      return nullptr;
   }
   return dynamic_pointer_cast<LMESH>(tx->mesh(mesh_num));
}
Esempio n. 6
0
void
SKY_BOX::hide()
{
   assert(_sky_instance);
   WORLD::undisplay(_sky_instance, false);
   err_adv(debug, "Skybox is disabled");
}
Esempio n. 7
0
void 
SKY_BOX::update_position() //centers the sky box around the camera
{
   Wpt eye = VIEW::eye();
   if (eye.dist_sqrd(xform().origin()) > 0) { //only update when really needed
      set_xform(Wtransf(eye));
      err_adv(debug, "SKY_BOX::update_position: updated skybox");
   }
}
Esempio n. 8
0
void 
SkinMeme::set_track_simplex(Bsimplex* s)  
{
   assert(_track_filter);
   if (!s) {
      _trackers.clear();
   } else if (!_track_filter->accept(s)) {
      err_adv(debug, "SkinMeme::set_track_simplex: error: filter rejects simplex");
   } else if (is_tracking()) {
      _trackers[0] = s;
   } else {
      add_track_simplex(s);
   }
}
Esempio n. 9
0
SubdivUpdater* 
SubdivUpdater::create(CBvert_list& verts)
{
   // Given an input region to keep updated,
   // create a SubdivUpdater to manage it: 

   LMESHptr m = dynamic_pointer_cast<LMESH>(verts.mesh());
   if (m) {
      return new SubdivUpdater(m, verts);
   } else
      err_adv(debug, "SubdivUpdater::create: can't get LMESH from vert list");

   return nullptr;
}
Esempio n. 10
0
bool 
Action_list::invoke() const 
{
   // XXX - for development/debug
   if (!can_invoke()) {
      err_adv(debug, "Action_list::invoke: error: can_invoke returns false");
      return false;
   }

   // even though we checked, we're still keeping track of
   // whether they do in fact report success:
   bool ret = true;
   for (Action_list::size_type i=0; i<size(); i++)
      ret = at(i)->invoke() && ret;
   assert(ret == true);
   return ret;
}
Esempio n. 11
0
void
HaloRefImage::update()
{
  // render the scene and read pixels to main memory
   // and/or texture memory

   if (!need_update())
      return;

   static bool debug = Config::get_var_bool("DEBUG_HALO_UPDATE",false);
   err_adv(debug, "HaloRefImage::update: updating...");

    check_resize();

   glPushAttrib(
      GL_LINE_BIT               |
      GL_DEPTH_BUFFER_BIT       |
      GL_ENABLE_BIT             |
      GL_LIGHTING_BIT           |
      GL_VIEWPORT               | // XXX - not needed
      GL_COLOR_BUFFER_BIT       | // XXX - not needed
      GL_TEXTURE_BIT              // XXX - not needed
      );

   // XXX - remove this:
   assert(_view && _view == VIEW::peek());

   // set up lights
   _view->setup_lights();

   // set default state
   // XXX - check
   glLineWidth(1.0);            // GL_LINE_BIT
   glDepthMask(GL_TRUE);        // GL_DEPTH_BUFFER_BIT
   glDepthFunc(GL_LESS);        // GL_DEPTH_BUFFER_BIT
   glEnable(GL_DEPTH_TEST);     // GL_DEPTH_BUFFER_BIT
   glDisable(GL_NORMALIZE);     // GL_ENABLE_BIT
   glDisable(GL_BLEND);         // GL_ENABLE_BIT
   glEnable(GL_CULL_FACE);      // GL_ENABLE_BIT

   glColorMaterial(GL_FRONT_AND_BACK, GL_AMBIENT_AND_DIFFUSE);
   glEnable(GL_COLOR_MATERIAL); // GL_ENABLE_BIT
   glShadeModel(GL_SMOOTH);     // GL_LIGHTING_BIT
  
   // set viewport to ref image size:
   glViewport(0,0,_width,_height); // GL_VIEWPORT_BIT
   draw_objects(_view->drawn());

   // copy image to main memory or texture memory
   // (or both) as requested:
   if (_update_main_mem) {
      if (use_fbos)
         glBindFramebuffer(GL_READ_FRAMEBUFFER, _fbo);
      else
         glReadBuffer(GL_AUX0); //because the image is constructed in aux0
      copy_to_ram();
      if (use_fbos)
         glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
      else
         glReadBuffer(GL_BACK);
   }
   if (_update_tex_mem)
      copy_to_tex_aux(); //copies from aux0

   // clear update flags until next update request is made:
   _update_main_mem = _update_tex_mem = false;

   glPopAttrib();

   // restore viewport to window size:
   int w, h;
   _view->get_size(w,h);
   glViewport(0,0,w,h);
}
Esempio n. 12
0
/******************************************************************************
Write out a jot .sm file.
******************************************************************************/
void
write_sm()
{
   LMESHptr mesh = make_shared<LMESH>();
   
   int i=0;

   //******** Build the mesh ********

   err_adv(debug, "read ply file: %d vertices, %d faces\n", nverts, nfaces);

   err_adv(debug, "building mesh:");

   // Add vertices to mesh
   err_adv(debug, "  adding vertices...");
   for (i = 0; i < nverts; i++)
      mesh->add_vertex(Wpt(vlist[i]->x, vlist[i]->y, vlist[i]->z));
   err_adv(debug, "  done\n");

   // Add per-vertex colors if needed
   if (per_vertex_color) {
      err_adv(debug, "  adding colors...");
      for (i = 0; i < nverts; i++)
         mesh->bv(i)->set_color(COLOR(vlist[i]->r, vlist[i]->g, vlist[i]->b));
      err_adv(debug, "  done\n");
   }

   // Add faces
   err_adv(debug, "  adding faces...");
   for (i = 0; i < nfaces; i++)
      add_face(mesh, flist[i]);
   err_adv(debug, "  done\n");

   //******** Filter the mesh ********

   err_adv(debug, "filtering mesh...");

   // Remove any isolated vertices
   for (i=mesh->nverts()-1; i>=0; i--) {
      if (mesh->bv(i)->degree() == 0) {
         mesh->remove_vertex(mesh->bv(i));
      }
   }
   mesh->changed();

   // Remove duplicate vertices while we're at it
   mesh->remove_duplicate_vertices(false); // don't keep the bastards

   // Check for consistent orientation of normals
   bool is_bad = false;
   for (i=0; i<mesh->nedges(); i++)
      if (!mesh->be(i)->consistent_orientation())
         is_bad = true;
   if (is_bad)
      err_msg("Warning: inconsistently oriented triangles -- can't fix");

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

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

   err_adv(debug, "done\n");

   //******** Write mesh ********

   err_adv(debug, "writing mesh...");
   mesh->write_stream(cout);
   err_adv(debug, "done\n");
}
Esempio n. 13
0
/******************************************************************************
Read in the PLY file from standard in.
******************************************************************************/
void
read_file()
{
   /*** Read in the original PLY object ***/

   PlyFile *in_ply = read_ply (stdin);

   for (int i = 0; i < in_ply->num_elem_types; i++) {

      /* prepare to read the i'th list of elements */
      int elem_count=0;
      const char *elem_name = setup_element_read_ply (in_ply, i, &elem_count);

      err_adv(debug, "%s: %d elements", elem_name, elem_count);

      if (strcmp("vertex", elem_name) == 0) {

         /* create a vertex list to hold all the vertices */
         vlist = (Vertex **) malloc (sizeof (Vertex *) * elem_count);
         nverts = elem_count;

         /* set up for getting vertex elements */

         setup_property_ply (in_ply, &vert_props[0]);
         setup_property_ply (in_ply, &vert_props[1]);
         setup_property_ply (in_ply, &vert_props[2]);

         int j;
         for (j = 0; j < in_ply->elems[i]->nprops; j++) {
            PlyProperty *prop;
            prop = in_ply->elems[i]->props[j];
            if (strcmp("r", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[3]);
               per_vertex_color = 1;
            }
            if (strcmp("g", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[4]);
               per_vertex_color = 1;
            }
            if (strcmp("b", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[5]);
               per_vertex_color = 1;
            }
            if (strcmp("nx", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[6]);
               has_normals = 1;
            }
            if (strcmp("ny", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[7]);
               has_normals = 1;
            }
            if (strcmp("nz", prop->name) == 0) {
               setup_property_ply (in_ply, &vert_props[8]);
               has_normals = 1;
            }
         }

         vert_other = get_other_properties_ply (in_ply, 
                                                offsetof(Vertex,other_props));

         /* grab all the vertex elements */
         for (j = 0; j < elem_count; j++) {
            vlist[j] = (Vertex *) malloc (sizeof (Vertex));
            vlist[j]->r = 1;
            vlist[j]->g = 1;
            vlist[j]->b = 1;
            get_element_ply (in_ply, (void *) vlist[j]);
         }
      }
      else if (strcmp("face", elem_name) == 0) {

         /* create a list to hold all the face elements */
         flist = (Face **) malloc (sizeof (Face *) * elem_count);
         nfaces = elem_count;

         /* set up for getting face elements */

         setup_property_ply (in_ply, &face_props[0]);
         face_other = get_other_properties_ply (in_ply, 
                                                offsetof(Face,other_props));

         /* grab all the face elements */
         for (int j = 0; j < elem_count; j++) {
            flist[j] = (Face *) malloc (sizeof (Face));
            get_element_ply (in_ply, (void *) flist[j]);
         }
      }
      else
         get_other_element_ply (in_ply);
   }

   close_ply (in_ply);
   free_ply (in_ply);
}
Esempio n. 14
0
int
FlatShadeTexture::draw(CVIEWptr& v)
{
   if (_ctrl)
      return _ctrl->draw(v);
   _cb->alpha = alpha();

   if (!_patch)
      return 0;

   // Don't draw w/ texture maps if there are no uv coords at all.
   // but don't check every frame whether there are uv coords:
   
   if (_check_uv_coords_stamp != _patch->stamp()) {
      _has_uv_coords = _patch->cur_faces().any_satisfy(HasUVFaceFilter());
      _check_uv_coords_stamp = _patch->stamp();
   }

   // Set gl state (lighting, shade model)
   glPushAttrib(GL_ENABLE_BIT | GL_LIGHTING_BIT | GL_CURRENT_BIT);
   glEnable(GL_LIGHTING);               // GL_ENABLE_BIT
   glShadeModel(GL_FLAT);               // GL_LIGHTING_BIT
   GL_COL(_patch->color(), alpha());    // GL_CURRENT_BIT
   
   if (debug_uv()) {

      //assign some texture coords if no tex_coord_gen is assigned
      if (!_patch->tex_coord_gen()) {
         _patch->set_tex_coord_gen(new GLSphirTexCoordGen);      
      }

      // decide what image file to use to show the uv-coords:
      str_ptr debug_uv_tex_name =
         Config::get_var_str("DEBUG_UV_TEX_MAP", "checkerboard.png",true);
      static str_ptr pre_path = Config::JOT_ROOT() + "nprdata/other_textures/";
      str_ptr path = pre_path + debug_uv_tex_name;

      // we only try a given pathname once. but if it fails
      // and they reset DEBUG_UV_TEX_MAP while running the
      // program we can pick up the change and try again.
      if (path != _debug_tex_path) {
         _debug_tex_path = path;
         TEXTUREglptr tex = new TEXTUREgl(_debug_tex_path);
         bool do_mipmap = Config::get_var_bool("DEBUG_TEX_USE_MIPMAP",false);
         tex->set_mipmap(do_mipmap);
         _debug_uv_tex = tex;
         _debug_uv_in_dl = false;

         if (debug) {
            cerr << "Loading debug uv texture " << **path << " ..." << endl;
         }

         if (!_debug_uv_tex->load_texture()) {
            cerr << "Can't load debug uv texture: "
                 << **_debug_tex_path
                 << endl
                 << "Set environment variable DEBUG_UV_TEX_MAP "
                 << "to an image file in "
                 << **pre_path
                 << " and try again."
                 << endl;
            _debug_uv_tex = 0;
         }
      }

      // Apply the texture if any faces have uv coordinates:
      if (_debug_uv_tex /*&& _has_uv_coords*/) //<- using auto UV
         _debug_uv_tex->apply_texture(); // GL_ENABLE_BIT

   } else {
      
      // XXX - dumb hack
      check_patch_texture_map();

      // if (_has_uv_coords)    <- using auto UV
      _patch->apply_texture(); // GL_ENABLE_BIT
   }

   // Set material parameters for OGL:
   GtexUtil::setup_material(_patch);

   // Try for the display list if it's valid
   if (!(_debug_uv == _debug_uv_in_dl && BasicTexture::draw(v))) {

      // Try to generate a display list
      int dl = _dl.get_dl(v, 1, _patch->stamp());
      if (dl) {
         glNewList(dl, GL_COMPILE);
         _debug_uv_in_dl = _debug_uv;
      }
      
      // Set up face culling for closed surfaces
      if (!set_face_culling()) 
         glLightModeli(GL_LIGHT_MODEL_TWO_SIDE, GL_TRUE);  // GL_LIGHTING_BIT
      
      FlatShadeStripCB *flat_cb = dynamic_cast<FlatShadeStripCB*>(_cb);
      if (flat_cb) {
         // send texture coordinates?
         if ((_debug_uv && _debug_uv_tex) ||
             (_has_uv_coords && _patch->has_texture())) {
            flat_cb->enable_texcoords();
         } else {
            flat_cb->disable_texcoords();
         }
      }
      err_adv(debug && _debug_uv, "  drawing uvs in flat shade");
      
      // draw the triangle strips
      _patch->draw_tri_strips(_cb);

      // end the display list here
      if (_dl.dl(v)) {
         _dl.close_dl(v);

         // the display list is built; now execute it
         BasicTexture::draw(v);
      }
   }

   // restore GL state
   glPopAttrib();

   // Have to move this outside the display list and gl push/pop attrib
   // or else it's all:
/*
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
  FlatShadeTexture::draw - End ***NOTE*** OpenGL Error: [500] 'Invalid Enumerator'
*/
   if (_debug_uv) {

      // Build the edge strip at the current subdivision level
      Bedge_list edges = _patch->cur_edges();
      edges.clear_flags();

      // If secondary edges shouldn't be drawn, set their flags
      // so they won't be drawn:
      if (!BMESH::show_secondary_faces())
         edges.secondary_edges().set_flags(1);

      // Draw uv-discontinuity boundaries as yellow lines.
      // Construct filter that accepts unreached uv-discontinuous
      // edges of this patch:
      UnreachedSimplexFilter    unreached;
      UVDiscontinuousEdgeFilter uvdisc;
      PatchEdgeFilter           mine(_patch->cur_patch());
      EdgeStrip disc_edges(edges, unreached + uvdisc + mine);
      if (!disc_edges.empty()) {
         GtexUtil::draw_strip(disc_edges, 3, Color::yellow, 0.8);
      }
   }

   GL_VIEW::print_gl_errors("FlatShadeTexture::draw - End");

   return _patch->num_faces();
}
Esempio n. 15
0
void 
ProxySurface::set_patch(Patch* p)
{
   err_adv(debug && _patch, "ProxySurface::set_patch: replacing patch");
   _patch = p;
}