diff options
author | don bright <hugh.m.bright@gmail.com> | 2012-10-23 04:44:54 (GMT) |
---|---|---|
committer | don bright <hugh.m.bright@gmail.com> | 2012-10-23 04:44:54 (GMT) |
commit | 5b92e171eae66a4be64cdd1b6ec114dbaf8e04e8 (patch) | |
tree | 658386bf9f1a959784c7f71a22f0ee7b8113643d | |
parent | 30fad0d4e44017c715cd81b807bc14598418e8a5 (diff) |
this svg-prints the 'marked' faces as dashed lines, revealing CGAL issues
with mark() and union() operations on Nef Polyhedron 2 objects.
-rw-r--r-- | src/PolySetCGALEvaluator.cc | 100 | ||||
-rw-r--r-- | src/cgalutils.cc | 40 |
2 files changed, 125 insertions, 15 deletions
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 11f19c1..78c4c5f 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -17,6 +17,7 @@ #include "openscad.h" // get_fragments_from_r() #include <boost/foreach.hpp> #include <vector> +#include <deque> typedef CGAL_Nef_polyhedron3::Point_3 Point_3; @@ -57,6 +58,7 @@ public: 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 ) { + out.str(""); out << " <!-- Halffacet visit -->\n"; out << " <!-- mark:" << hfacet->mark() << " -->\n"; if ( hfacet->plane().orthogonal_direction() != this->up ) { @@ -96,6 +98,96 @@ public: }; + +class Flattener2 { +public: + std::ostringstream 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 ) { + out.str(""); + out << " <!-- Halffacet visit -->\n"; + out << " <!-- mark:" << hfacet->mark() << " -->\n"; + if ( hfacet->plane().orthogonal_direction() != this->up ) { + out << "\ndown facing half-facet. skipping\n"; + out << " <!-- Halffacet visit end-->\n"; + std::cout << out.str(); + return; + } + + bool skip=false; + 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); + CGAL_For_all( c1, c2 ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->source()->point(); + if (point3d.z()!=0) skip=true; + } + } + if (skip) { + out << "\n facet not on zero plane. skipping\n"; + out << " <!-- Halffacet visit end-->\n"; + std::cout << out.str(); + return; + } + + int contour_counter = 0; + CGAL_forall_facet_cycles_of( i, hfacet ) { + CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(i), c2(c1); + std::vector<CGAL_Nef_polyhedron2::Explorer::Point> contour; + CGAL_For_all( c1, c2 ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->source()->point(); + CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); + contour.push_back( point2d ); + } + + tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); + + out << "\n<!-- ======== output accumulator 0: ==== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *output_nefpoly2d ); + + if ( contour_counter == 0 ) { + out << "\n <!-- contour is a body. make union(). " << contour.size() << " points. -->\n" ; + *(output_nefpoly2d) += *(tmpnef2d); + } else { + *(output_nefpoly2d) *= *(tmpnef2d); + if (debug) out << "\n<!-- contour is a hole. make intersection(). " << contour.size() << " points. -->\n"; + } + + out << "\n<!-- ======== output tmp nef2d: ====== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *tmpnef2d ); + out << "\n<!-- ======== output accumulator 1: ==== -->\n"; + out << dump_cgal_nef_polyhedron2_svg( *output_nefpoly2d ); + + contour_counter++; + } // next facet cycle (i.e. next contour) + out << " <!-- Halffacet visit end -->\n"; + std::cout << out.str(); + } // visit() +}; + + + + PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator) : PolySetEvaluator(cgalevaluator.getTree()), cgalevaluator(cgalevaluator) { @@ -169,7 +261,7 @@ 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; @@ -177,8 +269,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) std::cout << "<!-- volume. mark: " << i->mark() << " -->\n"; for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { std::cout << "<!-- shell. mark: " << i->mark() << " -->\n"; - sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); - sum.p3->visit_shell_objects( sface_handle , flattener ); +// if (i->mark()==1) { + sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); + sum.p3->visit_shell_objects( sface_handle , flattener ); +// } std::cout << "<!-- shell. end. -->\n"; } std::cout << "<!-- volume end. -->\n"; diff --git a/src/cgalutils.cc b/src/cgalutils.cc index 2932c9c..347fdd5 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -161,6 +161,12 @@ std::string svg_header() return out.str(); } +std::string svg_label(std::string s) +{ + std::stringstream out; + out << "<text fill='black' x='20' y='40' font-size='24'>" << s << "</text>"; + return out.str(); +} std::string svg_border() { std::stringstream out; @@ -263,6 +269,7 @@ std::string dump_cgal_nef_polyhedron2_face_svg( CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2, CGAL_Nef_polyhedron2::Explorer explorer, std::string color, + bool mark, CGAL_Iso_rectangle_2 bbox ) { std::stringstream out; @@ -272,16 +279,21 @@ 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 ); + double mod=0; + if (color=="green") mod=10; + out << " <!-- mark: " << c1->mark() << " -->\n"; out << " <line" - << " x1='" << CGAL::to_double(tp1.x()) << "'" - << " y1='" << CGAL::to_double(tp1.y()) << "'" - << " x2='" << CGAL::to_double(tp2.x()) << "'" - << " y2='" << CGAL::to_double(tp2.y()) << "'" - << " stroke='" << color << "' />\n"; + << " x1='" << CGAL::to_double(tp1.x()) + mod << "'" + << " y1='" << CGAL::to_double(tp1.y()) - mod << "'" + << " x2='" << CGAL::to_double(tp2.x()) + mod << "'" + << " y2='" << CGAL::to_double(tp2.y()) - mod << "'" + << " stroke='" << color << "'"; + if (mark) out << " stroke-dasharray='4 4' />\n"; + else out << " />\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) << "'" + << " cx='" << CGAL::to_double(tp1.x()+ (tp2.x()-tp1.x())* 7/8) + mod << "'" + << " cy='" << CGAL::to_double(tp1.y()+ (tp2.y()-tp1.y())* 7/8) - mod << "'" << " r='2'" << " fill='" << color << "' stroke='" << color << "' />\n"; } @@ -300,18 +312,22 @@ std::string dump_cgal_nef_polyhedron2_svg( const CGAL_Nef_polyhedron2 &N ) out << " <svg y='" << svg_counter << "' width='480px' height='480px' xmlns='http://www.w3.org/2000/svg' version='1.1'>\n"; out << svg_border() << "\n" << svg_axes() << "\n"; svg_counter+=480; - if ((svg_counter/480)%2==0) svg_counter += 24; + if ((svg_counter/480)%3==0) svg_counter += 24; + if ((svg_counter/480)%3==1) out << svg_label("old accumulator") << "\n"; + if ((svg_counter/480)%3==2) out << svg_label("new nef poly") << "\n"; + if ((svg_counter/480)%3==0) out << svg_label("new accumulator") << "\n"; + for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) { - out << " <!-- face begin -->\n"; + out << " <!-- face begin. mark: " << i->mark() << " -->\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, "red", bbox ); + out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, "red", i->mark(), bbox ); CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j; for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) { - out << " <!-- hole begin -->\n"; + out << " <!-- hole begin. mark: " << j->mark() << " -->\n"; CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 ); - out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", bbox ); + out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", j->mark(), bbox ); out << " <!-- hole end -->\n"; } out << " <!-- face end -->\n"; |