void operator()( HDS& hds) { typedef typename HDS::Vertex Vertex; typedef typename Vertex::Point Point; // create a cgal incremental builder CGAL::Polyhedron_incremental_builder_3<HDS> B( hds, true); B.begin_surface( t.num_vertices(), t.num_faces() ); // add the polyhedron vertices for( int i=0; i<t.num_vertices(); i++ ){ double x, y, z; t.get_vertex( i, x, y, z ); B.add_vertex( Point( x, y, z ) ); } std::vector<double> coords; std::vector<int> faces; t.output_store_in_mesh( coords, faces ); int nverts, tmpi = 0; while( tmpi < (int)faces.size() ){ nverts = faces[tmpi++]; if( nverts != 3 ) std::cout << "face has " << nverts << " vertices" << std::endl; B.begin_facet(); for( int i=0; i<nverts; i++ ){ B.add_vertex_to_facet( faces[tmpi++] ); } B.end_facet(); } // finish up the surface B.end_surface(); }
void polyhedron_edges( polyhedron &a, MySegments &e ) { e.empty(); if( a.e.size() == 0 && a.p.size() != 0 ) { a.compute_neighbors(); } for( unsigned int i = 0; i < a.e.size(); i++ ) { e.push_back( a.v[a.e[i].vi[0]] ); e.push_back( a.v[a.e[i].vi[1]] ); } }
Nef_polyhedron polyhedron_to_cgal( const polyhedron &p ){ polyhedron tmp = p.triangulate(); Polyhedron P; polyhedron_builder<HalfedgeDS> builder( tmp ); P.delegate( builder ); if( P.is_closed() ) return Nef_polyhedron( P ); else std::cout << "input polyhedron is not closed!" << std::endl; return Nef_polyhedron(); }
// make a unit cube polyhedron PolyhedronFromBounds(const idBounds &b) { // 3----------2 // |\ /| // | \ / | // | 7--6 | // | | | | // | 4--5 | // | / \ | // | / \ | // 0----------1 // static polyhedron p; if (p.e.size() == 0) { p.v.push_back(idVec4(-1, -1, 1, 1)); p.v.push_back(idVec4(1, -1, 1, 1)); p.v.push_back(idVec4(1, 1, 1, 1)); p.v.push_back(idVec4(-1, 1, 1, 1)); p.v.push_back(idVec4(-1, -1, -1, 1)); p.v.push_back(idVec4(1, -1, -1, 1)); p.v.push_back(idVec4(1, 1, -1, 1)); p.v.push_back(idVec4(-1, 1, -1, 1)); p.add_quad(0, 1, 2, 3); p.add_quad(7, 6, 5, 4); p.add_quad(1, 0, 4, 5); p.add_quad(2, 1, 5, 6); p.add_quad(3, 2, 6, 7); p.add_quad(0, 3, 7, 4); p.compute_neighbors(); p.recompute_planes(); p.v.empty(); // no need to copy this data since it'll be replaced } polyhedron p2(p); const idVec3 &min = b[0]; const idVec3 &max = b[1]; p2.v.empty(); p2.v.push_back(idVec4(min.x, min.y, max.z, 1)); p2.v.push_back(idVec4(max.x, min.y, max.z, 1)); p2.v.push_back(idVec4(max.x, max.y, max.z, 1)); p2.v.push_back(idVec4(min.x, max.y, max.z, 1)); p2.v.push_back(idVec4(min.x, min.y, min.z, 1)); p2.v.push_back(idVec4(max.x, min.y, min.z, 1)); p2.v.push_back(idVec4(max.x, max.y, min.z, 1)); p2.v.push_back(idVec4(min.x, max.y, min.z, 1)); p2.recompute_planes(); return p2; }
std::size_t polyhedron_hasher::hash(const polyhedron& v) { std::size_t seed(0); combine(seed, hash_std_vector_neurite_geometry_polygon(v.polygons())); return seed; }