예제 #1
0
int main()
{
  LCC_3 lcc;

  // Create two tetrahedra.
  Dart_handle d1 = lcc.make_tetrahedron(Point(-1, 0, 0), Point(0, 2, 0), 
                                        Point(1, 0, 0), Point(1, 1, 2));
  Dart_handle d2 = lcc.make_tetrahedron(Point(0, 2, -1),
                                        Point(-1, 0, -1),
                                        Point(1, 0, -1),
                                        Point(1, 1, -3));

  // Display all the vertices of the lcc by iterating on the
  // Vertex_attribute container.
  CGAL::set_ascii_mode(std::cout);
  std::cout<<"Vertices: ";
  for (LCC_3::Vertex_attribute_const_range::iterator 
         v=lcc.vertex_attributes().begin(),
         vend=lcc.vertex_attributes().end(); 
       v!=vend; ++v)
    std::cout << lcc.point_of_vertex_attribute(v) << "; ";
  std::cout<<std::endl;

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));  

  // 3-Sew the 2 tetrahedra along one facet
  lcc.sew<3>(d1, d2);

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));  

  // Translate the second tetrahedra by a given vector
  LCC_3::Vector v(3,1,1);
  for (LCC_3::One_dart_per_incident_cell_range<0,3>::iterator 
         it=lcc.one_dart_per_incident_cell<0,3>(d2).begin(),
         itend=lcc.one_dart_per_incident_cell<0,3>(d2).end();
       it!=itend; ++it)
  {
    lcc.point(it)=LCC_3::Traits::Construct_translated_point_3()
      (lcc.point(it),v);
  }

  // Display the vertices of each volume by iterating on darts.
  std::for_each(lcc.one_dart_per_cell<3>().begin(),
                lcc.one_dart_per_cell<3>().end(),
                Display_vol_vertices<LCC_3>(lcc));  

  // We display the lcc characteristics.
  std::cout<<"LCC characteristics: ";
  lcc.display_characteristics(std::cout) << ", valid=" << lcc.is_valid() 
                                         << std::endl;

  return EXIT_SUCCESS;
}
Dart_handle make_facet(LCC_3& lcc,const std::vector<Point>& points)
{
  Dart_handle d =
    CGAL::make_combinatorial_polygon<LCC_3>(lcc,(unsigned int)points.size());
  for (unsigned int i=0; i<points.size(); ++i)
  {
    lcc.set_vertex_attribute_of_dart(d, lcc.create_vertex_attribute(points[i]));
    d=lcc.beta<1>(d);
  }
  return d;
}
예제 #3
0
// Function used to display the voronoi diagram.
void display_voronoi(LCC_3& alcc, Dart_handle adart)
{
  // We remove the infinite volume plus all the volumes adjacent to it.
  // Indeed, we cannot view these volumes since they do not have
  // a "correct geometry". 
  std::stack<Dart_handle> toremove;
  int mark_toremove=alcc.get_new_mark();

  // adart belongs to the infinite volume.
  toremove.push(adart);
  CGAL::mark_cell<LCC_3,3>(alcc, adart, mark_toremove);
 
  // Now we get all the volumes adjacent to the infinite volume.
  for (LCC_3::Dart_of_cell_range<3>::iterator
         it=alcc.darts_of_cell<3>(adart).begin(),
         itend=alcc.darts_of_cell<3>(adart).end(); it!=itend; ++it)
  {
    if ( !alcc.is_marked(alcc.beta(it,3), mark_toremove) )
    {
      CGAL::mark_cell<LCC_3,3>(alcc, alcc.beta(it,3), mark_toremove);
      toremove.push(alcc.beta(it,3));
    }
  }
  
  while( !toremove.empty() )
  {
    CGAL::remove_cell<LCC_3, 3>(alcc, toremove.top());
    toremove.pop();
  }

  CGAL_assertion(alcc.is_without_boundary(1) && alcc.is_without_boundary(2));
  
  std::cout<<"Voronoi subdvision, only finite volumes:"<<std::endl<<"  ";
  alcc.display_characteristics(std::cout) << ", valid=" 
                                          << alcc.is_valid()
                                          << std::endl;

#ifdef CGAL_LCC_USE_VIEWER
  display_lcc(alcc);
#endif // CGAL_LCC_USE_VIEWER
}
예제 #4
0
int main(int narg, char** argv)
{
  if (narg>1 && (!strcmp(argv[1],"-h") || !strcmp(argv[1],"-?")) )
  {
    std::cout<<"Usage : voronoi_3 filename"<<std::endl   
             <<"   filename being a fine containing 3D points used to "
             <<" compute the Delaunay_triangulation_3."<<std::endl;
    return EXIT_FAILURE;
  }

  std::string filename;
  if ( narg==1 )
  {
    filename=std::string("data/points_3");
    std::cout<<"No filename given: use data/points_3 by default."<<std::endl;
  }
  else
    filename=std::string(argv[1]);
  
  // 1) Compute the Delaunay_triangulation_3.
  Triangulation T;

  std::ifstream iFile(filename.c_str());
  if (!iFile)
  {
    std::cout << "Problem reading file " << filename << std::endl;
    return EXIT_FAILURE;
  }
  
  std::istream_iterator<Point> begin(iFile), end;
  T.insert(begin, end);
  CGAL_assertion(T.is_valid(false));
 
  // 2) Convert the triangulation into a 3D lcc.
  LCC_3 lcc;
  std::map<Triangulation::Cell_handle,
           LCC_3::Dart_handle > vol_to_dart;

  Dart_handle dh=CGAL::import_from_triangulation_3<LCC_3, Triangulation>
    (lcc, T, &vol_to_dart);

  std::cout<<"Delaunay triangulation :"<<std::endl<<"  ";
  lcc.display_characteristics(std::cout) << ", valid=" 
                                         << lcc.is_valid() << std::endl;

  // 3) Compute the dual lcc.
  LCC_3 dual_lcc;
  Dart_handle ddh=lcc.dual(dual_lcc, dh);
  // Here, dual_lcc is the 3D Voronoi diagram.
  CGAL_assertion(dual_lcc.is_without_boundary());

  // 4) We update the geometry of dual_lcc by using the std::map
  //    face_to_dart.
  transform_dart_to_their_dual<LCC_3,Triangulation>
    (lcc, dual_lcc, vol_to_dart);
  set_geometry_of_dual<LCC_3,Triangulation>(dual_lcc, T, vol_to_dart);
  
  // 5) Display the dual_lcc characteristics.
  std::cout<<"Voronoi subdvision :"<<std::endl<<"  ";
  dual_lcc.display_characteristics(std::cout) << ", valid=" 
                                              << dual_lcc.is_valid()
                                              << std::endl;
  display_voronoi(dual_lcc, ddh);

  return EXIT_SUCCESS;
}
void constrained_delaunay_triangulation(LCC_3 &lcc, Dart_handle d1)
{
  CGAL::set_ascii_mode(std::cout);
  std::cout<<"Vertices: ";
  for (LCC_3::Vertex_attribute_const_range::iterator
         v=lcc.vertex_attributes().begin(),
         vend=lcc.vertex_attributes().end(); v!=vend; ++v)
    std::cout << lcc.point_of_vertex_attribute(v) << "; ";
  std::cout<<std::endl;
 
  LCC_3::Vector normal = CGAL::compute_normal_of_cell_2(lcc,d1);
  P_traits cdt_traits(normal);
  CDT cdt(cdt_traits); 
    
  //inserting the constraints edge by edge
  LCC_3::Dart_of_orbit_range<1>::iterator
    it(lcc.darts_of_orbit<1>(d1).begin());

  CDT::Vertex_handle previous=LCC_3::null_handle, first=LCC_3::null_handle,
    vh=LCC_3::null_handle;

   for (LCC_3::Dart_of_orbit_range<1>::iterator
          itend(lcc.darts_of_orbit<1>(d1).end()); it!=itend; ++it)
   {     
     vh = cdt.insert(lcc.point(it));
     vh->info()=it;
     if( first==NULL ){
       first=vh;
     }
     if( previous!=NULL){
       CGAL_assertion( previous !=vh );
       cdt.insert_constraint(previous,vh);
     }

     previous=vh;
   }
   cdt.insert_constraint(previous,first);
   CGAL_assertion(cdt.is_valid());
   
   // sets mark is_external
   for( CDT::All_faces_iterator fit = cdt.all_faces_begin(),
          fitend = cdt.all_faces_end(); fit != fitend; ++fit)
   {
     fit->info().is_external = false;
     fit->info().exist_edge[0]=false;
     fit->info().exist_edge[1]=false;
     fit->info().exist_edge[2]=false;
   }
	
   std::queue<CDT::Face_handle> face_queue;
      
   face_queue.push(cdt.infinite_vertex()->face());
   while(! face_queue.empty() )
   {
     CDT::Face_handle fh = face_queue.front();
     face_queue.pop();
     if(!fh->info().is_external)
     {
       fh->info().is_external = true;
       for(int i = 0; i <3; ++i)
       {
         if(!cdt.is_constrained(std::make_pair(fh, i)))
         {
           face_queue.push(fh->neighbor(i));
         }
       }
     }
   }

   for( CDT::Finite_edges_iterator eit = cdt.finite_edges_begin(),
          eitend = cdt.finite_edges_end(); eit != eitend; ++eit)
   {
     CDT::Face_handle fh = eit->first;
     int index = eit->second;
     CDT::Face_handle opposite_fh = fh->neighbor(index);
     if(cdt.is_constrained(std::make_pair(fh, index)))
     {
       fh->info().exist_edge[index]=true;
       opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true;
       
       if ( !fh->info().is_external && number_of_existing_edge(fh)==2 )
         face_queue.push(fh);
       if ( !opposite_fh->info().is_external &&
            number_of_existing_edge(opposite_fh)==2 )
         face_queue.push(opposite_fh);
     }
   }
   
   while( !face_queue.empty() )
   {
     CDT::Face_handle fh = face_queue.front();
     face_queue.pop();
     CGAL_assertion( number_of_existing_edge(fh)>=2 ); // i.e. ==2 or ==3
     CGAL_assertion( !fh->info().is_external );
     
     if (number_of_existing_edge(fh)==2)
     {
       int index = get_free_edge(fh);
       CDT::Face_handle opposite_fh = fh->neighbor(index);

       CGAL_assertion( !fh->info().exist_edge[index] );
       CGAL_assertion( !opposite_fh->info().
                       exist_edge[cdt.mirror_index(fh,index)] );
       
       const CDT::Vertex_handle va = fh->vertex(cdt. cw(index));
       const CDT::Vertex_handle vb = fh->vertex(cdt.ccw(index));
       
       Dart_handle ndart=
         CGAL::insert_cell_1_in_cell_2(lcc,va->info(),vb->info());         
       va->info()=lcc.beta<2>(ndart);

       fh->info().exist_edge[index]=true;
       opposite_fh->info().exist_edge[cdt.mirror_index(fh,index)]=true;
       
       if ( !opposite_fh->info().is_external &&
            number_of_existing_edge(opposite_fh)==2 )
         face_queue.push(opposite_fh);
     }
   }   
}
int main()
{
  LCC_3 lcc;

  // Create one tetrahedra.
  Dart_handle d1 = lcc.make_tetrahedron(Point(-1, 0, 0), Point(0, 2, 0),
                                        Point(1, 0, 0), Point(1, 1, 2));

  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
  constrained_delaunay_triangulation(lcc,d1);
  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
  lcc.clear();
  std::cout<<std::endl
           <<"###################################################### \n"
           <<std::endl;

  // Create one hexahedron.
  d1 = lcc.make_hexahedron(Point(0,0,0), Point(1,0,0), Point(1,1,0),
                           Point(0,1,0), Point(0,1,1), Point(0,0,1),
                           Point(1,0,1), Point(1,1,1));

  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
  
  constrained_delaunay_triangulation(lcc,d1);
  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;  
  
  constrained_delaunay_triangulation(lcc,lcc.beta<2>(d1));
  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
  lcc.clear();
  std::cout<<std::endl
           <<"###################################################### \n"
           <<std::endl;
  
  std::vector<Point> points;
  points.push_back(Point(0,0,0));
  points.push_back(Point(5,15,0));
  points.push_back(Point(8,18,0));
  points.push_back(Point(12,5,0));
  points.push_back(Point(8,3,0));
  points.push_back(Point(8,-9,0));
  points.push_back(Point(5,0,0));
  points.push_back(Point(2,-3,2));
  d1=make_facet(lcc,points);

  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
#ifdef CGAL_LCC_USE_VIEWER
  display_lcc(lcc);
#endif // CGAL_LCC_USE_VIEWER
  
  constrained_delaunay_triangulation(lcc,d1);
  lcc.display_characteristics(std::cout) << ", valid="
                                         << lcc.is_valid()<<std::endl;
#ifdef CGAL_LCC_USE_VIEWER
  display_lcc(lcc);
#endif // CGAL_LCC_USE_VIEWER

  lcc.clear();
  std::cout<<std::endl
           <<"###################################################### \n"
           <<std::endl;

  return EXIT_SUCCESS;
}