void maybeFlipInTreeBits() { Tr* t; for(std::size_t i = 0; i < inTrees.size(); i++) { t = inTrees[i]; t->maybeFlipInTreeBits(); } }
void _test_surface_neighbors_3_sphere( const Tr & ) { Tr T; int n=200, m=20; double r = 3; typedef typename Tr::Geom_traits Gt; typedef typename Gt::Point_3 Point; std::vector<Point> points; points.reserve(n+m); // Create n+m-4 points on a sphere of radius 2 CGAL::Random_points_on_sphere_3<Point> g(r); CGAL::cpp11::copy_n( g, n+m, std::back_inserter(points)); for(int i=0; i<n ; i++) T.insert(points[i]); //test with different calls: int k=0; for(int i=n;i<n+m;i++) { test_coords_and_neighbors(T, points[i], typename Gt::Vector_3(points[i]-CGAL::ORIGIN), typename Gt::FT(0.5),++k % 8); } }
void ShereMesh() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(sphere_function, // pointer to function Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere // Note that "2." above is the *squared* radius of the bounding sphere! // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.1, // radius bound 0.1); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; //Output mesh //Polyhedron polymesh; //bool result = CGAL::output_surface_facets_to_polyhedron(c2t3, polymesh); //std::cout << "output_surface_facets_to_polyhedron: " << result << "\n"; //Scommentare per salvare mesh su file std::ofstream out("mesh_sphere_test_low.off"); CGAL::output_surface_facets_to_off (out, c2t3); std::cout << "SAVED MESH\n"; //std::list<TriangleGT> triangleMesh; //std::back_insert_iterator<std::list<TriangleGT> > bii(triangleMesh); //output_surface_facets_to_triangle_soup(c2t3, bii); }
int main() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(moebius_function, // pointer to function Sphere_3(Point_3(0.0001, -0.0003, 0.), 2.)); // bounding sphere // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.05, // radius bound 0.05); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::ofstream out("out.off"); #ifndef NDEBUG const bool result = #endif CGAL::output_surface_facets_to_off(out, c2t3, CGAL::Surface_mesher::IO_VERBOSE | CGAL::Surface_mesher::IO_ORIENT_SURFACE); assert(result == false); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; }
void setInTreeInternalBits() { Tr* t; for(std::size_t i = 0; i < inTrees.size(); i++) { t = inTrees[i]; //std::cout << "Stm->setInTreeInternalBits() setting internal bits for inTree " << i << std::endl; t->setInternalBits(); } }
void setInTreeTaxBits() { Tr* t; for(std::size_t i = 0; i < inTrees.size(); i++) { t = inTrees[i]; t->setInTreeTaxBits(); //std::cout << "Stm.setInTreeTaxBits() setting taxBits for inTree " << i << " to " << t->taxBits; //std::cout << " firstOnePos " << t->firstOnePos << std::endl; } }
int main(int , char** argv) { Tr tr; C2T3 c2t3(tr); std::ifstream ifs(argv[1]); if( !ifs ) { std::cerr << "Usage:\n" << " " << argv[0] << " FILE\n" << "\n" << " FILE must be " << format_cgal_description << "\n"; return EXIT_FAILURE; } std::cout << " Reading " << argv[1] << std::endl; if( CGAL::Mesh_3::input_mesh(ifs, c2t3, true, &std::cerr) ) // if( CGAL::input_pslg_from_medit(ifs, // c2t3, // true, // debug // &std::cout) ) // debug to cout { display_faces_counts(tr, " ", &std::cout); std::cout << "\n Statistics:\n"; std::cout << "(vertices)\n"; display_vertices_by_surface_indices_statistics(tr, " ", &std::cout); std::cout << "(facets)\n"; display_facets_by_surface_indices_statistics(c2t3, " ", &std::cout); Compute_min_angle<Tr> min_angle(tr); double min = 180; for(Tr::Finite_cells_iterator cit = tr.finite_cells_begin(); cit != tr.finite_cells_end(); ++cit) if(cit->is_in_domain()) { const double angle = min_angle(cit); if( angle < min ) min = angle; } std::cout << "\nmin angle: " << min << "\n"; return EXIT_SUCCESS; } else return EXIT_FAILURE; }
void test_coords_and_neighbors(const Tr& T, const typename Tr::Geom_traits::Point_3& p, const typename Tr::Geom_traits::Vector_3& n, const typename Tr::Geom_traits::FT& tolerance, const int& version) { CGAL::Set_ieee_double_precision pfr; typedef std::pair<typename Tr::Geom_traits::Point_3, typename Tr::Geom_traits::FT > Point_coord_pair; std::vector<Point_coord_pair> coords; typename Tr::Geom_traits::FT norm; norm = test_coords(T, p, n,version, std::back_inserter(coords)).second; assert(test_norm( coords.begin(), coords.end(), norm)); assert(test_barycenter(coords.begin(), coords.end(), norm, p, tolerance)); //All function testing surface neighbors are // grouped together: std::vector< typename Tr::Geom_traits::Point_3 > neighbors; test_neighbors(T, p, n,version, std::back_inserter(neighbors)); assert(compare_neighbors(coords.begin(), coords.end(),neighbors.begin(), neighbors.end(), T.geom_traits())); //done }
void dump() { std::cout << "Stm dump(), nTax=" << this->nTax << std::endl; if(this->bigT == NULL) { std::cout << " bigT is not set" << std::endl; } else { std::cout << "---- bigT dump ---------" << std::endl; this->bigT->dump(); std::cout << "---- end of bigT dump --" << std::endl; } Tr* t; for(std::size_t i = 0; i < inTrees.size(); i++) { t = this->inTrees[i]; std::cout << "---- inTree " << i << " dump ---------" << std::endl; t->dump(); std::cout << "--------" << std::endl; } }
int main() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface Surface_3 surface(sphere_function, // pointer to function Sphere_3(CGAL::ORIGIN, 2.)); // bounding sphere // Note that "2." above is the *squared* radius of the bounding sphere! // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> criteria(30., // angular bound 0.1, // radius bound 0.1); // distance bound // meshing surface CGAL::make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; }
int main() { Tr tr; // 3D-Delaunay triangulation C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // defining the surface std::ifstream file_input("data/triceratops.off"); Polyhedral_surface surface(file_input); // defining meshing criteria CGAL::Surface_mesh_default_criteria_3<Tr> facets_criteria(30., // angular bound 0.5, // radius bound 0.5); // distance bound CGAL::Surface_mesh_default_edges_criteria_3<Tr> edges_criteria(0.5, // radius bound 0.5); // distance bound // meshing surface CGAL::make_piecewise_smooth_surface_mesh(c2t3, surface, facets_criteria, edges_criteria, CGAL::Manifold_tag()); std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; }
int main() { CGAL::Timer t; t.start(); // Define functions Function f1(&torus_function); Function f2(&sphere_function<5>); Function f3(&tanglecube_function); Function f4(&heart_function); Function f5(&klein_function); Function f6(&false_knot_function); Function f7(&knot1_function); Function f8(&octic_function); Function_vector v; v.push_back(&f1); //v.push_back(&f2); //v.push_back(&f3); //v.push_back(&f4); //v.push_back(&f5); //v.push_back(&f6); //v.push_back(&f7); //v.push_back(&f8); // Domain (Warning: Sphere_3 constructor uses square radius !) Mesh_domain domain(v, K::Sphere_3(CGAL::ORIGIN, 5.*5.), 1e-6); // Set mesh criteria Facet_criteria facet_criteria(30, 0.2, 0.02); // angle, size, approximation Cell_criteria cell_criteria(2., 0.4); // radius-edge ratio, size Mesh_criteria criteria(facet_criteria, cell_criteria); // Mesh generation C3t3 c3t3 = CGAL::make_mesh_3<C3t3>(domain, criteria, no_exude(), no_perturb()); // Perturbation (maximum cpu time: 10s, targeted dihedral angle: default) CGAL::perturb_mesh_3(c3t3, domain, time_limit = 10); // Exudation CGAL::exude_mesh_3(c3t3,12); CGAL::Random rand; t.stop(); std::cout << "Time elapsed for building the mesh: " << t.time() << std::endl; t.reset(); t.start(); int nr = 1500; std::vector<Point> points; points.reserve(nr); CGAL::Random_points_in_mesh_3<Point, C3t3, FastPolicy> g(c3t3); t.stop(); std::cout << "Time elapsed for init Random_points_in_mesh_3: " << t.time() << std::endl; t.reset(); t.start(); CGAL::cpp11::copy_n( g, nr, std::back_inserter(points)); t.stop(); std::cout << "Time elapsed for generating the points: " << t.time() << std::endl; t.reset(); Tr tr = c3t3.triangulation(); Tetrahedron3 tet; Tr::Finite_cells_iterator it = tr.finite_cells_begin(); for (; it != tr.finite_cells_end(); it++) { if (c3t3.is_in_complex(it)) { tet = tr.tetrahedron(it); break; } } t.start(); std::vector<Point> points_tet; points_tet.reserve(nr); CGAL::Random_points_in_tetrahedron_3<Point> g1(tet); CGAL::cpp11::copy_n(g1, nr, std::back_inserter(points_tet)); t.stop(); std::cout << "Time elapsed for " << nr << " points in one tetrahedron: " << t.time() << std::endl; t.reset(); std::cout << "The generated points are: " << std::endl; for (int i = 0; i < nr; i++) { std::cout << points[i].x() << " " << points[i].y() << " " << points[i].z() << std::endl; } points_tet.clear(); points.clear(); v.clear(); return 0; }
void sqr_it(Tr &ob){ ob.set_i(ob.get_i()*ob.get_i()); cout<<"经过sqr_it()函数后数据成员为:"<<ob.get_i()<<endl; }
OutputIterator test_neighbors(const Tr& T, const typename Tr::Geom_traits::Point_3& p, const typename Tr::Geom_traits::Vector_3& n, const int& version, OutputIterator out) { typedef CGAL::Voronoi_intersection_2_traits_3<typename Tr::Geom_traits> I_traits; //the result type of the certified version: typedef std::pair< OutputIterator, bool > NeighborIt_bool_pair; typename Tr::Cell_handle start; //test different function calls switch(version) { case 0:{ //certified call with Kernel: NeighborIt_bool_pair result_pair = CGAL::surface_neighbors_certified_3(T.points_begin(), T.points_end(), p, n, out, T.geom_traits()); assert(result_pair.second); out = result_pair.first; break;} case 1: { //certified call with instantiated traits:: NeighborIt_bool_pair result_pair = CGAL::surface_neighbors_certified_3(T.points_begin(), T.points_end(), p, out, I_traits(p,n)); assert(result_pair.second); out =result_pair.first; break;} //both versions with locate: case 2:{ start = T.locate(p); //certified call with Kernel and locate: out =CGAL::surface_neighbors_3(T, p,n,out, start); break;} case 3: { start = T.locate(p); //with instantiated traits and locate: out =CGAL::surface_neighbors_3(T,p,out, I_traits(p,n),start); break;} //taking all points: case 4: { //with instantiated traits and locate: out = CGAL::surface_neighbors_3(T,p,out,I_traits(p,n)); break;} case 5: { //certified call with Kernel and locate: out = CGAL::surface_neighbors_3(T, p,n,out); break;} //the last two with certification: case 6: { out = CGAL::surface_neighbors_3(T.points_begin(), T.points_end(), p, out,I_traits(p,n)); break; } case 7: { out = CGAL::surface_neighbors_3(T.points_begin(), T.points_end(), p,n,out,T.geom_traits()); break; } default: std::cout << "Switch function calls: Nothing is tested. " << std::endl; } return out; }
std::pair< OutputIterator, typename Tr::Geom_traits::FT> test_coords(const Tr& T, const typename Tr::Geom_traits::Point_3& p, const typename Tr::Geom_traits::Vector_3& n, const int& version, OutputIterator out) { typedef CGAL::Voronoi_intersection_2_traits_3<typename Tr::Geom_traits> I_traits; //coordinate computation result types typedef CGAL::Triple< OutputIterator, typename Tr::Geom_traits::FT, bool > Result_triple; //the result type of the certified version: typedef CGAL::Quadruple< OutputIterator, typename Tr::Geom_traits::FT, bool, bool > Result_quadruple; typename Tr::Cell_handle start; typename Tr::Geom_traits::FT norm = 1; // 1 for that default doesn't trigger an assert //test different function calls switch(version){ case 0:{ Result_triple result = CGAL::surface_neighbor_coordinates_3(T, p,n,out); assert(result.third); norm = result.second; break;} case 1: { Result_triple result = CGAL::surface_neighbor_coordinates_3(T, p,out,I_traits(p,n)); assert(result.third); norm = result.second; break;} //both versions with locate: case 2:{ start = T.locate(p); Result_triple result = CGAL::surface_neighbor_coordinates_3(T, p, n, out, start); assert(result.third); norm = result.second; break;} case 3: { start = T.locate(p); Result_triple result = CGAL::surface_neighbor_coordinates_3(T, p, out, I_traits(p,n), start); assert(result.third); norm = result.second; break;} //taking all points: case 4: { Result_triple result = CGAL::surface_neighbor_coordinates_3(T.points_begin(), T.points_end(), p, n, out, T.geom_traits()); assert(result.third); norm = result.second; break;} case 5: { Result_triple result = CGAL::surface_neighbor_coordinates_3(T.points_begin(), T.points_end(), p, out ,I_traits(p,n)); assert(result.third); norm = result.second; break;} //the last two with certification: case 6: { Result_quadruple result = CGAL::surface_neighbor_coordinates_certified_3 (T.points_begin(), T.points_end(),p,n, out, T.geom_traits()); assert(result.third && result.fourth); norm = result.second; break; } case 7: { Result_quadruple result = CGAL::surface_neighbor_coordinates_certified_3 (T.points_begin(), T.points_end(),p, out ,I_traits(p,n)); assert(result.third && result.fourth); norm = result.second; break; } default: std::cout << "Switch function calls: Nothing is tested. " << std::endl; } assert(norm > 0); return std::make_pair(out, norm); }
int main(int argc, char** argv) { int arg_count = 1; bool terminal_output = true; bool delaunay = false; bool verbose = false; if(argc < 2) { usage(argv); return 1; } while(argv[arg_count][0] == '-' && std::string(argv[arg_count]) != "--") { if(std::string(argv[arg_count]) == "-Q") terminal_output = false; else if(std::string(argv[arg_count]) == "-D") delaunay = true; else if(std::string(argv[arg_count]) == "-v") verbose = true; else { std::cerr << "Unknown option " << argv[arg_count] << std::endl; usage(argv); return 1; } ++arg_count; } if(std::string(argv[arg_count]) == "--") ++arg_count; if(argc < arg_count+1 || argc > arg_count+2) { usage(argv); return 1; } std::ifstream input(argv[arg_count]); if(input) { Tr t; CGAL::read_triangle_poly_file(t, input); if(delaunay) { if(verbose) std::cerr << "Make conforming Delaunay..." << std::endl; CGAL::make_conforming_Delaunay_2(t); } else { if(verbose) std::cerr << "Make conforming Gabriel..." << std::endl; CGAL::make_conforming_Gabriel_2(t); } if(argc==arg_count+1) { if(terminal_output) CGAL::write_triangle_poly_file(t, std::cout); } else { std::ofstream output(argv[arg_count+1]); CGAL::write_triangle_poly_file(t, output); } if(terminal_output) std::cerr << "Number of points: " << t.number_of_vertices() << std::endl << "Number of triangles: " << t.number_of_faces () << std::endl; } else { std::cerr << "Bad file: " << argv[arg_count] << std::endl; usage(argv); return 1; } return 0; }
int main() { Tr::Point p1(0,0,0); Tr::Point p2(1,0,0); Tr::Point p3(0,1,0); Tr::Point p4(0,0,1); Tr tr; tr.insert(p1); tr.insert(p2); tr.insert(p3); tr.insert(p4); Tr::Cell_handle ch = tr.finite_cells_begin(); int k = 0; Tr::Facet f = std::make_pair(ch,k); Tr::Cell::Subdomain_index sub_index = 1; Tr::Cell::Surface_patch_index surf_index = 2; Tr::Cell::Surface_patch_index surf_index_bis = 21; Tr::Vertex::Index index (surf_index); Tr::Vertex::Index index_bis(surf_index_bis); // Init cell tr.dual(ch); ch->set_subdomain_index(sub_index); // Init facet Tr::Bare_point facet_circum = tr.geom_traits().construct_weighted_circumcenter_3_object()( tr.point(ch, k+1), tr.point(ch, k+2), tr.point(ch, k+3)); ch->set_surface_patch_index(k,surf_index); ch->set_facet_surface_center(k,facet_circum); ch->set_facet_surface_center_index(k,index); // Init vertices ch->vertex(0)->set_dimension(2); ch->vertex(1)->set_dimension(2); ch->vertex(2)->set_dimension(2); ch->vertex(3)->set_dimension(2); ch->vertex(0)->set_index(index); ch->vertex(1)->set_index(index); ch->vertex(2)->set_index(index_bis); ch->vertex(3)->set_index(index_bis); // ----------------------------------- // Test edge criteria // ----------------------------------- Tr::Bare_point bp1 = tr.geom_traits().construct_point_3_object()(p1); Mc ec1(edge_size = 1); assert( ec1.edge_criteria_object().sizing_field(bp1,1,index) == 1 ); Mc ec2(edge_sizing_field = Esf(2)); assert( ec2.edge_criteria_object().sizing_field(bp1,1,index) == 2 ); Mc ec3(edge_sizing_field = 3.); assert( ec3.edge_criteria_object().sizing_field(bp1,1,index) == 3 ); Mc ec4(edge_size = 4.1, edge_sizing_field = Esf(4.2)); assert( ec4.edge_criteria_object().sizing_field(bp1,1,index) == 4.1 ); Mc ec5(sizing_field = 5.); assert( ec5.edge_criteria_object().sizing_field(bp1,1,index) == 5 ); Mc ec6(sizing_field = 6.1, edge_sizing_field = 6.2); assert( ec6.edge_criteria_object().sizing_field(bp1,1,index) == 6.2 ); Mc ec7(sizing_field = 7.1, edge_size = 7.2); assert( ec7.edge_criteria_object().sizing_field(bp1,1,index) == 7.2 ); // ----------------------------------- // Test facet criteria // ----------------------------------- typedef Tr::Geom_traits::FT FT; Tr::Geom_traits::Compute_squared_radius_3 squared_radius = tr.geom_traits().compute_squared_radius_3_object(); Tr::Geom_traits::Construct_point_3 cp = tr.geom_traits().construct_point_3_object(); FT radius_facet = CGAL::sqrt(squared_radius(cp(tr.point(ch, k+1)), cp(tr.point(ch, k+2)), cp(tr.point(ch, k+3)))); FT facet_size_ok = radius_facet*FT(10); FT facet_size_nok = radius_facet/FT(10); Mc fc1(facet_size = facet_size_ok); assert( ! fc1.facet_criteria_object()(tr, f) ); Mc fc2(facet_sizing_field = facet_size_ok); assert( ! fc2.facet_criteria_object()(tr, f) ); Mc fc3(facet_sizing_field = Fsf(facet_size_ok)); assert( ! fc3.facet_criteria_object()(tr, f) ); Mc fc4(facet_sizing_field = facet_size_nok, facet_size = facet_size_ok); assert( ! fc4.facet_criteria_object()(tr, f) ); Mc fc5(sizing_field = facet_size_ok); assert( ! fc5.facet_criteria_object()(tr, f) ); Mc fc6(facet_size = facet_size_ok, facet_sizing_field = facet_size_nok, sizing_field = facet_size_nok); assert( ! fc6.facet_criteria_object()(tr, f) ); Mc fc7(facet_sizing_field = Fsf(facet_size_ok), sizing_field = facet_size_nok); assert( ! fc7.facet_criteria_object()(tr, f) ); Mc fc8(facet_distance = 8.); Mc fc9(facet_angle = 9.); Mc fc10(facet_angle = 10.1, facet_distance = 10.2, facet_size = 10.3, facet_sizing_field = Fsf(10.4), sizing_field = 10.5); // Test construction from int Mc fc11(facet_size = 11); Mc fc12(facet_sizing_field = 12); Mc fc13(sizing_field = 13); // Test topological criterion creation Mc fc14(facet_topology = CGAL::FACET_VERTICES_ON_SURFACE); assert( ! fc14.facet_criteria_object()(tr, f) ); Mc fc15(facet_topology = CGAL::FACET_VERTICES_ON_SAME_SURFACE_PATCH); assert( fc15.facet_criteria_object()(tr, f) ); // ----------------------------------- // Test cell criteria // ----------------------------------- FT radius_cell = CGAL::sqrt(squared_radius(cp(tr.point(ch, 0)), cp(tr.point(ch, 1)), cp(tr.point(ch, 2)), cp(tr.point(ch, 3)))); FT cell_size_ok = radius_cell*FT(10); FT cell_size_nok = radius_cell/FT(10); Mc cc1(cell_size = cell_size_ok); assert( ! cc1.cell_criteria_object()(tr, ch) ); Mc cc2(cell_sizing_field = cell_size_ok); assert( ! cc2.cell_criteria_object()(tr, ch) ); Mc cc3(cell_sizing_field = Fsf(cell_size_ok)); assert( ! cc3.cell_criteria_object()(tr, ch) ); Mc cc4(cell_sizing_field = cell_size_nok, cell_size = cell_size_ok); assert( ! cc4.cell_criteria_object()(tr, ch) ); Mc cc5(sizing_field = cell_size_ok); assert( ! cc5.cell_criteria_object()(tr, ch) ); Mc cc6(cell_size = cell_size_ok, cell_sizing_field = cell_size_nok, sizing_field = cell_size_nok); assert( ! cc6.cell_criteria_object()(tr, ch) ); Mc cc7(cell_sizing_field = Csf(cell_size_ok), sizing_field = cell_size_nok); assert( ! cc7.cell_criteria_object()(tr, ch) ); Mc cc8(cell_radius_edge_ratio = 8.); Mc cc9(cell_radius_edge_ratio = 9.1, sizing_field = Csf(9.2) ); Mc cc10(cell_radius_edge_ratio = 10.1, cell_size = 10.2, cell_sizing_field = Csf(10.3), sizing_field = 10.4); // Test construction from int Mc cc11(cell_size = 11); Mc cc12(cell_sizing_field = 12); Mc cc13(sizing_field = 13); }
bool write_c3t3_to_vtk_xml_file(const C3t3 &c3t3, const std::string &file_name) { typedef typename C3t3::Triangulation Tr; typedef typename C3t3::Cells_in_complex_iterator Cell_iterator; typedef typename Tr::Finite_vertices_iterator Vertex_iterator; // Domain typedef Exact_predicates_inexact_constructions_kernel K; typedef K::FT FT; typedef K::Point_3 Point; // check that file extension is "vtu" CGAL_assertion(file_name.substr(file_name.length()-4,4) == ".vtu"); // open file std::ofstream vtk_file(file_name.c_str()); // header vtk_file << "<VTKFile type=\"UnstructuredGrid\" "; vtk_file << "version=\"0.1\" "; vtk_file << "byte_order=\"BigEndian\">" << std::endl; int indent_size = 2; std::string indent_unit(indent_size, ' '); std::string indent = indent_unit; vtk_file << indent + "<UnstructuredGrid>" << std::endl; // write mesh Tr t = c3t3.triangulation(); int num_vertices = t.number_of_vertices(); int num_cells = c3t3.number_of_cells_in_complex(); indent += indent_unit; vtk_file << indent + "<Piece NumberOfPoints=\"" << num_vertices << "\" "; vtk_file << "NumberOfCells=\"" << num_cells << "\">" << std::endl; // Write vertices indent += indent_unit; vtk_file << indent + "<Points>" << std::endl; indent += indent_unit; vtk_file << indent; vtk_file << "<DataArray type=\"Float32\" NumberOfComponents=\"3\" Format=\"ascii\">" << std::endl; std::map<Point, int> V; int i=0; indent += indent_unit; for (Vertex_iterator it=t.finite_vertices_begin(); it != t.finite_vertices_end(); ++it) { vtk_file << indent; vtk_file << it->point().x() << " " << it->point().y() << " " << it->point().z() << std::endl; V[it->point()] = i; ++i; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Points>" << std::endl; // Write tetrahedra vtk_file << indent << "<Cells>" << std::endl; indent += indent_unit; vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"connectivity\" Format=\"ascii\">"; vtk_file << std::endl; indent += indent_unit; Cell_iterator it; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { const typename Tr::Cell c(*it); const typename Tr::Vertex_handle v0 = c.vertex(0); const typename Tr::Vertex_handle v1 = c.vertex(1); const typename Tr::Vertex_handle v2 = c.vertex(2); const typename Tr::Vertex_handle v3 = c.vertex(3); vtk_file << indent; vtk_file << V[v0->point()] << " "; vtk_file << V[v1->point()] << " "; vtk_file << V[v2->point()] << " "; vtk_file << V[v3->point()] << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; // offsets // every element is a four node tetrahedron so all offsets are multiples of 4 vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"offsets\" Format=\"ascii\">"; vtk_file << std::endl; i = 4; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << i << std::endl; i += 4; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; // cell types (type 10 is a 4 node tetrahedron) vtk_file << indent; vtk_file << "<DataArray type=\"Int32\" Name=\"types\" Format=\"ascii\">"; vtk_file << std::endl; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << "10" << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Cells>" << std::endl; // cell data // only subdomain index is written here vtk_file << indent + "<CellData Scalars=\"scalars\">" << std::endl; indent += indent_unit; vtk_file << indent + "<DataArray type=\"Int32\" Name=\"subdomain index\" Format=\"ascii\">" << std::endl; indent += indent_unit; for (it = c3t3.cells_in_complex_begin(); it != c3t3.cells_in_complex_end(); ++it) { vtk_file << indent << c3t3.subdomain_index(it) << std::endl; } indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</DataArray>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</CellData>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</Piece>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << indent + "</UnstructuredGrid>" << std::endl; indent.erase(indent.length()-indent_size, indent_size); vtk_file << "</VTKFile>" << std::endl; return true; }
void _test_surface_neighbors_3_cube(const Tr &, const Transformation& transform, const int n = 75, typename Tr::Geom_traits::FT tolerance = typename Tr::Geom_traits::FT(1e-29), bool grid=true) { Tr T; int m=10; double r = 3; typedef typename Tr::Geom_traits Gt; typedef typename Gt::FT Coord_type; typedef typename Gt::Point_3 Point; typedef typename Gt::Point_2 Point_2; typedef typename Gt::Vector_3 Vector; //data points: generate random points in a square of length r std::vector<Point_2> points_2_data; points_2_data.reserve(n); if(grid) { CGAL::points_on_square_grid_2(r, n, std::back_inserter(points_2_data), CGAL::Creator_uniform_2<Coord_type,Point_2>()); } else { CGAL::Random_points_in_square_2<Point_2> g(r); CGAL::cpp11::copy_n(g, n, std::back_inserter(points_2_data)); } for(int i=0; i < n; i++) { T.insert(transform(Point(points_2_data[i].x(),points_2_data[i].y(), -r))); T.insert(transform(Point(points_2_data[i].x(),points_2_data[i].y(), r))); T.insert(transform(Point(-r, points_2_data[i].x(),points_2_data[i].y()))); T.insert(transform(Point(r, points_2_data[i].x(), points_2_data[i].y()))); T.insert(transform(Point(points_2_data[i].x(), -r, points_2_data[i].y()))); T.insert(transform(Point(points_2_data[i].x(), r, points_2_data[i].y()))); } //test_points: generate random points in a square of length r std::vector<Point_2> points_2_test; points_2_test.reserve(m); CGAL::Random_points_in_square_2<Point_2> g2(r-1.0); CGAL::cpp11::copy_n(g2, m, std::back_inserter(points_2_test)); int k=0; for(int i=0;i<m;i++) { //test point on z=r plane: test_coords_and_neighbors(T,transform(Point(points_2_test[i].x(), points_2_test[i].y(), r)), transform(Vector(0,0,1)),tolerance, ++k % 8); //test point on x=-r plane: test_coords_and_neighbors(T,transform(Point(-r, points_2_test[i].x(), points_2_test[i].y())), transform(Vector(-1,0,0)),tolerance, ++k % 8 ); //test point on x=r plane: test_coords_and_neighbors(T,transform(Point(r, points_2_test[i].x(), points_2_test[i].y())), transform(Vector(1,0,0)),tolerance,++k % 8 ); //test point on y=-r plane: test_coords_and_neighbors(T,transform(Point(points_2_test[i].x(), -r,points_2_test[i].y())), transform(Vector(0,-1,0)),tolerance,++k % 8 ); //test point on y=r plane: test_coords_and_neighbors(T,transform(Point(points_2_test[i].x(), r,points_2_test[i].y())), transform(Vector(0,1,0)),tolerance,++k % 8); } //test a sample point: //with Delaunay triangulation filering: test_coords_and_neighbors(T,transform(Point(points_2_data[n/2].x(), points_2_data[n/2].y(), r)), transform(Vector(0,0,1)),Coord_type(0),0); //considering all points: test_coords_and_neighbors(T,transform(Point(points_2_data[n/2].x(), points_2_data[n/2].y(), r)), transform(Vector(0,0,1)),Coord_type(0),4); }