Ejemplo n.º 1
0
polyhedron cgal_to_polyhedron( const Nef_polyhedron &NP ){
    Polyhedron P;
    polyhedron ret;
    
    if( NP.is_simple() ){
        NP.convert_to_polyhedron(P);
        std::vector<double> coords;
        std::vector<int> tris;
        int next_id = 0;
        std::map< Polyhedron::Vertex*, int > vid;
        for( Polyhedron::Vertex_iterator iter=P.vertices_begin(); iter!=P.vertices_end(); iter++ ){
            coords.push_back( CGAL::to_double( (*iter).point().x() ) );
            coords.push_back( CGAL::to_double( (*iter).point().y() ) );
            coords.push_back( CGAL::to_double( (*iter).point().z() ) );
            vid[ &(*iter) ] = next_id++;
        }
        
        for( Polyhedron::Facet_iterator iter=P.facets_begin(); iter!=P.facets_end(); iter++ ){
            Polyhedron::Halfedge_around_facet_circulator j = iter->facet_begin();
            tris.push_back( CGAL::circulator_size(j) );
            do {
                tris.push_back( std::distance(P.vertices_begin(), j->vertex()) );
            } while ( ++j != iter->facet_begin());
        }
        
        ret.initialize_load_from_mesh( coords, tris );
    } else {
        std::cout << "resulting polyhedron is not simple!" << std::endl;
    }
    return ret;
}
// Checks if there are two disconnected linestrings which both have the 2 coplanar facets
bool joinCreatesNoHole (Polyhedron::Halfedge_handle& heH) {
	pointVector otherFacetPnts = get_facetPoints(heH);		// Get points of other facet

	Polyhedron::Halfedge_around_facet_circulator hafIt = heH->opposite()->facet_begin();
	bool nextNotBorder	= false;				// starts with heH so false
	bool difFound		= false;				// if previous was not border
	bool refound		= false;				// if two border sections found with not border in between
	bool canJoinFacets	= true;					// output
	do {
		if (difFound ^ nextNotBorder) {			// heH->facet() != hafIt->opposite()->facet()) {
			if (refound) {
				canJoinFacets=false;			//if refound twice -> discconnected borders
				break;
			}
			refound		=  difFound;			// Set refound true
			difFound	= !difFound;			// Flip difFound
		}
		nextNotBorder = heH->facet() != hafIt->next()->opposite()->facet();
		if (difFound && nextNotBorder &&		// if current and next are not border and point is on other facet
			std::find(otherFacetPnts.begin(), otherFacetPnts.end(),hafIt->vertex()->point())!=otherFacetPnts.end()) {
				canJoinFacets=false;			// Point is touching
				break;
		}
	} while (++hafIt != heH->opposite()->facet_begin());
	return canJoinFacets;
}
bool triDoesNotIntersectFacet (Polyhedron::Halfedge_handle& heH, bool isOpposite) {

	Segment_3 checkSeg (heH->vertex()->point(),heH->prev()->prev()->vertex()->point());	
	Polyhedron::Halfedge_around_facet_circulator hafIt = heH->facet_begin()++;			// skip itself and first

	while (++hafIt != heH->prev()->facet_begin()) {
		if (CGAL::do_intersect(checkSeg,Segment_3(hafIt->vertex()->point(),hafIt->prev()->vertex()->point())))
			return false;
	} 
	if (!isOpposite)
		return triDoesNotIntersectFacet (heH->opposite(), true);
	else
		return true;
}
void Scene_polyhedron_selection_item::compute_elements()
{
    positions_facets.clear();
    positions_lines.clear();
    positions_points.clear();
    normals.clear();
    //The facets
    {


        for(Selection_set_facet::iterator
            it = selected_facets.begin(),
            end = selected_facets.end();
            it != end; ++it)
        {
            const Kernel::Vector_3 n =
                    CGAL::Polygon_mesh_processing::compute_face_normal(*it, *this->poly_item->polyhedron());

            normals.push_back(n.x());
            normals.push_back(n.y());
            normals.push_back(n.z());

            normals.push_back(n.x());
            normals.push_back(n.y());
            normals.push_back(n.z());

            normals.push_back(n.x());
            normals.push_back(n.y());
            normals.push_back(n.z());


            Polyhedron::Halfedge_around_facet_circulator
                    he = (*it)->facet_begin(),
                    cend = he;

            CGAL_For_all(he,cend)
            {
                const Kernel::Point_3& p = he->vertex()->point();
                positions_facets.push_back(p.x());
                positions_facets.push_back(p.y());
                positions_facets.push_back(p.z());
            }
        }
    }

    //The Lines
    {

        for(Selection_set_edge::iterator it = selected_edges.begin(); it != selected_edges.end(); ++it) {
            const Kernel::Point_3& a = (it->halfedge())->vertex()->point();
            const Kernel::Point_3& b = (it->halfedge())->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(b.x());
            positions_lines.push_back(b.y());
            positions_lines.push_back(b.z());
        }

    }

    //The points
    {
        for(Selection_set_vertex::iterator
            it = selected_vertices.begin(),
            end = selected_vertices.end();
            it != end; ++it)
        {
            const Kernel::Point_3& p = (*it)->point();
            positions_points.push_back(p.x());
            positions_points.push_back(p.y());
            positions_points.push_back(p.z());
        }
    }
}