mirror of https://github.com/vitalif/openscad
Merge branch 'gridfix'
commit
47fcde8d5c
|
@ -296,6 +296,63 @@ namespace CGALUtils {
|
|||
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);
|
||||
|
||||
class Polyhedron_writer {
|
||||
std::ostream *out;
|
||||
bool firstv;
|
||||
std::vector<int> indices;
|
||||
public:
|
||||
Polyhedron_writer() {}
|
||||
void write_header(std::ostream &stream,
|
||||
std::size_t vertices,
|
||||
std::size_t halfedges,
|
||||
std::size_t facets,
|
||||
bool normals = false) {
|
||||
this->out = &stream;
|
||||
*out << "polyhedron(points=[";
|
||||
firstv = true;
|
||||
}
|
||||
void write_footer() {
|
||||
*out << "]);" << std::endl;
|
||||
}
|
||||
void write_vertex( const double& x, const double& y, const double& z) {
|
||||
*out << (firstv ? "" : ",") << '[' << x << ',' << y << ',' << z << ']';
|
||||
firstv = false;
|
||||
}
|
||||
void write_facet_header() {
|
||||
*out << "], faces=[";
|
||||
firstv = true;
|
||||
}
|
||||
void write_facet_begin( std::size_t no) {
|
||||
*out << (firstv ? "" : ",") << '[';
|
||||
indices.clear();
|
||||
firstv = false;
|
||||
}
|
||||
void write_facet_vertex_index( std::size_t index) {
|
||||
indices.push_back(index);
|
||||
}
|
||||
void write_facet_end() {
|
||||
bool firsti = true;
|
||||
BOOST_REVERSE_FOREACH(int i, indices) {
|
||||
*out << (firsti ? "" : ",") << i;
|
||||
firsti = false;
|
||||
}
|
||||
*out << ']';
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Polyhedron>
|
||||
std::string printPolyhedron(const Polyhedron &p) {
|
||||
std::stringstream sstream;
|
||||
sstream.precision(20);
|
||||
|
||||
Polyhedron_writer writer;
|
||||
generic_print_polyhedron(sstream, p, writer);
|
||||
|
||||
return sstream.str();
|
||||
}
|
||||
|
||||
template std::string printPolyhedron(const CGAL_Polyhedron &p);
|
||||
|
||||
}; // namespace CGALUtils
|
||||
|
||||
#endif /* ENABLE_CGAL */
|
||||
|
|
|
@ -107,6 +107,8 @@ namespace CGALUtils {
|
|||
else {
|
||||
// Calculate best guess at face normal using Newell's method
|
||||
CGAL::normal_vector_newell_3(polygons.front().begin(), polygons.front().end(), normalvec);
|
||||
double sqrl = normalvec.squared_length();
|
||||
if (sqrl > 0.0) normalvec = normalvec / sqrt(sqrl);
|
||||
}
|
||||
|
||||
// Pass the normal vector to the (undocumented)
|
||||
|
|
|
@ -917,10 +917,13 @@ namespace CGALUtils {
|
|||
and let the tessellater deal with the holes, and then
|
||||
just output the resulting 3d triangles*/
|
||||
|
||||
CGAL::Vector_3<CGAL_Kernel3> nvec = plane.orthogonal_vector();
|
||||
K::Vector_3 normal(CGAL::to_double(nvec.x()), CGAL::to_double(nvec.y()), CGAL::to_double(nvec.z()));
|
||||
// We cannot trust the plane from Nef polyhedron to be correct.
|
||||
// Passing an incorrect normal vector can cause a crash in the constrained delaunay triangulator
|
||||
// See http://cgal-discuss.949826.n4.nabble.com/Nef3-Wrong-normal-vector-reported-causes-triangulator-crash-tt4660282.html
|
||||
// CGAL::Vector_3<CGAL_Kernel3> nvec = plane.orthogonal_vector();
|
||||
// K::Vector_3 normal(CGAL::to_double(nvec.x()), CGAL::to_double(nvec.y()), CGAL::to_double(nvec.z()));
|
||||
std::vector<Polygon> triangles;
|
||||
bool err = CGALUtils::tessellatePolygonWithHoles(polyholes, triangles, &normal);
|
||||
bool err = CGALUtils::tessellatePolygonWithHoles(polyholes, triangles, NULL);
|
||||
if (!err) {
|
||||
BOOST_FOREACH(const Polygon &p, triangles) {
|
||||
if (p.size() != 3) {
|
||||
|
|
|
@ -21,6 +21,7 @@ namespace CGALUtils {
|
|||
bool is_approximately_convex(const PolySet &ps);
|
||||
Geometry const* applyMinkowski(const Geometry::ChildList &children);
|
||||
|
||||
template <typename Polyhedron> std::string printPolyhedron(const Polyhedron &p);
|
||||
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>
|
||||
|
|
|
@ -461,7 +461,8 @@ int cmdline(const char *deps_output_file, const std::string &filename, Camera &c
|
|||
if (renderer == Render::CGAL && root_geom->getDimension() == 3) {
|
||||
const CGAL_Nef_polyhedron *N = dynamic_cast<const CGAL_Nef_polyhedron*>(root_geom.get());
|
||||
if (!N) {
|
||||
root_geom.reset(CGALUtils::createNefPolyhedronFromGeometry(*root_geom));
|
||||
N = CGALUtils::createNefPolyhedronFromGeometry(*root_geom);
|
||||
root_geom.reset(N);
|
||||
PRINT("Converted to Nef polyhedron");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue