summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-21 16:41:38 (GMT)
committerclifford <clifford@b57f626f-c46c-0410-a088-ec61d464b74c>2009-06-21 16:41:38 (GMT)
commite320641d0fddaa69fa1493fa99e447999bff78e9 (patch)
tree72e56c469ff7f2d6eeb318d9e3cabfc314e373a2
parent1f08d77f548ed12186523e8e47f62441730ef985 (diff)
Clifford Wolf:
Improved cube generation Added simple off viewer git-svn-id: http://svn.clifford.at/openscad/trunk@8 b57f626f-c46c-0410-a088-ec61d464b74c
-rw-r--r--cube.cc69
-rw-r--r--openscad.cc5
-rw-r--r--openscad.h9
-rw-r--r--viewoff.cc66
4 files changed, 135 insertions, 14 deletions
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<CGAL_HDS>
+{
+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 <CGAL/IO/Polyhedron_iostream.h>
-
-#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);
diff --git a/openscad.h b/openscad.h
index e48ae73..4b9abca 100644
--- a/openscad.h
+++ b/openscad.h
@@ -27,6 +27,9 @@
#include <stdlib.h>
#include <math.h>
+#include <fstream>
+#include <iostream>
+
class Value;
class Expression;
@@ -217,9 +220,13 @@ public:
#include <CGAL/Cartesian.h>
#include <CGAL/Polyhedron_3.h>
#include <CGAL/Nef_polyhedron_3.h>
+#include <CGAL/IO/Polyhedron_iostream.h>
-typedef CGAL::Extended_cartesian<CGAL::Gmpq> CGAL_Kernel;
+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_Polyhedron::HalfedgeDS CGAL_HDS;
+typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
typedef CGAL::Nef_polyhedron_3<CGAL_Kernel> 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 <CGAL/Cartesian.h>
+#include <CGAL/IO/Nef_polyhedron_iostream_3.h>
+#include <CGAL/IO/Polyhedron_VRML_1_ostream.h>
+#include <CGAL/IO/Polyhedron_iostream.h>
+#include <CGAL/Nef_polyhedron_3.h>
+#include <CGAL/Polyhedron_3.h>
+#include <CGAL/Simple_cartesian.h>
+#include <fstream>
+#include <iostream>
+#include <CGAL/IO/Qt_widget_Nef_3.h>
+#include <qapplication.h>
+
+#define VERBOSE 0
+
+typedef CGAL::Cartesian<CGAL::Gmpq> Kernel;
+typedef CGAL::Polyhedron_3<Kernel> Polyhedron;
+typedef CGAL::Nef_polyhedron_3<Kernel> Nef_polyhedron;
+
+int main(int argc, char **argv)
+{
+ QApplication a(argc, argv);
+
+ for (int i=1; i<argc; i++) {
+ std::ifstream inFile(argv[i]);
+ if (inFile.fail()) {
+ std::cerr << "unable to open file " << argv[i] << " for reading!" << std::endl;
+ exit(1);
+ }
+#if VERBOSE
+ printf("--- %s ---\n", argv[i]);
+#endif
+ Polyhedron P;
+ CGAL::scan_OFF(inFile, P, true);
+ if (inFile.bad()) {
+ std::cerr << "failed reading OFF file " << argv[i] << "!" << std::endl;
+ exit(1);
+ }
+#if VERBOSE
+ printf("P: Closed: %6s\n", P.is_closed() ? "yes" : "no");
+ printf("P: Vertices: %6d\n", (int)P.size_of_vertices());
+ printf("P: Halfedges: %6d\n", (int)P.size_of_halfedges());
+ printf("P: Facets: %6d\n", (int)P.size_of_facets());
+#endif
+ Nef_polyhedron NP(P);
+#if VERBOSE
+ printf("NP: Simple: %6s\n", NP.is_simple() ? "yes" : "no");
+ printf("NP: Valid: %6s\n", NP.is_valid() ? "yes" : "no");
+ printf("NP: Vertices: %6d\n", (int)NP.number_of_vertices());
+ printf("NP: Halfedges: %6d\n", (int)NP.number_of_halfedges());
+ printf("NP: Edges: %6d\n", (int)NP.number_of_edges());
+ printf("NP: Halffacets: %6d\n", (int)NP.number_of_halffacets());
+ printf("NP: Facets: %6d\n", (int)NP.number_of_facets());
+ printf("NP: Volumes: %6d\n", (int)NP.number_of_volumes());
+#endif
+ CGAL::Qt_widget_Nef_3<Nef_polyhedron>* w = new CGAL::Qt_widget_Nef_3<Nef_polyhedron>(NP);
+ if (i == 1)
+ a.setMainWidget(w);
+ w->show();
+ }
+
+ return a.exec();
+}
+
contact: Jan Huwald // Impressum