small cleanup - removed redundant dim field

527olive
Marius Kintel 2013-12-29 00:37:49 -05:00
parent d6ad2c7de1
commit bc4fae0d85
5 changed files with 46 additions and 62 deletions

View File

@ -6,37 +6,31 @@
CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p) CGAL_Nef_polyhedron::CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p)
{ {
if (p) { if (p) p3.reset(p);
dim = 3;
p3.reset(p);
}
else {
dim = 0;
}
} }
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other) CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other)
{ {
if (this->dim == 3) (*this->p3) += (*other.p3); (*this->p3) += (*other.p3);
return *this; return *this;
} }
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator*=(const CGAL_Nef_polyhedron &other) CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator*=(const CGAL_Nef_polyhedron &other)
{ {
if (this->dim == 3) (*this->p3) *= (*other.p3); (*this->p3) *= (*other.p3);
return *this; return *this;
} }
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator-=(const CGAL_Nef_polyhedron &other) CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator-=(const CGAL_Nef_polyhedron &other)
{ {
if (this->dim == 3) (*this->p3) -= (*other.p3); (*this->p3) -= (*other.p3);
return *this; return *this;
} }
CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other) CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other)
{ {
if (this->dim == 3) (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3); (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3);
return *this; return *this;
} }
@ -45,7 +39,7 @@ size_t CGAL_Nef_polyhedron::memsize() const
if (this->isEmpty()) return 0; if (this->isEmpty()) return 0;
size_t memsize = sizeof(CGAL_Nef_polyhedron); size_t memsize = sizeof(CGAL_Nef_polyhedron);
if (this->dim == 3) memsize += this->p3->bytes(); memsize += this->p3->bytes();
return memsize; return memsize;
} }
@ -56,9 +50,8 @@ size_t CGAL_Nef_polyhedron::memsize() const
*/ */
PolySet *CGAL_Nef_polyhedron::convertToPolyset() const PolySet *CGAL_Nef_polyhedron::convertToPolyset() const
{ {
if (this->isEmpty()) return new PolySet(this->dim); if (this->isEmpty()) return new PolySet(3);
PolySet *ps = NULL; PolySet *ps = NULL;
if (this->dim == 3) {
CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION); CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION);
ps = new PolySet(3); ps = new PolySet(3);
ps->setConvexity(this->convexity); ps->setConvexity(this->convexity);
@ -83,7 +76,6 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset() const
delete ps; ps = NULL; delete ps; ps = NULL;
} }
CGAL::set_error_behaviour(old_behaviour); CGAL::set_error_behaviour(old_behaviour);
}
return ps; return ps;
} }

View File

@ -10,19 +10,18 @@
class CGAL_Nef_polyhedron : public Geometry class CGAL_Nef_polyhedron : public Geometry
{ {
public: public:
CGAL_Nef_polyhedron(int dim = 0) : dim(dim) {} CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p = NULL);
CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p);
~CGAL_Nef_polyhedron() {} ~CGAL_Nef_polyhedron() {}
virtual size_t memsize() const; virtual size_t memsize() const;
// FIXME: Implement, but we probably want a high-resolution BBox.. // FIXME: Implement, but we probably want a high-resolution BBox..
virtual BoundingBox getBoundingBox() const { assert(false && "not implemented"); } virtual BoundingBox getBoundingBox() const { assert(false && "not implemented"); }
virtual std::string dump() const; virtual std::string dump() const;
virtual unsigned int getDimension() const { return this->dim; } virtual unsigned int getDimension() const { return 3; }
// Empty means it is a geometric node which has zero area/volume // Empty means it is a geometric node which has zero area/volume
virtual bool isEmpty() const { return !p3; } virtual bool isEmpty() const { return !p3; }
void reset() { dim=0; p3.reset(); } void reset() { p3.reset(); }
CGAL_Nef_polyhedron &operator+=(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron &operator+=(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron &operator*=(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron &operator*=(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other); CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other);
@ -31,8 +30,6 @@ public:
class PolySet *convertToPolyset() const; class PolySet *convertToPolyset() const;
void transform( const Transform3d &matrix ); void transform( const Transform3d &matrix );
shared_ptr<CGAL_Nef_polyhedron3> p3; shared_ptr<CGAL_Nef_polyhedron3> p3;
protected:
int dim;
}; };
#endif #endif

View File

@ -38,17 +38,13 @@
std::string CGAL_Nef_polyhedron::dump() const std::string CGAL_Nef_polyhedron::dump() const
{ {
if (this->dim==3)
return OpenSCAD::dump_svg( *this->p3 ); return OpenSCAD::dump_svg( *this->p3 );
else
return std::string("Nef Polyhedron with dimension != 2 or 3");
} }
void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) void CGAL_Nef_polyhedron::transform( const Transform3d &matrix )
{ {
if (!this->isEmpty()) { if (!this->isEmpty()) {
if (this->dim == 3) {
if (matrix.matrix().determinant() == 0) { if (matrix.matrix().determinant() == 0) {
PRINT("Warning: Scaling a 3D object with 0 - removing object"); PRINT("Warning: Scaling a 3D object with 0 - removing object");
this->reset(); this->reset();
@ -62,6 +58,5 @@ void CGAL_Nef_polyhedron::transform( const Transform3d &matrix )
} }
} }
} }
}
#endif // ENABLE_CGAL #endif // ENABLE_CGAL

View File

@ -103,7 +103,7 @@ GeometryEvaluator::ResultObject GeometryEvaluator::applyToChildren3D(const Abstr
const shared_ptr<const Geometry> &chgeom = item.second; const shared_ptr<const Geometry> &chgeom = item.second;
shared_ptr<const CGAL_Nef_polyhedron> chN; shared_ptr<const CGAL_Nef_polyhedron> chN;
if (!chgeom) { if (!chgeom) {
chN.reset(new CGAL_Nef_polyhedron(3)); // Create null polyhedron chN.reset(new CGAL_Nef_polyhedron); // Create null polyhedron
} }
else { else {
chN = dynamic_pointer_cast<const CGAL_Nef_polyhedron>(chgeom); chN = dynamic_pointer_cast<const CGAL_Nef_polyhedron>(chgeom);

View File

@ -402,7 +402,7 @@ void ZRemover::visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet )
static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps) static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps)
{ {
assert(ps.getDimension() == 3); assert(ps.getDimension() == 3);
if (ps.isEmpty()) return new CGAL_Nef_polyhedron(3); if (ps.isEmpty()) return new CGAL_Nef_polyhedron();
CGAL_Nef_polyhedron3 *N = NULL; CGAL_Nef_polyhedron3 *N = NULL;
bool plane_error = false; bool plane_error = false;