2011-07-31 03:58:51 +04:00
|
|
|
#include "PolySetCGALEvaluator.h"
|
2011-09-01 06:09:06 +04:00
|
|
|
#include "cgal.h"
|
2011-09-09 07:53:05 +04:00
|
|
|
#include "cgalutils.h"
|
2010-03-29 05:31:47 +04:00
|
|
|
#include "polyset.h"
|
2011-07-31 03:58:51 +04:00
|
|
|
#include "CGALEvaluator.h"
|
2010-03-29 05:31:47 +04:00
|
|
|
#include "projectionnode.h"
|
|
|
|
#include "dxflinextrudenode.h"
|
|
|
|
#include "dxfrotextrudenode.h"
|
2011-09-06 16:57:24 +04:00
|
|
|
#include "cgaladvnode.h"
|
2011-09-06 20:31:22 +04:00
|
|
|
#include "rendernode.h"
|
2010-03-29 05:31:47 +04:00
|
|
|
#include "dxfdata.h"
|
|
|
|
#include "dxftess.h"
|
|
|
|
#include "module.h"
|
|
|
|
|
|
|
|
#include "printutils.h"
|
|
|
|
#include "openscad.h" // get_fragments_from_r()
|
2011-09-04 22:35:23 +04:00
|
|
|
#include <boost/foreach.hpp>
|
2010-03-29 05:31:47 +04:00
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator)
|
|
|
|
: PolySetEvaluator(cgalevaluator.getTree()), cgalevaluator(cgalevaluator)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2011-09-09 07:53:05 +04:00
|
|
|
}
|
2010-04-12 04:16:36 +04:00
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
|
|
|
|
{
|
2011-09-06 22:37:07 +04:00
|
|
|
// Before projecting, union all children
|
|
|
|
CGAL_Nef_polyhedron sum;
|
|
|
|
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
|
|
|
|
if (v->modinst->tag_background) continue;
|
|
|
|
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
|
2011-09-07 04:33:16 +04:00
|
|
|
if (N.dim == 3) {
|
|
|
|
if (sum.empty()) sum = N.copy();
|
|
|
|
else sum += N;
|
|
|
|
}
|
2011-09-06 22:37:07 +04:00
|
|
|
}
|
2011-09-07 02:10:21 +04:00
|
|
|
if (sum.empty()) return NULL;
|
2010-03-29 05:31:47 +04:00
|
|
|
|
|
|
|
PolySet *ps = new PolySet();
|
|
|
|
ps->convexity = node.convexity;
|
|
|
|
ps->is2d = true;
|
|
|
|
|
|
|
|
if (node.cut_mode)
|
|
|
|
{
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet cube;
|
2010-03-29 05:31:47 +04:00
|
|
|
double infval = 1e8, eps = 0.1;
|
|
|
|
double x1 = -infval, x2 = +infval, y1 = -infval, y2 = +infval, z1 = 0, z2 = eps;
|
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
cube.append_poly(); // top
|
|
|
|
cube.append_vertex(x1, y1, z2);
|
|
|
|
cube.append_vertex(x2, y1, z2);
|
|
|
|
cube.append_vertex(x2, y2, z2);
|
|
|
|
cube.append_vertex(x1, y2, z2);
|
|
|
|
|
|
|
|
cube.append_poly(); // bottom
|
|
|
|
cube.append_vertex(x1, y2, z1);
|
|
|
|
cube.append_vertex(x2, y2, z1);
|
|
|
|
cube.append_vertex(x2, y1, z1);
|
|
|
|
cube.append_vertex(x1, y1, z1);
|
|
|
|
|
|
|
|
cube.append_poly(); // side1
|
|
|
|
cube.append_vertex(x1, y1, z1);
|
|
|
|
cube.append_vertex(x2, y1, z1);
|
|
|
|
cube.append_vertex(x2, y1, z2);
|
|
|
|
cube.append_vertex(x1, y1, z2);
|
|
|
|
|
|
|
|
cube.append_poly(); // side2
|
|
|
|
cube.append_vertex(x2, y1, z1);
|
|
|
|
cube.append_vertex(x2, y2, z1);
|
|
|
|
cube.append_vertex(x2, y2, z2);
|
|
|
|
cube.append_vertex(x2, y1, z2);
|
|
|
|
|
|
|
|
cube.append_poly(); // side3
|
|
|
|
cube.append_vertex(x2, y2, z1);
|
|
|
|
cube.append_vertex(x1, y2, z1);
|
|
|
|
cube.append_vertex(x1, y2, z2);
|
|
|
|
cube.append_vertex(x2, y2, z2);
|
|
|
|
|
|
|
|
cube.append_poly(); // side4
|
|
|
|
cube.append_vertex(x1, y2, z1);
|
|
|
|
cube.append_vertex(x1, y1, z1);
|
|
|
|
cube.append_vertex(x1, y1, z2);
|
|
|
|
cube.append_vertex(x1, y2, z2);
|
|
|
|
CGAL_Nef_polyhedron Ncube = this->cgalevaluator.evaluateCGALMesh(cube);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
|
|
|
// N.p3 *= CGAL_Nef_polyhedron3(CGAL_Plane(0, 0, 1, 0), CGAL_Nef_polyhedron3::INCLUDED);
|
2011-09-06 22:37:07 +04:00
|
|
|
sum *= Ncube;
|
|
|
|
if (!sum.p3->is_simple()) {
|
2010-03-29 05:31:47 +04:00
|
|
|
PRINTF("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design..");
|
|
|
|
goto cant_project_non_simple_polyhedron;
|
|
|
|
}
|
|
|
|
|
2011-09-06 22:37:07 +04:00
|
|
|
PolySet *ps3 = sum.convertToPolyset();
|
2010-03-29 05:31:47 +04:00
|
|
|
Grid2d<int> conversion_grid(GRID_COARSE);
|
2011-08-05 04:11:20 +04:00
|
|
|
for (size_t i = 0; i < ps3->polygons.size(); i++) {
|
|
|
|
for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
|
|
|
|
double x = ps3->polygons[i][j][0];
|
|
|
|
double y = ps3->polygons[i][j][1];
|
|
|
|
double z = ps3->polygons[i][j][2];
|
2010-03-29 05:31:47 +04:00
|
|
|
if (z != 0)
|
|
|
|
goto next_ps3_polygon_cut_mode;
|
|
|
|
if (conversion_grid.align(x, y) == i+1)
|
|
|
|
goto next_ps3_polygon_cut_mode;
|
|
|
|
conversion_grid.data(x, y) = i+1;
|
|
|
|
}
|
|
|
|
ps->append_poly();
|
2011-08-05 04:11:20 +04:00
|
|
|
for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
|
|
|
|
double x = ps3->polygons[i][j][0];
|
|
|
|
double y = ps3->polygons[i][j][1];
|
2010-03-29 05:31:47 +04:00
|
|
|
conversion_grid.align(x, y);
|
|
|
|
ps->insert_vertex(x, y);
|
|
|
|
}
|
|
|
|
next_ps3_polygon_cut_mode:;
|
|
|
|
}
|
2011-09-09 07:53:05 +04:00
|
|
|
delete ps3;
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2011-09-06 22:37:07 +04:00
|
|
|
if (!sum.p3->is_simple()) {
|
2010-03-29 05:31:47 +04:00
|
|
|
PRINTF("WARNING: Body of projection(cut = false) isn't valid 2-manifold! Modify your design..");
|
|
|
|
goto cant_project_non_simple_polyhedron;
|
|
|
|
}
|
|
|
|
|
2011-09-06 22:37:07 +04:00
|
|
|
PolySet *ps3 = sum.convertToPolyset();
|
2010-03-29 05:31:47 +04:00
|
|
|
CGAL_Nef_polyhedron np;
|
2011-08-05 04:11:20 +04:00
|
|
|
for (size_t i = 0; i < ps3->polygons.size(); i++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
|
|
|
int min_x_p = -1;
|
|
|
|
double min_x_val = 0;
|
2011-08-05 04:11:20 +04:00
|
|
|
for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
|
|
|
|
double x = ps3->polygons[i][j][0];
|
2010-03-29 05:31:47 +04:00
|
|
|
if (min_x_p < 0 || x < min_x_val) {
|
|
|
|
min_x_p = j;
|
|
|
|
min_x_val = x;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
int min_x_p1 = (min_x_p+1) % ps3->polygons[i].size();
|
|
|
|
int min_x_p2 = (min_x_p+ps3->polygons[i].size()-1) % ps3->polygons[i].size();
|
2011-08-05 04:11:20 +04:00
|
|
|
double ax = ps3->polygons[i][min_x_p1][0] - ps3->polygons[i][min_x_p][0];
|
|
|
|
double ay = ps3->polygons[i][min_x_p1][1] - ps3->polygons[i][min_x_p][1];
|
2010-03-29 05:31:47 +04:00
|
|
|
double at = atan2(ay, ax);
|
2011-08-05 04:11:20 +04:00
|
|
|
double bx = ps3->polygons[i][min_x_p2][0] - ps3->polygons[i][min_x_p][0];
|
|
|
|
double by = ps3->polygons[i][min_x_p2][1] - ps3->polygons[i][min_x_p][1];
|
2010-03-29 05:31:47 +04:00
|
|
|
double bt = atan2(by, bx);
|
|
|
|
|
|
|
|
double eps = 0.000001;
|
|
|
|
if (fabs(at - bt) < eps || (fabs(ax) < eps && fabs(ay) < eps) ||
|
|
|
|
(fabs(bx) < eps && fabs(by) < eps)) {
|
|
|
|
// this triangle is degenerated in projection
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::list<CGAL_Nef_polyhedron2::Point> plist;
|
2011-08-05 04:11:20 +04:00
|
|
|
for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
|
|
|
|
double x = ps3->polygons[i][j][0];
|
|
|
|
double y = ps3->polygons[i][j][1];
|
2010-03-29 05:31:47 +04:00
|
|
|
CGAL_Nef_polyhedron2::Point p = CGAL_Nef_polyhedron2::Point(x, y);
|
|
|
|
if (at > bt)
|
|
|
|
plist.push_front(p);
|
|
|
|
else
|
|
|
|
plist.push_back(p);
|
|
|
|
}
|
2011-09-02 23:37:43 +04:00
|
|
|
// FIXME: Should the CGAL_Nef_polyhedron2 be cached?
|
|
|
|
if (np.empty()) {
|
|
|
|
np.dim = 2;
|
|
|
|
np.p2 = new CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
(*np.p2) += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
|
|
|
|
}
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
2011-09-09 07:53:05 +04:00
|
|
|
delete ps3;
|
2011-09-01 06:09:06 +04:00
|
|
|
DxfData *dxf = np.convertToDxfData();
|
2011-09-01 19:03:34 +04:00
|
|
|
dxf_tesselate(ps, *dxf, 0, true, false, 0);
|
2011-09-04 00:44:41 +04:00
|
|
|
dxf_border_to_ps(ps, *dxf);
|
2011-09-01 06:09:06 +04:00
|
|
|
delete dxf;
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
cant_project_non_simple_polyhedron:
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2011-09-04 00:44:41 +04:00
|
|
|
static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path, double rot1, double rot2, double h1, double h2)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t j = 1; j < path.indices.size(); j++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
|
|
|
int k = j - 1;
|
|
|
|
|
2011-09-04 00:44:41 +04:00
|
|
|
double jx1 = dxf.points[path.indices[j]][0] * cos(rot1*M_PI/180) + dxf.points[path.indices[j]][1] * sin(rot1*M_PI/180);
|
|
|
|
double jy1 = dxf.points[path.indices[j]][0] * -sin(rot1*M_PI/180) + dxf.points[path.indices[j]][1] * cos(rot1*M_PI/180);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
2011-09-04 00:44:41 +04:00
|
|
|
double jx2 = dxf.points[path.indices[j]][0] * cos(rot2*M_PI/180) + dxf.points[path.indices[j]][1] * sin(rot2*M_PI/180);
|
|
|
|
double jy2 = dxf.points[path.indices[j]][0] * -sin(rot2*M_PI/180) + dxf.points[path.indices[j]][1] * cos(rot2*M_PI/180);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
2011-09-04 00:44:41 +04:00
|
|
|
double kx1 = dxf.points[path.indices[k]][0] * cos(rot1*M_PI/180) + dxf.points[path.indices[k]][1] * sin(rot1*M_PI/180);
|
|
|
|
double ky1 = dxf.points[path.indices[k]][0] * -sin(rot1*M_PI/180) + dxf.points[path.indices[k]][1] * cos(rot1*M_PI/180);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
2011-09-04 00:44:41 +04:00
|
|
|
double kx2 = dxf.points[path.indices[k]][0] * cos(rot2*M_PI/180) + dxf.points[path.indices[k]][1] * sin(rot2*M_PI/180);
|
|
|
|
double ky2 = dxf.points[path.indices[k]][0] * -sin(rot2*M_PI/180) + dxf.points[path.indices[k]][1] * cos(rot2*M_PI/180);
|
2010-03-29 05:31:47 +04:00
|
|
|
|
|
|
|
double dia1_len_sq = (jy1-ky2)*(jy1-ky2) + (jx1-kx2)*(jx1-kx2);
|
|
|
|
double dia2_len_sq = (jy2-ky1)*(jy2-ky1) + (jx2-kx1)*(jx2-kx1);
|
|
|
|
|
|
|
|
if (dia1_len_sq > dia2_len_sq)
|
|
|
|
{
|
|
|
|
ps->append_poly();
|
2011-09-04 00:44:41 +04:00
|
|
|
if (path.is_inner) {
|
2010-03-29 05:31:47 +04:00
|
|
|
ps->append_vertex(kx1, ky1, h1);
|
|
|
|
ps->append_vertex(jx1, jy1, h1);
|
|
|
|
ps->append_vertex(jx2, jy2, h2);
|
|
|
|
} else {
|
|
|
|
ps->insert_vertex(kx1, ky1, h1);
|
|
|
|
ps->insert_vertex(jx1, jy1, h1);
|
|
|
|
ps->insert_vertex(jx2, jy2, h2);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps->append_poly();
|
2011-09-04 00:44:41 +04:00
|
|
|
if (path.is_inner) {
|
2010-03-29 05:31:47 +04:00
|
|
|
ps->append_vertex(kx2, ky2, h2);
|
|
|
|
ps->append_vertex(kx1, ky1, h1);
|
|
|
|
ps->append_vertex(jx2, jy2, h2);
|
|
|
|
} else {
|
|
|
|
ps->insert_vertex(kx2, ky2, h2);
|
|
|
|
ps->insert_vertex(kx1, ky1, h1);
|
|
|
|
ps->insert_vertex(jx2, jy2, h2);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
ps->append_poly();
|
2011-09-04 00:44:41 +04:00
|
|
|
if (path.is_inner) {
|
2010-03-29 05:31:47 +04:00
|
|
|
ps->append_vertex(kx1, ky1, h1);
|
|
|
|
ps->append_vertex(jx1, jy1, h1);
|
|
|
|
ps->append_vertex(kx2, ky2, h2);
|
|
|
|
} else {
|
|
|
|
ps->insert_vertex(kx1, ky1, h1);
|
|
|
|
ps->insert_vertex(jx1, jy1, h1);
|
|
|
|
ps->insert_vertex(kx2, ky2, h2);
|
|
|
|
}
|
|
|
|
|
|
|
|
ps->append_poly();
|
2011-09-04 00:44:41 +04:00
|
|
|
if (path.is_inner) {
|
2010-03-29 05:31:47 +04:00
|
|
|
ps->append_vertex(jx2, jy2, h2);
|
|
|
|
ps->append_vertex(kx2, ky2, h2);
|
|
|
|
ps->append_vertex(jx1, jy1, h1);
|
|
|
|
} else {
|
|
|
|
ps->insert_vertex(jx2, jy2, h2);
|
|
|
|
ps->insert_vertex(kx2, ky2, h2);
|
|
|
|
ps->insert_vertex(jx1, jy1, h1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
|
|
|
DxfData *dxf;
|
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
if (node.filename.empty())
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2010-11-03 21:26:06 +03:00
|
|
|
// Before extruding, union all (2D) children nodes
|
|
|
|
// to a single DxfData, then tesselate this into a PolySet
|
2011-09-02 22:19:17 +04:00
|
|
|
CGAL_Nef_polyhedron sum;
|
2011-09-04 22:35:23 +04:00
|
|
|
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
|
2010-11-03 21:26:06 +03:00
|
|
|
if (v->modinst->tag_background) continue;
|
2011-09-02 22:19:17 +04:00
|
|
|
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
|
2011-09-07 01:59:08 +04:00
|
|
|
if (N.dim != 2) {
|
|
|
|
PRINT("ERROR: rotate_extrude() is not defined for 3D child objects!");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (sum.empty()) sum = N.copy();
|
|
|
|
else sum += N;
|
|
|
|
}
|
2010-11-03 21:26:06 +03:00
|
|
|
}
|
|
|
|
|
2011-09-07 01:59:08 +04:00
|
|
|
if (sum.empty()) return NULL;
|
2011-09-02 22:19:17 +04:00
|
|
|
dxf = sum.convertToDxfData();;
|
2010-03-29 05:31:47 +04:00
|
|
|
} else {
|
2011-09-04 00:44:41 +04:00
|
|
|
dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:03:34 +04:00
|
|
|
PolySet *ps = extrudeDxfData(node, *dxf);
|
|
|
|
delete dxf;
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
|
|
|
PolySet *PolySetCGALEvaluator::extrudeDxfData(const DxfLinearExtrudeNode &node, DxfData &dxf)
|
|
|
|
{
|
2010-03-29 05:31:47 +04:00
|
|
|
PolySet *ps = new PolySet();
|
|
|
|
ps->convexity = node.convexity;
|
|
|
|
|
|
|
|
double h1, h2;
|
|
|
|
|
|
|
|
if (node.center) {
|
|
|
|
h1 = -node.height/2.0;
|
|
|
|
h2 = +node.height/2.0;
|
|
|
|
} else {
|
|
|
|
h1 = 0;
|
|
|
|
h2 = node.height;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool first_open_path = true;
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t i = 0; i < dxf.paths.size(); i++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2011-09-01 19:03:34 +04:00
|
|
|
if (dxf.paths[i].is_closed)
|
2010-03-29 05:31:47 +04:00
|
|
|
continue;
|
|
|
|
if (first_open_path) {
|
|
|
|
PRINTF("WARNING: Open paths in dxf_linear_extrude(file = \"%s\", layer = \"%s\"):",
|
2011-09-03 08:10:36 +04:00
|
|
|
node.filename.c_str(), node.layername.c_str());
|
2010-03-29 05:31:47 +04:00
|
|
|
first_open_path = false;
|
|
|
|
}
|
|
|
|
PRINTF(" %9.5f %10.5f ... %10.5f %10.5f",
|
2011-09-04 00:44:41 +04:00
|
|
|
dxf.points[dxf.paths[i].indices.front()][0] / node.scale + node.origin_x,
|
|
|
|
dxf.points[dxf.paths[i].indices.front()][1] / node.scale + node.origin_y,
|
|
|
|
dxf.points[dxf.paths[i].indices.back()][0] / node.scale + node.origin_x,
|
|
|
|
dxf.points[dxf.paths[i].indices.back()][1] / node.scale + node.origin_y);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (node.has_twist)
|
|
|
|
{
|
|
|
|
dxf_tesselate(ps, dxf, 0, false, true, h1);
|
|
|
|
dxf_tesselate(ps, dxf, node.twist, true, true, h2);
|
|
|
|
for (int j = 0; j < node.slices; j++)
|
|
|
|
{
|
|
|
|
double t1 = node.twist*j / node.slices;
|
|
|
|
double t2 = node.twist*(j+1) / node.slices;
|
|
|
|
double g1 = h1 + (h2-h1)*j / node.slices;
|
|
|
|
double g2 = h1 + (h2-h1)*(j+1) / node.slices;
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t i = 0; i < dxf.paths.size(); i++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2011-09-01 19:03:34 +04:00
|
|
|
if (!dxf.paths[i].is_closed)
|
2010-03-29 05:31:47 +04:00
|
|
|
continue;
|
2011-09-04 00:44:41 +04:00
|
|
|
add_slice(ps, dxf, dxf.paths[i], t1, t2, g1, g2);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
dxf_tesselate(ps, dxf, 0, false, true, h1);
|
|
|
|
dxf_tesselate(ps, dxf, 0, true, true, h2);
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t i = 0; i < dxf.paths.size(); i++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2011-09-01 19:03:34 +04:00
|
|
|
if (!dxf.paths[i].is_closed)
|
2010-03-29 05:31:47 +04:00
|
|
|
continue;
|
2011-09-04 00:44:41 +04:00
|
|
|
add_slice(ps, dxf, dxf.paths[i], 0, 0, h1, h2);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
|
|
|
DxfData *dxf;
|
|
|
|
|
2011-09-03 08:10:36 +04:00
|
|
|
if (node.filename.empty())
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
2010-11-03 21:26:06 +03:00
|
|
|
// Before extruding, union all (2D) children nodes
|
|
|
|
// to a single DxfData, then tesselate this into a PolySet
|
2011-09-02 22:19:17 +04:00
|
|
|
CGAL_Nef_polyhedron sum;
|
2011-09-04 22:35:23 +04:00
|
|
|
BOOST_FOREACH (AbstractNode * v, node.getChildren()) {
|
2010-11-03 21:26:06 +03:00
|
|
|
if (v->modinst->tag_background) continue;
|
2011-09-02 22:19:17 +04:00
|
|
|
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(*v);
|
2011-09-07 01:59:08 +04:00
|
|
|
if (N.dim != 2) {
|
|
|
|
PRINT("ERROR: rotate_extrude() is not defined for 3D child objects!");
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
if (sum.empty()) sum = N.copy();
|
|
|
|
else sum += N;
|
|
|
|
}
|
2010-11-03 21:26:06 +03:00
|
|
|
}
|
|
|
|
|
2011-09-07 01:59:08 +04:00
|
|
|
if (sum.empty()) return NULL;
|
2011-09-02 22:19:17 +04:00
|
|
|
dxf = sum.convertToDxfData();
|
2010-03-29 05:31:47 +04:00
|
|
|
} else {
|
2011-09-04 00:44:41 +04:00
|
|
|
dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
2011-09-01 19:03:34 +04:00
|
|
|
PolySet *ps = rotateDxfData(node, *dxf);
|
|
|
|
delete dxf;
|
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::evaluatePolySet(const CgaladvNode &node)
|
2011-09-06 16:57:24 +04:00
|
|
|
{
|
|
|
|
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(node);
|
|
|
|
PolySet *ps = NULL;
|
|
|
|
if (!N.empty()) ps = N.convertToPolyset();
|
2011-09-09 07:53:05 +04:00
|
|
|
|
2011-09-06 16:57:24 +04:00
|
|
|
return ps;
|
|
|
|
}
|
|
|
|
|
2011-09-09 07:53:05 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::evaluatePolySet(const RenderNode &node)
|
2011-09-06 20:31:22 +04:00
|
|
|
{
|
|
|
|
CGAL_Nef_polyhedron N = this->cgalevaluator.evaluateCGALMesh(node);
|
|
|
|
PolySet *ps = NULL;
|
|
|
|
if (!N.empty()) ps = N.convertToPolyset();
|
|
|
|
return ps;
|
|
|
|
}
|
2011-09-06 16:57:24 +04:00
|
|
|
|
2011-09-01 19:03:34 +04:00
|
|
|
PolySet *PolySetCGALEvaluator::rotateDxfData(const DxfRotateExtrudeNode &node, DxfData &dxf)
|
|
|
|
{
|
2010-03-29 05:31:47 +04:00
|
|
|
PolySet *ps = new PolySet();
|
|
|
|
ps->convexity = node.convexity;
|
|
|
|
|
2011-09-04 22:35:23 +04:00
|
|
|
for (size_t i = 0; i < dxf.paths.size(); i++)
|
2010-03-29 05:31:47 +04:00
|
|
|
{
|
|
|
|
double max_x = 0;
|
2011-09-04 22:35:23 +04:00
|
|
|
for (size_t j = 0; j < dxf.paths[i].indices.size(); j++) {
|
2011-09-04 00:44:41 +04:00
|
|
|
max_x = fmax(max_x, dxf.points[dxf.paths[i].indices[j]][0]);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int fragments = get_fragments_from_r(max_x, node.fn, node.fs, node.fa);
|
|
|
|
|
2011-04-12 22:35:44 +04:00
|
|
|
double ***points;
|
|
|
|
points = new double**[fragments];
|
|
|
|
for (int j=0; j < fragments; j++) {
|
2011-09-04 00:44:41 +04:00
|
|
|
points[j] = new double*[dxf.paths[i].indices.size()];
|
2011-09-04 22:35:23 +04:00
|
|
|
for (size_t k=0; k < dxf.paths[i].indices.size(); k++)
|
2011-04-12 22:35:44 +04:00
|
|
|
points[j][k] = new double[3];
|
|
|
|
}
|
2010-03-29 05:31:47 +04:00
|
|
|
|
|
|
|
for (int j = 0; j < fragments; j++) {
|
|
|
|
double a = (j*2*M_PI) / fragments;
|
2011-09-04 22:35:23 +04:00
|
|
|
for (size_t k = 0; k < dxf.paths[i].indices.size(); k++) {
|
2011-09-04 00:44:41 +04:00
|
|
|
if (dxf.points[dxf.paths[i].indices[k]][0] == 0) {
|
2010-03-29 05:31:47 +04:00
|
|
|
points[j][k][0] = 0;
|
|
|
|
points[j][k][1] = 0;
|
|
|
|
} else {
|
2011-09-04 00:44:41 +04:00
|
|
|
points[j][k][0] = dxf.points[dxf.paths[i].indices[k]][0] * sin(a);
|
|
|
|
points[j][k][1] = dxf.points[dxf.paths[i].indices[k]][0] * cos(a);
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
2011-09-04 00:44:41 +04:00
|
|
|
points[j][k][2] = dxf.points[dxf.paths[i].indices[k]][1];
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = 0; j < fragments; j++) {
|
|
|
|
int j1 = j + 1 < fragments ? j + 1 : 0;
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t k = 0; k < dxf.paths[i].indices.size(); k++) {
|
|
|
|
int k1 = k + 1 < dxf.paths[i].indices.size() ? k + 1 : 0;
|
2010-03-29 05:31:47 +04:00
|
|
|
if (points[j][k][0] != points[j1][k][0] ||
|
|
|
|
points[j][k][1] != points[j1][k][1] ||
|
|
|
|
points[j][k][2] != points[j1][k][2]) {
|
|
|
|
ps->append_poly();
|
|
|
|
ps->append_vertex(points[j ][k ][0],
|
|
|
|
points[j ][k ][1], points[j ][k ][2]);
|
|
|
|
ps->append_vertex(points[j1][k ][0],
|
|
|
|
points[j1][k ][1], points[j1][k ][2]);
|
|
|
|
ps->append_vertex(points[j ][k1][0],
|
|
|
|
points[j ][k1][1], points[j ][k1][2]);
|
|
|
|
}
|
|
|
|
if (points[j][k1][0] != points[j1][k1][0] ||
|
|
|
|
points[j][k1][1] != points[j1][k1][1] ||
|
|
|
|
points[j][k1][2] != points[j1][k1][2]) {
|
|
|
|
ps->append_poly();
|
|
|
|
ps->append_vertex(points[j ][k1][0],
|
|
|
|
points[j ][k1][1], points[j ][k1][2]);
|
|
|
|
ps->append_vertex(points[j1][k ][0],
|
|
|
|
points[j1][k ][1], points[j1][k ][2]);
|
|
|
|
ps->append_vertex(points[j1][k1][0],
|
|
|
|
points[j1][k1][1], points[j1][k1][2]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-04-12 22:35:44 +04:00
|
|
|
|
|
|
|
for (int j=0; j < fragments; j++) {
|
2011-09-04 00:44:41 +04:00
|
|
|
for (size_t k=0; k < dxf.paths[i].indices.size(); k++)
|
2011-04-12 22:35:44 +04:00
|
|
|
delete[] points[j][k];
|
|
|
|
delete[] points[j];
|
|
|
|
}
|
|
|
|
delete[] points;
|
2010-03-29 05:31:47 +04:00
|
|
|
}
|
2011-09-09 07:53:05 +04:00
|
|
|
|
2010-03-29 05:31:47 +04:00
|
|
|
return ps;
|
|
|
|
}
|