Exemplo n.º 1
0
void
mark_nested_domains(CDT& cdt)
{
  for(typename CDT::All_faces_iterator it = cdt.all_faces_begin(); it != cdt.all_faces_end(); ++it){
    it->info().nesting_level = -1;
  }
  std::list<typename CDT::Edge> border;
  mark_domains(cdt, cdt.infinite_face(), 0, border);
  while(! border.empty()){
    typename CDT::Edge e = border.front();
    border.pop_front();
    typename CDT::Face_handle n = e.first->neighbor(e.second);
    if(n->info().nesting_level == -1){
      mark_domains(cdt, n, e.first->info().nesting_level+1, border);
    }
  }
}
void 
discoverComponents(const CDT & ct,
                   const SeedList& seeds)
{
  if (ct.dimension() != 2)
    return;

  // tag all faces inside
  for(typename CDT::All_faces_iterator fit = ct.all_faces_begin();
      fit != ct.all_faces_end();
      ++fit)
      fit->set_in_domain(true);

  // mark "outside" infinite component of the object
  discoverInfiniteComponent(ct);

  // mark "outside" components with a seed
  for(typename SeedList::const_iterator sit = seeds.begin();
      sit != seeds.end();
      ++sit)
  {
    typename CDT::Face_handle fh_loc = ct.locate(*sit);

    if(fh_loc == NULL || !fh_loc->is_in_domain())
      continue;

    std::list<typename CDT::Face_handle> queue;
    queue.push_back(fh_loc);
    while(!queue.empty())
    {
      typename CDT::Face_handle f = queue.front();
      queue.pop_front();
      f->set_in_domain(false);

      for(int i = 0; i < 3; ++i)
      {
        typename CDT::Face_handle ni = f->neighbor(i);
        if(ni->is_in_domain()
          && !ct.is_constrained(typename CDT::Edge(f,i))) //same component
        {
          queue.push_back(ni);
        }
      }
    }
  }
} 
std::list< CgalTrian> erGeometryExtractTrianglesWithMesh( InputSegmentIterator debut, InputSegmentIterator fin,double mesh_angle=0.125,double mesh_size=4.)
 {
   CgalDT cgadt ;
   for( InputSegmentIterator icg=debut;icg!=fin;icg++)
     {
       cgadt.insert_constraint(icg->source(),icg->target());
     };
   CGAL::refine_Delaunay_mesh_2(cgadt, Criteria(mesh_angle,mesh_size));
   
   CgalDT::Finite_edges_iterator bed,nif;
   // std::cout << "Nbre de noeuds:" << cgadt.number_of_vertices() << std::endl;
   // int i;
   // std::cin >> i;
   bed=cgadt.finite_edges_begin();
   nif=cgadt.finite_edges_end();
   CDT cdt;
   for(;bed!=nif;bed++)
     {
       CDT::Vertex_handle  va = cdt.insert(bed->first->vertex(cgadt.cw(bed->second))->point());
       CDT::Vertex_handle  vb = cdt.insert(bed->first->vertex(cgadt.ccw(bed->second))->point());
       if(cgadt.is_constrained(*bed))
	 {
	   cdt.insert_constraint(va,vb);
	 }
     }

   initializeID(cdt);
   discoverComponents(cdt);
   std::list<CgalTrian> triangs;
   CDT::All_faces_iterator deb=cdt.all_faces_begin();

   for(;deb!=cdt.all_faces_end();deb++)
     {
       if(deb->is_in_domain())
   	{ CgalTrian tri=cdt.triangle(deb);
   	  triangs.push_back(tri);
   	}
    };
     return triangs;
 };
std::list< CgalTrian> erGeometryExtractTriangles( InputSegmentIterator debut, InputSegmentIterator fin)
{
  CDT cdt ;
  for( InputSegmentIterator icg=debut;icg!=fin;icg++)
    {
      cdt.insert_constraint(icg->source(),icg->target());
    };
 
  initializeID(cdt);
  discoverComponents(cdt);
  std::list<CgalTrian> triangs;
  CDT::All_faces_iterator deb=cdt.all_faces_begin();

  for(;deb!=cdt.all_faces_end();deb++)
    {
      if(deb->is_in_domain())
	{ CgalTrian tri=cdt.triangle(deb);
	  triangs.push_back(tri);
	}
    };
    return triangs;
};