diff options
author | don bright <hugh.m.bright@gmail.com> | 2012-10-19 03:31:37 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2012-10-19 03:31:37 (GMT) |
commit | ddbdd58d16a4e4f0fa15096736922985e458ff99 (patch) | |
tree | b3b01ef08a7f548147e00f518b2bcecd6019f8a3 /src | |
parent | 8191c292b00af4fcfa22c7ab59db9e53e122e10c (diff) |
add OpenSCAD version to about dialog title.
improve SVG debugging output for Nef3 and Nef2 polyhedra.
Diffstat (limited to 'src')
-rw-r--r-- | src/AboutDialog.h | 4 | ||||
-rw-r--r-- | src/PolySetCGALEvaluator.cc | 84 | ||||
-rw-r--r-- | src/cgal.h | 2 | ||||
-rw-r--r-- | src/cgalutils.cc | 110 |
4 files changed, 150 insertions, 50 deletions
diff --git a/src/AboutDialog.h b/src/AboutDialog.h index 34122a0..1ae6533 100644 --- a/src/AboutDialog.h +++ b/src/AboutDialog.h @@ -3,12 +3,16 @@ #include "ui_AboutDialog.h" +#define STRINGIFY(x) #x +#define TOSTRING(x) STRINGIFY(x) + class AboutDialog : public QDialog, public Ui::AboutDialog { Q_OBJECT; public: AboutDialog(QWidget *) { setupUi(this); + this->setWindowTitle( QString("About OpenSCAD ") + QString(TOSTRING( OPENSCAD_VERSION)) ); this->aboutText->setOpenExternalLinks(true); QUrl flattr_qurl(":icons/flattr.png" ); this->aboutText->loadResource( QTextDocument::ImageResource, flattr_qurl ); diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 19f5325..2a002be 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -74,21 +74,78 @@ public: } tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); if ( contour_counter == 0 ) { - if (debug) out << "\ncontour is a body. make union(). " << contour.size() << " points.\n" ; + out << "\n <!-- contour is a body. make union(). " << contour.size() << " points. -->\n" ; *(output_nefpoly2d) += *(tmpnef2d); } else { *(output_nefpoly2d) *= *(tmpnef2d); - if (debug) out << "\ncontour is a hole. make intersection(). " << contour.size() << " points.\n"; + if (debug) out << "\n<!-- contour is a hole. make intersection(). " << contour.size() << " points. -->\n"; } - out << "\n------- tmp: -------\n"; - if (debug) out << dump_cgal_nef_polyhedron2( *tmpnef2d ); - out << "\n------- output accumulator: -------\n"; - if (debug) out << dump_cgal_nef_polyhedron2( *output_nefpoly2d ); + out << "\n<!-- ======== output tmp nef2d: ====== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *tmpnef2d ); + out << "\n<!-- ======== output accumulator: ==== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *output_nefpoly2d ); contour_counter++; } // next facet cycle (i.e. next contour) } // visit() }; + + + +class Flattener2 { +public: + std::stringstream out; + CGAL_Nef_polyhedron2::Boundary boundary; + shared_ptr<CGAL_Nef_polyhedron2> tmpnef2d; + shared_ptr<CGAL_Nef_polyhedron2> output_nefpoly2d; + CGAL::Direction_3<CGAL_Kernel3> up; + bool debug; + Flattener2(bool debug=false) + { + output_nefpoly2d.reset( new CGAL_Nef_polyhedron2() ); + boundary = CGAL_Nef_polyhedron2::INCLUDED; + up = CGAL::Direction_3<CGAL_Kernel3>(0,0,1); + this->debug = debug; + } + std::string dump() + { + return out.str(); + } + 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::Halffacet_const_handle hfacet ) { + int contour_counter = 0; + CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator i; + CGAL_forall_facet_cycles_of( i, hfacet ) { + CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(i), c2(c1); + std::list<CGAL_Nef_polyhedron2::Point> contour; + CGAL_For_all( c1, c2 ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->source()->point(); + CGAL_Nef_polyhedron2::Point point2d( point3d.x(), point3d.y() ); + contour.push_back( point2d ); + } + tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); + out << "\n<!-- ======== output tmp nef2d: ====== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *tmpnef2d ); + if ( contour_counter == 0 ) { + out << "\n <!-- contour is a body. make union(). " << contour.size() << " points. -->\n" ; + *(output_nefpoly2d) += *(tmpnef2d); + } else { + out << "\n <!-- contour is a hole. make intersection(). " << contour.size() << " points. -->\n"; + *(output_nefpoly2d) *= *(tmpnef2d); + } + out << "\n<!-- ======== output accumulator: ==== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *output_nefpoly2d ); + contour_counter++; + } // next facet cycle (i.e. next contour) + } // visit() +}; + + + PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator) : PolySetEvaluator(cgalevaluator.getTree()), cgalevaluator(cgalevaluator) { @@ -115,7 +172,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) } } - // std::cout << "----- input dump \n" << sum.dump_svg() << "\n"; + // std::cout << sum.dump_svg() << std::flush; // input dump CGAL_Nef_polyhedron nef_poly; @@ -160,8 +217,9 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) } // remove z coordinates to make CGAL_Nef_polyhedron2 + std::cout << "<svg width=\"480px\" height=\"100000px\" xmlns=\"http://www.w3.org/2000/svg\" version=\"1.1\">"; try { - Flattener flattener(true); + Flattener2 flattener(true); CGAL_Nef_polyhedron3::Volume_const_iterator i; CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; @@ -171,8 +229,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) sum.p3->visit_shell_objects( sface_handle , flattener ); } } + std::cout << flattener.out.str(); + std::cout << "</svg>" << std::flush; - std::cout << "------- flattener dump \n" << flattener.dump() << "\n"; + //std::cout << "------- flattener dump \n" << flattener.dump() << "\n"; nef_poly.p2 = flattener.output_nefpoly2d; nef_poly.dim = 2; } catch (const CGAL::Failure_exception &e) { @@ -181,8 +241,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) CGAL::set_error_behaviour(old_behaviour); - std::cout << "------- 3d cut dump \n" << sum.dump_svg() << "\n"; - std::cout << "------- 2d output dump \n" << nef_poly.dump_svg() << "\n"; + //std::cout << sum.dump_svg() << std::flush; // cut dump + //std::cout << nef_poly.dump_svg() << std::flush; // post-flattener dump + + //std::cout << "------- 2d output dump \n" << nef_poly.dump_svg() << "\n"; // Extract polygons in the XY plane, ignoring all other polygons // FIXME: If the polyhedron is really thin, there might be unwanted polygons // in the XY plane, causing the resulting 2D polygon to be self-intersection @@ -54,8 +54,6 @@ typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron; typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS; typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder; -typedef CGAL::Cartesian<NT>::Iso_cuboid_3 CGAL_Iso_cuboid_3; - #ifdef PREV_NDEBUG #define NDEBUG PREV_NDEBUG #endif diff --git a/src/cgalutils.cc b/src/cgalutils.cc index b3a9407..10c5bbc 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -6,8 +6,12 @@ #include "cgal.h" #include <CGAL/bounding_box.h> typedef CGAL::Point_3<CGAL_Kernel3> CGAL_Point_3; -typedef CGAL::Point_2<CGAL::Simple_cartesian<NT> > CGAL_Point_2; -typedef CGAL::Simple_cartesian<NT>::Iso_rectangle_2 CGAL_Iso_rectangle_2; +typedef CGAL_Kernel3::Iso_cuboid_3 CGAL_Iso_cuboid_3; + +typedef CGAL_Nef_polyhedron2::Explorer::Point CGAL_Point_2; +// Note- Explorer::Point is incompatible with CGAL::Point_2<CGAL_Kernel2> +typedef CGAL_Kernel2::Iso_rectangle_2 CGAL_Iso_rectangle_2; + #include <boost/algorithm/string.hpp> #include <map> @@ -150,10 +154,9 @@ CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) - CGAL_Point_2 project_svg_3to2( CGAL_Point_3 p, CGAL_Iso_cuboid_3 bbox ) { - // do extremely simple fake isometric projection, based on bounding box + // do simple fake isometric projection, based on bounding box double x = CGAL::to_double( p.x() ); double y = CGAL::to_double( p.y() ); double z = CGAL::to_double( p.z() ); @@ -161,12 +164,12 @@ CGAL_Point_2 project_svg_3to2( CGAL_Point_3 p, CGAL_Iso_cuboid_3 bbox ) double screenh = 480; double xcenter = screenw / 2; double ycenter = screenh / 2; - double xdist = ( 2 * CGAL::to_double( bbox.xmax() - bbox.xmin() ) ); - double ydist = ( 2 * CGAL::to_double( bbox.ymax() - bbox.ymin() ) ); - double zdist = ( 2 * CGAL::to_double( bbox.zmax() - bbox.zmin() ) ); - double xscale = (xdist==0) ? 1 : screenw / (xdist * 1.618); - double yscale = (ydist==0) ? 1 : screenh / (ydist * 1.618 * 3); - double zscale = (zdist==0) ? 1 : screenh / (zdist * 1.618); + double xdist = ( CGAL::to_double( bbox.xmax() - bbox.xmin() ) ); + double ydist = ( CGAL::to_double( bbox.ymax() - bbox.ymin() ) ); + double zdist = ( CGAL::to_double( bbox.zmax() - bbox.zmin() ) ); + double xscale = (xdist==0) ? 1 : screenw / (xdist * 2 * 1.618); + double yscale = (ydist==0) ? 1 : screenh / (ydist * 2 * 1.618 * 3); + double zscale = (zdist==0) ? 1 : screenh / (zdist * 2 * 1.618); double tx = xcenter + x * xscale + y * yscale; double ty = ycenter - z * zscale - y * yscale; return CGAL_Point_2( tx, ty ); @@ -174,29 +177,41 @@ CGAL_Point_2 project_svg_3to2( CGAL_Point_3 p, CGAL_Iso_cuboid_3 bbox ) CGAL_Point_2 project_svg_2to2( CGAL_Point_2 p, CGAL_Iso_rectangle_2 bbox ) { - CGAL_Point_3 origin( 0, 0, 0 ); + // pass thru 3d projection by making 'y' into 'z'. +/* CGAL_Point_3 origin( 0, 0, 0 ); CGAL_Iso_cuboid_3 bbox3d( bbox.xmin(), bbox.ymin(), origin.z(), bbox.xmax(), bbox.ymax(), origin.z() ); CGAL_Point_3 point3d( p.x(), origin.z() , p.y() ); - return project_svg_3to2( point3d, bbox3d ); + return project_svg_3to2( point3d, bbox3d );*/ + double x = CGAL::to_double( p.x() ); + double y = CGAL::to_double( p.y() ); + double screenw = 480; + double screenh = 480; + double borderw = screenw * 0.1618; + double borderh = screenh * 0.1618; + double vizw = screenw - borderw*2; + double vizh = screenh - borderh*2; + double bboxw = 0 ; CGAL::to_double( bbox.xmax() - bbox.xmin() ); + double bboxh = 0 ; CGAL::to_double( bbox.ymax() - bbox.ymin() ); + double xinbox = CGAL::to_double( p.x() ) - CGAL::to_double( bbox.xmin() ); + double yinbox = CGAL::to_double( p.y() ) - CGAL::to_double( bbox.ymin() ); + double tx = borderw + ( xinbox / bboxw ) * ( vizw ); + double ty = borderh + ( yinbox / bboxh ) * ( vizh ); + std::cout << "\nx, y " << x << "," << y << "\n"; + std::cout << "xinb, yinb " << xinbox << "," << yinbox << "\n"; + std::cout << "vizw, vizh " << vizw << "," << vizh << "\n"; + std::cout << "tx, ty " << tx << "," << ty << "\n"; + return CGAL_Point_2( tx, ty ); } // for debugging, not necessarily pretty or useful for users. std::string dump_cgal_nef_polyhedron2_face_svg( CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1, CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2, - CGAL_Nef_polyhedron2::Explorer explorer ) + CGAL_Nef_polyhedron2::Explorer explorer, + CGAL_Iso_rectangle_2 &bbox, + std::string color ) { - std::vector<CGAL_Point_2> points; - CGAL_For_all(c1, c2) - if ( explorer.is_standard( explorer.source( c1 ) ) ) { - points.push_back( explorer.point( explorer.source( c1 ) ) ); - std::cout << points.size() << " point size\n"; - } - CGAL_Iso_rectangle_2 bbox( 0,0,0,0 ); - if ( points.size() > 0 ) - bbox = CGAL::bounding_box( points.begin(), points.end() ); - std::stringstream out; CGAL_For_all(c1, c2) { if ( explorer.is_standard( explorer.target(c1) ) ) { @@ -204,38 +219,59 @@ std::string dump_cgal_nef_polyhedron2_face_svg( CGAL_Point_2 target = explorer.point( explorer.target( c1 ) ); CGAL_Point_2 tp1 = project_svg_2to2( source, bbox ); CGAL_Point_2 tp2 = project_svg_2to2( target, bbox ); - out << " <line" + out << " <line" << " x1='" << CGAL::to_double(tp1.x()) << "'" - << " x2='" << CGAL::to_double(tp1.y()) << "'" - << " y1='" << CGAL::to_double(tp2.x()) << "'" + << " y1='" << CGAL::to_double(tp1.y()) << "'" + << " x2='" << CGAL::to_double(tp2.x()) << "'" << " y2='" << CGAL::to_double(tp2.y()) << "'" - << " stroke='red' />\n"; + << " stroke='" << color << "' />\n"; + // crude "arrowhead" to indicate directionality + out << " <circle" + << " cx='" << CGAL::to_double(tp1.x()+ (tp2.x()-tp1.x())* 7/8) << "'" + << " cy='" << CGAL::to_double(tp1.y()+ (tp2.y()-tp1.y())* 7/8) << "'" + << " r='2'" + << " fill='" << color << "' stroke='" << color << "' />\n"; + } } return out.str(); } +static int svgcounter=0; + std::string dump_cgal_nef_polyhedron2_svg( const CGAL_Nef_polyhedron2 &N ) { std::stringstream out; CGAL_Nef_polyhedron2::Explorer explorer = N.explorer(); + CGAL_Iso_rectangle_2 bbox = CGAL::bounding_box ( explorer.points_begin(), explorer.points_end() ); + + out << " <!-- bounding box: " + << CGAL::to_double( bbox.xmin() ) << "," + << CGAL::to_double( bbox.ymin() ) << " " + << CGAL::to_double( bbox.xmax() ) << "," + << CGAL::to_double( bbox.ymax() ) << " " + << "-->\n"; + CGAL_Nef_polyhedron2::Explorer::Face_const_iterator i; - out << "<svg width='480px' height='480px' xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"; - out << "<polyline points='0,0 480,0 480,480 0,480' style='fill:none;stroke:black' />\n"; - out << "<polyline points='10,455 10,475 10,465 18,465 2,465 10,465 14,461 6,469 10,465' style='fill:none;stroke:black;' />"; + out << " <svg y='" << svgcounter << "' width='480px' height='480px' xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"; + out << " <polyline points='0,0 480,0 480,480 0,480' style='fill:none;stroke:black' />\n"; + out << " <polyline points='10,455 10,475 10,465 18,465 2,465 10,465 14,461 6,469 10,465' style='fill:none;stroke:black;' />\n"; + svgcounter+=480; + if ((svgcounter/480)%2==0) svgcounter += 24; for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) { + out << " <!-- body face begin -->\n"; CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1 = explorer.face_cycle( i ), c2 ( c1 ); - out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer ); + out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, bbox, "red" ); + out << " <!-- body face end -->\n"; -/* - holes not implemented CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j; for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) { + out << " <!-- hole face begin -->\n"; CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 ); - out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer ); + out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, bbox, "green" ); + out << " <!-- hole face end -->\n"; } -*/ } out << "</svg>"; std::string tmp = out.str(); @@ -302,7 +338,7 @@ class NefPoly3_dumper_svg { public: std::stringstream out; CGAL_Iso_cuboid_3 bbox; - NefPoly3_dumper_svg(const CGAL_Nef_polyhedron3& N) {} + NefPoly3_dumper_svg(const CGAL_Nef_polyhedron3& N) { } void setbbox( CGAL_Iso_cuboid_3 bbox ) { this->bbox = bbox; } void visit(CGAL_Nef_polyhedron3::Vertex_const_handle v) {} void visit(CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} @@ -349,7 +385,7 @@ std::string dump_cgal_nef_polyhedron3_svg( const CGAL_Nef_polyhedron3 &N ) std::stringstream out; out << "<svg width='480px' height='480px' xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"; out << "<polyline points='0,0 480,0 480,480 0,480' style='fill:none;stroke:black' />\n"; - out << "<polyline points='10,455 10,475 10,465 18,465 2,465 10,465 14,461 6,469 10,465' style='fill:none;stroke:black;' />"; + out << "<polyline points='10,455 10,475 10,465 18,465 2,465 10,465 14,461 6,469 10,465' style='fill:none;stroke:black;' />\n"; out << "<!--CGAL_Nef_polyhedron3 dump begin-->\n"; std::vector<CGAL_Point_3> points; |