mirror of https://github.com/vitalif/openscad
Small refactoring: Split out Polyhedron-related functions to from cgalutils.cc to cgalutils-polyhedron.cc
parent
bc30dca513
commit
4eaf8797c2
|
@ -472,6 +472,7 @@ HEADERS += src/cgal.h \
|
|||
|
||||
SOURCES += src/cgalutils.cc \
|
||||
src/cgalutils-tess.cc \
|
||||
src/cgalutils-polyhedron.cc \
|
||||
src/cgalutils-tess-old.cc \
|
||||
src/CGALCache.cc \
|
||||
src/CGALRenderer.cc \
|
||||
|
|
|
@ -57,8 +57,6 @@ typedef CGAL::Nef_polyhedron_3<CGAL_Kernel3> CGAL_Nef_polyhedron3;
|
|||
typedef CGAL_Nef_polyhedron3::Aff_transformation_3 CGAL_Aff_transformation;
|
||||
|
||||
typedef CGAL::Polyhedron_3<CGAL_Kernel3> CGAL_Polyhedron;
|
||||
typedef CGAL_Polyhedron::HalfedgeDS CGAL_HDS;
|
||||
typedef CGAL::Polyhedron_incremental_builder_3<CGAL_HDS> CGAL_Polybuilder;
|
||||
|
||||
typedef CGAL::Point_3<CGAL_Kernel3> CGAL_Point_3;
|
||||
typedef CGAL::Iso_cuboid_3<CGAL_Kernel3> CGAL_Iso_cuboid_3;
|
||||
|
|
|
@ -0,0 +1,308 @@
|
|||
#ifdef ENABLE_CGAL
|
||||
|
||||
#include "cgalutils.h"
|
||||
#include "polyset.h"
|
||||
#include "printutils.h"
|
||||
#include "polyset-utils.h"
|
||||
#include "grid.h"
|
||||
|
||||
#include "cgal.h"
|
||||
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
|
||||
|
||||
#include <boost/foreach.hpp>
|
||||
|
||||
namespace /* anonymous */ {
|
||||
template<typename Result, typename V>
|
||||
Result vector_convert(V const& v) {
|
||||
return Result(CGAL::to_double(v[0]),CGAL::to_double(v[1]),CGAL::to_double(v[2]));
|
||||
}
|
||||
|
||||
#undef GEN_SURFACE_DEBUG
|
||||
|
||||
template <typename Polyhedron>
|
||||
class CGAL_Build_PolySet : public CGAL::Modifier_base<typename Polyhedron::HalfedgeDS>
|
||||
{
|
||||
typedef typename Polyhedron::HalfedgeDS HDS;
|
||||
typedef CGAL::Polyhedron_incremental_builder_3<typename Polyhedron::HalfedgeDS> CGAL_Polybuilder;
|
||||
public:
|
||||
typedef typename CGAL_Polybuilder::Point_3 CGALPoint;
|
||||
|
||||
const PolySet &ps;
|
||||
CGAL_Build_PolySet(const PolySet &ps) : ps(ps) { }
|
||||
|
||||
/*
|
||||
Using Grid here is important for performance reasons. See following model.
|
||||
If we don't grid the geometry before converting to a Nef Polyhedron, the quads
|
||||
in the cylinders to tessellated into triangles since floating point
|
||||
incertainty causes the faces to not be 100% planar. The incertainty is exaggerated
|
||||
by the transform. This wasn't a problem earlier since we used Nef for everything,
|
||||
but optimizations since then has made us keep it in floating point space longer.
|
||||
|
||||
minkowski() {
|
||||
cube([200, 50, 7], center = true);
|
||||
rotate([90,0,0]) cylinder($fn = 8, h = 1, r = 8.36, center = true);
|
||||
rotate([0,90,0]) cylinder($fn = 8, h = 1, r = 8.36, center = true);
|
||||
}
|
||||
*/
|
||||
#if 1 // Use Grid
|
||||
void operator()(HDS& hds) {
|
||||
CGAL_Polybuilder B(hds, true);
|
||||
|
||||
std::vector<CGALPoint> vertices;
|
||||
Grid3d<int> grid(GRID_FINE);
|
||||
std::vector<size_t> indices(3);
|
||||
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
BOOST_REVERSE_FOREACH(Vector3d v, p) {
|
||||
if (!grid.has(v)) {
|
||||
// align v to the grid; the CGALPoint will receive the aligned vertex
|
||||
grid.align(v) = vertices.size();
|
||||
vertices.push_back(CGALPoint(v[0], v[1], v[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("polyhedron(faces=[");
|
||||
int pidx = 0;
|
||||
#endif
|
||||
B.begin_surface(vertices.size(), ps.polygons.size());
|
||||
BOOST_FOREACH(const CGALPoint &p, vertices) {
|
||||
B.add_vertex(p);
|
||||
}
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
if (pidx++ > 0) printf(",");
|
||||
#endif
|
||||
indices.clear();
|
||||
BOOST_FOREACH(const Vector3d &v, p) {
|
||||
indices.push_back(grid.data(v));
|
||||
}
|
||||
|
||||
// We perform this test since there is a bug in CGAL's
|
||||
// Polyhedron_incremental_builder_3::test_facet() which
|
||||
// fails to detect duplicate indices
|
||||
bool err = false;
|
||||
for (std::size_t i = 0; i < indices.size(); ++i) {
|
||||
// check if vertex indices[i] is already in the sequence [0..i-1]
|
||||
for (std::size_t k = 0; k < i && !err; ++k) {
|
||||
if (indices[k] == indices[i]) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!err && B.test_facet(indices.begin(), indices.end())) {
|
||||
B.add_facet(indices.begin(), indices.end());
|
||||
}
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("[");
|
||||
int fidx = 0;
|
||||
BOOST_FOREACH(size_t i, indices) {
|
||||
if (fidx++ > 0) printf(",");
|
||||
printf("%ld", i);
|
||||
}
|
||||
printf("]");
|
||||
#endif
|
||||
}
|
||||
B.end_surface();
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("],\n");
|
||||
#endif
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("points=[");
|
||||
for (int i=0;i<vertices.size();i++) {
|
||||
if (i > 0) printf(",");
|
||||
const CGALPoint &p = vertices[i];
|
||||
printf("[%g,%g,%g]", CGAL::to_double(p.x()), CGAL::to_double(p.y()), CGAL::to_double(p.z()));
|
||||
}
|
||||
printf("]);\n");
|
||||
#endif
|
||||
}
|
||||
#else // Don't use Grid
|
||||
void operator()(HDS& hds)
|
||||
{
|
||||
CGAL_Polybuilder B(hds, true);
|
||||
Reindexer<Vector3d> vertices;
|
||||
std::vector<size_t> indices(3);
|
||||
|
||||
// Estimating same # of vertices as polygons (very rough)
|
||||
B.begin_surface(ps.polygons.size(), ps.polygons.size());
|
||||
int pidx = 0;
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("polyhedron(faces=[");
|
||||
#endif
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
if (pidx++ > 0) printf(",");
|
||||
#endif
|
||||
indices.clear();
|
||||
BOOST_REVERSE_FOREACH(const Vector3d &v, p) {
|
||||
size_t s = vertices.size();
|
||||
size_t idx = vertices.lookup(v);
|
||||
// If we added a vertex, also add it to the CGAL builder
|
||||
if (idx == s) B.add_vertex(CGALPoint(v[0], v[1], v[2]));
|
||||
indices.push_back(idx);
|
||||
}
|
||||
// We perform this test since there is a bug in CGAL's
|
||||
// Polyhedron_incremental_builder_3::test_facet() which
|
||||
// fails to detect duplicate indices
|
||||
bool err = false;
|
||||
for (std::size_t i = 0; i < indices.size(); ++i) {
|
||||
// check if vertex indices[i] is already in the sequence [0..i-1]
|
||||
for (std::size_t k = 0; k < i && !err; ++k) {
|
||||
if (indices[k] == indices[i]) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!err && B.test_facet(indices.begin(), indices.end())) {
|
||||
B.add_facet(indices.begin(), indices.end());
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("[");
|
||||
int fidx = 0;
|
||||
BOOST_FOREACH(size_t i, indices) {
|
||||
if (fidx++ > 0) printf(",");
|
||||
printf("%ld", i);
|
||||
}
|
||||
printf("]");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
B.end_surface();
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("],\n");
|
||||
|
||||
printf("points=[");
|
||||
for (int vidx=0;vidx<vertices.size();vidx++) {
|
||||
if (vidx > 0) printf(",");
|
||||
const Vector3d &v = vertices.getArray()[vidx];
|
||||
printf("[%g,%g,%g]", v[0], v[1], v[2]);
|
||||
}
|
||||
printf("]);\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
// This code is from CGAL/demo/Polyhedron/Scene_nef_polyhedron_item.cpp
|
||||
// quick hacks to convert polyhedra from exact to inexact and vice-versa
|
||||
template <class Polyhedron_input, class Polyhedron_output>
|
||||
struct Copy_polyhedron_to : public CGAL::Modifier_base<typename Polyhedron_output::HalfedgeDS>
|
||||
{
|
||||
Copy_polyhedron_to(const Polyhedron_input& in_poly) : in_poly(in_poly) {}
|
||||
|
||||
void operator()(typename Polyhedron_output::HalfedgeDS& out_hds)
|
||||
{
|
||||
typedef typename Polyhedron_output::HalfedgeDS Output_HDS;
|
||||
|
||||
CGAL::Polyhedron_incremental_builder_3<Output_HDS> builder(out_hds);
|
||||
|
||||
typedef typename Polyhedron_input::Vertex_const_iterator Vertex_const_iterator;
|
||||
typedef typename Polyhedron_input::Facet_const_iterator Facet_const_iterator;
|
||||
typedef typename Polyhedron_input::Halfedge_around_facet_const_circulator HFCC;
|
||||
|
||||
builder.begin_surface(in_poly.size_of_vertices(),
|
||||
in_poly.size_of_facets(),
|
||||
in_poly.size_of_halfedges());
|
||||
|
||||
for (Vertex_const_iterator
|
||||
vi = in_poly.vertices_begin(), end = in_poly.vertices_end();
|
||||
vi != end ; ++vi) {
|
||||
typename Polyhedron_output::Point_3 p(::CGAL::to_double(vi->point().x()),
|
||||
::CGAL::to_double(vi->point().y()),
|
||||
::CGAL::to_double(vi->point().z()));
|
||||
builder.add_vertex(p);
|
||||
}
|
||||
|
||||
typedef CGAL::Inverse_index<Vertex_const_iterator> Index;
|
||||
Index index(in_poly.vertices_begin(), in_poly.vertices_end());
|
||||
|
||||
for (Facet_const_iterator
|
||||
fi = in_poly.facets_begin(), end = in_poly.facets_end();
|
||||
fi != end; ++fi) {
|
||||
HFCC hc = fi->facet_begin();
|
||||
HFCC hc_end = hc;
|
||||
// std::size_t n = circulator_size(hc);
|
||||
// CGAL_assertion(n >= 3);
|
||||
builder.begin_facet ();
|
||||
do {
|
||||
builder.add_vertex_to_facet(index[hc->vertex()]);
|
||||
++hc;
|
||||
} while(hc != hc_end);
|
||||
builder.end_facet();
|
||||
}
|
||||
builder.end_surface();
|
||||
} // end operator()(..)
|
||||
private:
|
||||
const Polyhedron_input& in_poly;
|
||||
}; // end Copy_polyhedron_to<>
|
||||
|
||||
}
|
||||
|
||||
namespace CGALUtils {
|
||||
|
||||
template <class Polyhedron_A, class Polyhedron_B>
|
||||
void copyPolyhedron(const Polyhedron_A &poly_a, Polyhedron_B &poly_b)
|
||||
{
|
||||
Copy_polyhedron_to<Polyhedron_A, Polyhedron_B> modifier(poly_a);
|
||||
poly_b.delegate(modifier);
|
||||
}
|
||||
|
||||
template void copyPolyhedron(const CGAL::Polyhedron_3<CGAL::Epick> &, CGAL_Polyhedron &);
|
||||
template void copyPolyhedron(const CGAL_Polyhedron &, CGAL::Polyhedron_3<CGAL::Epick> &);
|
||||
|
||||
template <typename Polyhedron>
|
||||
bool createPolyhedronFromPolySet(const PolySet &ps, Polyhedron &p)
|
||||
{
|
||||
bool err = false;
|
||||
CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION);
|
||||
try {
|
||||
CGAL_Build_PolySet<Polyhedron> builder(ps);
|
||||
p.delegate(builder);
|
||||
}
|
||||
catch (const CGAL::Assertion_exception &e) {
|
||||
PRINTB("CGAL error in CGALUtils::createPolyhedronFromPolySet: %s", e.what());
|
||||
err = true;
|
||||
}
|
||||
CGAL::set_error_behaviour(old_behaviour);
|
||||
return err;
|
||||
}
|
||||
|
||||
template bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p);
|
||||
template bool createPolyhedronFromPolySet(const PolySet &ps, CGAL::Polyhedron_3<CGAL::Epick> &p);
|
||||
|
||||
template <typename Polyhedron>
|
||||
bool createPolySetFromPolyhedron(const Polyhedron &p, PolySet &ps)
|
||||
{
|
||||
bool err = false;
|
||||
typedef typename Polyhedron::Vertex Vertex;
|
||||
typedef typename Polyhedron::Vertex_const_iterator VCI;
|
||||
typedef typename Polyhedron::Facet_const_iterator FCI;
|
||||
typedef typename Polyhedron::Halfedge_around_facet_const_circulator HFCC;
|
||||
|
||||
for (FCI fi = p.facets_begin(); fi != p.facets_end(); ++fi) {
|
||||
HFCC hc = fi->facet_begin();
|
||||
HFCC hc_end = hc;
|
||||
ps.append_poly();
|
||||
do {
|
||||
Vertex const& v = *((hc++)->vertex());
|
||||
double x = CGAL::to_double(v.point().x());
|
||||
double y = CGAL::to_double(v.point().y());
|
||||
double z = CGAL::to_double(v.point().z());
|
||||
ps.append_vertex(x, y, z);
|
||||
} while (hc != hc_end);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
template bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Epick> &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Epeck> &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Simple_cartesian<long> > &p, PolySet &ps);
|
||||
|
||||
}; // namespace CGALUtils
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
280
src/cgalutils.cc
280
src/cgalutils.cc
|
@ -34,238 +34,6 @@ namespace /* anonymous */ {
|
|||
Result vector_convert(V const& v) {
|
||||
return Result(CGAL::to_double(v[0]),CGAL::to_double(v[1]),CGAL::to_double(v[2]));
|
||||
}
|
||||
|
||||
#undef GEN_SURFACE_DEBUG
|
||||
|
||||
class CGAL_Build_PolySet : public CGAL::Modifier_base<CGAL_HDS>
|
||||
{
|
||||
public:
|
||||
typedef CGAL_Polybuilder::Point_3 CGALPoint;
|
||||
|
||||
const PolySet &ps;
|
||||
CGAL_Build_PolySet(const PolySet &ps) : ps(ps) { }
|
||||
|
||||
/*
|
||||
Using Grid here is important for performance reasons. See following model.
|
||||
If we don't grid the geometry before converting to a Nef Polyhedron, the quads
|
||||
in the cylinders to tessellated into triangles since floating point
|
||||
incertainty causes the faces to not be 100% planar. The incertainty is exaggerated
|
||||
by the transform. This wasn't a problem earlier since we used Nef for everything,
|
||||
but optimizations since then has made us keep it in floating point space longer.
|
||||
|
||||
minkowski() {
|
||||
cube([200, 50, 7], center = true);
|
||||
rotate([90,0,0]) cylinder($fn = 8, h = 1, r = 8.36, center = true);
|
||||
rotate([0,90,0]) cylinder($fn = 8, h = 1, r = 8.36, center = true);
|
||||
}
|
||||
*/
|
||||
#if 1 // Use Grid
|
||||
void operator()(CGAL_HDS& hds) {
|
||||
CGAL_Polybuilder B(hds, true);
|
||||
|
||||
std::vector<CGALPoint> vertices;
|
||||
Grid3d<int> grid(GRID_FINE);
|
||||
std::vector<size_t> indices(3);
|
||||
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
BOOST_REVERSE_FOREACH(Vector3d v, p) {
|
||||
if (!grid.has(v)) {
|
||||
// align v to the grid; the CGALPoint will receive the aligned vertex
|
||||
grid.align(v) = vertices.size();
|
||||
vertices.push_back(CGALPoint(v[0], v[1], v[2]));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("polyhedron(faces=[");
|
||||
int pidx = 0;
|
||||
#endif
|
||||
B.begin_surface(vertices.size(), ps.polygons.size());
|
||||
BOOST_FOREACH(const CGALPoint &p, vertices) {
|
||||
B.add_vertex(p);
|
||||
}
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
if (pidx++ > 0) printf(",");
|
||||
#endif
|
||||
indices.clear();
|
||||
BOOST_FOREACH(const Vector3d &v, p) {
|
||||
indices.push_back(grid.data(v));
|
||||
}
|
||||
|
||||
// We perform this test since there is a bug in CGAL's
|
||||
// Polyhedron_incremental_builder_3::test_facet() which
|
||||
// fails to detect duplicate indices
|
||||
bool err = false;
|
||||
for (std::size_t i = 0; i < indices.size(); ++i) {
|
||||
// check if vertex indices[i] is already in the sequence [0..i-1]
|
||||
for (std::size_t k = 0; k < i && !err; ++k) {
|
||||
if (indices[k] == indices[i]) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!err && B.test_facet(indices.begin(), indices.end())) {
|
||||
B.add_facet(indices.begin(), indices.end());
|
||||
}
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("[");
|
||||
int fidx = 0;
|
||||
BOOST_FOREACH(size_t i, indices) {
|
||||
if (fidx++ > 0) printf(",");
|
||||
printf("%ld", i);
|
||||
}
|
||||
printf("]");
|
||||
#endif
|
||||
}
|
||||
B.end_surface();
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("],\n");
|
||||
#endif
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("points=[");
|
||||
for (int i=0;i<vertices.size();i++) {
|
||||
if (i > 0) printf(",");
|
||||
const CGALPoint &p = vertices[i];
|
||||
printf("[%g,%g,%g]", CGAL::to_double(p.x()), CGAL::to_double(p.y()), CGAL::to_double(p.z()));
|
||||
}
|
||||
printf("]);\n");
|
||||
#endif
|
||||
}
|
||||
#else // Don't use Grid
|
||||
void operator()(CGAL_HDS& hds)
|
||||
{
|
||||
CGAL_Polybuilder B(hds, true);
|
||||
Reindexer<Vector3d> vertices;
|
||||
std::vector<size_t> indices(3);
|
||||
|
||||
// Estimating same # of vertices as polygons (very rough)
|
||||
B.begin_surface(ps.polygons.size(), ps.polygons.size());
|
||||
int pidx = 0;
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("polyhedron(faces=[");
|
||||
#endif
|
||||
BOOST_FOREACH(const Polygon &p, ps.polygons) {
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
if (pidx++ > 0) printf(",");
|
||||
#endif
|
||||
indices.clear();
|
||||
BOOST_REVERSE_FOREACH(const Vector3d &v, p) {
|
||||
size_t s = vertices.size();
|
||||
size_t idx = vertices.lookup(v);
|
||||
// If we added a vertex, also add it to the CGAL builder
|
||||
if (idx == s) B.add_vertex(CGALPoint(v[0], v[1], v[2]));
|
||||
indices.push_back(idx);
|
||||
}
|
||||
// We perform this test since there is a bug in CGAL's
|
||||
// Polyhedron_incremental_builder_3::test_facet() which
|
||||
// fails to detect duplicate indices
|
||||
bool err = false;
|
||||
for (std::size_t i = 0; i < indices.size(); ++i) {
|
||||
// check if vertex indices[i] is already in the sequence [0..i-1]
|
||||
for (std::size_t k = 0; k < i && !err; ++k) {
|
||||
if (indices[k] == indices[i]) {
|
||||
err = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!err && B.test_facet(indices.begin(), indices.end())) {
|
||||
B.add_facet(indices.begin(), indices.end());
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("[");
|
||||
int fidx = 0;
|
||||
BOOST_FOREACH(size_t i, indices) {
|
||||
if (fidx++ > 0) printf(",");
|
||||
printf("%ld", i);
|
||||
}
|
||||
printf("]");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
B.end_surface();
|
||||
#ifdef GEN_SURFACE_DEBUG
|
||||
printf("],\n");
|
||||
|
||||
printf("points=[");
|
||||
for (int vidx=0;vidx<vertices.size();vidx++) {
|
||||
if (vidx > 0) printf(",");
|
||||
const Vector3d &v = vertices.getArray()[vidx];
|
||||
printf("[%g,%g,%g]", v[0], v[1], v[2]);
|
||||
}
|
||||
printf("]);\n");
|
||||
#endif
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
// This code is from CGAL/demo/Polyhedron/Scene_nef_polyhedron_item.cpp
|
||||
// quick hacks to convert polyhedra from exact to inexact and vice-versa
|
||||
template <class Polyhedron_input,
|
||||
class Polyhedron_output>
|
||||
struct Copy_polyhedron_to
|
||||
: public CGAL::Modifier_base<typename Polyhedron_output::HalfedgeDS>
|
||||
{
|
||||
Copy_polyhedron_to(const Polyhedron_input& in_poly)
|
||||
: in_poly(in_poly) {}
|
||||
|
||||
void operator()(typename Polyhedron_output::HalfedgeDS& out_hds)
|
||||
{
|
||||
typedef typename Polyhedron_output::HalfedgeDS Output_HDS;
|
||||
|
||||
CGAL::Polyhedron_incremental_builder_3<Output_HDS> builder(out_hds);
|
||||
|
||||
typedef typename Polyhedron_input::Vertex_const_iterator Vertex_const_iterator;
|
||||
typedef typename Polyhedron_input::Facet_const_iterator Facet_const_iterator;
|
||||
typedef typename Polyhedron_input::Halfedge_around_facet_const_circulator HFCC;
|
||||
|
||||
builder.begin_surface(in_poly.size_of_vertices(),
|
||||
in_poly.size_of_facets(),
|
||||
in_poly.size_of_halfedges());
|
||||
|
||||
for(Vertex_const_iterator
|
||||
vi = in_poly.vertices_begin(), end = in_poly.vertices_end();
|
||||
vi != end ; ++vi)
|
||||
{
|
||||
typename Polyhedron_output::Point_3 p(::CGAL::to_double(vi->point().x()),
|
||||
::CGAL::to_double(vi->point().y()),
|
||||
::CGAL::to_double(vi->point().z()));
|
||||
builder.add_vertex(p);
|
||||
}
|
||||
|
||||
typedef CGAL::Inverse_index<Vertex_const_iterator> Index;
|
||||
Index index(in_poly.vertices_begin(), in_poly.vertices_end());
|
||||
|
||||
for(Facet_const_iterator
|
||||
fi = in_poly.facets_begin(), end = in_poly.facets_end();
|
||||
fi != end; ++fi)
|
||||
{
|
||||
HFCC hc = fi->facet_begin();
|
||||
HFCC hc_end = hc;
|
||||
// std::size_t n = circulator_size(hc);
|
||||
// CGAL_assertion(n >= 3);
|
||||
builder.begin_facet ();
|
||||
do {
|
||||
builder.add_vertex_to_facet(index[hc->vertex()]);
|
||||
++hc;
|
||||
} while(hc != hc_end);
|
||||
builder.end_facet();
|
||||
}
|
||||
builder.end_surface();
|
||||
} // end operator()(..)
|
||||
private:
|
||||
const Polyhedron_input& in_poly;
|
||||
}; // end Copy_polyhedron_to<>
|
||||
|
||||
template <class Poly_A, class Poly_B>
|
||||
void copy_to(const Poly_A& poly_a, Poly_B& poly_b)
|
||||
{
|
||||
Copy_polyhedron_to<Poly_A, Poly_B> modifier(poly_a);
|
||||
poly_b.delegate(modifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps)
|
||||
|
@ -294,8 +62,8 @@ static CGAL_Nef_polyhedron *createNefPolyhedronFromPolySet(const PolySet &ps)
|
|||
// Apply hull
|
||||
CGAL::Polyhedron_3<K> r;
|
||||
CGAL::convex_hull_3(points.begin(), points.end(), r);
|
||||
CGAL::Polyhedron_3<CGAL_Kernel3> r_exact;
|
||||
copy_to(r,r_exact);
|
||||
CGAL_Polyhedron r_exact;
|
||||
CGALUtils::copyPolyhedron(r, r_exact);
|
||||
return new CGAL_Nef_polyhedron(new CGAL_Nef_polyhedron3(r_exact));
|
||||
}
|
||||
|
||||
|
@ -341,22 +109,6 @@ static CGAL_Nef_polyhedron *createNefPolyhedronFromPolygon2d(const Polygon2d &po
|
|||
|
||||
namespace CGALUtils {
|
||||
|
||||
bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p)
|
||||
{
|
||||
bool err = false;
|
||||
CGAL::Failure_behaviour old_behaviour = CGAL::set_error_behaviour(CGAL::THROW_EXCEPTION);
|
||||
try {
|
||||
CGAL_Build_PolySet builder(ps);
|
||||
p.delegate(builder);
|
||||
}
|
||||
catch (const CGAL::Assertion_exception &e) {
|
||||
PRINTB("CGAL error in CGALUtils::createPolyhedronFromPolySet: %s", e.what());
|
||||
err = true;
|
||||
}
|
||||
CGAL::set_error_behaviour(old_behaviour);
|
||||
return err;
|
||||
}
|
||||
|
||||
bool applyHull(const Geometry::ChildList &children, PolySet &result)
|
||||
{
|
||||
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
|
||||
|
@ -1010,34 +762,6 @@ namespace CGALUtils {
|
|||
return explored_facets.size() == ps.polygons.size();
|
||||
}
|
||||
|
||||
template <typename Polyhedron>
|
||||
bool createPolySetFromPolyhedron(const Polyhedron &p, PolySet &ps)
|
||||
{
|
||||
bool err = false;
|
||||
typedef typename Polyhedron::Vertex Vertex;
|
||||
typedef typename Polyhedron::Vertex_const_iterator VCI;
|
||||
typedef typename Polyhedron::Facet_const_iterator FCI;
|
||||
typedef typename Polyhedron::Halfedge_around_facet_const_circulator HFCC;
|
||||
|
||||
for (FCI fi = p.facets_begin(); fi != p.facets_end(); ++fi) {
|
||||
HFCC hc = fi->facet_begin();
|
||||
HFCC hc_end = hc;
|
||||
ps.append_poly();
|
||||
do {
|
||||
Vertex const& v = *((hc++)->vertex());
|
||||
double x = CGAL::to_double(v.point().x());
|
||||
double y = CGAL::to_double(v.point().y());
|
||||
double z = CGAL::to_double(v.point().z());
|
||||
ps.append_vertex(x, y, z);
|
||||
} while (hc != hc_end);
|
||||
}
|
||||
return err;
|
||||
}
|
||||
|
||||
template bool createPolySetFromPolyhedron(const CGAL_Polyhedron &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Epick> &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Epeck> &p, PolySet &ps);
|
||||
template bool createPolySetFromPolyhedron(const CGAL::Polyhedron_3<CGAL::Simple_cartesian<long> > &p, PolySet &ps);
|
||||
|
||||
/*
|
||||
Create a PolySet from a Nef Polyhedron 3. return false on success,
|
||||
|
|
|
@ -21,10 +21,13 @@ namespace CGALUtils {
|
|||
bool is_approximately_convex(const PolySet &ps);
|
||||
Geometry const* applyMinkowski(const Geometry::ChildList &children);
|
||||
|
||||
CGAL_Nef_polyhedron *createNefPolyhedronFromGeometry(const class Geometry &geom);
|
||||
template <typename Polyhedron> bool createPolySetFromPolyhedron(const Polyhedron &p, PolySet &ps);
|
||||
template <typename Polyhedron> bool createPolyhedronFromPolySet(const PolySet &ps, Polyhedron &p);
|
||||
template <class Polyhedron_A, class Polyhedron_B>
|
||||
void copyPolyhedron(const Polyhedron_A &poly_a, Polyhedron_B &poly_b);
|
||||
|
||||
CGAL_Nef_polyhedron *createNefPolyhedronFromGeometry(const class Geometry &geom);
|
||||
bool createPolySetFromNefPolyhedron3(const CGAL_Nef_polyhedron3 &N, PolySet &ps);
|
||||
bool createPolyhedronFromPolySet(const PolySet &ps, CGAL_Polyhedron &p);
|
||||
|
||||
bool tessellatePolygon(const PolygonK &polygon,
|
||||
Polygons &triangles,
|
||||
|
|
|
@ -676,6 +676,7 @@ set(CGAL_SOURCES
|
|||
../src/CGAL_Nef_polyhedron.cc
|
||||
../src/cgalutils.cc
|
||||
../src/cgalutils-tess.cc
|
||||
../src/cgalutils-polyhedron.cc
|
||||
../src/cgalutils-tess-old.cc
|
||||
../src/CGALCache.cc
|
||||
../src/CGAL_Nef_polyhedron_DxfData.cc
|
||||
|
|
Loading…
Reference in New Issue