void Scene_polyhedron_item::compute_normals_and_vertices(void) const { positions_facets.resize(0); positions_lines.resize(0); positions_feature_lines.resize(0); normals_flat.resize(0); normals_gouraud.resize(0); //Facets typedef Polyhedron::Traits Kernel; typedef Kernel::Point_3 Point; typedef Kernel::Vector_3 Vector; typedef Polyhedron::Facet_iterator Facet_iterator; typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator; Facet_iterator f = poly->facets_begin(); for(f = poly->facets_begin(); f != poly->facets_end(); f++) { if (f == boost::graph_traits<Polyhedron>::null_face()) continue; if(!is_triangle(f->halfedge(),*poly)) { triangulate_facet(f); } else { int i=0; HF_circulator he = f->facet_begin(); HF_circulator end = he; CGAL_For_all(he,end) { // If Flat shading:1 normal per polygon added once per vertex Vector n = CGAL::Polygon_mesh_processing::compute_face_normal(f, *poly); normals_flat.push_back(n.x()); normals_flat.push_back(n.y()); normals_flat.push_back(n.z()); //// If Gouraud shading: 1 normal per vertex n = CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), *poly); normals_gouraud.push_back(n.x()); normals_gouraud.push_back(n.y()); normals_gouraud.push_back(n.z()); //position const Point& p = he->vertex()->point(); positions_facets.push_back(p.x()); positions_facets.push_back(p.y()); positions_facets.push_back(p.z()); positions_facets.push_back(1.0); i = (i+1) %3; } } }
void Viewer::compute_elements() { //Facets if(is_Triangulated()) { pos_facets.resize(0); flat_normals.resize(0); smooth_normals.resize(0); colors.resize(0); LCC &lcc = *scene->lcc; for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), itend=lcc.attributes<3>().end(); it!=itend; ++it ) { if ( it->info().is_visible() ) { for(LCC::One_dart_per_incident_cell_range<2,3>::iterator dartIter=lcc.one_dart_per_incident_cell<2,3> (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) { // We draw the polygon // double r = (double)dartIter->attribute<3>()->info().r()/255.0; float r = (float)lcc.info<3>(dartIter).color().r()/255.0; float g = (float)lcc.info<3>(dartIter).color().g()/255.0; float b = (float)lcc.info<3>(dartIter).color().b()/255.0; if ( !lcc.is_free(dartIter, 3) ) { r += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().r()/255.0; g += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().g()/255.0; b += (float)lcc.info<3>(lcc.beta(dartIter,3)).color().b()/255.0; r /= 2; g /= 2; b /= 2; } colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); colors.push_back(r);colors.push_back(g);colors.push_back(b); //compute flat normals LCC::Vector normal = CGAL::compute_normal_of_cell_2(lcc,dartIter); normal = normal/(CGAL::sqrt(normal*normal)); flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); flat_normals.push_back(normal.x());flat_normals.push_back(normal.y());flat_normals.push_back(normal.z()); for (LCC::Dart_of_orbit_range<1>::const_iterator orbitIter = lcc.darts_of_orbit<1>(dartIter).begin(); orbitIter.cont(); ++orbitIter) { //compute Smooth normals LCC::Vector normal = CGAL::compute_normal_of_cell_0(lcc,orbitIter); normal = normal/(CGAL::sqrt(normal*normal)); smooth_normals.push_back(normal.x());smooth_normals.push_back(normal.y());smooth_normals.push_back(normal.z()); const LCC::Point& p = lcc.point(orbitIter); pos_facets.push_back(p.x()); pos_facets.push_back(p.y()); pos_facets.push_back(p.z()); } } } } } else triangulate_facet(); //Edges { pos_lines.resize(0); LCC &lcc = *scene->lcc; if ( !lcc.is_empty() ) { for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), itend=lcc.attributes<3>().end(); it!=itend; ++it ) { if ( it->info().is_visible() ) { for(LCC::One_dart_per_incident_cell_range<1,3>::iterator dartIter=lcc.one_dart_per_incident_cell<1,3> (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) { const LCC::Point& p = lcc.point(dartIter); Dart_handle d2 = lcc.other_extremity(dartIter); if ( d2!=NULL ) { const LCC::Point& p2 = lcc.point(d2); pos_lines.push_back(p.x()); pos_lines.push_back(p.y()); pos_lines.push_back(p.z()); pos_lines.push_back(p2.x()); pos_lines.push_back(p2.y()); pos_lines.push_back(p2.z()); } } } } } } //Points { pos_points.resize(0); LCC &lcc = *scene->lcc; if ( lcc.is_empty() ) { bb = LCC::Point(CGAL::ORIGIN).bbox(); bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer return; } bool empty = true; for (LCC::Attribute_range<3>::type::iterator it=lcc.attributes<3>().begin(), itend=lcc.attributes<3>().end(); it!=itend; ++it ) { if ( it->info().is_visible() ) { for(LCC::One_dart_per_incident_cell_range<0,3>::iterator dartIter=lcc.one_dart_per_incident_cell<0,3> (lcc.dart_of_attribute<3>(it)).begin(); dartIter.cont(); ++dartIter) { const LCC::Point& p = lcc.point(dartIter); pos_points.push_back(p.x()); pos_points.push_back(p.y()); pos_points.push_back(p.z()); if ( empty ) { bb = p.bbox(); empty = false; } else bb = bb + p.bbox(); } } } if ( lcc.is_empty() ) { bb = LCC::Point(CGAL::ORIGIN).bbox(); bb = bb + LCC::Point(1,1,1).bbox(); // To avoid a warning from Qglviewer } } }
void Scene_polyhedron_item::compute_normals_and_vertices(void) const { positions_facets.resize(0); positions_lines.resize(0); positions_feature_lines.resize(0); normals_flat.resize(0); normals_gouraud.resize(0); number_of_null_length_edges = 0; number_of_degenerated_faces = 0; //Facets typedef Polyhedron::Traits Kernel; typedef Kernel::Point_3 Point; typedef Kernel::Vector_3 Vector; typedef Polyhedron::Facet_iterator Facet_iterator; typedef Polyhedron::Halfedge_around_facet_circulator HF_circulator; self_intersect = CGAL::Polygon_mesh_processing::does_self_intersect(*poly); Facet_iterator f = poly->facets_begin(); for(f = poly->facets_begin(); f != poly->facets_end(); f++) { if(!is_triangle(f->halfedge(),*poly)) { is_triangulated = false; triangulate_facet(f); } else { int i=0; HF_circulator he = f->facet_begin(); HF_circulator end = he; CGAL_For_all(he,end) { // If Flat shading:1 normal per polygon added once per vertex Vector n = CGAL::Polygon_mesh_processing::compute_face_normal(f, *poly); normals_flat.push_back(n.x()); normals_flat.push_back(n.y()); normals_flat.push_back(n.z()); //// If Gouraud shading: 1 normal per vertex n = CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), *poly); normals_gouraud.push_back(n.x()); normals_gouraud.push_back(n.y()); normals_gouraud.push_back(n.z()); //position const Point& p = he->vertex()->point(); positions_facets.push_back(p.x()); positions_facets.push_back(p.y()); positions_facets.push_back(p.z()); positions_facets.push_back(1.0); i = (i+1) %3; } if(CGAL::Polygon_mesh_processing::is_degenerated(f, *poly, get(CGAL::vertex_point, *poly), poly->traits())) number_of_degenerated_faces++; } }