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;
}
예제 #2
0
// Write the CGAL mesh to a file specified
void Vol2mesh :: write(string output_file){
	
	// Create file parts object of the output file
    FileParts outfile(output_file);
    
    // Store the output file in the private member
    output_file_.assign(output_file);

	// Ouptut the file in *.mesh format
    if (outfile.ext.compare(".mesh") == 0){		
        std::ofstream medit_file(output_file.c_str());
        c3t3_.output_to_medit(medit_file);
    
    // Output the file in *.vtu, *.vtk, or *.ex2 format (uses VTK library)
    } else {
        
        // Convert CGAL object to a vtkUnstructuredGrid (http://cgal-discuss.949826.n4.nabble.com/mesh-to-vtk-output-td3586974.html)
        vtkUnstructuredGrid *output; //vtk object to convert into
        
        // Do not include sub-domains if disabled
        if (disable_subdomains_){
			output = CGAL::output_c3t3_to_vtk_unstructured_grid(c3t3_); 
		} else {
			output = output_c3t3_subdomain_to_vtk_unstructured_grid(c3t3_);  
		}
        output->Squeeze();

		// Ouput in the *.vtu format
        if (outfile.ext.compare(".vtu") == 0){
            vtkXMLDataSetWriter *vtu = vtkXMLDataSetWriter::New(); 
            vtu->SetInput(output);
            vtu->SetFileName(output_file.c_str());
            vtu->Write(); 
            
        // Output in the *.vtk format    
        } else if (outfile.ext.compare(".vtk") == 0){
            vtkUnstructuredGridWriter *vtk = vtkUnstructuredGridWriter::New();
            vtk->SetInput(output);
            vtk->SetFileName(output_file.c_str());
            vtk->Write();
        
        // Output in the ExodusII (*.ex2) format    
        } else if (outfile.ext.compare(".ex2") == 0){  
			vtkExodusIIWriter *exII = vtkExodusIIWriter::New();	
			exII->SetFileName(output_file.c_str());
            exII->SetInput(output);        
            exII->Write();

        // Produce an error if the file extension is not understood
        } else {
            printf("ERROR: The desired output file type (*.%s) is not supported (see vol2mesh.cpp)\n", outfile.ext.c_str());
            exit(102);
        }
    }
}