mirror of https://github.com/vitalif/openscad
FIXME leaking polyset by altering functions signatures
parent
f175bae46a
commit
0a2b7ca0d4
|
@ -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) {
|
||||
PRINTB("CGAL error in CGAL_Nef_polyhedron3(): %s", e.what());
|
||||
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("Alternate construction failed. CGAL error in CGAL_Nef_polyhedron3(): %s", e.what());
|
||||
}
|
||||
CGAL::set_error_behaviour(old_behaviour);
|
||||
return CGAL_Nef_polyhedron(N);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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 );
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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.");
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue