summaryrefslogtreecommitdiff
path: root/module.cc
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-11-25 20:47:54 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-11-25 20:47:54 (GMT)
commit07acb6714e1c07531710b81b41dfd978bfce78d3 (patch)
tree097a8d039a8727c0bc65e419673160643b327946 /module.cc
parent14c9d3200ac21ab9fc8988289c355d6a5d219553 (diff)
Clifford Wolf:
Added intersection_for() git-svn-id: http://svn.clifford.at/openscad/trunk@138 b57f626f-c46c-0410-a088-ec61d464b74c
Diffstat (limited to 'module.cc')
-rw-r--r--module.cc69
1 files changed, 55 insertions, 14 deletions
diff --git a/module.cc b/module.cc
index 4e18c4a..7b7c5ec 100644
--- a/module.cc
+++ b/module.cc
@@ -232,48 +232,78 @@ QString AbstractNode::mk_cache_id() const
QCache<QString, CGAL_Nef_polyhedron> AbstractNode::cgal_nef_cache(100000);
-CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
+static CGAL_Nef_polyhedron render_cgal_nef_polyhedron_backend(const AbstractNode *that, bool intersect)
{
- QString cache_id = mk_cache_id();
- if (cgal_nef_cache.contains(cache_id)) {
- progress_report();
- return *cgal_nef_cache[cache_id];
+ QString cache_id = that->mk_cache_id();
+ if (that->cgal_nef_cache.contains(cache_id)) {
+ that->progress_report();
+ return *that->cgal_nef_cache[cache_id];
}
+ bool is_first = true;
CGAL_Nef_polyhedron N;
- foreach (AbstractNode *v, children) {
+ foreach (AbstractNode *v, that->children) {
if (v->modinst->tag_background)
continue;
- N += v->render_cgal_nef_polyhedron();
+ if (is_first)
+ N = v->render_cgal_nef_polyhedron();
+ else if (intersect)
+ N *= v->render_cgal_nef_polyhedron();
+ else
+ N += v->render_cgal_nef_polyhedron();
+ is_first = false;
}
- cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.number_of_vertices());
- progress_report();
+ that->cgal_nef_cache.insert(cache_id, new CGAL_Nef_polyhedron(N), N.number_of_vertices());
+ that->progress_report();
return N;
}
+CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const
+{
+ return render_cgal_nef_polyhedron_backend(this, false);
+}
+
+CGAL_Nef_polyhedron AbstractIntersectionNode::render_cgal_nef_polyhedron() const
+{
+ return render_cgal_nef_polyhedron_backend(this, true);
+}
+
#endif /* ENABLE_CGAL */
-CSGTerm *AbstractNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+static CSGTerm *render_csg_term_backend(const AbstractNode *that, bool intersect, double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background)
{
CSGTerm *t1 = NULL;
- foreach(AbstractNode *v, children) {
+ foreach(AbstractNode *v, that->children) {
CSGTerm *t2 = v->render_csg_term(m, highlights, background);
if (t2 && !t1) {
t1 = t2;
} else if (t2 && t1) {
- t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
+ if (intersect)
+ t1 = new CSGTerm(CSGTerm::TYPE_INTERSECTION, t1, t2);
+ else
+ t1 = new CSGTerm(CSGTerm::TYPE_UNION, t1, t2);
}
}
- if (t1 && modinst->tag_highlight && highlights)
+ if (t1 && that->modinst->tag_highlight && highlights)
highlights->append(t1->link());
- if (t1 && modinst->tag_background && background) {
+ if (t1 && that->modinst->tag_background && background) {
background->append(t1);
return NULL;
}
return t1;
}
+CSGTerm *AbstractNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+{
+ return render_csg_term_backend(this, false, m, highlights, background);
+}
+
+CSGTerm *AbstractIntersectionNode::render_csg_term(double m[16], QVector<CSGTerm*> *highlights, QVector<CSGTerm*> *background) const
+{
+ return render_csg_term_backend(this, true, m, highlights, background);
+}
+
QString AbstractNode::dump(QString indent) const
{
if (dump_cache.isEmpty()) {
@@ -285,6 +315,17 @@ QString AbstractNode::dump(QString indent) const
return dump_cache;
}
+QString AbstractIntersectionNode::dump(QString indent) const
+{
+ if (dump_cache.isEmpty()) {
+ QString text = indent + QString("n%1: intersection() {\n").arg(idx);
+ foreach (AbstractNode *v, children)
+ text += v->dump(indent + QString("\t"));
+ ((AbstractNode*)this)->dump_cache = text + indent + "}\n";
+ }
+ return dump_cache;
+}
+
int progress_report_count;
void (*progress_report_f)(const class AbstractNode*, void*, int);
void *progress_report_vp;
contact: Jan Huwald // Impressum