Exemple #1
0
bool 
PAPER_DOLL::init(CGESTUREptr& g)
{
   if (!(g && g->is_stroke()))
      return false;

   if (g->below_min_length() || g->below_min_spread())
      return false;

   if (!g->is_ellipse()) {
      err_adv(debug, "PAPER_DOLL::init: non-ellipse");
      return false;
   }
   Panel* p = dynamic_cast<Panel*>(
      Bsurface::get_surface(get_top_level(VisRefImage::get_faces(g->pts())))
      );
   err_adv(debug, "PAPER_DOLL::init: %s panel", p?"found":"could not find");
   if (!(p && p->is_selected())) {
      err_adv(debug, "PAPER_DOLL::init: ellipse not over selected panel");
      return false;
   }
   assert(p && p->bfaces().size() > 0);
   Bface_list faces = Bface_list::reachable_faces(p->bfaces().front());
   assert(!faces.empty());
   if (!faces.is_planar(deg2rad(1.0))) {
      err_adv(debug, "PAPER_DOLL::init: region is not planar");
      return false;
   }

   EdgeStrip boundary = faces.get_boundary();
   if (boundary.empty()) {
      err_adv(debug, "PAPER_DOLL::init: region has no boundary");
      return false;
   }

   Bsurface_list surfs = Bsurface::get_surfaces(faces);
   if (!are_all_bsurfaces<Panel>(surfs)) {
      err_adv(debug, "PAPER_DOLL::init: region not all panels");
      return 0;
   }

   err_adv(debug, "PAPER_DOLL::init: proceeding...");

   err_adv(debug, "  boundary edges: %d, components: %d, panels: %d",
           boundary.edges().size(), boundary.num_line_strips(), surfs.num()
      );

   if (get_instance()->build_primitive(faces)) {
      err_adv(debug, "  ... succeeded");
      return true;
   }
   err_adv(debug, "  ... failed");
   return false;
}
Exemple #2
0
inline bool
create_sides(
   CBface_list& faces,
   CVertMapper& tmap,
   CVertMapper& bmap,
   Primitive* p
   )
{
   assert(p && tmap.is_valid() && bmap.is_valid());
   Bface_list ret;

   EdgeStrip boundary = faces.get_boundary();
   assert(!boundary.empty());

   EdgeStrip top_strip = tmap.a_to_b(boundary);
   EdgeStrip bot_strip = bmap.a_to_b(boundary);
   assert(!(top_strip.empty() || bot_strip.empty()));

   UVpt a, b, c, d;
   Bedge *top_e, *bot_e;
   Bface *top_f, *bot_f;
   Bvert *v1, *v2, *v3, *v4;
   for (int i = 0; i < top_strip.num(); i++) {
      top_e = top_strip.edge(i);
      bot_e = bot_strip.edge(i);
      top_f = top_e->get_face();
      bot_f = bot_e->get_face();
      v1 = top_strip.vert(i);
      v2 = top_e->other_vertex(v1);
      v3 = bot_strip.vert(i);
      v4 = bot_e->other_vertex(v3);
      bool has_uv = UVdata::get_uvs(top_f, a, b, c);
      if (has_uv) {
         assert(top_f->is_quad() && bot_f->is_quad());
         a = UVdata::get_uv(v1, top_f);
         b = UVdata::get_uv(v2, top_f);
         c = UVdata::get_uv(v3, bot_f);
         d = UVdata::get_uv(v4, bot_f);
         if (c[0]==0 && d[0]==0) 
            c[0] = d[0] = a[0]+abs((UVdata::get_uv(top_f->other_vertex(v1, v2), top_f))[0]-a[0]);
         if (top_f->other_vertex(top_f->weak_edge()) == v1)
            p->add_quad(v1, v3, v4, v2, a, c, d, b);
         else {
            assert(top_f->other_vertex(top_f->weak_edge()) == v2);
            p->add_quad(v3, v4, v2, v1, c, d, b, a);
         }
      } else {
         p->add_quad(v1, v3, v4, v2);
      }
   }

   return true;
}