From e320641d0fddaa69fa1493fa99e447999bff78e9 Mon Sep 17 00:00:00 2001 From: clifford Date: Sun, 21 Jun 2009 16:41:38 +0000 Subject: Clifford Wolf: Improved cube generation Added simple off viewer git-svn-id: http://svn.clifford.at/openscad/trunk@8 b57f626f-c46c-0410-a088-ec61d464b74c diff --git a/cube.cc b/cube.cc index 7840c63..c692a0d 100644 --- a/cube.cc +++ b/cube.cc @@ -58,16 +58,69 @@ void register_builtin_cube() builtin_modules["cube"] = new CubeModule(); } +class CGAL_Build_cube : public CGAL::Modifier_base +{ +public: + const CubeNode *n; + CGAL_Build_cube(const CubeNode *n) : n(n) { } + void operator()(CGAL_HDS& hds) { + CGAL_Polybuilder B(hds, true); + B.begin_surface(8, 6, 24); + typedef CGAL_HDS::Vertex::Point Point; + B.add_vertex(Point(-n->x/2, -n->y/2, +n->z/2)); // 0 + B.add_vertex(Point(+n->x/2, -n->y/2, +n->z/2)); // 1 + B.add_vertex(Point(+n->x/2, +n->y/2, +n->z/2)); // 2 + B.add_vertex(Point(-n->x/2, +n->y/2, +n->z/2)); // 3 + B.add_vertex(Point(-n->x/2, -n->y/2, -n->z/2)); // 4 + B.add_vertex(Point(+n->x/2, -n->y/2, -n->z/2)); // 5 + B.add_vertex(Point(+n->x/2, +n->y/2, -n->z/2)); // 6 + B.add_vertex(Point(-n->x/2, +n->y/2, -n->z/2)); // 7 + B.begin_facet(); + B.add_vertex_to_facet(0); + B.add_vertex_to_facet(1); + B.add_vertex_to_facet(2); + B.add_vertex_to_facet(3); + B.end_facet(); + B.begin_facet(); + B.add_vertex_to_facet(7); + B.add_vertex_to_facet(6); + B.add_vertex_to_facet(5); + B.add_vertex_to_facet(4); + B.end_facet(); + B.begin_facet(); + B.add_vertex_to_facet(4); + B.add_vertex_to_facet(5); + B.add_vertex_to_facet(1); + B.add_vertex_to_facet(0); + B.end_facet(); + B.begin_facet(); + B.add_vertex_to_facet(5); + B.add_vertex_to_facet(6); + B.add_vertex_to_facet(2); + B.add_vertex_to_facet(1); + B.end_facet(); + B.begin_facet(); + B.add_vertex_to_facet(6); + B.add_vertex_to_facet(7); + B.add_vertex_to_facet(3); + B.add_vertex_to_facet(2); + B.end_facet(); + B.begin_facet(); + B.add_vertex_to_facet(7); + B.add_vertex_to_facet(4); + B.add_vertex_to_facet(0); + B.add_vertex_to_facet(3); + B.end_facet(); + B.end_surface(); + } +}; + CGAL_Nef_polyhedron CubeNode::render_cgal_nef_polyhedron() const { - 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)); - CGAL_Nef_polyhedron N = N1 * N2 * N3 * N4 * N5 * N6; + CGAL_Polyhedron P; + CGAL_Build_cube builder(this); + P.delegate(builder); + CGAL_Nef_polyhedron N(P); progress_report(); return N; } diff --git a/openscad.cc b/openscad.cc index 99d9056..988b4c2 100644 --- a/openscad.cc +++ b/openscad.cc @@ -22,11 +22,6 @@ #include "openscad.h" -#include - -#include -#include - void report_func(const class AbstractNode*, void*, int mark) { printf("CSG rendering progress: %.2f%%\n", (mark*100.0) / progress_report_count); diff --git a/openscad.h b/openscad.h index e48ae73..4b9abca 100644 --- a/openscad.h +++ b/openscad.h @@ -27,6 +27,9 @@ #include #include +#include +#include + class Value; class Expression; @@ -217,9 +220,13 @@ public: #include #include #include +#include -typedef CGAL::Extended_cartesian CGAL_Kernel; +typedef CGAL::Cartesian CGAL_Kernel; +// typedef CGAL::Extended_cartesian CGAL_Kernel; typedef CGAL::Polyhedron_3 CGAL_Polyhedron; +typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS; +typedef CGAL::Polyhedron_incremental_builder_3 CGAL_Polybuilder; typedef CGAL::Nef_polyhedron_3 CGAL_Nef_polyhedron; typedef CGAL_Nef_polyhedron::Aff_transformation_3 CGAL_Aff_transformation; typedef CGAL_Nef_polyhedron::Vector_3 CGAL_Vector; diff --git a/viewoff.cc b/viewoff.cc new file mode 100644 index 0000000..bfc0b78 --- /dev/null +++ b/viewoff.cc @@ -0,0 +1,66 @@ + +// g++ -o viewoff -lCGAL -lCGAL_Qt3 -I/opt/qt3/include/ -L/opt/qt3/lib/ -lqt viewoff.cc + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define VERBOSE 0 + +typedef CGAL::Cartesian Kernel; +typedef CGAL::Polyhedron_3 Polyhedron; +typedef CGAL::Nef_polyhedron_3 Nef_polyhedron; + +int main(int argc, char **argv) +{ + QApplication a(argc, argv); + + for (int i=1; i* w = new CGAL::Qt_widget_Nef_3(NP); + if (i == 1) + a.setMainWidget(w); + w->show(); + } + + return a.exec(); +} + -- cgit v0.10.1