summaryrefslogtreecommitdiff
path: root/src/PolySetCGALEvaluator.cc
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-05-24 14:16:20 (GMT)
committerMarius Kintel <marius@kintel.net>2013-05-24 14:16:20 (GMT)
commit26046f6f0c4a774cbbb2af8ae7dc0e687963440c (patch)
tree38ff04fc460e8aa55134fb1ee6167fafb90a3423 /src/PolySetCGALEvaluator.cc
parenteefcd6d0b271642d470cd55bc47d1579d943938e (diff)
parent95e399e06c6522f3fa67679808a1d52815368efa (diff)
Merge branch 'master' into epec-kernel
Diffstat (limited to 'src/PolySetCGALEvaluator.cc')
-rw-r--r--src/PolySetCGALEvaluator.cc137
1 files changed, 75 insertions, 62 deletions
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc
index 5976daf..f0c274f 100644
--- a/src/PolySetCGALEvaluator.cc
+++ b/src/PolySetCGALEvaluator.cc
@@ -202,27 +202,38 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node)
return ps;
}
-static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path, double rot1, double rot2, double h1, double h2)
+static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path,
+ double rot1, double rot2,
+ double h1, double h2,
+ double scale1_x, double scale1_y,
+ double scale2_x, double scale2_y)
{
+ // FIXME: If scale2 == 0 we need to handle tessellation separately
bool splitfirst = sin(rot2 - rot1) >= 0.0;
- for (size_t j = 1; j < path.indices.size(); j++)
- {
+ for (size_t j = 1; j < path.indices.size(); j++) {
int k = j - 1;
- 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);
+ double jx1 = scale1_x * (dxf.points[path.indices[j]][0] * cos(rot1*M_PI/180) +
+ dxf.points[path.indices[j]][1] * sin(rot1*M_PI/180));
+ double jy1 = scale1_y * (dxf.points[path.indices[j]][0] * -sin(rot1*M_PI/180) +
+ dxf.points[path.indices[j]][1] * cos(rot1*M_PI/180));
- 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);
+ double jx2 = scale2_x * (dxf.points[path.indices[j]][0] * cos(rot2*M_PI/180) +
+ dxf.points[path.indices[j]][1] * sin(rot2*M_PI/180));
+ double jy2 = scale2_y * (dxf.points[path.indices[j]][0] * -sin(rot2*M_PI/180) +
+ dxf.points[path.indices[j]][1] * cos(rot2*M_PI/180));
- 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);
+ double kx1 = scale1_x * (dxf.points[path.indices[k]][0] * cos(rot1*M_PI/180) +
+ dxf.points[path.indices[k]][1] * sin(rot1*M_PI/180));
+ double ky1 = scale1_y * (dxf.points[path.indices[k]][0] * -sin(rot1*M_PI/180) +
+ dxf.points[path.indices[k]][1] * cos(rot1*M_PI/180));
- 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);
+ double kx2 = scale2_x * (dxf.points[path.indices[k]][0] * cos(rot2*M_PI/180) +
+ dxf.points[path.indices[k]][1] * sin(rot2*M_PI/180));
+ double ky2 = scale2_y * (dxf.points[path.indices[k]][0] * -sin(rot2*M_PI/180) +
+ dxf.points[path.indices[k]][1] * cos(rot2*M_PI/180));
- if (splitfirst)
- {
+ if (splitfirst) {
ps->append_poly();
if (path.is_inner) {
ps->append_vertex(kx1, ky1, h1);
@@ -234,19 +245,20 @@ static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path, doub
ps->insert_vertex(jx2, jy2, h2);
}
- ps->append_poly();
- if (path.is_inner) {
- 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);
+ if (scale2_x > 0 || scale2_y > 0) {
+ ps->append_poly();
+ if (path.is_inner) {
+ 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
- {
+ else {
ps->append_poly();
if (path.is_inner) {
ps->append_vertex(kx1, ky1, h1);
@@ -258,15 +270,17 @@ static void add_slice(PolySet *ps, const DxfData &dxf, DxfData::Path &path, doub
ps->insert_vertex(kx2, ky2, h2);
}
- ps->append_poly();
- if (path.is_inner) {
- 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);
+ if (scale2_x > 0 || scale2_y > 0) {
+ ps->append_poly();
+ if (path.is_inner) {
+ 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);
+ }
}
}
}
@@ -298,7 +312,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const LinearExtrudeNode &node)
if (sum.isNull()) return NULL;
dxf = sum.convertToDxfData();;
} else {
- dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
+ dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale_x);
}
PolySet *ps = extrudeDxfData(node, *dxf);
@@ -322,50 +336,49 @@ PolySet *PolySetCGALEvaluator::extrudeDxfData(const LinearExtrudeNode &node, Dxf
}
bool first_open_path = true;
- for (size_t i = 0; i < dxf.paths.size(); i++)
- {
- if (dxf.paths[i].is_closed)
- continue;
+ for (size_t i = 0; i < dxf.paths.size(); i++) {
+ if (dxf.paths[i].is_closed) continue;
if (first_open_path) {
PRINTB("WARNING: Open paths in dxf_linear_extrude(file = \"%s\", layer = \"%s\"):",
node.filename % node.layername);
first_open_path = false;
}
PRINTB(" %9.5f %10.5f ... %10.5f %10.5f",
- (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));
+ (dxf.points[dxf.paths[i].indices.front()][0] / node.scale_x + node.origin_x) %
+ (dxf.points[dxf.paths[i].indices.front()][1] / node.scale_y + node.origin_y) %
+ (dxf.points[dxf.paths[i].indices.back()][0] / node.scale_x + node.origin_x) %
+ (dxf.points[dxf.paths[i].indices.back()][1] / node.scale_y + node.origin_y));
}
- 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++)
- {
+ if (node.has_twist) {
+ dxf_tesselate(ps, dxf, 0, Vector2d(1,1), false, true, h1); // bottom
+ if (node.scale_x > 0 || node.scale_y > 0) {
+ dxf_tesselate(ps, dxf, node.twist, Vector2d(node.scale_x, node.scale_y), true, true, h2); // top
+ }
+ 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;
- for (size_t i = 0; i < dxf.paths.size(); i++)
- {
- if (!dxf.paths[i].is_closed)
- continue;
- add_slice(ps, dxf, dxf.paths[i], t1, t2, g1, g2);
+ double s1x = 1 - (1-node.scale_x)*j / node.slices;
+ double s1y = 1 - (1-node.scale_y)*j / node.slices;
+ double s2x = 1 - (1-node.scale_x)*(j+1) / node.slices;
+ double s2y = 1 - (1-node.scale_y)*(j+1) / node.slices;
+ for (size_t i = 0; i < dxf.paths.size(); i++) {
+ if (!dxf.paths[i].is_closed) continue;
+ add_slice(ps, dxf, dxf.paths[i], t1, t2, g1, g2, s1x, s1y, s2x, s2y);
}
}
}
- else
- {
- dxf_tesselate(ps, dxf, 0, false, true, h1);
- dxf_tesselate(ps, dxf, 0, true, true, h2);
- for (size_t i = 0; i < dxf.paths.size(); i++)
- {
- if (!dxf.paths[i].is_closed)
- continue;
- add_slice(ps, dxf, dxf.paths[i], 0, 0, h1, h2);
+ else {
+ dxf_tesselate(ps, dxf, 0, Vector2d(1,1), false, true, h1); //bottom
+ if (node.scale_x > 0 || node.scale_y > 0) {
+ dxf_tesselate(ps, dxf, 0, Vector2d(node.scale_x, node.scale_y), true, true, h2); // top
+ }
+ for (size_t i = 0; i < dxf.paths.size(); i++) {
+ if (!dxf.paths[i].is_closed) continue;
+ add_slice(ps, dxf, dxf.paths[i], 0, 0, h1, h2, 1, 1, node.scale_x, node.scale_y);
}
}
contact: Jan Huwald // Impressum