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; }
void transform_big(Nef_polyhedron& N,int n, int s) { Vertex_const_iterator vi(N.vertices_begin()); x_min = vi->point().hx()/vi->point().hw(); x_max = vi->point().hx()/vi->point().hw(); y_min = vi->point().hy()/vi->point().hw(); y_max = vi->point().hy()/vi->point().hw(); z_min = vi->point().hz()/vi->point().hw(); z_max = vi->point().hz()/vi->point().hw(); for(;vi != N.vertices_end();++vi) { if(vi->point().hx()/vi->point().hw() < x_min) x_min = vi->point().hx()/vi->point().hw(); if(vi->point().hx()/vi->point().hw() > x_max) x_max = vi->point().hx()/vi->point().hw(); if(vi->point().hy()/vi->point().hw() < y_min) y_min = vi->point().hy()/vi->point().hw(); if(vi->point().hy()/vi->point().hw() > y_max) y_max = vi->point().hy()/vi->point().hw(); if(vi->point().hz()/vi->point().hw() < z_min) z_min = vi->point().hz()/vi->point().hw(); if(vi->point().hz()/vi->point().hw() > z_max) z_max = vi->point().hz()/vi->point().hw(); } // x_min-=(x_min<=0?0:1); // y_min-=(y_min<=0?0:1); // z_max+=(z_max<=0?1:0); N.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(-x_min,-y_min,-z_max))); N.transform(Aff_transformation_3(CGAL::SCALING, n*s+2,x_max-x_min)); N.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(0,0,s/2))); }
int main(int argc, char* argv[]) { assert(argc>1 && argc < 7); int nx = argc>2 ? std::atoi(argv[2]) : 2; int ny = argc>3 ? std::atoi(argv[3]) : 2; int nz = argc>4 ? std::atoi(argv[4]) : 2; std::ifstream in(argv[1]); Nef_polyhedron Nin; in >> Nin; Nin.transform(Aff_transformation_3(CGAL::SCALING,2,1)); std::ostringstream out1; ggen g(out1, Nin); g.print(nx,ny,nz); std::istringstream in1(out1.str()); Nef_polyhedron N1; in1 >> N1; RT s = g.size_x(); N1.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(s,s,s,2))); CGAL_assertion(N1.is_valid()); std::ostringstream out2; CGAL::Random r; if(argc>5) { tgen t2(out2,s,std::atoi(argv[5])); t2.create_tetrahedra(nx+1,ny+1,nz+1); } else { tgen t2(out2,s); t2.create_tetrahedra(nx+1,ny+1,nz+1); } std::istringstream in2(out2.str()); Nef_polyhedron N2; in2 >> N2; CGAL_assertion(N2.is_valid()); cgal_nef3_timer_on = true; #if defined CGAL_NEF3_UNION N1.join(N2); #elif defined CGAL_NEF3_INTERSECTION N1.intersection(N2); #elif defined CGAL_NEF3_DIFFERENCE N1.difference(N2); #else N1.symmetric_difference(N2); #endif }
void transform_form(const Nef_polyhedron& N, Nef_polyhedron& F) { Vertex_const_iterator vi(N.vertices_begin()); x_max = CGAL_NTS abs(vi->point().hx()/vi->point().hw()); y_max = CGAL_NTS abs(vi->point().hy()/vi->point().hw()); z_max = CGAL_NTS abs(vi->point().hz()/vi->point().hw()); for(; vi != N.vertices_end(); ++vi) { if(CGAL_NTS abs(vi->point().hx()/vi->point().hw()) > x_max) x_max = CGAL_NTS abs(vi->point().hx()/vi->point().hw()); if(CGAL_NTS abs(vi->point().hy()/vi->point().hw()) > y_max) y_max = CGAL_NTS abs(vi->point().hy()/vi->point().hw()); if(CGAL_NTS abs(vi->point().hz()/vi->point().hw()) > z_max) z_max = CGAL_NTS abs(vi->point().hz()/vi->point().hw()); } x_max*105/100; y_max*105/100; z_max*105/100; F.transform(Aff_transformation_3(x_max,0,0, 0,y_max,0, 0,0,z_max, 1)); F.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(0,0,z_max))); }
void transform_small(Nef_polyhedron& N, int s, int l, int x, int y) { N.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3(-x_min,-y_min,-z_min))); N.transform(Aff_transformation_3(CGAL::SCALING, s*l, x_max-x_min)); N.transform(Aff_transformation_3(CGAL::TRANSLATION, Vector_3((2*x+1)*s/2,(2*y+1)*s/2,s/4))); }
int main(int argc, char* argv[]) { // We've put the typedefs here as VC7 gives us an ICE if they are global typedefs typedef Nef_polyhedron::SNC_structure SNC_structure; typedef CGAL::visual_hull_creator<SNC_structure> VHC; if(argc!=2) { std::cerr << "Usage: visual_hull file" << std::endl; std::cerr << "For more information read the README file" << std::endl; return 1; } std::ifstream in(argv[1]); NaryInt ni; CGAL::Timer t; Point_3 room_min = read_point(in); Point_3 room_max = read_point(in); int ncameras; in >> ncameras; for(int cam=0; cam<ncameras; ++cam) { Point_3 camera(read_point(in)); int npolygons; in >> npolygons; std::list<std::list<Point_3> > polygon_list; for(int poly=0; poly<npolygons; ++poly) { int npoints; in >> npoints; std::list<Point_3> input_points; for(int pnt=0; pnt<npoints; ++pnt) input_points.push_back(read_point(in)); polygon_list.push_back(input_points); } std::list<std::list<Point_3> >::iterator li; for(li=polygon_list.begin(); li!=polygon_list.end(); ++li) { std::list<Point_3>::iterator pi(li->begin()), pimin(pi), pi_next,pi_prev; for(; pi!=li->end(); ++pi) { if(CGAL::lexicographically_xyz_smaller(*pi,*pimin)) pimin=pi; } pi_next=pi_prev=pimin; ++pi_next; if(pi_next==li->end()) pi_next=li->begin(); if(pi_prev==li->begin()) pi_prev=li->end(); --pi_prev; if(CGAL::orientation(*pi_prev,*pimin,*pi_next,camera) == CGAL::POSITIVE) li->reverse(); } t.start(); Nef_polyhedron N; VHC vhc(room_min, room_max, camera, polygon_list); N.delegate(vhc,true); CGAL_assertion(N.is_valid()); t.stop(); std::cerr << "create view " << t.time() << std::endl; t.reset(); ni.add_polyhedron(N); } Nef_polyhedron result = ni.get_intersection(); QApplication a(argc,argv); CGAL::Qt_widget_Nef_3<Nef_polyhedron>* w = new CGAL::Qt_widget_Nef_3<Nef_polyhedron>(result); a.setMainWidget(w); w->show(); a.exec(); }
int main(int argc, char *argv[]) { int c; while (EOF != (c = getopt(argc, argv, "dPXACSp:"))) switch (c) { case 'd': if (debuglevel == LOG_DEBUG) { debuglevel++; } else { debuglevel = LOG_DEBUG; } break; case 'P': support_enable = false; break; case 'X': axes_enable = false; break; case 'A': axessupport_enable = false; break; case 'C': characteristics_enable = false; break; case 'S': solution_enable = false; break; case 'p': prefix = std::string(optarg); break; } Nef_nary_union unioner; // solution try { if (solution_enable) { unioner.add_polyhedron(build_solution(thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s", x.what()); } // characteristics try { if (characteristics_enable) { unioner.add_polyhedron(build_characteristics()); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add charactistics: %s", x.what()); } // add the cut support try { if (support_enable) { unioner.add_polyhedron( build_cutsupport(2 * thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add cut supports: %s", x.what()); } // add the axes support try { if (axessupport_enable) { unioner.add_polyhedron( build_axessupport(thickness)); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes supports: %s", x.what()); } // axes try { if (axes_enable) { unioner.add_polyhedron(build_axes()); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add axes: %s", x.what()); } // extract debug(LOG_DEBUG, DEBUG_LOG, 0, "extracting image"); Nef_polyhedron image = unioner.get_union(); // output debug(LOG_DEBUG, DEBUG_LOG, 0, "convert for output"); Polyhedron P; image.convert_to_polyhedron(P); std::cout << P; // output halves if (prefix.size() > 0) { PartWriter pw(prefix); pw(PartWriter::BACK_PART, image, offset); pw(PartWriter::FRONT_PART, image, offset); pw(PartWriter::LEFT_PART, image, offset); pw(PartWriter::RIGHT_PART, image, offset); pw(PartWriter::TOP_PART, image, offset); pw(PartWriter::BOTTOM_PART, image, offset); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed"); } debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete"); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { assert(argc>1 && argc < 7); int nx = argc>2 ? std::atoi(argv[2]) : 2; int ny = argc>3 ? std::atoi(argv[3]) : 2; int nz = argc>4 ? std::atoi(argv[4]) : 2; std::ifstream in(argv[1]); Nef_polyhedron Nin; in >> Nin; Nin.transform(Aff_transformation_3(CGAL::SCALING,2,1)); std::ostringstream out1; ggen g(out1, Nin); g.print(nx,ny,nz); std::istringstream in1(out1.str()); Nef_polyhedron N1; in1 >> N1; RT s = g.size_x(); N1.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(s,s,s,2))); CGAL_assertion(N1.is_valid()); std::ostringstream out2; CGAL::Random r; if(argc>5) { tgen t2(out2,s,std::atoi(argv[5])); t2.create_tetrahedra(nx+1,ny+1,nz+1); } else { tgen t2(out2,s); t2.create_tetrahedra(nx+1,ny+1,nz+1); } std::istringstream in2(out2.str()); Nef_polyhedron N2; in2 >> N2; CGAL_assertion(N2.is_valid()); char* dir="nef3/"; char* tetrahedra="tetrahedra"; char* grid="grid"; char* suffix=".nef3"; char* us="_"; char* full_suffix = new char[strlen(argv[2])+strlen(argv[3])+strlen(argv[4])+strlen(argv[5])+strlen(suffix)+5]; strcpy(full_suffix, us); strcat(full_suffix, argv[2]); strcat(full_suffix, us); strcat(full_suffix, argv[3]); strcat(full_suffix, us); strcat(full_suffix, argv[4]); strcat(full_suffix, us); strcat(full_suffix, argv[5]); strcat(full_suffix, suffix); char* full_tetrahedra = new char[strlen(dir)+strlen(tetrahedra)+strlen(full_suffix)+1]; strcpy(full_tetrahedra, dir); strcat(full_tetrahedra, tetrahedra); strcat(full_tetrahedra, full_suffix); std::ofstream out_tetrahedra(full_tetrahedra); out_tetrahedra << N2; char* full_grid = new char[strlen(dir)+strlen(grid)+strlen(full_suffix)+1]; strcpy(full_grid, dir); strcat(full_grid, grid); strcat(full_grid, full_suffix); std::ofstream out_grid(full_grid); out_grid << N1; }
/** * \brief main function for example6 */ int main(int argc, char *argv[]) { int c; while (EOF != (c = getopt(argc, argv, "dSACIXNPFxp:"))) switch (c) { case 'd': if (debuglevel == LOG_DEBUG) { debuglevel++; } else { debuglevel = LOG_DEBUG; } break; case 'S': show_solution = !show_solution; break; case 'A': show_alternatives = !show_alternatives; break; case 'C': show_characteristics = !show_characteristics; break; case 'I': show_initial = !show_initial; break; case 'X': show_axes = !show_axes; break; case 'N': show_negative = !show_negative; break; case 'F': show_fcurve = !show_fcurve; break; case 'P': show_support = !show_support; break; case 'p': prefix = std::string(optarg); break; case 'x': yzslicing = false; break; } debug(LOG_DEBUG, DEBUG_LOG, 0, "nonuniqueness of solution of a " "partial differential equation"); // start building up the union of things to be restricted to a box Nef_nary_union unioner; // create a the solution surface try { if (show_solution) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding solution surface"); unioner.add_polyhedron(build_solution(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "solution surface added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add solution: %s", x.what()); } // create an alternative solution surface try { if (show_alternatives) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding alternatives"); unioner.add_polyhedron(build_alternative(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "alternatives added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add alternatives: %s", x.what()); } // add additional characteristics try { if (show_characteristics) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding characteristics"); unioner.add_polyhedron(build_characteristics()); debug(LOG_DEBUG, DEBUG_LOG, 0, "characteristics added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add characteristics: %s", x.what()); } // add negative characteristics try { if (show_negative) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding neg characteristics"); unioner.add_polyhedron(build_xcharacteristics()); debug(LOG_DEBUG, DEBUG_LOG, 0, "neg characteristics added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add negative characteristics: %s", x.what()); } // add the FCurve try { if (show_fcurve) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding fcurve"); unioner.add_polyhedron(build_fcurve()); debug(LOG_DEBUG, DEBUG_LOG, 0, "fcurve added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add fcurve: %s", x.what()); } // add the support sheet try { if (show_support) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding support"); unioner.add_polyhedron(build_support(sheetthickness)); debug(LOG_DEBUG, DEBUG_LOG, 0, "support added"); } } catch (std::exception& x) { debug(LOG_ERR, DEBUG_LOG, 0, "failed to add support: %s", x.what()); } // add the initial curve if (show_initial) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding initial curve"); unioner.add_polyhedron(build_initialcurve()); debug(LOG_DEBUG, DEBUG_LOG, 0, "initial curve added"); } // extract union debug(LOG_DEBUG, DEBUG_LOG, 0, "extract the image component union"); Nef_polyhedron image = unioner.get_union(); debug(LOG_DEBUG, DEBUG_LOG, 0, "base image constructed"); // restrict everything to a box debug(LOG_DEBUG, DEBUG_LOG, 0, "restrict to a box"); Build_Box box(point(-0.1, -2, -2), point(4, 2, 2)); Polyhedron boxp; boxp.delegate(box); image = image * boxp; debug(LOG_DEBUG, DEBUG_LOG, 0, "restriction complete"); // add axes if (show_axes) { debug(LOG_DEBUG, DEBUG_LOG, 0, "adding axes"); image = image + build_axes(); debug(LOG_DEBUG, DEBUG_LOG, 0, "axes added"); } // output Polyhedron P; debug(LOG_DEBUG, DEBUG_LOG, 0, "convert to polyhedron for output"); image.convert_to_polyhedron(P); std::cout << P; // write parts if (prefix.size() > 0) { PartWriter pw(prefix); pw(PartWriter::LEFT_PART, image); pw(PartWriter::RIGHT_PART, image); pw(PartWriter::FRONT_PART, image); pw(PartWriter::BACK_PART, image); } else { debug(LOG_DEBUG, DEBUG_LOG, 0, "part output suppressed"); } // that's it debug(LOG_DEBUG, DEBUG_LOG, 0, "output complete"); return EXIT_SUCCESS; }
int main(int argc, char* argv[]) { assert(argc>1 && argc < 8); int nx = argc>2 ? std::atoi(argv[2]) : 2; int ny = argc>3 ? std::atoi(argv[3]) : 2; int nz = argc>4 ? std::atoi(argv[4]) : 2; int n = argc>5 ? std::atoi(argv[5]) : 2; std::ifstream in(argv[1]); Nef_polyhedron Nin; in >> Nin; Nin.transform(Aff_transformation_3(CGAL::SCALING,100,1)); std::ostringstream out1; ggen g(out1, Nin); g.print(nx,ny,nz); std::istringstream in1(out1.str()); Nef_polyhedron N1; in1 >> N1; RT s = g.size_x(); N1.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(s,s,s,2))); CGAL_assertion(N1.is_valid()); std::ostringstream out2; if(argc>6) { tgen t2(out2,s,std::atoi(argv[6])); t2.create_tetrahedra(nx+1,ny+1,nz+1); } else { tgen t2(out2,s); t2.create_tetrahedra(nx+1,ny+1,nz+1); } std::istringstream in2(out2.str()); Nef_polyhedron N2; in2 >> N2; CGAL_assertion(N2.is_valid()); #if defined CGAL_NEF3_UNION N1=N1.join(N2); #elif defined CGAL_NEF3_INTERSECTION N1=N1.intersection(N2); #elif defined CGAL_NEF3_DIFFERENCE N1=N1.difference(N2); #else N1=N1.symmetric_difference(N2); #endif RT b=s*(nx+1); N1.transform(Aff_transformation_3(CGAL::TRANSLATION,Vector_3(-b,-b,-b,2))); CGAL::Timer pl; pl.start(); Point_source P(CGAL::to_double(b)/2); for(int i=0;i<n;++i) { N1.locate(*P++); } pl.stop(); std::cout << "Input_size: " << N1.number_of_vertices() << std::endl; std::cout << "Number_of_point_location_queries: " << n << std::endl; std::cout << "Total_runtime: " << pl.time() << std::endl; std::cout << "Runtime_per_query: " << pl.time()/n << std::endl; }