void subdiv_border( Polyhedron& P) { if ( P.size_of_facets() == 0) return; // We use that new halfedges are appended at the end. Edge_iterator last_e = P.edges_end(); -- last_e; // the last of the old edges Edge_iterator e = P.edges_begin(); // create trisected border edges do { if ( e->opposite()->is_border()) trisect_border_halfedge( P, e->opposite()); else if ( e->is_border()) trisect_border_halfedge( P, e); } while ( e++ != last_e); e = P.edges_begin(); // smooth points on border edges std::vector<Point> pts; // store new smoothed points temporarily do { if ( e->opposite()->is_border()) smooth_border_vertices( e->opposite(), std::back_inserter(pts)); else if ( e->is_border()) smooth_border_vertices( e, std::back_inserter(pts)); } while ( e++ != last_e); e = P.edges_begin(); // copy smoothed points back std::vector<Point>::iterator i = pts.begin(); do { if ( e->opposite()->is_border()) { e->vertex()->point() = *i++; e->opposite()->vertex()->point() = *i++; e->opposite()->next()->vertex()->point() = *i++; } else if ( e->is_border()) { e->opposite()->vertex()->point() = *i++; e->vertex()->point() = *i++; e->next()->vertex()->point() = *i++; } } while ( e++ != last_e); CGAL_assertion( i == pts.end()); CGAL_postcondition( P.is_valid()); }
void Scene_polyhedron_transform_item::direct_draw_edges() const { typedef Kernel::Point_3 Point; typedef Polyhedron::Edge_const_iterator Edge_iterator; ::glDisable(GL_LIGHTING); ::glBegin(GL_LINES); Edge_iterator he; for(he = poly->edges_begin(); he != poly->edges_end(); he++) { const Point& a = he->vertex()->point(); const Point& b = he->opposite()->vertex()->point(); ::glVertex3d(a.x()-center_.x,a.y()-center_.y,a.z()-center_.z); ::glVertex3d(b.x()-center_.x,b.y()-center_.y,b.z()-center_.z); } ::glEnd(); ::glEnable(GL_LIGHTING); }
void Scene_polyhedron_transform_item::compute_elements() const { positions_lines.resize(0); typedef Kernel::Point_3 Point; typedef Polyhedron::Edge_const_iterator Edge_iterator; Edge_iterator he; for(he = poly->edges_begin(); he != poly->edges_end(); he++) { const Point& a = he->vertex()->point(); const Point& b = he->opposite()->vertex()->point(); positions_lines.push_back(a.x()-center_.x); positions_lines.push_back(a.y()-center_.y); positions_lines.push_back(a.z()-center_.z); positions_lines.push_back(b.x()-center_.x); positions_lines.push_back(b.y()-center_.y); positions_lines.push_back(b.z()-center_.z); } }
void Scene_textured_polyhedron_item::compute_normals_and_vertices(void) { positions_facets.resize(0); positions_lines.resize(0); textures_map_facets.resize(0); textures_map_lines.resize(0); normals.resize(0); typedef ::EPIC_kernel Kernel; typedef CGAL::Textured_items Items; typedef Kernel::Point_3 Point; typedef Kernel::Vector_3 Vector; typedef CGAL::Polyhedron_3<Kernel,Items> Base; typedef Base::Halfedge_around_facet_circulator Halfedge_around_facet_circulator; typedef Base::Edge_iterator Edge_iterator; typedef Base::Facet Facet; typedef Base::Facet_iterator Facet_iterator; //Facets Facet_iterator f = poly->facets_begin(); for(f = poly->facets_begin(); f != poly->facets_end(); f++) { Halfedge_around_facet_circulator he = f->facet_begin(); Halfedge_around_facet_circulator end = he; CGAL_For_all(he,end) { // If Flat shading:1 normal per polygon added once per vertex if (cur_shading == Flat || cur_shading == FlatPlusEdges) { Vector n = CGAL::Polygon_mesh_processing:: compute_face_normal(f, static_cast<Base&>(*poly)); normals.push_back(n[0]); normals.push_back(n[1]); normals.push_back(n[2]); } // If Gouraud shading: 1 normal per vertex else if(cur_shading == Gouraud) { const Facet::Normal_3& n = he->vertex()->normal(); normals.push_back(n[0]); normals.push_back(n[1]); normals.push_back(n[2]); } //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); const double u = he->vertex()->u(); const double v = he->vertex()->v(); textures_map_facets.push_back(u); textures_map_facets.push_back(v); } } //Lines typedef Kernel::Point_3 Point; typedef Base::Edge_iterator Edge_iterator; Edge_iterator he; for(he = poly->edges_begin(); he != poly->edges_end(); he++) { const Point& a = he->vertex()->point(); const Point& b = he->opposite()->vertex()->point(); positions_lines.push_back(a.x()); positions_lines.push_back(a.y()); positions_lines.push_back(a.z()); positions_lines.push_back(1.0); const double u = he->vertex()->u(); const double v = he->vertex()->v(); textures_map_lines.push_back(u); textures_map_lines.push_back(v); positions_lines.push_back(b.x()); positions_lines.push_back(b.y()); positions_lines.push_back(b.z()); positions_lines.push_back(1.0); const double ou = he->opposite()->vertex()->u(); const double ov = he->opposite()->vertex()->v(); textures_map_lines.push_back(ou); textures_map_lines.push_back(ov); } }