mirror of https://github.com/vitalif/openscad
Clifford Wolf:
Improved cube generation Added simple off viewer git-svn-id: http://svn.clifford.at/openscad/trunk@8 b57f626f-c46c-0410-a088-ec61d464b74cstl_dim
parent
1f08d77f54
commit
e320641d0f
69
cube.cc
69
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue