diff options
author | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-06-21 12:43:52 (GMT) |
---|---|---|
committer | clifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c> | 2009-06-21 12:43:52 (GMT) |
commit | 1f08d77f548ed12186523e8e47f62441730ef985 (patch) | |
tree | b9190fb4773899404c7f51692a9478ab06914aef | |
parent | e24a87b8a37b8f71be30d99251908a5d80bb8bc7 (diff) |
Clifford Wolf:
CSG Evaluation now functional
git-svn-id: http://svn.clifford.at/openscad/trunk@7 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r-- | cube.cc | 7 | ||||
-rw-r--r-- | difference.cc | 2 | ||||
-rw-r--r-- | example.scad | 4 | ||||
-rw-r--r-- | intersect.cc | 2 | ||||
-rw-r--r-- | module.cc | 33 | ||||
-rw-r--r-- | openscad.cc | 10 | ||||
-rw-r--r-- | openscad.h | 13 | ||||
-rw-r--r-- | parser.y | 6 | ||||
-rw-r--r-- | trans.cc | 1 | ||||
-rw-r--r-- | union.cc | 1 |
10 files changed, 71 insertions, 8 deletions
@@ -60,13 +60,16 @@ void register_builtin_cube() CGAL_Nef_polyhedron CubeNode::render_cgal_nef_polyhedron() const { - CGAL_Nef_polyhedron N1(CGAL_Plane(+1, 0, 0, -x/2)); + CGAL_Plane P1 = CGAL_Plane(+1, 0, 0, -x/2); + CGAL_Nef_polyhedron N1(P1); CGAL_Nef_polyhedron N2(CGAL_Plane(-1, 0, 0, -x/2)); CGAL_Nef_polyhedron N3(CGAL_Plane( 0, +1, 0, -y/2)); CGAL_Nef_polyhedron N4(CGAL_Plane( 0, -1, 0, -y/2)); CGAL_Nef_polyhedron N5(CGAL_Plane( 0, 0, +1, -z/2)); CGAL_Nef_polyhedron N6(CGAL_Plane( 0, 0, -1, -z/2)); - return N1 * N2 * N3 * N4 * N5 * N6; + CGAL_Nef_polyhedron N = N1 * N2 * N3 * N4 * N5 * N6; + progress_report(); + return N; } QString CubeNode::dump(QString indent) const diff --git a/difference.cc b/difference.cc index beeea20..a1f9025 100644 --- a/difference.cc +++ b/difference.cc @@ -52,7 +52,9 @@ CGAL_Nef_polyhedron DifferenceNode::render_cgal_nef_polyhedron() const N = v->render_cgal_nef_polyhedron(); else N -= v->render_cgal_nef_polyhedron(); + first = false; } + progress_report(); return N; } diff --git a/example.scad b/example.scad index 7a80a5d..8a1fad4 100644 --- a/example.scad +++ b/example.scad @@ -24,8 +24,8 @@ module test001() module test002() { difference() { - cube(1); - trans([0.5, 0.5, 0.5]) cube(1); + cube([2 2 0.5]); + cube([0.5 0.5 2]); } } diff --git a/intersect.cc b/intersect.cc index c9743c7..29dd4e3 100644 --- a/intersect.cc +++ b/intersect.cc @@ -52,7 +52,9 @@ CGAL_Nef_polyhedron IntersectNode::render_cgal_nef_polyhedron() const N = v->render_cgal_nef_polyhedron(); else N *= v->render_cgal_nef_polyhedron(); + first = false; } + progress_report(); return N; } @@ -191,6 +191,7 @@ CGAL_Nef_polyhedron AbstractNode::render_cgal_nef_polyhedron() const CGAL_Nef_polyhedron N; foreach (AbstractNode *v, children) N += v->render_cgal_nef_polyhedron(); + progress_report(); return N; } @@ -202,3 +203,35 @@ QString AbstractNode::dump(QString indent) const return text + indent + "}\n"; } +int progress_report_count; +void (*progress_report_f)(const class AbstractNode*, void*, int); +void *progress_report_vp; + +void AbstractNode::progress_prepare() +{ + foreach (AbstractNode *v, children) + v->progress_prepare(); + progress_mark = ++progress_report_count; +} + +void AbstractNode::progress_report() const +{ + if (progress_report_f) + progress_report_f(this, progress_report_vp, progress_mark); +} + +void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp) +{ + progress_report_count = 0; + progress_report_f = f; + progress_report_vp = vp; + root->progress_prepare(); +} + +void progress_report_fin() +{ + progress_report_count = 0; + progress_report_f = NULL; + progress_report_vp = NULL; +} + diff --git a/openscad.cc b/openscad.cc index d4a411f..99d9056 100644 --- a/openscad.cc +++ b/openscad.cc @@ -27,6 +27,11 @@ #include <fstream> #include <iostream> +void report_func(const class AbstractNode*, void*, int mark) +{ + printf("CSG rendering progress: %.2f%%\n", (mark*100.0) / progress_report_count); +} + int main() { int rc = 0; @@ -52,7 +57,12 @@ int main() CGAL_Nef_polyhedron N; CGAL_Polyhedron P; + + progress_report_prep(root_node, report_func, NULL); N = root_node->render_cgal_nef_polyhedron(); + progress_report_fin(); + printf("CSG rendering finished.\n"); + N.convert_to_Polyhedron(P); std::ofstream outFile("output.off"); @@ -218,7 +218,7 @@ public: #include <CGAL/Polyhedron_3.h> #include <CGAL/Nef_polyhedron_3.h> -typedef CGAL::Cartesian<CGAL::Gmpq> CGAL_Kernel; +typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel; typedef CGAL::Polyhedron_3<CGAL_Kernel> CGAL_Polyhedron; typedef CGAL::Nef_polyhedron_3<CGAL_Kernel> CGAL_Nef_polyhedron; typedef CGAL_Nef_polyhedron::Aff_transformation_3 CGAL_Aff_transformation; @@ -231,11 +231,22 @@ class AbstractNode public: QVector<AbstractNode*> children; + int progress_mark; + void progress_prepare(); + void progress_report() const; + virtual ~AbstractNode(); virtual CGAL_Nef_polyhedron render_cgal_nef_polyhedron() const; virtual QString dump(QString indent) const; }; +extern int progress_report_count; +extern void (*progress_report_f)(const class AbstractNode*, void*, int); +extern void *progress_report_vp; + +void progress_report_prep(AbstractNode *root, void (*f)(const class AbstractNode *node, void *vp, int mark), void *vp); +void progress_report_fin(); + #endif /* HIDE_ABSTRACT_NODE_DETAILS */ extern AbstractModule *parse(FILE *f, int debug); @@ -137,9 +137,9 @@ module_instantciation_list: /* empty */ { $$ = new ModuleInstanciation(); } | - module_instantciation module_instantciation_list { - $$ = $2; - $$->children.append($1); + module_instantciation_list module_instantciation { + $$ = $1; + $$->children.append($2); } ; single_module_instantciation: @@ -60,6 +60,7 @@ CGAL_Nef_polyhedron TransNode::render_cgal_nef_polyhedron() const N += v->render_cgal_nef_polyhedron(); CGAL_Aff_transformation t(CGAL::TRANSLATION, CGAL_Vector(x, y, z)); N.transform(t); + progress_report(); return N; } @@ -48,6 +48,7 @@ CGAL_Nef_polyhedron UnionNode::render_cgal_nef_polyhedron() const CGAL_Nef_polyhedron N; foreach (AbstractNode *v, children) N += v->render_cgal_nef_polyhedron(); + progress_report(); return N; } |