mirror of https://github.com/vitalif/openscad
small cleanup - removed redundant dim field
parent
d6ad2c7de1
commit
bc4fae0d85
|
@ -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,34 +50,32 @@ 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);
|
bool err = true;
|
||||||
bool err = true;
|
std::string errmsg("");
|
||||||
std::string errmsg("");
|
CGAL_Polyhedron P;
|
||||||
CGAL_Polyhedron P;
|
try {
|
||||||
try {
|
// Cast away constness:
|
||||||
// Cast away constness:
|
// convert_to_Polyhedron() wasn't const in earlier versions of CGAL.
|
||||||
// convert_to_Polyhedron() wasn't const in earlier versions of CGAL.
|
CGAL_Nef_polyhedron3 *nonconst_nef3 = const_cast<CGAL_Nef_polyhedron3*>(this->p3.get());
|
||||||
CGAL_Nef_polyhedron3 *nonconst_nef3 = const_cast<CGAL_Nef_polyhedron3*>(this->p3.get());
|
err = nefworkaround::convert_to_Polyhedron<CGAL_Kernel3>( *(nonconst_nef3), P );
|
||||||
err = nefworkaround::convert_to_Polyhedron<CGAL_Kernel3>( *(nonconst_nef3), P );
|
//this->p3->convert_to_Polyhedron(P);
|
||||||
//this->p3->convert_to_Polyhedron(P);
|
|
||||||
}
|
|
||||||
catch (const CGAL::Failure_exception &e) {
|
|
||||||
err = true;
|
|
||||||
errmsg = std::string(e.what());
|
|
||||||
}
|
|
||||||
if (!err) err = createPolySetFromPolyhedron(P, *ps);
|
|
||||||
if (err) {
|
|
||||||
PRINT("ERROR: CGAL NefPolyhedron->Polyhedron conversion failed.");
|
|
||||||
if (errmsg!="") PRINTB("ERROR: %s",errmsg);
|
|
||||||
delete ps; ps = NULL;
|
|
||||||
}
|
|
||||||
CGAL::set_error_behaviour(old_behaviour);
|
|
||||||
}
|
}
|
||||||
|
catch (const CGAL::Failure_exception &e) {
|
||||||
|
err = true;
|
||||||
|
errmsg = std::string(e.what());
|
||||||
|
}
|
||||||
|
if (!err) err = createPolySetFromPolyhedron(P, *ps);
|
||||||
|
if (err) {
|
||||||
|
PRINT("ERROR: CGAL NefPolyhedron->Polyhedron conversion failed.");
|
||||||
|
if (errmsg!="") PRINTB("ERROR: %s",errmsg);
|
||||||
|
delete ps; ps = NULL;
|
||||||
|
}
|
||||||
|
CGAL::set_error_behaviour(old_behaviour);
|
||||||
return ps;
|
return ps;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
||||||
|
|
|
@ -38,28 +38,23 @@
|
||||||
|
|
||||||
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();
|
}
|
||||||
}
|
else {
|
||||||
else {
|
CGAL_Aff_transformation t(
|
||||||
CGAL_Aff_transformation t(
|
matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
||||||
matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
|
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
||||||
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
|
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3), matrix(3,3));
|
||||||
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3), matrix(3,3));
|
this->p3->transform(t);
|
||||||
this->p3->transform(t);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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);
|
||||||
|
|
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue