summaryrefslogtreecommitdiff
path: root/src/PolySetCGALEvaluator.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2012-10-23 04:44:54 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2012-10-23 04:44:54 (GMT)
commit5b92e171eae66a4be64cdd1b6ec114dbaf8e04e8 (patch)
tree658386bf9f1a959784c7f71a22f0ee7b8113643d /src/PolySetCGALEvaluator.cc
parent30fad0d4e44017c715cd81b807bc14598418e8a5 (diff)
this svg-prints the 'marked' faces as dashed lines, revealing CGAL issues
with mark() and union() operations on Nef Polyhedron 2 objects.
Diffstat (limited to 'src/PolySetCGALEvaluator.cc')
-rw-r--r--src/PolySetCGALEvaluator.cc100
1 files changed, 97 insertions, 3 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";
contact: Jan Huwald // Impressum