diff options
author | Marius Kintel <marius@kintel.net> | 2013-03-18 19:04:04 (GMT) |
---|---|---|
committer | Marius Kintel <marius@kintel.net> | 2013-03-18 19:04:04 (GMT) |
commit | 398b44c82a485f7ea5784c84946b7fcb81a9a105 (patch) | |
tree | 7a3decb76520278ce5bb6e25cd446307431141d9 /src/cgalutils.cc | |
parent | eb9139b34ee8e0c5ac9f94f93078165c6e5edd56 (diff) | |
parent | eb8772539cb38691e11ca85215bd2ea16bdddb62 (diff) |
Merge pull request #311 from openscad/resize5
Resize5
Diffstat (limited to 'src/cgalutils.cc')
-rw-r--r-- | src/cgalutils.cc | 55 |
1 files changed, 53 insertions, 2 deletions
diff --git a/src/cgalutils.cc b/src/cgalutils.cc index 51838df..8b4c476 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -147,7 +147,7 @@ CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) { - CGAL_Iso_cuboid_3 result(-1,-1,-1,1,1,1); + CGAL_Iso_cuboid_3 result(0,0,0,0,0,0); CGAL_Nef_polyhedron3::Vertex_const_iterator vi; std::vector<CGAL_Nef_polyhedron3::Point_3> points; // can be optimized by rewriting bounding_box to accept vertices @@ -160,7 +160,7 @@ CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ) { - CGAL_Iso_rectangle_2e result(-1,-1,1,1); + CGAL_Iso_rectangle_2e result(0,0,0,0); CGAL_Nef_polyhedron2::Explorer explorer = N.explorer(); CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator vi; std::vector<CGAL_Point_2e> points; @@ -173,5 +173,56 @@ CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ) return result; } +void ZRemover::visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) +{ + log << " <!-- ZRemover Halffacet visit. Mark: " << hfacet->mark() << " -->\n"; + if ( hfacet->plane().orthogonal_direction() != this->up ) { + log << " <!-- ZRemover down-facing half-facet. skipping -->\n"; + log << " <!-- ZRemover Halffacet visit end-->\n"; + return; + } + + // possible optimization - throw out facets that are vertically oriented + + CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator fci; + int contour_counter = 0; + CGAL_forall_facet_cycles_of( fci, hfacet ) { + if ( fci.is_shalfedge() ) { + log << " <!-- ZRemover Halffacet cycle begin -->\n"; + CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(fci), cend(c1); + std::vector<CGAL_Nef_polyhedron2::Explorer::Point> contour; + CGAL_For_all( c1, cend ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->target()->point(); + CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); + contour.push_back( point2d ); + } + if (contour.size()==0) continue; + + log << " <!-- is_simple_2:" << CGAL::is_simple_2( contour.begin(), contour.end() ) << " --> \n"; + + tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); + + if ( contour_counter == 0 ) { + log << " <!-- contour is a body. make union(). " << contour.size() << " points. -->\n" ; + *(output_nefpoly2d) += *(tmpnef2d); + } else { + log << " <!-- contour is a hole. make intersection(). " << contour.size() << " points. -->\n"; + *(output_nefpoly2d) *= *(tmpnef2d); + } + + /*log << "\n<!-- ======== output tmp nef: ==== -->\n" + << OpenSCAD::dump_svg( *tmpnef2d ) << "\n" + << "\n<!-- ======== output accumulator: ==== -->\n" + << OpenSCAD::dump_svg( *output_nefpoly2d ) << "\n";*/ + + contour_counter++; + } else { + log << " <!-- ZRemover trivial facet cycle skipped -->\n"; + } + log << " <!-- ZRemover Halffacet cycle end -->\n"; + } + log << " <!-- ZRemover Halffacet visit end -->\n"; +} + #endif /* ENABLE_CGAL */ |