diff options
Diffstat (limited to 'src/CGALEvaluator.cc')
-rw-r--r-- | src/CGALEvaluator.cc | 26 |
1 files changed, 21 insertions, 5 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 86118d7..20c5d5e 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -680,16 +680,32 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps) else // not (this->is2d) { CGAL_Nef_polyhedron3 *N = NULL; + bool plane_error = false; CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { - // FIXME: Are we leaking memory for the CGAL_Polyhedron object? - CGAL_Polyhedron *P = createPolyhedronFromPolySet(ps); - if (P) { - N = new CGAL_Nef_polyhedron3(*P); + CGAL_Polyhedron P; + bool err = createPolyhedronFromPolySet(ps,P); + if (!err) N = new CGAL_Nef_polyhedron3(P); + } + catch (const CGAL::Assertion_exception &e) { + if (std::string(e.what()).find("Plane_constructor")!=std::string::npos) { + if (std::string(e.what()).find("has_on")!=std::string::npos) { + PRINT("PolySet has nonplanar faces. Attempting alternate construction"); + plane_error=true; + } + } else { + PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); } } + if (plane_error) try { + PolySet ps2; + CGAL_Polyhedron P; + tessellate_3d_faces( ps, ps2 ); + bool err = createPolyhedronFromPolySet(ps2,P); + if (!err) N = new CGAL_Nef_polyhedron3(P); + } catch (const CGAL::Assertion_exception &e) { - PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); + PRINTB("Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): %s", e.what()); } CGAL::set_error_behaviour(old_behaviour); return CGAL_Nef_polyhedron(N); |