int main(int argc, char*argv[])
{
  const char* fname = (argc>1)?argv[1]:"data/elephant.off";
  // Create and fill polyhedron
  Polyhedron polyhedron;
  std::ifstream input(fname);
  input >> polyhedron;
  if(input.bad()){
    std::cerr << "Error: Cannot read file " <<  fname << std::endl;
    return EXIT_FAILURE;
  }
  input.close();

  // Implicit function built by AABB_tree projection queries
  Polyhedral_wrapper polyhedral_wrapper(polyhedron, 3, 0.01, -0.01);
  Mesh_domain domain(polyhedral_wrapper, polyhedral_wrapper.bounding_sphere(), 1e-4);

  // Set mesh criteria
  Facet_criteria facet_criteria(20, 5, 0.002); // angle, size, approximation
  Cell_criteria cell_criteria(4, 0.05); // radius-edge ratio, size
  Mesh_criteria criteria(facet_criteria, cell_criteria);

  // Mesh generation
  C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria);

  // Output
  std::ofstream medit_file("out.mesh");
  CGAL::output_to_medit(medit_file, c3t3);

  return 0;
}
  void operator()() const
  {
    typedef CGAL::Mesh_3::Robust_intersection_traits_3<K> Gt;
    typedef CGAL::Polyhedral_mesh_domain_with_features_3<Gt> Mesh_domain;
    
    typedef typename CGAL::Mesh_triangulation_3<
      Mesh_domain,
      typename CGAL::Kernel_traits<Mesh_domain>::Kernel,
      Concurrency_tag>::type Tr;
    typedef CGAL::Mesh_complex_3_in_triangulation_3 <
      Tr,
      typename Mesh_domain::Corner_index,
      typename Mesh_domain::Curve_segment_index > C3t3;

    typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
    typedef typename Mesh_criteria::Edge_criteria Edge_criteria;
    typedef typename Mesh_criteria::Facet_criteria Facet_criteria;
    typedef typename Mesh_criteria::Cell_criteria Cell_criteria;

    //-------------------------------------------------------
    // Data generation
    //-------------------------------------------------------
    std::cout << "\tSeed is\t"
      << CGAL::default_random.get_seed() << std::endl;
    Mesh_domain domain("data/cube.off", &CGAL::default_random);
    domain.detect_features();

    // Set mesh criteria
    Edge_criteria edge_criteria(0.2);
    Facet_criteria facet_criteria(30, 0.2, 0.02);
    Cell_criteria cell_criteria(3, 0.2);
    Mesh_criteria criteria(edge_criteria, facet_criteria, cell_criteria);

    // Mesh generation
    C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                        CGAL::parameters::no_exude(),
                                        CGAL::parameters::no_perturb());
    
    CGAL::remove_far_points_in_mesh_3(c3t3);

    // Verify
    this->verify(c3t3,domain,criteria,
                 Polyhedral_tag()); //, 1099, 1099, 1158, 1158, 4902, 4902);

    std::ofstream out_medit("test-medit.mesh");
    CGAL::output_to_medit(out_medit, c3t3);
    CGAL::output_to_tetgen("test-tetgen", c3t3);
    std::ofstream out_binary("test-binary.mesh.cgal",
                             std::ios_base::out|std::ios_base::binary);
    CGAL::Mesh_3::save_binary_file(out_binary, c3t3);
    out_binary.close();
    C3t3 c3t3_bis;
    std::ifstream in_binary("test-binary.mesh.cgal",
                             std::ios_base::in|std::ios_base::binary);
    CGAL::Mesh_3::load_binary_file(in_binary, c3t3_bis);
    assert(c3t3_bis.triangulation() == c3t3.triangulation());

  }
Ejemplo n.º 3
0
  void test_cell(const FT radius,
                 const FT radius_edge,
                 const bool is_cell1_bad = false,
                 const bool is_cell2_bad = false,
                 const bool compare_cells = false) const
  {
    typedef typename Cell_criteria::Cell_badness Badness;

    Cell_handle cell1 = cell_handle(c1_);
    Cell_handle cell2 = cell_handle(c2_);

    Cell_criteria cell_criteria(radius_edge,radius);

    Badness b1 = cell_criteria(cell1);
    Badness b2 = cell_criteria(cell2);

    std::cerr << "\t[Radius bound: " << radius
              << " - Radius-edge bound: " << radius_edge
              << "]\tc1 is ";

    if ( b1 )
      std::cerr << "BAD q=<" << b1->first << ";" << b1->second << ">";
    else
      std::cerr << "GOOD ";

    std::cerr << "\t\tc2 is ";
    if ( b2 )
      std::cerr << "BAD q=<" << b2->first << ";" << b2->second << ">";
    else
      std::cerr << "GOOD";

    assert( is_cell1_bad == (bool)b1 );
    assert( is_cell2_bad == (bool)b2 );

    // b1 is badder than b2
    if ( compare_cells )
    {
      std::cerr << "\t\tq(c1) < q(c2)";
      assert(*b1<*b2);
    }

    std::cerr << std::endl;
  }
  void image() const
  {
    typedef CGAL::Image_3 Image;
    typedef CGAL::Labeled_image_mesh_domain_3<Image, K_e_i> Mesh_domain;

    typedef typename CGAL::Mesh_triangulation_3<
      Mesh_domain,
      CGAL::Kernel_traits<Mesh_domain>::Kernel,
      Concurrency_tag>::type Tr;
    typedef CGAL::Mesh_complex_3_in_triangulation_3<Tr> C3t3;

    typedef CGAL::Mesh_criteria_3<Tr> Mesh_criteria;
    typedef typename Mesh_criteria::Facet_criteria Facet_criteria;
    typedef typename Mesh_criteria::Cell_criteria Cell_criteria;

    //-------------------------------------------------------
    // Data generation
    //-------------------------------------------------------
    Image image;
    image.read("data/liver.inr.gz");

    std::cout << "\tSeed is\t"
      << CGAL::get_default_random().get_seed() << std::endl;
    Mesh_domain domain(image, 1e-9, &CGAL::get_default_random());

    // Set mesh criteria
    Facet_criteria facet_criteria(25, 20*image.vx(), 5*image.vx());
    Cell_criteria cell_criteria(4, 25*image.vx());
    Mesh_criteria criteria(facet_criteria, cell_criteria);

    // Mesh generation
    C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria,
                                        CGAL::parameters::no_exude(),
                                        CGAL::parameters::no_perturb());

    // Verify
    this->verify_c3t3_volume(c3t3, 1772330*0.95, 1772330*1.05);
    this->verify(c3t3,domain,criteria, Bissection_tag());

    typedef typename Mesh_domain::Surface_patch_index Patch_id;
    CGAL_static_assertion(CGAL::Output_rep<Patch_id>::is_specialized);
    CGAL_USE_TYPE(Patch_id);
  }