2011-09-01 06:09:06 +04:00
|
|
|
#include "CGAL_Nef_polyhedron.h"
|
2011-08-22 21:31:56 +04:00
|
|
|
#include "cgal.h"
|
2011-09-08 00:04:59 +04:00
|
|
|
#include "cgalutils.h"
|
2011-08-22 21:31:56 +04:00
|
|
|
#include "polyset.h"
|
2011-09-06 16:57:24 +04:00
|
|
|
#include "dxfdata.h"
|
|
|
|
#include "dxftess.h"
|
2011-09-01 06:09:06 +04:00
|
|
|
#include <CGAL/minkowski_sum_3.h>
|
|
|
|
|
|
|
|
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other)
|
|
|
|
{
|
2011-09-01 22:03:35 +04:00
|
|
|
if (this->dim == 2) (*this->p2) += (*other.p2);
|
|
|
|
else if (this->dim == 3) (*this->p3) += (*other.p3);
|
2011-09-01 06:09:06 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator*=(const CGAL_Nef_polyhedron &other)
|
|
|
|
{
|
2011-09-01 22:03:35 +04:00
|
|
|
if (this->dim == 2) (*this->p2) *= (*other.p2);
|
|
|
|
else if (this->dim == 3) (*this->p3) *= (*other.p3);
|
2011-09-01 06:09:06 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator-=(const CGAL_Nef_polyhedron &other)
|
|
|
|
{
|
2011-09-01 22:03:35 +04:00
|
|
|
if (this->dim == 2) (*this->p2) -= (*other.p2);
|
|
|
|
else if (this->dim == 3) (*this->p3) -= (*other.p3);
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
extern CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL_Nef_polyhedron2 &b);
|
|
|
|
|
|
|
|
CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other)
|
|
|
|
{
|
|
|
|
if (this->dim == 2) (*this->p2) = minkowski2(*this->p2, *other.p2);
|
|
|
|
else if (this->dim == 3) (*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3);
|
2011-09-01 06:09:06 +04:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
int CGAL_Nef_polyhedron::weight() const
|
|
|
|
{
|
2011-09-01 22:03:35 +04:00
|
|
|
if (this->dim == 2) return this->p2->explorer().number_of_vertices();
|
|
|
|
if (this->dim == 3) return this->p3->number_of_vertices();
|
2011-09-01 06:09:06 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2011-08-22 21:31:56 +04:00
|
|
|
|
|
|
|
/*!
|
|
|
|
Creates a new PolySet and initializes it with the data from this polyhedron
|
2011-08-25 00:25:15 +04:00
|
|
|
|
|
|
|
This method is not const since convert_to_Polyhedron() wasn't const
|
|
|
|
in earlier versions of CGAL.
|
2011-08-22 21:31:56 +04:00
|
|
|
*/
|
2011-08-25 00:25:15 +04:00
|
|
|
PolySet *CGAL_Nef_polyhedron::convertToPolyset()
|
2011-08-22 21:31:56 +04:00
|
|
|
{
|
2011-09-06 16:57:24 +04:00
|
|
|
assert(!this->empty());
|
2011-09-08 00:04:59 +04:00
|
|
|
PolySet *ps = NULL;
|
2011-09-06 16:57:24 +04:00
|
|
|
if (this->dim == 2) {
|
2011-09-08 00:04:59 +04:00
|
|
|
ps = new PolySet();
|
2011-09-06 16:57:24 +04:00
|
|
|
DxfData *dd = this->convertToDxfData();
|
|
|
|
ps->is2d = true;
|
|
|
|
dxf_tesselate(ps, *dd, 0, true, false, 0);
|
|
|
|
dxf_border_to_ps(ps, *dd);
|
|
|
|
delete dd;
|
|
|
|
}
|
|
|
|
else if (this->dim == 3) {
|
|
|
|
CGAL_Polyhedron P;
|
|
|
|
this->p3->convert_to_Polyhedron(P);
|
2011-09-08 00:04:59 +04:00
|
|
|
ps = createPolySetFromPolyhedron(P);
|
2011-08-22 21:31:56 +04:00
|
|
|
}
|
|
|
|
return ps;
|
|
|
|
}
|
2011-09-01 06:09:06 +04:00
|
|
|
|
2011-09-01 22:03:35 +04:00
|
|
|
/*!
|
|
|
|
Deep copy
|
|
|
|
*/
|
|
|
|
CGAL_Nef_polyhedron CGAL_Nef_polyhedron::copy() const
|
2011-09-01 06:09:06 +04:00
|
|
|
{
|
2011-09-01 22:03:35 +04:00
|
|
|
CGAL_Nef_polyhedron copy = *this;
|
|
|
|
if (copy.p2) copy.p2 = new CGAL_Nef_polyhedron2(*copy.p2);
|
|
|
|
else if (copy.p3) copy.p3 = new CGAL_Nef_polyhedron3(*copy.p3);
|
|
|
|
return copy;
|
2011-09-01 06:09:06 +04:00
|
|
|
}
|