summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarius Kintel <marius@kintel.net>2013-02-12 04:33:31 (GMT)
committerMarius Kintel <marius@kintel.net>2013-05-10 11:45:28 (GMT)
commit130e10778e9d74ceb07dfc813b85d75a52a71e10 (patch)
treef11ad6722ff461864d83906b29bbabe148858693
parentb5079a189aa70cf36e9a4ded6d891df6ae78ac58 (diff)
Initial code to support scaling of linear_extrude(). Part of Issue #273
-rw-r--r--src/CGALRenderer.cc2
-rw-r--r--src/CGAL_Nef_polyhedron.cc2
-rw-r--r--src/PolySetCGALEvaluator.cc124
-rw-r--r--src/dxftess-cgal.cc6
-rw-r--r--src/dxftess-glu.cc6
-rw-r--r--src/dxftess.h2
-rw-r--r--src/import.cc2
-rw-r--r--src/linearextrude.cc7
-rw-r--r--src/primitives.cc2
9 files changed, 82 insertions, 71 deletions
diff --git a/src/CGALRenderer.cc b/src/CGALRenderer.cc
index 4357e44..aadc2b4 100644
--- a/src/CGALRenderer.cc
+++ b/src/CGALRenderer.cc
@@ -52,7 +52,7 @@ CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root)
this->polyhedron = NULL;
this->polyset = new PolySet();
this->polyset->is2d = true;
- dxf_tesselate(this->polyset, *dd, 0, true, false, 0);
+ dxf_tesselate(this->polyset, *dd, 0, 1, true, false, 0);
delete dd;
}
else if (root.dim == 3) {
diff --git a/src/CGAL_Nef_polyhedron.cc b/src/CGAL_Nef_polyhedron.cc
index 8906595..d9cd174 100644
--- a/src/CGAL_Nef_polyhedron.cc
+++ b/src/CGAL_Nef_polyhedron.cc
@@ -90,7 +90,7 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset()
ps = new PolySet();
DxfData *dd = this->convertToDxfData();
ps->is2d = true;
- dxf_tesselate(ps, *dd, 0, true, false, 0);
+ dxf_tesselate(ps, *dd, 0, 1, true, false, 0);
dxf_border_to_ps(ps, *dd);
delete dd;
}
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc
index 5976daf..6d0704e 100644
--- a/src/PolySetCGALEvaluator.cc
+++ b/src/PolySetCGALEvaluator.cc
@@ -202,27 +202,37 @@ 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, double scale2)
{
+ // 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 * (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 * (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 * (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 * (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 * (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 * (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 * (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 * (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 +244,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 > 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 +269,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 > 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);
+ }
}
}
}
@@ -322,10 +335,8 @@ 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);
@@ -339,33 +350,32 @@ PolySet *PolySetCGALEvaluator::extrudeDxfData(const LinearExtrudeNode &node, Dxf
}
- 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, 1, false, true, h1);
+ if (node.scale > 0) {
+ dxf_tesselate(ps, dxf, node.twist, node.scale, 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;
- 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 s1 = 1 - (1-node.scale)*j / node.slices;
+ double s2 = 1 - (1-node.scale)*(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, s1, s2);
}
}
}
- 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, 1, false, true, h1);
+ if (node.scale > 0) {
+ dxf_tesselate(ps, dxf, 0, node.scale, 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, 1, node.scale);
}
}
diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc
index 0197473..fffa4f1 100644
--- a/src/dxftess-cgal.cc
+++ b/src/dxftess-cgal.cc
@@ -101,7 +101,7 @@ void mark_inner_outer(std::vector<struct triangle> &tri, Grid2d<point_info_t> &p
}
}
-void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_triangle_splitting */, double h)
+void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, double scale, bool up, bool /* do_triangle_splitting */, double h)
{
CDT cdt;
@@ -124,8 +124,8 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool /* do_tr
struct point_info_t *first_pi = NULL, *prev_pi = NULL;
for (size_t j = 1; j < dxf.paths[i].indices.size(); j++)
{
- double x = dxf.points[dxf.paths[i].indices[j]][0];
- double y = dxf.points[dxf.paths[i].indices[j]][1];
+ double x = scale * dxf.points[dxf.paths[i].indices[j]][0];
+ double y = scale * dxf.points[dxf.paths[i].indices[j]][1];
if (point_info.has(x, y)) {
// FIXME: How can the same path set contain the same point twice?
diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc
index 3f87729..38b09e9 100644
--- a/src/dxftess-glu.cc
+++ b/src/dxftess-glu.cc
@@ -201,7 +201,7 @@ inline void do_emplace( boost::unordered_multimap<int, pair_ii> &tri_by_atan2, i
rot: CLOCKWISE rotation around positive Z axis
*/
-void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_triangle_splitting, double h)
+void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, double scale, bool up, bool do_triangle_splitting, double h)
{
GLUtesselator *tobj = gluNewTess();
@@ -244,8 +244,8 @@ void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_trian
dxf.points[dxf.paths[i].indices[j]][1],
h) = std::pair<int,int>(i, j);
vl.push_back(tess_vdata());
- vl.back().v[0] = dxf.points[dxf.paths[i].indices[j]][0];
- vl.back().v[1] = dxf.points[dxf.paths[i].indices[j]][1];
+ vl.back().v[0] = scale * dxf.points[dxf.paths[i].indices[j]][0];
+ vl.back().v[1] = scale * dxf.points[dxf.paths[i].indices[j]][1];
vl.back().v[2] = h;
gluTessVertex(tobj, vl.back().v, vl.back().v);
}
diff --git a/src/dxftess.h b/src/dxftess.h
index d3af36e..92c85ea 100644
--- a/src/dxftess.h
+++ b/src/dxftess.h
@@ -3,7 +3,7 @@
class DxfData;
class PolySet;
-void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, bool up, bool do_triangle_splitting, double h);
+void dxf_tesselate(PolySet *ps, DxfData &dxf, double rot, double scale, bool up, bool do_triangle_splitting, double h);
void dxf_border_to_ps(PolySet *ps, const DxfData &dxf);
#endif
diff --git a/src/import.cc b/src/import.cc
index bb44d70..bf21780 100644
--- a/src/import.cc
+++ b/src/import.cc
@@ -294,7 +294,7 @@ PolySet *ImportNode::evaluate_polyset(class PolySetEvaluator *) const
p = new PolySet();
DxfData dd(this->fn, this->fs, this->fa, this->filename, this->layername, this->origin_x, this->origin_y, this->scale);
p->is2d = true;
- dxf_tesselate(p, dd, 0, true, false, 0);
+ dxf_tesselate(p, dd, 0, 1, true, false, 0);
dxf_border_to_ps(p, dd);
}
else
diff --git a/src/linearextrude.cc b/src/linearextrude.cc
index bc678e6..89e92ba 100644
--- a/src/linearextrude.cc
+++ b/src/linearextrude.cc
@@ -91,7 +91,7 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI
node->height = height.toDouble();
node->convexity = (int)convexity.toDouble();
origin.getVec2(node->origin_x, node->origin_y);
- node->scale = scale.toDouble();
+ node->scale = scale.isUndefined() ? 1 : scale.toDouble();
if (center.type() == Value::BOOL)
node->center = center.toBool();
@@ -102,8 +102,8 @@ AbstractNode *LinearExtrudeModule::instantiate(const Context *ctx, const ModuleI
if (node->convexity <= 0)
node->convexity = 1;
- if (node->scale <= 0)
- node->scale = 1;
+ if (node->scale < 0)
+ node->scale = 0;
if (twist.type() == Value::NUMBER) {
node->twist = twist.toDouble();
@@ -166,6 +166,7 @@ std::string LinearExtrudeNode::toString() const
if (this->has_twist) {
stream << ", twist = " << this->twist << ", slices = " << this->slices;
}
+ stream << ", scale = " << this->scale;
stream << ", $fn = " << this->fn << ", $fa = " << this->fa << ", $fs = " << this->fs << ")";
return stream.str();
diff --git a/src/primitives.cc b/src/primitives.cc
index be1ec6f..3298073 100644
--- a/src/primitives.cc
+++ b/src/primitives.cc
@@ -546,7 +546,7 @@ sphere_next_r2:
p->is2d = true;
p->convexity = convexity;
- dxf_tesselate(p, dd, 0, true, false, 0);
+ dxf_tesselate(p, dd, 0, 1, true, false, 0);
dxf_border_to_ps(p, dd);
}
contact: Jan Huwald // Impressum