summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/CGALEvaluator.cc54
-rw-r--r--src/OpenCSGRenderer.cc3
-rw-r--r--src/PolySetCGALEvaluator.cc70
-rw-r--r--src/cgalrenderer.cc4
-rw-r--r--src/csgterm.cc10
-rw-r--r--src/csgterm.h5
-rw-r--r--src/dxfdata.cc91
-rw-r--r--src/dxfdata.h14
-rw-r--r--src/dxfdim.cc8
-rw-r--r--src/dxftess-cgal.cc4
-rw-r--r--src/dxftess-glu.cc10
-rw-r--r--src/dxftess.cc8
-rw-r--r--src/export.cc12
-rw-r--r--src/import.cc2
-rw-r--r--src/nef2dxf.cc2
-rw-r--r--src/polyset.cc136
-rw-r--r--src/polyset.h35
-rw-r--r--src/primitives.cc6
-rw-r--r--src/surface.cc2
19 files changed, 248 insertions, 228 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index 021537c..c251343 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -193,10 +193,10 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
DxfData dd(N);
for (int i=0; i < dd.points.size(); i++) {
- CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd.points[i].x, dd.points[i].y);
+ CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd.points[i][0], dd.points[i][1]);
p = t.transform(p);
- dd.points[i].x = to_double(p.x());
- dd.points[i].y = to_double(p.y());
+ dd.points[i][0] = to_double(p.x());
+ dd.points[i][1] = to_double(p.y());
}
PolySet ps;
@@ -309,7 +309,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const AbstractPolyNode &node
class CGAL_Build_PolySet : public CGAL::Modifier_base<CGAL_HDS>
{
public:
- typedef CGAL_HDS::Vertex::Point Point;
+ typedef CGAL_HDS::Vertex::Point CGALPoint;
const PolySet &ps;
CGAL_Build_PolySet(const PolySet &ps) : ps(ps) { }
@@ -318,16 +318,16 @@ public:
{
CGAL_Polybuilder B(hds, true);
- QList<PolySet::Point> vertices;
+ QList<CGALPoint> vertices;
Grid3d<int> vertices_idx(GRID_FINE);
- for (int i = 0; i < ps.polygons.size(); i++) {
+ for (size_t i = 0; i < ps.polygons.size(); i++) {
const PolySet::Polygon *poly = &ps.polygons[i];
- for (int j = 0; j < poly->size(); j++) {
- const PolySet::Point *p = &poly->at(j);
- if (!vertices_idx.has(p->x, p->y, p->z)) {
- vertices_idx.data(p->x, p->y, p->z) = vertices.size();
- vertices.append(*p);
+ for (size_t j = 0; j < poly->size(); j++) {
+ const Vector3d &p = poly->at(j);
+ if (!vertices_idx.has(p[0], p[1], p[2])) {
+ vertices_idx.data(p[0], p[1], p[2]) = vertices.size();
+ vertices.append(CGALPoint(p[0], p[1], p[2]));
}
}
}
@@ -337,21 +337,21 @@ public:
printf("=== CGAL Surface ===\n");
#endif
- for (int i = 0; i < vertices.size(); i++) {
- const PolySet::Point *p = &vertices[i];
- B.add_vertex(Point(p->x, p->y, p->z));
+ for (size_t i = 0; i < vertices.size(); i++) {
+ const CGALPoint &p = vertices[i];
+ B.add_vertex(p);
#ifdef GEN_SURFACE_DEBUG
- printf("%d: %f %f %f\n", i, p->x, p->y, p->z);
+ printf("%d: %f %f %f\n", i, p[0], p[1], p[2]);
#endif
}
- for (int i = 0; i < ps.polygons.size(); i++) {
+ for (size_t i = 0; i < ps.polygons.size(); i++) {
const PolySet::Polygon *poly = &ps.polygons[i];
QHash<int,int> fc;
bool facet_is_degenerated = false;
- for (int j = 0; j < poly->size(); j++) {
- const PolySet::Point *p = &poly->at(j);
- int v = vertices_idx.data(p->x, p->y, p->z);
+ for (size_t j = 0; j < poly->size(); j++) {
+ const Vector3d &p = poly->at(j);
+ int v = vertices_idx.data(p[0], p[1], p[2]);
if (fc[v]++ > 0)
facet_is_degenerated = true;
}
@@ -361,13 +361,13 @@ public:
#ifdef GEN_SURFACE_DEBUG
printf("F:");
#endif
- for (int j = 0; j < poly->size(); j++) {
- const PolySet::Point *p = &poly->at(j);
+ for (size_t j = 0; j < poly->size(); j++) {
+ const Vector3d &p = poly->at(j);
#ifdef GEN_SURFACE_DEBUG
- printf(" %d (%f,%f,%f)", vertices_idx.data(p->x, p->y, p->z), p->x, p->y, p->z);
+ printf(" %d (%f,%f,%f)", vertices_idx.data(p[0], p[1], p[2]), p[0], p[1], p[2]);
#endif
if (!facet_is_degenerated)
- B.add_vertex_to_facet(vertices_idx.data(p->x, p->y, p->z));
+ B.add_vertex_to_facet(vertices_idx.data(p[0], p[1], p[2]));
}
#ifdef GEN_SURFACE_DEBUG
if (facet_is_degenerated)
@@ -494,10 +494,10 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)
PolyReducer(const PolySet &ps) : grid(GRID_COARSE), poly_n(1)
{
int point_n = 1;
- for (int i = 0; i < ps.polygons.size(); i++) {
- for (int j = 0; j < ps.polygons[i].size(); j++) {
- double x = ps.polygons[i][j].x;
- double y = ps.polygons[i][j].y;
+ for (size_t i = 0; i < ps.polygons.size(); i++) {
+ for (size_t j = 0; j < ps.polygons[i].size(); j++) {
+ double x = ps.polygons[i][j][0];
+ double y = ps.polygons[i][j][1];
if (this->grid.has(x, y)) {
this->polygons[this->poly_n].append(this->grid.data(x, y));
} else {
diff --git a/src/OpenCSGRenderer.cc b/src/OpenCSGRenderer.cc
index 9030d11..6cbe849 100644
--- a/src/OpenCSGRenderer.cc
+++ b/src/OpenCSGRenderer.cc
@@ -28,6 +28,9 @@
#include "OpenCSGRenderer.h"
#include "polyset.h"
#include "csgterm.h"
+#ifdef ENABLE_OPENCSG
+# include <opencsg.h>
+#endif
class OpenCSGPrim : public OpenCSG::Primitive
{
diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc
index e769730..c269045 100644
--- a/src/PolySetCGALEvaluator.cc
+++ b/src/PolySetCGALEvaluator.cc
@@ -77,11 +77,11 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
PolySet *ps3 = new PolySet();
cgal_nef3_to_polyset(ps3, &N);
Grid2d<int> conversion_grid(GRID_COARSE);
- for (int i = 0; i < ps3->polygons.size(); i++) {
- for (int j = 0; j < ps3->polygons[i].size(); j++) {
- double x = ps3->polygons[i][j].x;
- double y = ps3->polygons[i][j].y;
- double z = ps3->polygons[i][j].z;
+ for (size_t i = 0; i < ps3->polygons.size(); i++) {
+ for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
+ double x = ps3->polygons[i][j][0];
+ double y = ps3->polygons[i][j][1];
+ double z = ps3->polygons[i][j][2];
if (z != 0)
goto next_ps3_polygon_cut_mode;
if (conversion_grid.align(x, y) == i+1)
@@ -89,9 +89,9 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
conversion_grid.data(x, y) = i+1;
}
ps->append_poly();
- for (int j = 0; j < ps3->polygons[i].size(); j++) {
- double x = ps3->polygons[i][j].x;
- double y = ps3->polygons[i][j].y;
+ for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
+ double x = ps3->polygons[i][j][0];
+ double y = ps3->polygons[i][j][1];
conversion_grid.align(x, y);
ps->insert_vertex(x, y);
}
@@ -110,12 +110,12 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
cgal_nef3_to_polyset(ps3, &N);
CGAL_Nef_polyhedron np;
np.dim = 2;
- for (int i = 0; i < ps3->polygons.size(); i++)
+ for (size_t i = 0; i < ps3->polygons.size(); i++)
{
int min_x_p = -1;
double min_x_val = 0;
- for (int j = 0; j < ps3->polygons[i].size(); j++) {
- double x = ps3->polygons[i][j].x;
+ for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
+ double x = ps3->polygons[i][j][0];
if (min_x_p < 0 || x < min_x_val) {
min_x_p = j;
min_x_val = x;
@@ -123,11 +123,11 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
}
int min_x_p1 = (min_x_p+1) % ps3->polygons[i].size();
int min_x_p2 = (min_x_p+ps3->polygons[i].size()-1) % ps3->polygons[i].size();
- double ax = ps3->polygons[i][min_x_p1].x - ps3->polygons[i][min_x_p].x;
- double ay = ps3->polygons[i][min_x_p1].y - ps3->polygons[i][min_x_p].y;
+ double ax = ps3->polygons[i][min_x_p1][0] - ps3->polygons[i][min_x_p][0];
+ double ay = ps3->polygons[i][min_x_p1][1] - ps3->polygons[i][min_x_p][1];
double at = atan2(ay, ax);
- double bx = ps3->polygons[i][min_x_p2].x - ps3->polygons[i][min_x_p].x;
- double by = ps3->polygons[i][min_x_p2].y - ps3->polygons[i][min_x_p].y;
+ double bx = ps3->polygons[i][min_x_p2][0] - ps3->polygons[i][min_x_p][0];
+ double by = ps3->polygons[i][min_x_p2][1] - ps3->polygons[i][min_x_p][1];
double bt = atan2(by, bx);
double eps = 0.000001;
@@ -138,9 +138,9 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
}
std::list<CGAL_Nef_polyhedron2::Point> plist;
- for (int j = 0; j < ps3->polygons[i].size(); j++) {
- double x = ps3->polygons[i][j].x;
- double y = ps3->polygons[i][j].y;
+ for (size_t j = 0; j < ps3->polygons[i].size(); j++) {
+ double x = ps3->polygons[i][j][0];
+ double y = ps3->polygons[i][j][1];
CGAL_Nef_polyhedron2::Point p = CGAL_Nef_polyhedron2::Point(x, y);
if (at > bt)
plist.push_front(p);
@@ -168,17 +168,17 @@ static void add_slice(PolySet *ps, DxfData::Path *pt, double rot1, double rot2,
{
int k = j - 1;
- double jx1 = pt->points[j]->x * cos(rot1*M_PI/180) + pt->points[j]->y * sin(rot1*M_PI/180);
- double jy1 = pt->points[j]->x * -sin(rot1*M_PI/180) + pt->points[j]->y * cos(rot1*M_PI/180);
+ double jx1 = (*pt->points[j])[0] * cos(rot1*M_PI/180) + (*pt->points[j])[1] * sin(rot1*M_PI/180);
+ double jy1 = (*pt->points[j])[0] * -sin(rot1*M_PI/180) + (*pt->points[j])[1] * cos(rot1*M_PI/180);
- double jx2 = pt->points[j]->x * cos(rot2*M_PI/180) + pt->points[j]->y * sin(rot2*M_PI/180);
- double jy2 = pt->points[j]->x * -sin(rot2*M_PI/180) + pt->points[j]->y * cos(rot2*M_PI/180);
+ double jx2 = (*pt->points[j])[0] * cos(rot2*M_PI/180) + (*pt->points[j])[1] * sin(rot2*M_PI/180);
+ double jy2 = (*pt->points[j])[0] * -sin(rot2*M_PI/180) + (*pt->points[j])[1] * cos(rot2*M_PI/180);
- double kx1 = pt->points[k]->x * cos(rot1*M_PI/180) + pt->points[k]->y * sin(rot1*M_PI/180);
- double ky1 = pt->points[k]->x * -sin(rot1*M_PI/180) + pt->points[k]->y * cos(rot1*M_PI/180);
+ double kx1 = (*pt->points[k])[0] * cos(rot1*M_PI/180) + (*pt->points[k])[1] * sin(rot1*M_PI/180);
+ double ky1 = (*pt->points[k])[0] * -sin(rot1*M_PI/180) + (*pt->points[k])[1] * cos(rot1*M_PI/180);
- double kx2 = pt->points[k]->x * cos(rot2*M_PI/180) + pt->points[k]->y * sin(rot2*M_PI/180);
- double ky2 = pt->points[k]->x * -sin(rot2*M_PI/180) + pt->points[k]->y * cos(rot2*M_PI/180);
+ double kx2 = (*pt->points[k])[0] * cos(rot2*M_PI/180) + (*pt->points[k])[1] * sin(rot2*M_PI/180);
+ double ky2 = (*pt->points[k])[0] * -sin(rot2*M_PI/180) + (*pt->points[k])[1] * cos(rot2*M_PI/180);
double dia1_len_sq = (jy1-ky2)*(jy1-ky2) + (jx1-kx2)*(jx1-kx2);
double dia2_len_sq = (jy2-ky1)*(jy2-ky1) + (jx2-kx1)*(jx2-kx1);
@@ -281,10 +281,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node,
first_open_path = false;
}
PRINTF(" %9.5f %10.5f ... %10.5f %10.5f",
- dxf->paths[i].points.first()->x / node.scale + node.origin_x,
- dxf->paths[i].points.first()->y / node.scale + node.origin_y,
- dxf->paths[i].points.last()->x / node.scale + node.origin_x,
- dxf->paths[i].points.last()->y / node.scale + node.origin_y);
+ (*dxf->paths[i].points.first())[0] / node.scale + node.origin_x,
+ (*dxf->paths[i].points.first())[1] / node.scale + node.origin_y,
+ (*dxf->paths[i].points.last())[0] / node.scale + node.origin_x,
+ (*dxf->paths[i].points.last())[1] / node.scale + node.origin_y);
}
@@ -355,7 +355,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,
{
double max_x = 0;
for (int j = 0; j < dxf->paths[i].points.count(); j++) {
- max_x = fmax(max_x, dxf->paths[i].points[j]->x);
+ max_x = fmax(max_x, (*dxf->paths[i].points[j])[0]);
}
int fragments = get_fragments_from_r(max_x, node.fn, node.fs, node.fa);
@@ -371,14 +371,14 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,
for (int j = 0; j < fragments; j++) {
double a = (j*2*M_PI) / fragments;
for (int k = 0; k < dxf->paths[i].points.count(); k++) {
- if (dxf->paths[i].points[k]->x == 0) {
+ if ((*dxf->paths[i].points[k])[0] == 0) {
points[j][k][0] = 0;
points[j][k][1] = 0;
} else {
- points[j][k][0] = dxf->paths[i].points[k]->x * sin(a);
- points[j][k][1] = dxf->paths[i].points[k]->x * cos(a);
+ points[j][k][0] = (*dxf->paths[i].points[k])[0] * sin(a);
+ points[j][k][1] = (*dxf->paths[i].points[k])[0] * cos(a);
}
- points[j][k][2] = dxf->paths[i].points[k]->y;
+ points[j][k][2] = (*dxf->paths[i].points[k])[1];
}
}
diff --git a/src/cgalrenderer.cc b/src/cgalrenderer.cc
index 551c061..687a0f1 100644
--- a/src/cgalrenderer.cc
+++ b/src/cgalrenderer.cc
@@ -73,8 +73,8 @@ void CGALRenderer::draw(bool showfaces, bool showedges) const
for (int i=0; i < this->polyset->polygons.size(); i++) {
glBegin(GL_POLYGON);
for (int j=0; j < this->polyset->polygons[i].size(); j++) {
- PolySet::Point p = this->polyset->polygons[i][j];
- glVertex3d(p.x, p.y, -0.1);
+ const Vector3d &p = this->polyset->polygons[i][j];
+ glVertex3d(p[0], p[1], -0.1);
}
glEnd();
}
diff --git a/src/csgterm.cc b/src/csgterm.cc
index 930a540..411cb12 100644
--- a/src/csgterm.cc
+++ b/src/csgterm.cc
@@ -229,3 +229,13 @@ QString CSGChain::dump()
return text;
}
+BoundingBox CSGChain::getBoundingBox() const
+{
+ BoundingBox bbox;
+ for (size_t i=0;i<polysets.size();i++) {
+ if (types[i] != CSGTerm::TYPE_DIFFERENCE) {
+ bbox.extend(polysets[i]->getBoundingBox());
+ }
+ }
+ return bbox;
+}
diff --git a/src/csgterm.h b/src/csgterm.h
index 4ee6faa..c1dc0fd 100644
--- a/src/csgterm.h
+++ b/src/csgterm.h
@@ -3,6 +3,7 @@
#include <QString>
#include <QVector>
+#include "polyset.h"
class CSGTerm
{
@@ -15,7 +16,7 @@ public:
};
type_e type;
- class PolySet *polyset;
+ PolySet *polyset;
QString label;
CSGTerm *left;
CSGTerm *right;
@@ -46,6 +47,8 @@ public:
void add(PolySet *polyset, double *m, CSGTerm::type_e type, QString label);
void import(CSGTerm *term, CSGTerm::type_e type = CSGTerm::TYPE_UNION);
QString dump();
+
+ BoundingBox getBoundingBox() const;
};
#endif
diff --git a/src/dxfdata.cc b/src/dxfdata.cc
index 55d00b4..78ab454 100644
--- a/src/dxfdata.cc
+++ b/src/dxfdata.cc
@@ -37,10 +37,9 @@
#include <assert.h>
struct Line {
- typedef DxfData::Point Point;
- Point *p[2];
+ Vector2d *p[2];
bool disabled;
- Line(Point *p1, Point *p2) { p[0] = p1; p[1] = p2; disabled = false; }
+ Line(Vector2d *p1, Vector2d *p2) { p[0] = p1; p[1] = p2; disabled = false; }
Line() { p[0] = NULL; p[1] = NULL; disabled = false; }
};
@@ -162,16 +161,16 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
}
else if (mode == "CIRCLE") {
int n = get_fragments_from_r(radius, fn, fs, fa);
- Point center(xverts[0], yverts[0]);
+ Vector2d center(xverts[0], yverts[0]);
for (int i = 0; i < n; i++) {
double a1 = (2*M_PI*i)/n;
double a2 = (2*M_PI*(i+1))/n;
- ADD_LINE(cos(a1)*radius + center.x, sin(a1)*radius + center.y,
- cos(a2)*radius + center.x, sin(a2)*radius + center.y);
+ ADD_LINE(cos(a1)*radius + center[0], sin(a1)*radius + center[1],
+ cos(a2)*radius + center[0], sin(a2)*radius + center[1]);
}
}
else if (mode == "ARC") {
- Point center(xverts[0], yverts[0]);
+ Vector2d center(xverts[0], yverts[0]);
int n = get_fragments_from_r(radius, fn, fs, fa);
while (arc_start_angle > arc_stop_angle)
arc_stop_angle += 360.0;
@@ -181,29 +180,29 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
double a2 = ((arc_stop_angle-arc_start_angle)*(i+1))/n;
a1 = (arc_start_angle + a1) * M_PI / 180.0;
a2 = (arc_start_angle + a2) * M_PI / 180.0;
- ADD_LINE(cos(a1)*radius + center.x, sin(a1)*radius + center.y,
- cos(a2)*radius + center.x, sin(a2)*radius + center.y);
+ ADD_LINE(cos(a1)*radius + center[0], sin(a1)*radius + center[1],
+ cos(a2)*radius + center[0], sin(a2)*radius + center[1]);
}
}
else if (mode == "ELLIPSE") {
// Commented code is meant as documentation of vector math
while (ellipse_start_angle > ellipse_stop_angle) ellipse_stop_angle += 2 * M_PI;
// Vector2d center(xverts[0], yverts[0]);
- Point center(xverts[0], yverts[0]);
+ Vector2d center(xverts[0], yverts[0]);
// Vector2d ce(xverts[1], yverts[1]);
- Point ce(xverts[1], yverts[1]);
+ Vector2d ce(xverts[1], yverts[1]);
// double r_major = ce.length();
- double r_major = sqrt(ce.x*ce.x + ce.y*ce.y);
+ double r_major = sqrt(ce[0]*ce[0] + ce[1]*ce[1]);
// double rot_angle = ce.angle();
double rot_angle;
{
// double dot = ce.dot(Vector2d(1.0, 0.0));
- double dot = ce.x;
+ double dot = ce[0];
double cosval = dot / r_major;
if (cosval > 1.0) cosval = 1.0;
if (cosval < -1.0) cosval = -1.0;
rot_angle = acos(cosval);
- if (ce.y < 0.0) rot_angle = 2 * M_PI - rot_angle;
+ if (ce[1] < 0.0) rot_angle = 2 * M_PI - rot_angle;
}
// the ratio stored in 'radius; due to the parser code not checking entity type
@@ -212,24 +211,24 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
int n = get_fragments_from_r(r_major, fn, fs, fa);
n = (int)ceil(n * sweep_angle / (2 * M_PI));
// Vector2d p1;
- Point p1;
+ Vector2d p1;
for (int i=0;i<=n;i++) {
double a = (ellipse_start_angle + sweep_angle*i/n);
// Vector2d p2(cos(a)*r_major, sin(a)*r_minor);
- Point p2(cos(a)*r_major, sin(a)*r_minor);
+ Vector2d p2(cos(a)*r_major, sin(a)*r_minor);
// p2.rotate(rot_angle);
- Point p2_rot(cos(rot_angle)*p2.x - sin(rot_angle)*p2.y,
- sin(rot_angle)*p2.x + cos(rot_angle)*p2.y);
+ Vector2d p2_rot(cos(rot_angle)*p2[0] - sin(rot_angle)*p2[1],
+ sin(rot_angle)*p2[0] + cos(rot_angle)*p2[1]);
// p2 += center;
- p2_rot.x += center.x;
- p2_rot.y += center.y;
+ p2_rot[0] += center[0];
+ p2_rot[1] += center[1];
if (i > 0) {
// ADD_LINE(p1[0], p1[1], p2[0], p2[1]);
- ADD_LINE(p1.x, p1.y, p2_rot.x, p2_rot.y);
+ ADD_LINE(p1[0], p1[1], p2_rot[0], p2_rot[1]);
}
// p1 = p2;
- p1.x = p2_rot.x;
- p1.y = p2_rot.y;
+ p1[0] = p2_rot[0];
+ p1[1] = p2_rot[1];
}
}
else if (mode == "INSERT") {
@@ -238,10 +237,10 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
int n = blockdata[iddata].size();
for (int i = 0; i < n; i++) {
double a = arc_start_angle * M_PI / 180.0;
- double lx1 = blockdata[iddata][i].p[0]->x * ellipse_start_angle;
- double ly1 = blockdata[iddata][i].p[0]->y * ellipse_stop_angle;
- double lx2 = blockdata[iddata][i].p[1]->x * ellipse_start_angle;
- double ly2 = blockdata[iddata][i].p[1]->y * ellipse_stop_angle;
+ double lx1 = (*blockdata[iddata][i].p[0])[0] * ellipse_start_angle;
+ double ly1 = (*blockdata[iddata][i].p[0])[1] * ellipse_stop_angle;
+ double lx2 = (*blockdata[iddata][i].p[1])[0] * ellipse_start_angle;
+ double ly2 = (*blockdata[iddata][i].p[1])[1] * ellipse_stop_angle;
double px1 = (cos(a)*lx1 - sin(a)*ly1) * scale + xverts[0];
double py1 = (sin(a)*lx1 + cos(a)*ly1) * scale + yverts[0];
double px2 = (cos(a)*lx2 - sin(a)*ly2) * scale + xverts[0];
@@ -381,7 +380,7 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
foreach (int i, enabled_lines) {
for (int j = 0; j < 2; j++) {
- QVector<int> *lv = &grid.data(lines[i].p[j]->x, lines[i].p[j]->y);
+ QVector<int> *lv = &grid.data((*lines[i].p[j])[0], (*lines[i].p[j])[1]);
for (int ki = 0; ki < lv->count(); ki++) {
int k = lv->at(ki);
if (k == i || lines[k].disabled)
@@ -404,20 +403,20 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
this_path->points.append(lines[current_line].p[current_point]);
while (1) {
this_path->points.append(lines[current_line].p[!current_point]);
- Point *ref_point = lines[current_line].p[!current_point];
+ const Vector2d &ref_point = *lines[current_line].p[!current_point];
lines[current_line].disabled = true;
enabled_lines.remove(current_line);
- QVector<int> *lv = &grid.data(ref_point->x, ref_point->y);
+ QVector<int> *lv = &grid.data(ref_point[0], ref_point[1]);
for (int ki = 0; ki < lv->count(); ki++) {
int k = lv->at(ki);
if (lines[k].disabled)
continue;
- if (grid.eq(ref_point->x, ref_point->y, lines[k].p[0]->x, lines[k].p[0]->y)) {
+ if (grid.eq(ref_point[0], ref_point[1], (*lines[k].p[0])[0], (*lines[k].p[0])[1])) {
current_line = k;
current_point = 0;
goto found_next_line_in_open_path;
}
- if (grid.eq(ref_point->x, ref_point->y, lines[k].p[1]->x, lines[k].p[1]->y)) {
+ if (grid.eq(ref_point[0], ref_point[1], (*lines[k].p[1])[0], (*lines[k].p[1])[1])) {
current_line = k;
current_point = 1;
goto found_next_line_in_open_path;
@@ -440,20 +439,20 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
this_path->points.append(lines[current_line].p[current_point]);
while (1) {
this_path->points.append(lines[current_line].p[!current_point]);
- Point *ref_point = lines[current_line].p[!current_point];
+ const Vector2d &ref_point = *lines[current_line].p[!current_point];
lines[current_line].disabled = true;
enabled_lines.remove(current_line);
- QVector<int> *lv = &grid.data(ref_point->x, ref_point->y);
+ QVector<int> *lv = &grid.data(ref_point[0], ref_point[1]);
for (int ki = 0; ki < lv->count(); ki++) {
int k = lv->at(ki);
if (lines[k].disabled)
continue;
- if (grid.eq(ref_point->x, ref_point->y, lines[k].p[0]->x, lines[k].p[0]->y)) {
+ if (grid.eq(ref_point[0], ref_point[1], (*lines[k].p[0])[0], (*lines[k].p[0])[1])) {
current_line = k;
current_point = 0;
goto found_next_line_in_closed_path;
}
- if (grid.eq(ref_point->x, ref_point->y, lines[k].p[1]->x, lines[k].p[1]->y)) {
+ if (grid.eq(ref_point[0], ref_point[1], (*lines[k].p[1])[0], (*lines[k].p[1])[1])) {
current_line = k;
current_point = 1;
goto found_next_line_in_closed_path;
@@ -471,7 +470,7 @@ DxfData::DxfData(double fn, double fs, double fa, QString filename, QString laye
for (int i = 0; i < this->paths.count(); i++) {
printf("Path %d (%s):\n", i, this->paths[i].is_closed ? "closed" : "open");
for (int j = 0; j < this->paths[i].points.count(); j++)
- printf(" %f %f\n", this->paths[i].points[j]->x, this->paths[i].points[j]->y);
+ printf(" %f %f\n", (*this->paths[i].points[j])[0], (*this->paths[i].points[j])[1]);
}
printf("--------------------\n");
fflush(stdout);
@@ -488,11 +487,11 @@ void DxfData::fixup_path_direction()
if (!this->paths[i].is_closed)
break;
this->paths[i].is_inner = true;
- double min_x = this->paths[i].points[0]->x;
+ double min_x = (*this->paths[i].points[0])[0];
int min_x_point = 0;
for (int j = 1; j < this->paths[i].points.count(); j++) {
- if (this->paths[i].points[j]->x < min_x) {
- min_x = this->paths[i].points[j]->x;
+ if ((*this->paths[i].points[j])[0] < min_x) {
+ min_x = (*this->paths[i].points[j])[0];
min_x_point = j;
}
}
@@ -500,10 +499,10 @@ void DxfData::fixup_path_direction()
int b = min_x_point;
int a = b == 0 ? this->paths[i].points.count() - 2 : b - 1;
int c = b == this->paths[i].points.count() - 1 ? 1 : b + 1;
- double ax = this->paths[i].points[a]->x - this->paths[i].points[b]->x;
- double ay = this->paths[i].points[a]->y - this->paths[i].points[b]->y;
- double cx = this->paths[i].points[c]->x - this->paths[i].points[b]->x;
- double cy = this->paths[i].points[c]->y - this->paths[i].points[b]->y;
+ double ax = (*this->paths[i].points[a])[0] - (*this->paths[i].points[b])[0];
+ double ay = (*this->paths[i].points[a])[1] - (*this->paths[i].points[b])[1];
+ double cx = (*this->paths[i].points[c])[0] - (*this->paths[i].points[b])[0];
+ double cy = (*this->paths[i].points[c])[1] - (*this->paths[i].points[b])[1];
#if 0
printf("Rotate check:\n");
printf(" a/b/c indices = %d %d %d\n", a, b, c);
@@ -518,9 +517,9 @@ void DxfData::fixup_path_direction()
}
}
-DxfData::Point *DxfData::addPoint(double x, double y)
+Vector2d *DxfData::addPoint(double x, double y)
{
- this->points.append(Point(x, y));
+ this->points.append(Vector2d(x, y));
return &this->points.last();
}
diff --git a/src/dxfdata.h b/src/dxfdata.h
index d59ff5a..e71a740 100644
--- a/src/dxfdata.h
+++ b/src/dxfdata.h
@@ -3,17 +3,15 @@
#include <QList>
#include <QString>
+#include <Eigen/Dense>
+
+using Eigen::Vector2d;
class DxfData
{
public:
- struct Point {
- double x, y;
- Point() : x(0), y(0) { }
- Point(double x, double y) : x(x), y(y) { }
- };
struct Path {
- QList<Point*> points;
+ QList<Vector2d*> points;
bool is_closed, is_inner;
Path() : is_closed(false), is_inner(false) { }
};
@@ -33,7 +31,7 @@ public:
}
};
- QList<Point> points;
+ QList<Vector2d> points;
QList<Path> paths;
QList<Dim> dims;
@@ -43,7 +41,7 @@ public:
DxfData(const struct CGAL_Nef_polyhedron &N);
#endif
- Point *addPoint(double x, double y);
+ Vector2d *addPoint(double x, double y);
private:
void fixup_path_direction();
diff --git a/src/dxfdim.cc b/src/dxfdim.cc
index f8008f5..666b53d 100644
--- a/src/dxfdim.cc
+++ b/src/dxfdim.cc
@@ -157,10 +157,10 @@ Value builtin_dxf_cross(const Context *ctx, const QVector<QString> &argnames, co
for (int i = 0, j = 0; i < dxf.paths.count(); i++) {
if (dxf.paths[i].points.count() != 2)
continue;
- coords[j][0] = dxf.paths[i].points[0]->x;
- coords[j++][1] = dxf.paths[i].points[0]->y;
- coords[j][0] = dxf.paths[i].points[1]->x;
- coords[j++][1] = dxf.paths[i].points[1]->y;
+ coords[j][0] = (*dxf.paths[i].points[0])[0];
+ coords[j++][1] = (*dxf.paths[i].points[0])[1];
+ coords[j][0] = (*dxf.paths[i].points[1])[0];
+ coords[j++][1] = (*dxf.paths[i].points[1])[1];
if (j == 4) {
double x1 = coords[0][0], y1 = coords[0][1];
diff --git a/src/dxftess-cgal.cc b/src/dxftess-cgal.cc
index adb7e9a..754d161 100644
--- a/src/dxftess-cgal.cc
+++ b/src/dxftess-cgal.cc
@@ -115,8 +115,8 @@ void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool /* do_tr
struct point_info_t *first_pi = NULL, *prev_pi = NULL;
for (int j = 1; j < dxf->paths[i].points.count(); j++)
{
- double x = dxf->paths[i].points[j]->x;
- double y = dxf->paths[i].points[j]->y;
+ double x = (*dxf->paths[i].points[j])[0];
+ double y = (*dxf->paths[i].points[j])[1];
if (point_info.has(x, y)) {
// FIXME: How can the same path set contain the same point twice?
diff --git a/src/dxftess-glu.cc b/src/dxftess-glu.cc
index 63fa2e5..691872d 100644
--- a/src/dxftess-glu.cc
+++ b/src/dxftess-glu.cc
@@ -232,12 +232,12 @@ void dxf_tesselate(PolySet *ps, DxfData *dxf, double rot, bool up, bool do_trian
continue;
gluTessBeginContour(tobj);
for (int j = 1; j < dxf->paths[i].points.count(); j++) {
- point_to_path.data(dxf->paths[i].points[j]->x,
- dxf->paths[i].points[j]->y,
- h) = QPair<int,int>(i, j);
+ point_to_path.data((*dxf->paths[i].points[j])[0],
+ (*dxf->paths[i].points[j])[1],
+ h) = QPair<int,int>(i, j);
vl.append(tess_vdata());
- vl.last().v[0] = dxf->paths[i].points[j]->x;
- vl.last().v[1] = dxf->paths[i].points[j]->y;
+ vl.last().v[0] = (*dxf->paths[i].points[j])[0];
+ vl.last().v[1] = (*dxf->paths[i].points[j])[1];
vl.last().v[2] = h;
gluTessVertex(tobj, vl.last().v, vl.last().v);
}
diff --git a/src/dxftess.cc b/src/dxftess.cc
index 03ed244..73d235f 100644
--- a/src/dxftess.cc
+++ b/src/dxftess.cc
@@ -43,14 +43,14 @@ void dxf_border_to_ps(PolySet *ps, DxfData *dxf)
const DxfData::Path &pt = dxf->paths[i];
if (!pt.is_closed)
continue;
- ps->borders.append(PolySet::Polygon());
+ ps->borders.push_back(PolySet::Polygon());
for (int j = 1; j < pt.points.count(); j++) {
- double x = pt.points[j]->x, y = pt.points[j]->y, z = 0.0;
+ double x = (*pt.points[j])[0], y = (*pt.points[j])[1], z = 0.0;
ps->grid.align(x, y, z);
if (pt.is_inner) {
- ps->borders.last().append(PolySet::Point(x, y, z));
+ ps->borders.back().push_back(Vector3d(x, y, z));
} else {
- ps->borders.last().insert(0, PolySet::Point(x, y, z));
+ ps->borders.back().insert(ps->borders.back().begin(), Vector3d(x, y, z));
}
}
}
diff --git a/src/export.cc b/src/export.cc
index 1f9046e..c87e917 100644
--- a/src/export.cc
+++ b/src/export.cc
@@ -171,12 +171,12 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo
for (int i=0; i<dd.paths.size(); i++)
{
for (int j=1; j<dd.paths[i].points.size(); j++) {
- DxfData::Point *p1 = dd.paths[i].points[j-1];
- DxfData::Point *p2 = dd.paths[i].points[j];
- double x1 = p1->x;
- double y1 = p1->y;
- double x2 = p2->x;
- double y2 = p2->y;
+ const Vector2d &p1 = *dd.paths[i].points[j-1];
+ const Vector2d &p2 = *dd.paths[i].points[j];
+ double x1 = p1[0];
+ double y1 = p1[1];
+ double x2 = p2[0];
+ double y2 = p2[1];
output << " 0\n"
<< "LINE\n";
// Some importers (e.g. Inkscape) needs a layer to be specified
diff --git a/src/import.cc b/src/import.cc
index fdac5b9..7435d4d 100644
--- a/src/import.cc
+++ b/src/import.cc
@@ -36,6 +36,8 @@
#include "openscad.h" // handle_dep()
#include <QFile>
+#include <QRegExp>
+#include <QStringList>
#include <sys/types.h>
#include <sys/stat.h>
#include <sstream>
diff --git a/src/nef2dxf.cc b/src/nef2dxf.cc
index b22e605..cbefa9c 100644
--- a/src/nef2dxf.cc
+++ b/src/nef2dxf.cc
@@ -53,7 +53,7 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
this_point = grid.align(x, y);
} else {
this_point = grid.align(x, y) = points.size();
- points.append(Point(x, y));
+ points.append(Vector2d(x, y));
}
if (first_point < 0) {
paths.append(Path());
diff --git a/src/polyset.cc b/src/polyset.cc
index eda6304..19b0bba 100644
--- a/src/polyset.cc
+++ b/src/polyset.cc
@@ -34,6 +34,7 @@
#endif
#include <Eigen/Core>
#include <Eigen/LU>
+#include <QColor>
PolySet::PolySet() : grid(GRID_FINE)
{
@@ -61,26 +62,26 @@ void PolySet::unlink()
void PolySet::append_poly()
{
- polygons.append(Polygon());
+ polygons.push_back(Polygon());
}
void PolySet::append_vertex(double x, double y, double z)
{
grid.align(x, y, z);
- polygons.last().append(Point(x, y, z));
+ polygons.back().push_back(Vector3d(x, y, z));
}
void PolySet::insert_vertex(double x, double y, double z)
{
grid.align(x, y, z);
- polygons.last().insert(0, Point(x, y, z));
+ polygons.back().insert(polygons.back().begin(), Vector3d(x, y, z));
}
-static void gl_draw_triangle(GLint *shaderinfo, const PolySet::Point *p0, const PolySet::Point *p1, const PolySet::Point *p2, bool e0, bool e1, bool e2, double z, bool mirrored)
+static void gl_draw_triangle(GLint *shaderinfo, const Vector3d &p0, const Vector3d &p1, const Vector3d &p2, bool e0, bool e1, bool e2, double z, bool mirrored)
{
- double ax = p1->x - p0->x, bx = p1->x - p2->x;
- double ay = p1->y - p0->y, by = p1->y - p2->y;
- double az = p1->z - p0->z, bz = p1->z - p2->z;
+ double ax = p1[0] - p0[0], bx = p1[0] - p2[0];
+ double ay = p1[1] - p0[1], by = p1[1] - p2[1];
+ double az = p1[2] - p0[2], bz = p1[2] - p2[2];
double nx = ay*bz - az*by;
double ny = az*bx - ax*bz;
double nz = ax*by - ay*bx;
@@ -92,39 +93,39 @@ static void gl_draw_triangle(GLint *shaderinfo, const PolySet::Point *p0, const
double e1f = e1 ? 2.0 : -1.0;
double e2f = e2 ? 2.0 : -1.0;
glVertexAttrib3d(shaderinfo[3], e0f, e1f, e2f);
- glVertexAttrib3d(shaderinfo[4], p1->x, p1->y, p1->z + z);
- glVertexAttrib3d(shaderinfo[5], p2->x, p2->y, p2->z + z);
+ glVertexAttrib3d(shaderinfo[4], p1[0], p1[1], p1[2] + z);
+ glVertexAttrib3d(shaderinfo[5], p2[0], p2[1], p2[2] + z);
glVertexAttrib3d(shaderinfo[6], 0.0, 1.0, 0.0);
- glVertex3d(p0->x, p0->y, p0->z + z);
+ glVertex3d(p0[0], p0[1], p0[2] + z);
if (!mirrored) {
glVertexAttrib3d(shaderinfo[3], e0f, e1f, e2f);
- glVertexAttrib3d(shaderinfo[4], p0->x, p0->y, p0->z + z);
- glVertexAttrib3d(shaderinfo[5], p2->x, p2->y, p2->z + z);
+ glVertexAttrib3d(shaderinfo[4], p0[0], p0[1], p0[2] + z);
+ glVertexAttrib3d(shaderinfo[5], p2[0], p2[1], p2[2] + z);
glVertexAttrib3d(shaderinfo[6], 0.0, 0.0, 1.0);
- glVertex3d(p1->x, p1->y, p1->z + z);
+ glVertex3d(p1[0], p1[1], p1[2] + z);
}
glVertexAttrib3d(shaderinfo[3], e0f, e1f, e2f);
- glVertexAttrib3d(shaderinfo[4], p0->x, p0->y, p0->z + z);
- glVertexAttrib3d(shaderinfo[5], p1->x, p1->y, p1->z + z);
+ glVertexAttrib3d(shaderinfo[4], p0[0], p0[1], p0[2] + z);
+ glVertexAttrib3d(shaderinfo[5], p1[0], p1[1], p1[2] + z);
glVertexAttrib3d(shaderinfo[6], 1.0, 0.0, 0.0);
- glVertex3d(p2->x, p2->y, p2->z + z);
+ glVertex3d(p2[0], p2[1], p2[2] + z);
if (mirrored) {
glVertexAttrib3d(shaderinfo[3], e0f, e1f, e2f);
- glVertexAttrib3d(shaderinfo[4], p0->x, p0->y, p0->z + z);
- glVertexAttrib3d(shaderinfo[5], p2->x, p2->y, p2->z + z);
+ glVertexAttrib3d(shaderinfo[4], p0[0], p0[1], p0[2] + z);
+ glVertexAttrib3d(shaderinfo[5], p2[0], p2[1], p2[2] + z);
glVertexAttrib3d(shaderinfo[6], 0.0, 0.0, 1.0);
- glVertex3d(p1->x, p1->y, p1->z + z);
+ glVertex3d(p1[0], p1[1], p1[2] + z);
}
}
else
#endif
{
- glVertex3d(p0->x, p0->y, p0->z + z);
+ glVertex3d(p0[0], p0[1], p0[2] + z);
if (!mirrored)
- glVertex3d(p1->x, p1->y, p1->z + z);
- glVertex3d(p2->x, p2->y, p2->z + z);
+ glVertex3d(p1[0], p1[1], p1[2] + z);
+ glVertex3d(p2[0], p2[1], p2[2] + z);
if (mirrored)
- glVertex3d(p1->x, p1->y, p1->z + z);
+ glVertex3d(p1[0], p1[1], p1[2] + z);
}
}
@@ -193,52 +194,52 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m
const Polygon *poly = &polygons[i];
if (poly->size() == 3) {
if (z < 0) {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(2), &poly->at(1), true, true, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(2), poly->at(1), true, true, true, z, mirrored);
} else {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(1), &poly->at(2), true, true, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(1), poly->at(2), true, true, true, z, mirrored);
}
}
else if (poly->size() == 4) {
if (z < 0) {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(3), &poly->at(1), true, false, true, z, mirrored);
- gl_draw_triangle(shaderinfo, &poly->at(2), &poly->at(1), &poly->at(3), true, false, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(3), poly->at(1), true, false, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(2), poly->at(1), poly->at(3), true, false, true, z, mirrored);
} else {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(1), &poly->at(3), true, false, true, z, mirrored);
- gl_draw_triangle(shaderinfo, &poly->at(2), &poly->at(3), &poly->at(1), true, false, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(1), poly->at(3), true, false, true, z, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(2), poly->at(3), poly->at(1), true, false, true, z, mirrored);
}
}
else {
- Point center;
+ Vector3d center;
for (int j = 0; j < poly->size(); j++) {
- center.x += poly->at(j).x;
- center.y += poly->at(j).y;
+ center[0] += poly->at(j)[0];
+ center[1] += poly->at(j)[1];
}
- center.x /= poly->size();
- center.y /= poly->size();
+ center[0] /= poly->size();
+ center[1] /= poly->size();
for (int j = 1; j <= poly->size(); j++) {
if (z < 0) {
- gl_draw_triangle(shaderinfo, &center, &poly->at(j % poly->size()), &poly->at(j - 1),
+ gl_draw_triangle(shaderinfo, center, poly->at(j % poly->size()), poly->at(j - 1),
false, true, false, z, mirrored);
} else {
- gl_draw_triangle(shaderinfo, &center, &poly->at(j - 1), &poly->at(j % poly->size()),
+ gl_draw_triangle(shaderinfo, center, poly->at(j - 1), poly->at(j % poly->size()),
false, true, false, z, mirrored);
}
}
}
}
}
- const QVector<Polygon> *borders_p = &borders;
+ const std::vector<Polygon> *borders_p = &borders;
if (borders_p->size() == 0)
borders_p = &polygons;
for (int i = 0; i < borders_p->size(); i++) {
const Polygon *poly = &borders_p->at(i);
for (int j = 1; j <= poly->size(); j++) {
- Point p1 = poly->at(j - 1), p2 = poly->at(j - 1);
- Point p3 = poly->at(j % poly->size()), p4 = poly->at(j % poly->size());
- p1.z -= zbase/2, p2.z += zbase/2;
- p3.z -= zbase/2, p4.z += zbase/2;
- gl_draw_triangle(shaderinfo, &p2, &p1, &p3, true, true, false, 0, mirrored);
- gl_draw_triangle(shaderinfo, &p2, &p3, &p4, false, true, true, 0, mirrored);
+ Vector3d p1 = poly->at(j - 1), p2 = poly->at(j - 1);
+ Vector3d p3 = poly->at(j % poly->size()), p4 = poly->at(j % poly->size());
+ p1[2] -= zbase/2, p2[2] += zbase/2;
+ p3[2] -= zbase/2, p4[2] += zbase/2;
+ gl_draw_triangle(shaderinfo, p2, p1, p3, true, true, false, 0, mirrored);
+ gl_draw_triangle(shaderinfo, p2, p3, p4, false, true, true, 0, mirrored);
}
}
glEnd();
@@ -247,24 +248,24 @@ void PolySet::render_surface(colormode_e colormode, csgmode_e csgmode, double *m
const Polygon *poly = &polygons[i];
glBegin(GL_TRIANGLES);
if (poly->size() == 3) {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(1), &poly->at(2), true, true, true, 0, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(1), poly->at(2), true, true, true, 0, mirrored);
}
else if (poly->size() == 4) {
- gl_draw_triangle(shaderinfo, &poly->at(0), &poly->at(1), &poly->at(3), true, false, true, 0, mirrored);
- gl_draw_triangle(shaderinfo, &poly->at(2), &poly->at(3), &poly->at(1), true, false, true, 0, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(0), poly->at(1), poly->at(3), true, false, true, 0, mirrored);
+ gl_draw_triangle(shaderinfo, poly->at(2), poly->at(3), poly->at(1), true, false, true, 0, mirrored);
}
else {
- Point center;
+ Vector3d center;
for (int j = 0; j < poly->size(); j++) {
- center.x += poly->at(j).x;
- center.y += poly->at(j).y;
- center.z += poly->at(j).z;
+ center[0] += poly->at(j)[0];
+ center[1] += poly->at(j)[1];
+ center[2] += poly->at(j)[2];
}
- center.x /= poly->size();
- center.y /= poly->size();
- center.z /= poly->size();
+ center[0] /= poly->size();
+ center[1] /= poly->size();
+ center[2] /= poly->size();
for (int j = 1; j <= poly->size(); j++) {
- gl_draw_triangle(shaderinfo, &center, &poly->at(j - 1), &poly->at(j % poly->size()), false, true, false, 0, mirrored);
+ gl_draw_triangle(shaderinfo, center, poly->at(j - 1), poly->at(j % poly->size()), false, true, false, 0, mirrored);
}
}
glEnd();
@@ -290,8 +291,8 @@ void PolySet::render_edges(colormode_e colormode, csgmode_e csgmode) const
const Polygon *poly = &borders[i];
glBegin(GL_LINE_LOOP);
for (int j = 0; j < poly->size(); j++) {
- const Point *p = &poly->at(j);
- glVertex3d(p->x, p->y, z);
+ const Vector3d &p = poly->at(j);
+ glVertex3d(p[0], p[1], z);
}
glEnd();
}
@@ -300,9 +301,9 @@ void PolySet::render_edges(colormode_e colormode, csgmode_e csgmode) const
const Polygon *poly = &borders[i];
glBegin(GL_LINES);
for (int j = 0; j < poly->size(); j++) {
- const Point *p = &poly->at(j);
- glVertex3d(p->x, p->y, -zbase/2);
- glVertex3d(p->x, p->y, +zbase/2);
+ const Vector3d &p = poly->at(j);
+ glVertex3d(p[0], p[1], -zbase/2);
+ glVertex3d(p[0], p[1], +zbase/2);
}
glEnd();
}
@@ -311,10 +312,23 @@ void PolySet::render_edges(colormode_e colormode, csgmode_e csgmode) const
const Polygon *poly = &polygons[i];
glBegin(GL_LINE_LOOP);
for (int j = 0; j < poly->size(); j++) {
- const Point *p = &poly->at(j);
- glVertex3d(p->x, p->y, p->z);
+ const Vector3d &p = poly->at(j);
+ glVertex3d(p[0], p[1], p[2]);
}
glEnd();
}
}
}
+
+BoundingBox PolySet::getBoundingBox() const
+{
+ BoundingBox bbox;
+ for (int i = 0; i < polygons.size(); i++) {
+ const Polygon &poly = polygons[i];
+ for (int j = 0; j < poly.size(); j++) {
+ const Vector3d &p = poly[j];
+ bbox.extend(p);
+ }
+ }
+ return bbox;
+}
diff --git a/src/polyset.h b/src/polyset.h
index aae32f6..8f23130 100644
--- a/src/polyset.h
+++ b/src/polyset.h
@@ -1,27 +1,21 @@
#ifndef POLYSET_H_
#define POLYSET_H_
-#include <GL/glew.h> // this must be included before the GL headers
-#include <qgl.h>
-
+#include <GL/glew.h>
#include "grid.h"
-#ifdef ENABLE_OPENCSG
-# include <opencsg.h>
-#endif
+#include <vector>
+#include <Eigen/Core>
+#include <Eigen/Geometry>
-#include <QCache>
+using Eigen::Vector3d;
+typedef Eigen::AlignedBox<double, 3> BoundingBox;
class PolySet
{
public:
- struct Point {
- double x, y, z;
- Point() : x(0), y(0), z(0) { }
- Point(double x, double y, double z) : x(x), y(y), z(z) { }
- };
- typedef QList<Point> Polygon;
- QVector<Polygon> polygons;
- QVector<Polygon> borders;
+ typedef std::vector<Vector3d> Polygon;
+ std::vector<Polygon> polygons;
+ std::vector<Polygon> borders;
Grid3d<void*> grid;
bool is2d;
@@ -31,15 +25,10 @@ public:
~PolySet();
void append_poly();
- void append_vertex(double x, double y, double z);
- void insert_vertex(double x, double y, double z);
+ void append_vertex(double x, double y, double z = 0.0);
+ void insert_vertex(double x, double y, double z = 0.0);
- void append_vertex(double x, double y) {
- append_vertex(x, y, 0.0);
- }
- void insert_vertex(double x, double y) {
- insert_vertex(x, y, 0.0);
- }
+ BoundingBox getBoundingBox() const;
enum colormode_e {
COLORMODE_NONE,
diff --git a/src/primitives.cc b/src/primitives.cc
index 204bb11..3f88c75 100644
--- a/src/primitives.cc
+++ b/src/primitives.cc
@@ -520,7 +520,7 @@ sphere_next_r2:
p->unlink();
return NULL;
}
- dd.points.append(DxfData::Point(x, y));
+ dd.points.append(Vector2d(x, y));
}
if (this->paths.vec.size() == 0)
@@ -528,7 +528,7 @@ sphere_next_r2:
dd.paths.append(DxfData::Path());
for (size_t i=0; i<this->points.vec.size(); i++) {
assert(i < dd.points.size()); // FIXME: Not needed, but this used to be an 'if'
- DxfData::Point *p = &dd.points[i];
+ Vector2d *p = &dd.points[i];
dd.paths.last().points.append(p);
}
if (dd.paths.last().points.size() > 0) {
@@ -544,7 +544,7 @@ sphere_next_r2:
for (size_t j=0; j<this->paths.vec[i]->vec.size(); j++) {
int idx = this->paths.vec[i]->vec[j]->num;
if (idx < dd.points.size()) {
- DxfData::Point *p = &dd.points[idx];
+ Vector2d *p = &dd.points[idx];
dd.paths.last().points.append(p);
}
}
diff --git a/src/surface.cc b/src/surface.cc
index 94d039e..2a4fec6 100644
--- a/src/surface.cc
+++ b/src/surface.cc
@@ -35,6 +35,8 @@
#include "visitor.h"
#include <QFile>
+#include <QRegExp>
+#include <QStringList>
#include <sstream>
class SurfaceModule : public AbstractModule
contact: Jan Huwald // Impressum