diff options
author | Don Bright <hugh.m.bright@gmail.com> | 2013-12-14 23:20:35 (GMT) |
---|---|---|
committer | Don Bright <hugh.m.bright@gmail.com> | 2013-12-14 23:20:35 (GMT) |
commit | 0a2b7ca0d4d7fb1acda9996d69b25ff6b5495856 (patch) | |
tree | 465fb326c433297bb88182de7f215ff21925cf5f | |
parent | f175bae46a8f15823780c5a9c89b11476acb3107 (diff) |
FIXME leaking polyset by altering functions signatures
-rw-r--r-- | src/CGALEvaluator.cc | 24 | ||||
-rw-r--r-- | src/CGAL_Nef_polyhedron.cc | 5 | ||||
-rw-r--r-- | src/cgalutils.h | 4 | ||||
-rw-r--r-- | src/dxftess-cgal.cc | 16 | ||||
-rw-r--r-- | src/dxftess.h | 1 | ||||
-rw-r--r-- | src/import.cc | 3 | ||||
-rw-r--r-- | src/polyset.h | 1 |
7 files changed, 44 insertions, 10 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index ec01315..26d3e4c 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -668,16 +668,30 @@ 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; + createPolyhedronFromPolySet(ps,P); + N = new CGAL_Nef_polyhedron3(P); + } + catch (const CGAL::Assertion_exception &e) { + if (std::string(e.what()).find("Plane_constructor")!=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_faces( ps, ps2 ); + createPolyhedronFromPolySet(ps2,P); + 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); diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc index 440f4ed..2d5bba5 100644 --- a/src/CGAL_Nef_polyhedron.cc +++ b/src/CGAL_Nef_polyhedron.cc @@ -97,11 +97,14 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() else if (this->dim == 3) { CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); try { + ps = new PolySet(); CGAL_Polyhedron P; this->p3->convert_to_Polyhedron(P); - ps = createPolySetFromPolyhedron(P); + bool err = createPolySetFromPolyhedron(P, ps); + if (err) delete ps; } catch (const CGAL::Precondition_exception &e) { + delete ps; PRINTB("CGAL error in CGAL_Nef_polyhedron::convertToPolyset(): %s", e.what()); } CGAL::set_error_behaviour(old_behaviour); diff --git a/src/cgalutils.h b/src/cgalutils.h index d25fd4c..50b819a 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -2,8 +2,8 @@ #define CGALUTILS_H_ #include <cgal.h> -class PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p); -CGAL_Polyhedron *createPolyhedronFromPolySet(const class PolySet &ps); +bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, class PolySet &ps); +bool createPolyhedronFromPolySet(const class PolySet &ps, class CGAL_Polyhedron &p); CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ); CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ); diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc index 16eaf9f..a3ebccf 100644 --- a/src/dxftess-cgal.cc +++ b/src/dxftess-cgal.cc @@ -335,3 +335,19 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool u dxf.paths[path[2]].is_inner = !up; } } + +void triangulate_polygon( const PolySet::Polygon &pgon, std::vector<PolySet::Polygon> &triangles ) +{ +} + +/* given a 3d PolySet with 'near planar' faces, triangulate the faces +so CGAL Nef Polyhedron will accept them. */ +void tessellate_3d_faces( PolySet &inps, PolySet &outps ) { + for (size_t i = 0; i < inps.polygons.size(); i++) { + const PolySet::Polygon *pgon = &inps.polygons[i]; + for (size_t j = 0; j < pgon->size(); j++) { + Vector3d v = pgon->at(j); + } + } +} + diff --git a/src/dxftess.h b/src/dxftess.h index f0f27b5..3d96747 100644 --- a/src/dxftess.h +++ b/src/dxftess.h @@ -7,5 +7,6 @@ class DxfData; class PolySet; void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, Vector2d scale, bool up, bool do_triangle_splitting, double h); void dxf_border_to_ps(PolySet *ps, const DxfData &dxf); +void tessellate_3d_faces( PolySet &inps, PolySet &outps ); #endif diff --git a/src/import.cc b/src/import.cc index 3897331..af905fc 100644 --- a/src/import.cc +++ b/src/import.cc @@ -284,7 +284,8 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const file >> poly; file.close(); - p = createPolySetFromPolyhedron(poly); + p = new PolySet(); + bool err = createPolySetFromPolyhedron(poly, *p); } #else PRINT("WARNING: OFF import requires CGAL."); diff --git a/src/polyset.h b/src/polyset.h index 6626f79..5c97396 100644 --- a/src/polyset.h +++ b/src/polyset.h @@ -26,7 +26,6 @@ public: void append_vertex(double x, double y, double z = 0.0); void insert_vertex(double x, double y, double z = 0.0); size_t memsize() const; - BoundingBox getBoundingBox() const; #define CSGMODE_DIFFERENCE_FLAG 0x10 |