allow resize to use CGAL's engine to deal with precision issues per discussion

with Marius and Giles
transformprecision
Don Bright 2014-01-30 17:21:54 -06:00
parent 79f6baf264
commit 80df04074d
4 changed files with 31 additions and 13 deletions

View File

@ -28,7 +28,8 @@ public:
CGAL_Nef_polyhedron &minkowski(const CGAL_Nef_polyhedron &other);
CGAL_Nef_polyhedron *copy() const;
class PolySet *convertToPolyset() const;
void transform( const Transform3d &matrix );
void transform( const CGAL_Nef_polyhedron3::Aff_transformation_3 &t );
void transform( const Transform3d &t );
shared_ptr<CGAL_Nef_polyhedron3> p3;
};

View File

@ -42,21 +42,38 @@ std::string CGAL_Nef_polyhedron::dump() const
}
void CGAL_Nef_polyhedron::transform( const Transform3d &matrix )
void CGAL_Nef_polyhedron::transform( const CGAL_Nef_polyhedron3::Aff_transformation_3 &t )
{
if (!this->isEmpty()) {
if (matrix.matrix().determinant() == 0) {
if (CGAL::sign_of_determinant<NT3>(
t.cartesian(0,0),t.cartesian(0,1),t.cartesian(0,2),
t.cartesian(1,0),t.cartesian(1,1),t.cartesian(1,2),
t.cartesian(2,0),t.cartesian(2,1),t.cartesian(2,2)
)==0) {
PRINT("Warning: Scaling a 3D object with 0 - removing object");
this->reset();
}
else {
CGAL_Aff_transformation t(
matrix(0,0), matrix(0,1), matrix(0,2), matrix(0,3),
matrix(1,0), matrix(1,1), matrix(1,2), matrix(1,3),
matrix(2,0), matrix(2,1), matrix(2,2), matrix(2,3), matrix(3,3));
this->p3->transform(t);
}
}
}
void CGAL_Nef_polyhedron::transform( const Transform3d &t )
{
if (!this->isEmpty()) {
if (t.matrix().determinant()==0) {
PRINT("Warning: Scaling a 3D object with 0 - removing object");
this->reset();
}
else {
CGAL_Nef_polyhedron3::Aff_transformation_3 aff(
t(0,0),t(0,1),t(0,2),t(0,3),
t(1,0),t(1,1),t(1,2),t(1,3),
t(2,0),t(2,1),t(2,2),t(2,3),t(3,3) );
this->p3->transform(aff);
}
}
}
#endif // ENABLE_CGAL

View File

@ -203,13 +203,12 @@ void GeometryEvaluator::applyResize3D(CGAL_Nef_polyhedron &N,
if (autosize[i] && newsize[i]==0) scale[i] = autoscale;
}
Eigen::Matrix4d t;
t << CGAL::to_double(scale[0]), 0, 0, 0,
0, CGAL::to_double(scale[1]), 0, 0,
0, 0, CGAL::to_double(scale[2]), 0,
0, 0, 0, 1;
CGAL_Nef_polyhedron3::Aff_transformation_3 aff(
scale[0], 0, 0,
0, scale[1], 0,
0, 0, scale[2], 1 );
N.transform(Transform3d(t));
N.transform( aff );
return;
}

View File

@ -842,6 +842,7 @@ list(APPEND CGALPNGTEST_FILES ${FEATURES_FILES} ${SCAD_DXF_FILES} ${EXAMPLE_FILE
list(APPEND CGALPNGTEST_FILES ${CMAKE_SOURCE_DIR}/../testdata/scad/misc/include-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/use-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-nan-inf-tests.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/bugs/transform-precision.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles-test.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/localfiles_dir/localfiles-compatibility-test.scad
${CMAKE_SOURCE_DIR}/../testdata/scad/misc/rotate-empty-bbox.scad