void geometryUtils::subdivide_create_center_vertex(Polyhedron& P, Facet_iterator f) { Vector_3 vec(0.0, 0.0, 0.0); std::size_t order = 0; HF_circulator h = f->facet_begin(); do { vec = vec + (h->vertex()->point() - CGAL::ORIGIN); ++order; } while (++h != f->facet_begin()); CGAL_assertion(order >= 3); // guaranteed by definition of polyhedron Point_3 center = CGAL::ORIGIN + (vec / static_cast<double> (order)); Halfedge_handle new_center = P.create_center_vertex(f->halfedge()); new_center->vertex()->point() = center; }
void CGALDelaunay::TriangulateUsingCGAL(vector<Vertex_handle> * DelaunayTriangulationVertices, vector<vector<float> > * PointsToBeInserted, Triangulation * T, vector<float> *bufferPointer, vector<float> *colorPointer, int*totalVertices) { //CHECK TO SEE IF THE POINT TO ADD NEEDS TO BE EITHER MODIFIED OR ADDED //ROS_INFO("SIZE OF DELAUNAY VERTICES:%i", DelaunayTriangulationVertices->size()); //ROS_INFO("SIZE OF VERTICES to be added:%i", PointsToBeInserted->size()); for(int i = 0;i<PointsToBeInserted->size();i++) { vector<float> currentPoint = PointsToBeInserted->at(i); T->insert(Point(currentPoint[0],currentPoint[1], currentPoint[2])); } //CONVERT DELAUNAY TRIANGULATION TO CONVEX HULL Polyhedron_3 chull; CGAL::convex_hull_3_to_polyhedron_3(*T, chull); int count = 0; int vec3Order[] = {0,1,2}; vector<float> emptyVector; *bufferPointer = emptyVector; *colorPointer = emptyVector; for( Polyhedron_3::Facet_iterator fit = chull.facets_begin(); fit != chull.facets_end(); ++fit){ vector<Point> currentFacet; HF_circulator h = fit->facet_begin(); size_t order = 0; vector<vector<float> > TriangleVec; do { Point currentPoint = h->vertex()->point(); vector<float> tempVec; tempVec.push_back(currentPoint.x()); tempVec.push_back(currentPoint.y()); tempVec.push_back(currentPoint.z()); TriangleVec.push_back(tempVec); } while(++h != fit->facet_begin()); BufferActions::addVec3ToBuffer(vec3Order, bufferPointer, &TriangleVec, 3); BufferActions::addVec3ToBuffer(vec3Order, colorPointer, &TriangleVec, 3); count += 3; } *totalVertices= count; }
void Scene_polyhedron_item::compute_elements() { v_poly.resize(0); v_edge.resize(0); normal_flat.resize(0); normal_smooth.resize(0); Polyhedron& polyhedron =*poly; //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; for(f = polyhedron.facets_begin(); f != polyhedron.facets_end(); f++) { // If Flat shading: 1 normal per polygon Vector n = CGAL::Polygon_mesh_processing::compute_face_normal(f, polyhedron); normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); normal_flat.push_back(n.x()); normal_flat.push_back(n.y()); normal_flat.push_back(n.z()); // revolve around current face to get vertices HF_circulator he = f->facet_begin(); HF_circulator end = he; CGAL_For_all(he,end) { Vector n = CGAL::Polygon_mesh_processing::compute_vertex_normal(he->vertex(), polyhedron); normal_smooth.push_back(n.x()); normal_smooth.push_back(n.y()); normal_smooth.push_back(n.z()); const Point& p = he->vertex()->point(); v_poly.push_back(p.x()); v_poly.push_back(p.y()); v_poly.push_back(p.z()); } }
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 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++; } }