예제 #1
0
// Récupère la face de travail du point d'impact
int DegradeAnObject::getFacetFromPoint(Point_3 p, Facet &fs, int index) {
	for(Facet_iterator fi = polys[index].facets_begin(); fi != polys[index].facets_end() ; ++fi) {
		Point_3 p1 = fi->halfedge()->vertex()->point();
		Point_3 p2 = fi->halfedge()->next()->vertex()->point();
		Point_3 p3 = fi->halfedge()->next()->next()->vertex()->point();
		if(isAPointInATriangle(p, p1, p2, p3)) { 
			fs = *fi;
			return 1;
		}
	}
	return 0;
}
예제 #2
0
// Warning : only for triangle mesh. NO. QUAD. MESH.
// Récupère les faces correspondantes au point d'impact et retourne leurs nombres.
int DegradeAnObject::getFacetsFromPoint(Point_3 p, std::vector<Facet> &fs, std::vector<int> &index) {
	for(int i = 0 ; i < polys.size() ; i++) {
		for(Facet_iterator fi = polys[i].facets_begin(); fi != polys[i].facets_end() ; ++fi) {
			Point_3 p1 = fi->halfedge()->vertex()->point();
			Point_3 p2 = fi->halfedge()->next()->vertex()->point();
			Point_3 p3 = fi->halfedge()->next()->next()->vertex()->point();
			if(isAPointInATriangle(p, p1, p2, p3)) {
				index.push_back(i);
				fs.push_back(*fi);
			}
		}
	}
	return fs.size();
}
예제 #3
0
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;
}
예제 #4
0
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;
            }
        }
    }
예제 #5
0
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++;

        }
    }