Refactoring of CGAL functionality to allow for forward-declaration of CGAL classes in header files, reducing coupling and thus compilation times

stl_dim
Marius Kintel 2011-09-01 04:09:06 +02:00
parent c193372d2f
commit 1633fb0344
21 changed files with 256 additions and 248 deletions

View File

@ -119,7 +119,6 @@ FORMS += src/MainWindow.ui \
src/Preferences.ui
HEADERS += src/renderer.h \
src/cgalrenderer.h \
src/ThrownTogetherRenderer.h \
src/CGAL_renderer.h \
src/OGL_helper.h \
@ -127,7 +126,6 @@ HEADERS += src/renderer.h \
src/MainWindow.h \
src/Preferences.h \
src/builtin.h \
src/cgal.h \
src/context.h \
src/csgterm.h \
src/dxfdata.h \
@ -158,9 +156,7 @@ HEADERS += src/renderer.h \
src/traverser.h \
src/nodecache.h \
src/nodedumper.h \
src/CGALEvaluator.h \
src/PolySetEvaluator.h \
src/PolySetCGALEvaluator.h \
src/CSGTermEvaluator.h \
src/myqhash.h \
src/Tree.h \
@ -169,8 +165,6 @@ HEADERS += src/renderer.h \
SOURCES += src/openscad.cc \
src/mainwin.cc \
src/cgalrenderer.cc \
src/cgal.cc \
src/ThrownTogetherRenderer.cc \
src/glview.cc \
src/export.cc \
@ -187,9 +181,6 @@ SOURCES += src/openscad.cc \
src/primitives.cc \
src/projection.cc \
src/cgaladv.cc \
src/cgaladv_convexhull2.cc \
src/cgaladv_minkowski3.cc \
src/cgaladv_minkowski2.cc \
src/surface.cc \
src/control.cc \
src/render.cc \
@ -203,19 +194,33 @@ SOURCES += src/openscad.cc \
src/dxfrotextrude.cc \
src/highlighter.cc \
src/printutils.cc \
src/nef2dxf.cc \
src/Preferences.cc \
src/progress.cc \
src/editor.cc \
src/traverser.cc \
src/nodedumper.cc \
src/CGALEvaluator.cc \
src/PolySetEvaluator.cc \
src/PolySetCGALEvaluator.cc \
src/CSGTermEvaluator.cc \
src/qhash.cc \
src/Tree.cc \
src/mathc99.cc
src/mathc99.cc \
src/PolySetEvaluator.cc
cgal {
HEADERS += src/cgal.h \
src/cgalfwd.h \
src/CGALEvaluator.h \
src/PolySetCGALEvaluator.h \
src/cgalrenderer.h \
src/CGAL_Nef_polyhedron.h
SOURCES += src/CGALEvaluator.cc \
src/PolySetCGALEvaluator.cc \
src/cgalrenderer.cc \
src/CGAL_Nef_polyhedron.cc \
src/CGAL_Nef_polyhedron_DxfData.cc \
src/cgaladv_convexhull2.cc \
src/cgaladv_minkowski2.cc
}
macx {
HEADERS += src/AppleEvents.h \

View File

@ -10,6 +10,7 @@
#include "dxfdata.h"
#include "dxftess.h"
#include "cgal.h"
#include <CGAL/assertions_behaviour.h>
#include <CGAL/exceptions.h>
@ -46,45 +47,25 @@ void CGALEvaluator::process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedr
assert(false && "Dimension of Nef polyhedron must be 2 or 3");
}
if (target.dim == 2) {
switch (op) {
case CGE_UNION:
target.p2 += src.p2;
break;
case CGE_INTERSECTION:
target.p2 *= src.p2;
break;
case CGE_DIFFERENCE:
target.p2 -= src.p2;
break;
case CGE_MINKOWSKI:
target.p2 = minkowski2(target.p2, src.p2);
break;
case CGE_HULL:
//FIXME: Port convex hull to a binary operator or process it all in the end somehow
// target.p2 = convexhull2(target.p2, src.p2);
// target.p2 = convexhull2(polys);
break;
}
}
else if (target.dim == 3) {
switch (op) {
case CGE_UNION:
target.p3 += src.p3;
break;
case CGE_INTERSECTION:
target.p3 *= src.p3;
break;
case CGE_DIFFERENCE:
target.p3 -= src.p3;
break;
case CGE_MINKOWSKI:
target.p3 = minkowski3(target.p3, src.p3);
break;
case CGE_HULL:
// FIXME: Print warning: hull() not supported in 3D
break;
}
switch (op) {
case CGE_UNION:
target += src;
break;
case CGE_INTERSECTION:
target *= src;
break;
case CGE_DIFFERENCE:
target -= src;
break;
case CGE_MINKOWSKI:
target = target.minkowski(src);
break;
case CGE_HULL:
//FIXME: Port convex hull to a binary operator or process it all in the end somehow
// target.p2 = convexhull2(target.p2, src.p2);
// target.p2 = convexhull2(polys);
// FIXME: Print warning: hull() not supported in 3D
break;
}
}
@ -191,27 +172,28 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
node.matrix[0], node.matrix[4], node.matrix[12],
node.matrix[1], node.matrix[5], node.matrix[13], node.matrix[15]);
DxfData dd(N);
for (int i=0; i < dd.points.size(); i++) {
CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd.points[i][0], dd.points[i][1]);
DxfData *dd = N.convertToDxfData();
for (int i=0; i < dd->points.size(); i++) {
CGAL_Kernel2::Point_2 p = CGAL_Kernel2::Point_2(dd->points[i][0], dd->points[i][1]);
p = t.transform(p);
dd.points[i][0] = to_double(p.x());
dd.points[i][1] = to_double(p.y());
dd->points[i][0] = to_double(p.x());
dd->points[i][1] = to_double(p.y());
}
PolySet ps;
ps.is2d = true;
dxf_tesselate(&ps, &dd, 0, true, false, 0);
dxf_tesselate(&ps, dd, 0, true, false, 0);
N = evaluateCGALMesh(ps);
ps.refcount = 0;
delete dd;
}
else if (N.dim == 3) {
CGAL_Aff_transformation t(
node.matrix[0], node.matrix[4], node.matrix[ 8], node.matrix[12],
node.matrix[1], node.matrix[5], node.matrix[ 9], node.matrix[13],
node.matrix[2], node.matrix[6], node.matrix[10], node.matrix[14], node.matrix[15]);
N.p3.transform(t);
N.p3->transform(t);
}
this->cache.insert(this->tree.getString(node), N);
}
@ -574,9 +556,9 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)
}
}
CGAL_Nef_polyhedron2 toNef()
CGAL_Nef_polyhedron2 *toNef()
{
CGAL_Nef_polyhedron2 N;
CGAL_Nef_polyhedron2 *N = new CGAL_Nef_polyhedron2;
QHashIterator< int, QList<int> > it(polygons);
while (it.hasNext()) {
@ -586,7 +568,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)
int p = it.value()[j];
plist.push_back(points[p]);
}
N += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
*N += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
}
return N;
@ -642,7 +624,7 @@ CGAL_Nef_polyhedron CGALEvaluator::evaluateCGALMesh(const PolySet &ps)
#if 0
std::cout << P;
#endif
CGAL_Nef_polyhedron3 N(P);
CGAL_Nef_polyhedron3 *N = new CGAL_Nef_polyhedron3(P);
return CGAL_Nef_polyhedron(N);
}
catch (CGAL::Assertion_exception e) {

View File

@ -4,7 +4,7 @@
#include "myqhash.h"
#include "visitor.h"
#include "Tree.h"
#include "cgal.h"
#include "CGAL_Nef_polyhedron.h"
#include "PolySetCGALEvaluator.h"
#include <string>

View File

@ -1,5 +1,55 @@
#include "CGAL_Nef_polyhedron.h"
#include "cgal.h"
#include "polyset.h"
#include <CGAL/minkowski_sum_3.h>
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator+=(const CGAL_Nef_polyhedron &other)
{
if (other.dim == 2) {
(*this->p2) += (*other.p2);
this->dim = 2;
}
if (other.dim == 3) {
(*this->p3) += (*other.p3);
this->dim = 3;
}
return *this;
}
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator*=(const CGAL_Nef_polyhedron &other)
{
if (other.dim == 2) {
(*this->p2) *= (*other.p2);
this->dim = 2;
}
if (other.dim == 3) {
(*this->p3) *= (*other.p3);
this->dim = 3;
}
return *this;
}
CGAL_Nef_polyhedron& CGAL_Nef_polyhedron::operator-=(const CGAL_Nef_polyhedron &other)
{
if (other.dim == 2) {
(*this->p2) -= (*other.p2);
this->dim = 2;
}
if (other.dim == 3) {
(*this->p3) -= (*other.p3);
this->dim = 3;
}
return *this;
}
int CGAL_Nef_polyhedron::weight() const
{
if (dim == 2)
return p2->explorer().number_of_vertices();
if (dim == 3)
return p3->number_of_vertices();
return 0;
}
/*!
Creates a new PolySet and initializes it with the data from this polyhedron
@ -11,7 +61,7 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset()
{
PolySet *ps = new PolySet();
CGAL_Polyhedron P;
this->p3.convert_to_Polyhedron(P);
this->p3->convert_to_Polyhedron(P);
typedef CGAL_Polyhedron::Vertex Vertex;
typedef CGAL_Polyhedron::Vertex_const_iterator VCI;
@ -44,3 +94,18 @@ PolySet *CGAL_Nef_polyhedron::convertToPolyset()
}
return ps;
}
extern CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL_Nef_polyhedron2 &b);
CGAL_Nef_polyhedron &CGAL_Nef_polyhedron::minkowski(const CGAL_Nef_polyhedron &other)
{
if (other.dim == 2) {
(*this->p2) = minkowski2(*this->p2, *other.p2);
this->dim = 2;
}
if (other.dim == 3) {
(*this->p3) = CGAL::minkowski_sum_3(*this->p3, *other.p3);
this->dim = 3;
}
return *this;
}

31
src/CGAL_Nef_polyhedron.h Normal file
View File

@ -0,0 +1,31 @@
#ifndef CGAL_NEF_POLYHEDRON_H_
#define CGAL_NEF_POLYHEDRON_H_
#ifdef ENABLE_CGAL
#include "cgalfwd.h"
class CGAL_Nef_polyhedron
{
public:
CGAL_Nef_polyhedron() : dim(0) {}
CGAL_Nef_polyhedron(CGAL_Nef_polyhedron2 *p) : dim(2), p2(p) {}
CGAL_Nef_polyhedron(CGAL_Nef_polyhedron3 *p) : dim(3), p3(p) { }
~CGAL_Nef_polyhedron() {}
CGAL_Nef_polyhedron &operator+=(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron &operator*=(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron &operator-=(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other);
int weight() const;
class PolySet *convertToPolyset();
class DxfData *convertToDxfData() const;
int dim;
CGAL_Nef_polyhedron2 *p2;
CGAL_Nef_polyhedron3 *p3;
};
#endif /* ENABLE_CGAL */
#endif

View File

@ -26,19 +26,21 @@
#include "dxfdata.h"
#include "grid.h"
#include "CGAL_Nef_polyhedron.h"
#include "cgal.h"
#ifdef ENABLE_CGAL
DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
DxfData *CGAL_Nef_polyhedron::convertToDxfData() const
{
assert(N.dim == 2);
assert(this->dim == 2);
DxfData *dxfdata = new DxfData();
Grid2d<int> grid(GRID_COARSE);
typedef CGAL_Nef_polyhedron2::Explorer Explorer;
typedef Explorer::Face_const_iterator fci_t;
typedef Explorer::Halfedge_around_face_const_circulator heafcc_t;
Explorer E = N.p2.explorer();
Explorer E = this->p2->explorer();
for (fci_t fit = E.faces_begin(), facesend = E.faces_end(); fit != facesend; ++fit)
{
@ -52,26 +54,27 @@ DxfData::DxfData(const struct CGAL_Nef_polyhedron &N)
if (grid.has(x, y)) {
this_point = grid.align(x, y);
} else {
this_point = grid.align(x, y) = points.size();
points.append(Vector2d(x, y));
this_point = grid.align(x, y) = dxfdata->points.size();
dxfdata->points.append(Vector2d(x, y));
}
if (first_point < 0) {
paths.append(Path());
dxfdata->paths.append(DxfData::Path());
first_point = this_point;
}
if (this_point != last_point) {
paths.last().points.append(&points[this_point]);
dxfdata->paths.last().points.append(&dxfdata->points[this_point]);
last_point = this_point;
}
}
}
if (first_point >= 0) {
paths.last().is_closed = 1;
paths.last().points.append(&points[first_point]);
dxfdata->paths.last().is_closed = 1;
dxfdata->paths.last().points.append(&dxfdata->points[first_point]);
}
}
fixup_path_direction();
dxfdata->fixup_path_direction();
return dxfdata;
}
#endif // ENABLE_CGAL

View File

@ -1,4 +1,5 @@
#include "PolySetCGALEvaluator.h"
#include "cgal.h"
#include "polyset.h"
#include "CGALEvaluator.h"
#include "projectionnode.h"
@ -67,8 +68,8 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
cube->unlink();
// N.p3 *= CGAL_Nef_polyhedron3(CGAL_Plane(0, 0, 1, 0), CGAL_Nef_polyhedron3::INCLUDED);
N.p3 *= Ncube.p3;
if (!N.p3.is_simple()) {
N *= Ncube;
if (!N.p3->is_simple()) {
PRINTF("WARNING: Body of projection(cut = true) isn't valid 2-manifold! Modify your design..");
goto cant_project_non_simple_polyhedron;
}
@ -99,7 +100,7 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
}
else
{
if (!N.p3.is_simple()) {
if (!N.p3->is_simple()) {
PRINTF("WARNING: Body of projection(cut = false) isn't valid 2-manifold! Modify your design..");
goto cant_project_non_simple_polyhedron;
}
@ -144,13 +145,13 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node, Abstr
else
plist.push_back(p);
}
np.p2 += CGAL_Nef_polyhedron2(plist.begin(), plist.end(),
CGAL_Nef_polyhedron2::INCLUDED);
(*np.p2) += CGAL_Nef_polyhedron2(plist.begin(), plist.end(), CGAL_Nef_polyhedron2::INCLUDED);
}
DxfData dxf(np);
dxf_tesselate(ps, &dxf, 0, true, false, 0);
dxf_border_to_ps(ps, &dxf);
DxfData *dxf = np.convertToDxfData();
dxf_tesselate(ps, dxf, 0, true, false, 0);
dxf_border_to_ps(ps, dxf);
ps3->unlink();
delete dxf;
}
cant_project_non_simple_polyhedron:
@ -246,10 +247,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfLinearExtrudeNode &node,
N.dim = 2;
foreach (AbstractNode * v, node.getChildren()) {
if (v->modinst->tag_background) continue;
N.p2 += this->cgalevaluator.evaluateCGALMesh(*v).p2;
N += this->cgalevaluator.evaluateCGALMesh(*v);
}
dxf = new DxfData(N);
dxf = N.convertToDxfData();;
} else {
dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
}
@ -337,10 +338,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const DxfRotateExtrudeNode &node,
N.dim = 2;
foreach (AbstractNode * v, node.getChildren()) {
if (v->modinst->tag_background) continue;
N.p2 += this->cgalevaluator.evaluateCGALMesh(*v).p2;
N += this->cgalevaluator.evaluateCGALMesh(*v);
}
dxf = new DxfData(N);
dxf = N.convertToDxfData();
} else {
dxf = new DxfData(node.fn, node.fs, node.fa, node.filename, node.layername, node.origin_x, node.origin_y, node.scale);
}

View File

@ -31,73 +31,6 @@ typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
struct CGAL_Nef_polyhedron
{
int dim;
CGAL_Nef_polyhedron2 p2;
CGAL_Nef_polyhedron3 p3;
CGAL_Nef_polyhedron() {
dim = 0;
}
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron2 &p) {
dim = 2;
p2 = p;
}
CGAL_Nef_polyhedron(const CGAL_Nef_polyhedron3 &p) {
dim = 3;
p3 = p;
}
CGAL_Nef_polyhedron& operator+=(const CGAL_Nef_polyhedron &other) {
if (other.dim == 2) {
this->p2 += other.p2;
this->dim = 2;
}
if (other.dim == 3) {
this->p3 += other.p3;
this->dim = 3;
}
return *this;
}
CGAL_Nef_polyhedron& operator*=(const CGAL_Nef_polyhedron &other) {
if (other.dim == 2) {
this->p2 *= other.p2;
this->dim = 2;
}
if (other.dim == 3) {
this->p3 *= other.p3;
this->dim = 3;
}
return *this;
}
CGAL_Nef_polyhedron& operator-=(const CGAL_Nef_polyhedron &other) {
if (other.dim == 2) {
this->p2 -= other.p2;
this->dim = 2;
}
if (other.dim == 3) {
this->p3 -= other.p3;
this->dim = 3;
}
return *this;
}
int weight() {
if (dim == 2)
return p2.explorer().number_of_vertices();
if (dim == 3)
return p3.number_of_vertices();
return 0;
}
class PolySet *convertToPolyset();
};
#endif /* ENABLE_CGAL */
#endif

View File

@ -29,17 +29,10 @@
#include "context.h"
#include "builtin.h"
#include "printutils.h"
#include "cgal.h"
#include "visitor.h"
#include <sstream>
#include <assert.h>
#ifdef ENABLE_CGAL
extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b);
extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b);
extern CGAL_Nef_polyhedron2 convexhull2(std::list<CGAL_Nef_polyhedron2> a);
#endif
enum cgaladv_type_e {
MINKOWSKI,
GLIDE,

View File

@ -34,7 +34,6 @@
#include <CGAL/minkowski_sum_2.h>
extern CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b);
extern CGAL_Poly2 nef2p2(CGAL_Nef_polyhedron2 p);
//-----------------------------------------------------------------------------
@ -120,7 +119,7 @@ static CGAL_Nef_polyhedron2 p2nef2(CGAL_Poly2 p2) {
return CGAL_Nef_polyhedron2(points.begin(), points.end(), CGAL_Nef_polyhedron2::INCLUDED);
}
CGAL_Nef_polyhedron2 minkowski2(CGAL_Nef_polyhedron2 a, CGAL_Nef_polyhedron2 b)
CGAL_Nef_polyhedron2 minkowski2(const CGAL_Nef_polyhedron2 &a, const CGAL_Nef_polyhedron2 &b)
{
CGAL_Poly2 ap = nef2p2(a), bp = nef2p2(b);

View File

@ -1,39 +0,0 @@
/*
* OpenSCAD (www.openscad.org)
* Copyright (C) 2009-2011 Clifford Wolf <clifford@clifford.at> and
* Marius Kintel <marius@kintel.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* As a special exception, you have permission to link this program
* with the CGAL library and distribute executables, as long as you
* follow the requirements of the GNU GPL in regard to all of the
* software in the executable aside from CGAL.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
*/
#ifdef ENABLE_CGAL
#include "cgal.h"
#include <CGAL/minkowski_sum_3.h>
extern CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b);
CGAL_Nef_polyhedron3 minkowski3(CGAL_Nef_polyhedron3 a, CGAL_Nef_polyhedron3 b)
{
return CGAL::minkowski_sum_3(a, b);
}
#endif

27
src/cgalfwd.h Normal file
View File

@ -0,0 +1,27 @@
#ifndef CGALFWD_H_
#define CGALFWD_H_
#ifdef ENABLE_CGAL
namespace CGAL {
class Gmpq;
template <class T> class Extended_cartesian;
class HDS_items;
template <class A, typename Items_, typename Mark_> class Nef_polyhedron_2;
}
typedef CGAL::Gmpq NT;
typedef CGAL::Extended_cartesian<NT> CGAL_Kernel2;
typedef CGAL::Nef_polyhedron_2<CGAL_Kernel2, CGAL::HDS_items, bool> CGAL_Nef_polyhedron2;
namespace CGAL {
template <class T> class Cartesian;
template<class T> struct Default_items;
class SNC_indexed_items;
template <typename Kernel_, typename Items_, typename Mark_> class Nef_polyhedron_3;
}
typedef CGAL::Cartesian<NT> CGAL_Kernel3;
typedef CGAL::Nef_polyhedron_3<CGAL_Kernel3, CGAL::SNC_indexed_items, bool> CGAL_Nef_polyhedron3;
#endif /* ENABLE_CGAL */
#endif

View File

@ -29,17 +29,20 @@
#include "CGAL_renderer.h"
#include "dxfdata.h"
#include "dxftess.h"
#include "CGAL_Nef_polyhedron.h"
#include "cgal.h"
#include "Preferences.h"
CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root)
{
if (root.dim == 2) {
DxfData dd(root);
DxfData *dd = root.convertToDxfData();
this->polyhedron = NULL;
this->polyset = new PolySet();
this->polyset->is2d = true;
dxf_tesselate(this->polyset, &dd, 0, true, false, 0);
dxf_tesselate(this->polyset, dd, 0, true, false, 0);
delete dd;
}
else if (root.dim == 3) {
this->polyset = NULL;
@ -54,7 +57,7 @@ CGALRenderer::CGALRenderer(const CGAL_Nef_polyhedron &root) : root(root)
Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).green(),
Preferences::inst()->color(Preferences::CGAL_FACE_FRONT_COLOR).blue());
CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(this->root.p3, this->polyhedron);
CGAL::OGL::Nef3_Converter<CGAL_Nef_polyhedron3>::convert_to_OGLPolyhedron(*this->root.p3, this->polyhedron);
this->polyhedron->init();
}
}
@ -86,7 +89,7 @@ void CGALRenderer::draw(bool showfaces, bool showedges) const
typedef Explorer::Face_const_iterator fci_t;
typedef Explorer::Halfedge_around_face_const_circulator heafcc_t;
typedef Explorer::Point Point;
Explorer E = this->root.p2.explorer();
Explorer E = this->root.p2->explorer();
// Draw 2D edges
glDisable(GL_DEPTH_TEST);

View File

@ -2,7 +2,7 @@
#define CGALRENDERER_H_
#include "renderer.h"
#include "cgal.h"
#include "CGAL_Nef_polyhedron.h"
class CGALRenderer : public Renderer
{

View File

@ -37,13 +37,9 @@ public:
DxfData();
DxfData(double fn, double fs, double fa, QString filename, QString layername = QString(), double xorigin = 0.0, double yorigin = 0.0, double scale = 1.0);
#ifdef ENABLE_CGAL
DxfData(const struct CGAL_Nef_polyhedron &N);
#endif
Vector2d *addPoint(double x, double y);
private:
void fixup_path_direction();
};

View File

@ -24,6 +24,7 @@
*
*/
#include "export.h"
#include "printutils.h"
#include "polyset.h"
#include "dxfdata.h"
@ -34,6 +35,7 @@
#include <errno.h>
#ifdef ENABLE_CGAL
#include "CGAL_Nef_polyhedron.h"
#include "cgal.h"
/*!
@ -43,7 +45,7 @@
void export_stl(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialog *pd)
{
CGAL_Polyhedron P;
root_N->p3.convert_to_Polyhedron(P);
root_N->p3->convert_to_Polyhedron(P);
typedef CGAL_Polyhedron::Vertex Vertex;
typedef CGAL_Polyhedron::Vertex_const_iterator VCI;
@ -131,12 +133,12 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo
<< " 2\n"
<< "ENTITIES\n";
DxfData dd(*root_N);
for (int i=0; i<dd.paths.size(); i++)
DxfData *dd =root_N->convertToDxfData();
for (int i=0; i<dd->paths.size(); i++)
{
for (int j=1; j<dd.paths[i].points.size(); j++) {
const Vector2d &p1 = *dd.paths[i].points[j-1];
const Vector2d &p2 = *dd.paths[i].points[j];
for (int j=1; j<dd->paths[i].points.size(); j++) {
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];
@ -173,6 +175,7 @@ void export_dxf(CGAL_Nef_polyhedron *root_N, QTextStream &output, QProgressDialo
output << " 0\n"
<<"EOF\n";
delete dd;
setlocale(LC_NUMERIC, ""); // Set default locale
}

View File

@ -2,9 +2,9 @@
#define EXPORT_H_
#ifdef ENABLE_CGAL
#include "cgal.h"
void cgal_nef3_to_polyset(PolySet *ps, CGAL_Nef_polyhedron *root_N);
void export_stl(class CGAL_Nef_polyhedron *root_N, class QTextStream &output, class QProgressDialog *pd);
void cgal_nef3_to_polyset(class PolySet *ps, class CGAL_Nef_polyhedron *root_N);
void export_stl(CGAL_Nef_polyhedron *root_N, class QTextStream &output, class QProgressDialog *pd);
void export_off(CGAL_Nef_polyhedron *root_N, class QTextStream &output, QProgressDialog *pd);
void export_dxf(CGAL_Nef_polyhedron *root_N, class QTextStream &output, QProgressDialog *pd);
#endif

View File

@ -46,8 +46,6 @@
#ifdef USE_PROGRESSWIDGET
#include "ProgressWidget.h"
#endif
#include "CGALEvaluator.h"
#include "PolySetCGALEvaluator.h"
#include "ThrownTogetherRenderer.h"
#include <QMenu>
@ -84,7 +82,11 @@ using namespace boost::lambda;
#ifdef ENABLE_CGAL
#include "CGALEvaluator.h"
#include "PolySetCGALEvaluator.h"
#include "cgalrenderer.h"
#include "CGAL_Nef_polyhedron.h"
#include "cgal.h"
#endif // ENABLE_CGAL
@ -1232,41 +1234,41 @@ void MainWindow::actionRenderCGAL()
if (this->root_N->dim == 2) {
PRINTF(" Top level object is a 2D object:");
QApplication::processEvents();
PRINTF(" Empty: %6s", this->root_N->p2.is_empty() ? "yes" : "no");
PRINTF(" Empty: %6s", this->root_N->p2->is_empty() ? "yes" : "no");
QApplication::processEvents();
PRINTF(" Plane: %6s", this->root_N->p2.is_plane() ? "yes" : "no");
PRINTF(" Plane: %6s", this->root_N->p2->is_plane() ? "yes" : "no");
QApplication::processEvents();
PRINTF(" Vertices: %6d", (int)this->root_N->p2.explorer().number_of_vertices());
PRINTF(" Vertices: %6d", (int)this->root_N->p2->explorer().number_of_vertices());
QApplication::processEvents();
PRINTF(" Halfedges: %6d", (int)this->root_N->p2.explorer().number_of_halfedges());
PRINTF(" Halfedges: %6d", (int)this->root_N->p2->explorer().number_of_halfedges());
QApplication::processEvents();
PRINTF(" Edges: %6d", (int)this->root_N->p2.explorer().number_of_edges());
PRINTF(" Edges: %6d", (int)this->root_N->p2->explorer().number_of_edges());
QApplication::processEvents();
PRINTF(" Faces: %6d", (int)this->root_N->p2.explorer().number_of_faces());
PRINTF(" Faces: %6d", (int)this->root_N->p2->explorer().number_of_faces());
QApplication::processEvents();
PRINTF(" FaceCycles: %6d", (int)this->root_N->p2.explorer().number_of_face_cycles());
PRINTF(" FaceCycles: %6d", (int)this->root_N->p2->explorer().number_of_face_cycles());
QApplication::processEvents();
PRINTF(" ConnComp: %6d", (int)this->root_N->p2.explorer().number_of_connected_components());
PRINTF(" ConnComp: %6d", (int)this->root_N->p2->explorer().number_of_connected_components());
QApplication::processEvents();
}
if (this->root_N->dim == 3) {
PRINTF(" Top level object is a 3D object:");
PRINTF(" Simple: %6s", this->root_N->p3.is_simple() ? "yes" : "no");
PRINTF(" Simple: %6s", this->root_N->p3->is_simple() ? "yes" : "no");
QApplication::processEvents();
PRINTF(" Valid: %6s", this->root_N->p3.is_valid() ? "yes" : "no");
PRINTF(" Valid: %6s", this->root_N->p3->is_valid() ? "yes" : "no");
QApplication::processEvents();
PRINTF(" Vertices: %6d", (int)this->root_N->p3.number_of_vertices());
PRINTF(" Vertices: %6d", (int)this->root_N->p3->number_of_vertices());
QApplication::processEvents();
PRINTF(" Halfedges: %6d", (int)this->root_N->p3.number_of_halfedges());
PRINTF(" Halfedges: %6d", (int)this->root_N->p3->number_of_halfedges());
QApplication::processEvents();
PRINTF(" Edges: %6d", (int)this->root_N->p3.number_of_edges());
PRINTF(" Edges: %6d", (int)this->root_N->p3->number_of_edges());
QApplication::processEvents();
PRINTF(" Halffacets: %6d", (int)this->root_N->p3.number_of_halffacets());
PRINTF(" Halffacets: %6d", (int)this->root_N->p3->number_of_halffacets());
QApplication::processEvents();
PRINTF(" Facets: %6d", (int)this->root_N->p3.number_of_facets());
PRINTF(" Facets: %6d", (int)this->root_N->p3->number_of_facets());
QApplication::processEvents();
PRINTF(" Volumes: %6d", (int)this->root_N->p3.number_of_volumes());
PRINTF(" Volumes: %6d", (int)this->root_N->p3->number_of_volumes());
QApplication::processEvents();
}
@ -1367,7 +1369,7 @@ void MainWindow::actionExportSTLorOFF(bool)
return;
}
if (!this->root_N->p3.is_simple()) {
if (!this->root_N->p3->is_simple()) {
PRINT("Object isn't a valid 2-manifold! Modify your design..");
clearCurrentOutput();
return;
@ -1386,7 +1388,7 @@ void MainWindow::actionExportSTLorOFF(bool)
QProgressDialog *pd = new QProgressDialog(
stl_mode ? "Exporting object to STL file..." : "Exporting object to OFF file...",
QString(), 0, this->root_N->p3.number_of_facets() + 1);
QString(), 0, this->root_N->p3->number_of_facets() + 1);
pd->setValue(0);
pd->setAutoClose(false);
pd->show();

View File

@ -41,7 +41,7 @@
#include <vector>
#ifdef ENABLE_CGAL
#include "cgal.h"
#include "CGAL_Nef_polyhedron.h"
#include <CGAL/assertions_behaviour.h>
#endif

View File

@ -139,9 +139,10 @@ include_directories(${CGAL_INCLUDE_DIRS})
#
# cgaltest
#
add_executable(cgaltest cgaltest.cc ../src/cgal.cc ../src/CSGTermEvaluator.cc ../src/CGALEvaluator.cc
../src/PolySetCGALEvaluator.cc ../src/qhash.cc ../src/nef2dxf.cc
../src/cgaladv_minkowski2.cc ../src/cgaladv_minkowski3.cc ${COMMON_SOURCES})
add_executable(cgaltest cgaltest.cc ../src/CGAL_Nef_polyhedron.cc ../src/CSGTermEvaluator.cc
../src/CGALEvaluator.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc
../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc
${COMMON_SOURCES})
set_target_properties(cgaltest PROPERTIES COMPILE_FLAGS "-DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENGL_LIBRARY})
@ -149,9 +150,10 @@ target_link_libraries(cgaltest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_
# opencsgtest
#
add_executable(opencsgtest opencsgtest.cc OffscreenView.cc OffscreenContext.mm
../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc ../src/CSGTermEvaluator.cc ../src/cgal.cc ../src/CGALEvaluator.cc
../src/PolySetCGALEvaluator.cc ../src/qhash.cc ../src/nef2dxf.cc
../src/cgaladv_minkowski2.cc ../src/cgaladv_minkowski3.cc
../src/OpenCSGRenderer.cc ../src/ThrownTogetherRenderer.cc
../src/CSGTermEvaluator.cc ../src/CGAL_Nef_polyhedron.cc
../src/CGALEvaluator.cc ../src/PolySetCGALEvaluator.cc ../src/qhash.cc
../src/CGAL_Nef_polyhedron_DxfData.cc ../src/cgaladv_minkowski2.cc
${COMMON_SOURCES})
set_target_properties(opencsgtest PROPERTIES COMPILE_FLAGS "-DENABLE_OPENCSG -DENABLE_CGAL ${CGAL_CXX_FLAGS_INIT}")
target_link_libraries(opencsgtest ${CGAL_LIBRARY} ${CGAL_3RD_PARTY_LIBRARIES} ${QT_LIBRARIES} ${OPENCSG_LIBRARY} ${GLEW_LIBRARY} ${COCOA_LIBRARY} ${OPENGL_LIBRARY})

View File

@ -32,6 +32,7 @@
#include "export.h"
#include "builtin.h"
#include "Tree.h"
#include "CGAL_Nef_polyhedron.h"
#include "CGALEvaluator.h"
#include "PolySetCGALEvaluator.h"
@ -42,6 +43,7 @@
#include <QTextStream>
#include <getopt.h>
#include <iostream>
#include <assert.h>
QString commandline_commands;
const char *make_command = NULL;