IMP_COMPILER_ENABLE_WARNINGS int main(int, char * []) { double pts[][3] = {{3.3874, 3.3577, 2.86547}, {4.20832, 3.04325, 3.05838}, {3.63033, 2.62921, 2.50657}, {4.3492, 2.80494, 1.99437}, {5.24092, 2.81322, 2.11588}, {6.00076, 3.29489, 2.1409}, {5.53583, 3.6421, 1.45294}, {5.97231, 2.95352, 1.07171}, {5.29922, 3.54395, 0.980338}, {5.46575, 3.92853, 0.183865}}; typedef CGAL::Exact_predicates_inexact_constructions_kernel IKernel; typedef IKernel::Point_3 Bare_point; typedef CGAL::Weighted_point<Bare_point, IKernel::RT> Weighted_point; unsigned int size = sizeof(pts) / (3 * sizeof(double)); IMP::base::Vector<Weighted_point> l; for (unsigned int i = 0; i < size; ++i) { l.push_back( Weighted_point(Bare_point(pts[i][0], pts[i][1], pts[i][2]), .9 * .9)); std::cout << ".color " << i << std::endl; std::cout << ".sphere " << pts[i][0] << " " << pts[i][1] << " " << pts[i][2] << " " << .9 << std::endl; } CGAL::Polyhedron_3<IKernel> p; CGAL::Union_of_balls_3<CGAL::Skin_surface_traits_3<IKernel> > skin_surface( l.begin(), l.end()); // CGAL::mesh_skin_surface_3(skin_surface, p); return 0; }
int main(int, char *[]) { double pts[][3]={{3.3874, 3.3577, 2.86547}, {4.20832, 3.04325, 3.05838}, {3.63033, 2.62921, 2.50657}, {4.3492, 2.80494, 1.99437}, {5.24092, 2.81322, 2.11588}, {6.00076, 3.29489, 2.1409}, {5.53583, 3.6421, 1.45294}, {5.97231, 2.95352, 1.07171}, {5.29922, 3.54395, 0.980338}, {5.46575, 3.92853, 0.183865}}; typedef CGAL::Exact_predicates_exact_constructions_kernel Kernel; typedef Kernel::Point_3 Bare_point; typedef Kernel::Weighted_point_3 Weighted_point; size_t size=sizeof(pts)/(3*sizeof(double)); std::vector<Weighted_point> l(size); for (size_t i=0; i< size; ++i) { l[i]= Weighted_point(Bare_point(pts[i][0], pts[i][1], pts[i][2]), .9*.9); std::cout << ".color " << i << std::endl; std::cout << ".sphere " << pts[i][0] << " " << pts[i][1] << " " << pts[i][2] << " " << .9 << std::endl; } CGAL::Polyhedron_3<Kernel> p; CGAL::Union_of_balls_3<CGAL::Skin_surface_traits_3<Kernel> > skin_surface(l.begin(), l.end()); return 0; }
int main() { std::list<Weighted_point> l; FT shrinkfactor = 0.5; l.push_front(Weighted_point(Bare_point(0, 0, 0), 1)); l.push_front(Weighted_point(Bare_point(0, 1, 0), 2)); l.push_front(Weighted_point(Bare_point(0, 0, 2), 1)); Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); Polyhedron p; CGAL::mesh_skin_surface_3(skin_surface, p); for (Polyhedron::Facet_iterator fit = p.facets_begin(); fit != p.facets_end(); ++fit) { // Retrieve the generating simplex from the regular triangulation const Skin_surface_3::Simplex &s = fit->containing_simplex(); // Get the weighted points from the simplex Skin_surface_3::Weighted_point wp[4]; switch (s.dimension()) { case 0: { Skin_surface_3::Vertex_handle vh = s; wp[0] = vh->point(); break; } case 1: { Skin_surface_3::Edge e = s; wp[0] = e.first->vertex(e.second)->point(); wp[1] = e.first->vertex(e.third)->point(); break; } case 2: { Skin_surface_3::Facet f = s; wp[0] = f.first->vertex((f.second + 1) & 3)->point(); wp[1] = f.first->vertex((f.second + 2) & 3)->point(); wp[2] = f.first->vertex((f.second + 3) & 3)->point(); break; } case 3: { Skin_surface_3::Cell_handle ch = s; wp[0] = ch->vertex(0)->point(); wp[1] = ch->vertex(1)->point(); wp[2] = ch->vertex(2)->point(); wp[3] = ch->vertex(3)->point(); break; } } } return 0; }
int main(int argc, char *argv[]) { const char *filename; if (argc == 2) { filename = argv[1]; } else { filename = "../data/2LWG.pdb"; //filename = "../data/1t7i.pdb"; } std::list<Weighted_point> l; double shrinkfactor = 0.5; // Container for molecular system std::vector<System> systems; // Retrieve input balls: extract_balls_from_pdb<K>(filename,systems,std::back_inserter(l)); /** Faster ? Polyhedron p; CGAL::make_skin_surface_mesh_3(p, l.begin(), l.end(), shrinkfactor); **/ Polyhedron p; // Construct skin surface: std::cout << "Constructing skin surface..." <<std::endl; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); // Extract mesh from the skin surface: std::cout << "Meshing skin surface..." <<std::endl; CGAL::mesh_skin_surface_3(skin_surface, p); /** The coarse mesh is refined to obtain a better approximation. Each triangle is subdivided into 4 triangles. */ //std::cout << "Refining the coarse mesh..." <<std::endl; //CGAL::subdivide_skin_surface_mesh_3(skin_surface, p); // Output in OFF format std::ofstream out("mesh.off"); out << p; out.close(); // Output that can be used in PyMol std::ofstream cgo("cgo.py"); write_cgo<Skin_surface_3, Polyhedron>(p, cgo); cgo.close(); return 0; }
std::pair<algebra::Vector3Ds, Ints> get_skin_surface( const algebra::Sphere3Ds &ss) { IMP_FUNCTION_LOG; typedef IKernel::Point_3 Bare_point; typedef CGAL::Weighted_point<Bare_point, IKernel::RT> Weighted_point; IMP::Vector<Weighted_point> l(ss.size()); for (unsigned int i = 0; i < ss.size(); ++i) { l[i] = Weighted_point(trp<IKernel>(ss[i].get_center()), algebra::get_squared(ss[i].get_radius())); } CGAL::Polyhedron_3<IKernel> p; CGAL::Union_of_balls_3<CGAL::Skin_surface_traits_3<IKernel> > skin_surface( l.begin(), l.end()); CGAL::mesh_skin_surface_3(skin_surface, p); return get_indexed_facets(p); }
void operator()(std::string & filename) { std::cout << s << " " << filename << std::endl; std::ifstream in(filename.c_str()); std::list<Weighted_point> l; double x,y,z,w; while (in >> x >> y >> z >> w) l.push_front(Weighted_point(Bare_point(x,y,z),w)); Skin_surface skin_surface(l.begin(), l.end(), s); TMC &tmc = skin_surface.triangulated_mixed_complex(); // CGAL::Triangulated_mixed_complex_observer_3<TMC, Skin_surface> // observer(skin_surface.shrink_factor()); // triangulate_mixed_complex_3(skin_surface.get_regular_triangulation(), // skin_surface.shrink_factor(), // tmc, // observer, // false); for (TMC_Finite_vertices_iterator vit = tmc.finite_vertices_begin(); vit != tmc.finite_vertices_end(); vit++) { if (tmc.is_infinite(vit->cell())) { std::cerr << "ERROR: is_infinite (main)" << std::endl; } Exact_K::FT val = vit->cell()->info().second->value(vit->point()); std::list<TMC_Cell_handle> cells; tmc.incident_cells(vit, std::back_inserter(cells)); for (std::list<TMC_Cell_handle>::iterator cell = cells.begin(); cell != cells.end(); cell++) { if (!tmc.is_infinite(*cell)) { Exact_K::FT val2 = (*cell)->info().second->value(vit->point()); // NGHK: Make exact: //assert(val == val2); assert(std::abs(CGAL::to_double(val-val2)) < 1e-8); } } } }
void operator()(std::string filename) { std::cout << filename << std::endl; std::list<Weighted_point> l; std::ifstream in(filename.c_str()); assert(in.is_open()); Weighted_point wp; while (in >> wp) l.push_front(wp); Skin_surface_3 skin_surface(l.begin(), l.end(), s); Polyhedron p; CGAL::mesh_skin_surface_3(skin_surface, p); assert(p.is_valid() && p.is_closed()); //std::cout << p << std::endl; }
int main() { std::list<Weighted_point> l; FT shrinkfactor = 0.5; l.push_front(Weighted_point(Bare_point( 1,-1,-1), 1.25)); l.push_front(Weighted_point(Bare_point( 1, 1, 1), 1.25)); l.push_front(Weighted_point(Bare_point(-1, 1,-1), 1.25)); l.push_front(Weighted_point(Bare_point(-1,-1, 1), 1.25)); Polyhedron p; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); CGAL::mesh_skin_surface_3(skin_surface, p); CGAL::subdivide_skin_surface_mesh_3(skin_surface, p); std::ofstream out("mesh.off"); out << p; return 0; }
ofMesh & ofxCGALSkinSurface::makeSkinSurfaceMesh() { std::list<Weighted_point> l; FT shrinkfactor = shrinkFactor; for(int i=0; i<points.size(); i++) { float px = points[i].point.x; float py = points[i].point.y; float pz = points[i].point.z; float radius = points[i].radius; l.push_front(Weighted_point(Bare_point(px, py, pz), radius * radius)); } Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); Polyhedron p; CGAL::mesh_skin_surface_3(skin_surface, p); if(bSubdiv == true) { CGAL::subdivide_skin_surface_mesh_3(skin_surface, p); } mesh.clear(); map<Point_3, int> point_indices; int count = 0; for (auto it=p.vertices_begin(); it!=p.vertices_end(); ++it) { auto& p = it->point(); mesh.addVertex(ofVec3f(p.x(), p.y(), p.z())); point_indices[p] = count++; } for (auto it=p.facets_begin(); it!=p.facets_end(); ++it) { mesh.addIndex(point_indices[it->halfedge()->vertex()->point()]); mesh.addIndex(point_indices[it->halfedge()->next()->vertex()->point()]); mesh.addIndex(point_indices[it->halfedge()->prev()->vertex()->point()]); } }
void ElPoly::DefineSkin(int NSample){ std::list<Weighted_point> l; FT shrinkfactor = 0.5; double *Plot = new double[pNType()*CUBE(NSample)]; double *Count = new double[CUBE(NSample)]; double Thre = 10.; double Radius = pEdge(0)/(double)NSample; for(int p=0;p<pNPart();p++){ int t = pType(p); int vx = (int)(pPos(p,0)/pEdge(0)*NSample); int vy = (int)(pPos(p,1)/pEdge(1)*NSample); int vz = (int)(pPos(p,2)/pEdge(2)*NSample); int vTot = (vz*NSample+vy)*NSample+vx; Plot[vTot*pNType()+t] += 1.; } double *Norm = (double *)calloc(pNType(),sizeof(double)); for(int t=0;t<pNType();t++){ for(int v=0;v<CUBE(NSample);v++){ if(Norm[t] < Plot[v*pNType()+t]) Norm[t] = Plot[v*pNType()+t]; } Norm[t] = Norm[t] <= 0. ? 1. : Norm[t]; } for(int vx=0;vx<NSample;vx++){ double x = vx*pEdge(0)/(double)NSample; for(int vy=0;vy<NSample;vy++){ double y = vy*pEdge(1)/(double)NSample; for(int vz=0;vz<NSample;vz++){ double z = vz*pEdge(2)/(double)NSample; int vTot = (vz*NSample+vy)*NSample+vx; if(Plot[vTot*pNType()] > Thre){ l.push_front(Weighted_point(Bare_point(x,y,z),Radius)); } } } } Polyhedron Polyhe; Skin_surface_3 skin_surface(l.begin(), l.end(), shrinkfactor); CGAL::mesh_skin_surface_3(skin_surface, Polyhe); // CGAL::subdivide_skin_surface_mesh_3(skin_surface, Polyhe); // std::ofstream out("mesh.off"); // out << Polyhe; glDeleteLists(Dr->Particles,1); Dr->Particles = glGenLists(1); glNewList(Dr->Particles,GL_COMPILE); // Polyhedron::Facet_iterator fcUp = Polyhe.facets_begin(); // for(;fcUp != Polyhe.facets_end(); ++fcUp){ // Polyhedron::Supports_facet_halfedge = fcUp.halfedge(); // //Halfedge_around_facet_circulator heUp = fcUp.halfedge(); // } // for (Vertex_iterator vit = Polyhe.vertices_begin();vit != Polyhe.vertices_end(); vit++){ // // Vector n = policy.normal(vit); // // n = n/sqrt(n*n); // cout << vit->point() << std::endl; // Halfedge_iterator heUp = Polyhe.halfedges_begin(); // for(;heUp != Polyhe.halfedges_end(); ++heUp){ // //Polyhedron::Halfedge_handle Half = *heUp; // Vertex_handle veUp = heUp->vertex(); // K::Point_3 pf1 = vit->point(); // } // } CGAL::Inverse_index<Vertex_handle> index(Polyhe.vertices_begin(), Polyhe.vertices_end()); for(Facet_iterator fi = Polyhe.facets_begin();fi != Polyhe.facets_end(); ++fi) { HFC hc = fi->facet_begin(); HFC hc_end = hc; Polyhedron::Vertex_handle vf1 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf2 = (*hc).vertex(); hc++; Polyhedron::Vertex_handle vf3 = (*hc).vertex(); hc++; K::Point_3 pf1 = vf1->point(); K::Point_3 pf2 = vf2->point(); K::Point_3 pf3 = vf3->point(); Vettore v1(pf1.x(),pf1.y(),pf1.z()); Vettore v2(pf2.x(),pf2.y(),pf2.z()); Vettore v3(pf3.x(),pf3.y(),pf3.z()); Vettore vN(3); v1.Mult(InvScaleUn); v2.Mult(InvScaleUn); v3.Mult(InvScaleUn); vN = (v1-v2) ^ (v3-v2); //if(vN.Norm() > 2.*AreaMean) continue; double Sfumatura = .3*Mat->Casuale(); glColor4f(0.1,.4+Sfumatura,0.2,1.); //glColor4f(HueUp[p].r,HueUp[p].g,HueUp[p].b,HueUp[p].a); DrTria(&v1,&v2,&v3,&vN); glColor4f(1.,.0,0.,1.); DrTriaContour(&v1,&v2,&v3); // glPushMatrix();//Particle // glBegin(GL_LINES); // do { // Polyhedron::Vertex_handle vh = (*hc).vertex(); // K::Point_3 pf1 = vh->point(); // glVertex3d(pf1.x(),pf1.y(),pf1.z()); // } while (++hc != hc_end); // glEnd(); // glPopMatrix();//Particle } glEndList(); // Tr tr; // 3D-Delaunay triangulation // C2t3 c2t3 (tr); // 2D-complex in 3D-Delaunay triangulation // Surface_3 surface(sphere_function,Sphere_3(CGAL::ORIGIN, 2.)); // Surface_mesh_default_criteria_3<Tr> criteria(30., 0.1,0.1); // // meshing surface // make_surface_mesh(c2t3, surface, criteria, CGAL::Non_manifold_tag()); // std::cout << "Final number of points: " << tr.number_of_vertices() << "\n"; // DT dt; // for(int c=0;c<Gen->NChain;c++){ // if(CHAIN_IF_TYPE(Ch[c].Type,CHAIN_UP) )continue; // Point_3<K> ChPos(pPos(c,CLat1),pPos(c,CLat2),pPos(c,CNorm)); // dt.insert(ChPos); // } // Face_iterator fcTr = dt.finite_faces_begin(); // glDeleteLists(Dr->Particles,1); // Dr->Particles = glGenLists(1); // glNewList(Dr->Particles,GL_COMPILE); // for(;fcTr != dt.faces_end(); ++fcTr){ // Vertex_handle vf1 = fcTr->vertex(0), // vf2 = fcTr->vertex(1),vf3 = fcTr->vertex(2); // Point pf1 = vf1->point(); // Point pf2 = vf2->point(); // Point pf3 = vf3->point(); // Vettore v1(pf1.x() - pf2.x(),pf1.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore v2(pf3.x() - pf2.x(),pf3.y() - pf2.y(),pf1.z()-pf2.z()); // Vettore vN(3); // vN = v1 ^ v2; // DrTira(v1,v2,v3,vN); // } // glEndList(); }