#1225 Fix nan or inf normal vector output

master
Marius Kintel 2015-02-23 21:21:31 -05:00
parent 56f3552404
commit b13075d2a5
2 changed files with 16 additions and 1 deletions

View File

@ -150,9 +150,16 @@ void export_stl(const PolySet &ps, std::ostream &output)
// so the default value of "1 0 0" can be used. If the vertices are not
// collinear then the unit normal must be calculated from the
// components.
output << " facet normal ";
Vector3d normal = (p[1] - p[0]).cross(p[2] - p[0]);
normal.normalize();
output << " facet normal " << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
if (is_finite(normal) && !is_nan(normal)) {
output << normal[0] << " " << normal[1] << " " << normal[2] << "\n";
}
else {
output << "0 0 0\n";
}
output << " outer loop\n";
BOOST_FOREACH(const Vector3d &v, p) {

View File

@ -24,6 +24,14 @@ using Eigen::Matrix4d;
bool matrix_contains_infinity( const Transform3d &m );
bool matrix_contains_nan( const Transform3d &m );
template<typename Derived> bool is_finite(const Eigen::MatrixBase<Derived>& x) {
return ( (x - x).array() == (x - x).array()).all();
}
template<typename Derived> bool is_nan(const Eigen::MatrixBase<Derived>& x) {
return ((x.array() == x.array())).all();
}
BoundingBox operator*(const Transform3d &m, const BoundingBox &box);
class Color4f : public Eigen::Vector4f