diff --git a/src/export.cc b/src/export.cc index 7e7c6c61..36d70368 100644 --- a/src/export.cc +++ b/src/export.cc @@ -64,6 +64,9 @@ void exportFile(const class Geometry *root_geom, std::ostream &output, FileForma case OPENSCAD_DXF: assert(false && "Export Nef polyhedron as DXF not supported"); break; + case OPENSCAD_NEFDBG: + output << N->dump(); + break; default: assert(false && "Unknown file format"); } @@ -80,6 +83,9 @@ void exportFile(const class Geometry *root_geom, std::ostream &output, FileForma case OPENSCAD_AMF: export_amf(*ps, output); break; + case OPENSCAD_NEFDBG: + PRINT("Not a CGALNefPoly. Add some CSG ops."); + break; default: assert(false && "Unsupported file format"); } diff --git a/src/export.h b/src/export.h index 095c0c07..0cf7377f 100644 --- a/src/export.h +++ b/src/export.h @@ -12,7 +12,8 @@ enum FileFormat { OPENSCAD_OFF, OPENSCAD_AMF, OPENSCAD_DXF, - OPENSCAD_SVG + OPENSCAD_SVG, + OPENSCAD_NEFDBG }; // void exportFile(const class Geometry *root_geom, std::ostream &output, FileFormat format); diff --git a/src/openscad.cc b/src/openscad.cc index ed5b25cd..8c4ac8e8 100644 --- a/src/openscad.cc +++ b/src/openscad.cc @@ -344,6 +344,7 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c const char *ast_output_file = NULL; const char *term_output_file = NULL; const char *echo_output_file = NULL; + const char *nefdbg_output_file = NULL; std::string suffix = boosty::extension_str( output_file ); boost::algorithm::to_lower( suffix ); @@ -358,6 +359,7 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c else if (suffix == ".ast") ast_output_file = output_file; else if (suffix == ".term") term_output_file = output_file; else if (suffix == ".echo") echo_output_file = output_file; + else if (suffix == ".nefdbg") nefdbg_output_file = output_file; else { PRINTB("Unknown suffix for output file %s\n", output_file); return 1; @@ -540,6 +542,11 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c fstream.close(); } } + + if (nefdbg_output_file) { + if (!checkAndExport(root_geom, 3, OPENSCAD_NEFDBG, nefdbg_output_file)) + return 1; + } #else PRINT("OpenSCAD has been compiled without CGAL support!\n"); return 1; diff --git a/src/svg.cc b/src/svg.cc index 855ceb12..2bb82a4d 100644 --- a/src/svg.cc +++ b/src/svg.cc @@ -16,7 +16,9 @@ std::string svg_header( int widthpx, int heightpx ) { std::stringstream out; out << ""; + << " xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"; + out << "\n"; + out << "\n"; return out.str(); } @@ -189,6 +191,92 @@ std::string dump_svg( const CGAL_Nef_polyhedron2 &N ) return tmp; } +std::string point_dump( CGAL_Point_3 p ) +{ + std::stringstream out; + out << CGAL::to_double(p.x()) << "," + << CGAL::to_double(p.y()) << "," + << CGAL::to_double(p.z()); + return out.str(); +} + +std::string point_dump( CGAL::Sphere_point p ) +{ + std::stringstream out; + out << CGAL::to_double(p.x()) << "," + << CGAL::to_double(p.y()) << "," + << CGAL::to_double(p.z()); + return out.str(); +} + +std::string vert_dump( CGAL_Nef_polyhedron3::Vertex_const_handle vch ) +{ + return point_dump( vch->point() ); +} + +std::string vert_dump( CGAL_Nef_polyhedron3::Nef_polyhedron_S2::SVertex_const_handle vch ) +{ + return point_dump( vch->point() ); +} + +/* +Dump the 'sphere map' of every vertex in a CGAL Nef Polyhedron3 +see http://doc.cgal.org/latest/Nef_3/index.html +*/ +std::string sphere_map_dump( const CGAL_Nef_polyhedron3& N) +{ + std::stringstream out; + typedef CGAL_Nef_polyhedron3::Vertex_const_iterator Vertex_const_iterator; + typedef CGAL_Nef_polyhedron3::Nef_polyhedron_S2 Nef_polyhedron_S2; + typedef Nef_polyhedron_S2::SVertex_const_handle SVertex_const_handle; + typedef Nef_polyhedron_S2::SHalfedge_const_handle SHalfedge_const_handle; + typedef Nef_polyhedron_S2::SHalfloop_const_handle SHalfloop_const_handle; + typedef Nef_polyhedron_S2::SFace_const_iterator SFace_const_iterator; + typedef Nef_polyhedron_S2::SFace_cycle_const_iterator SFace_cycle_const_iterator; + Vertex_const_iterator v; + out << "\n"; + int counter = 0; + for (v = N.vertices_begin(); v!= N.vertices_end(); v++ ) { + counter++; + out << "\n"; + Nef_polyhedron_S2 S(N.get_sphere_map(v)); + + out << " vertex sphere map info\n"; + out << " number of svertices: " << S.number_of_svertices() << std::endl; + out << " number of shalfedges: " << S.number_of_shalfedges() << std::endl; + out << " number of shalfloops: " << S.number_of_shalfloops() << std::endl; + out << " number of sfaces: " << S.number_of_sfaces() << std::endl; + out << " number of sface cycles: " << S.number_of_sface_cycles() << std::endl; + out << " connected_components: " << S.number_of_connected_components() << "\n"; + out << " integrity check...(asserts if not OK)\n"; + S.check_integrity_and_topological_planarity(); +// S.print_statistics( out ); + int i=0; + SFace_const_iterator sf; + for(sf = S.sfaces_begin(); sf != S.sfaces_end(); sf++) { + SFace_cycle_const_iterator it; + out << " the sface cycles of sface " << i++ << " start with an\n"; + for(it = sf->sface_cycles_begin(); it != sf->sface_cycles_end(); it++) { + if (it.is_svertex()) + out << " svertex at position " + << vert_dump( SVertex_const_handle(it) ) << "\n"; + else if (it.is_shalfedge()) + out << " shalfedge from " + << vert_dump( SHalfedge_const_handle(it)->source() ) << " to " + << vert_dump( SHalfedge_const_handle(it)->target() ) << std::endl; + else if (it.is_shalfloop()) + out << " shalfloop lying in the plane " + << SHalfloop_const_handle(it)->circle() << std::endl; + else + out << " unknown bug\n"; + } + } + out << "\n vertex sphere map end -->\n"; + } + out << "\n"; + return out.str(); +} // This uses the Shell Explorer pattern from the CGAL Manual to dump the 3d Nef Polyhedron information // http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html#Subsection_29.7.2 @@ -200,11 +288,27 @@ public: { bbox = CGALUtils::boundingBox(N); } - void visit(CGAL_Nef_polyhedron3::Vertex_const_handle ) {} - void visit(CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} - void visit(CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} - void visit(CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} - void visit(CGAL_Nef_polyhedron3::SFace_const_handle ) {} + void visit(CGAL_Nef_polyhedron3::Vertex_const_handle vch) + { + CGAL_Point_3 p = vch->point(); + out << " \n"; + } + void visit(CGAL_Nef_polyhedron3::Halfedge_const_handle ) + { + out << " \n"; + } + void visit(CGAL_Nef_polyhedron3::SHalfedge_const_handle ) + { + out << " \n"; + } + void visit(CGAL_Nef_polyhedron3::SHalfloop_const_handle ) + { + out << " \n"; + } + void visit(CGAL_Nef_polyhedron3::SFace_const_handle ) + { + out << " \n"; + } void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { int contour_count = 0; @@ -254,6 +358,18 @@ std::string dump_svg( const CGAL_Nef_polyhedron3 &N ) out << "\n"; out << svg_header() << "\n" << svg_border() << "\n"; out << svg_styleblock( linewidth ) << "\n" << svg_axes() << "\n"; + out << "\n\n"; + out << "\n"; + out << sphere_map_dump( N ); CGAL_Nef_polyhedron3::Volume_const_iterator c; CGAL_forall_volumes(c,N) {