summaryrefslogtreecommitdiff
path: root/src/CGALEvaluator.cc
diff options
context:
space:
mode:
authordon bright <hugh.m.bright@gmail.com>2013-03-11 02:35:30 (GMT)
committerdon bright <hugh.m.bright@gmail.com>2013-03-11 02:35:30 (GMT)
commit5559ae9a6af459021c5b7ab4a823f491dce822a0 (patch)
treeccea074154b71c24ab0aee3150d4b07eef896a05 /src/CGALEvaluator.cc
parent33a54b52f2c54c4ac66881d63b852b472f5589f1 (diff)
move transform from CGALEvaluator to Nef_polyhedron - reuse in resize(). also
move ZRemover code to cgalutils, also cleanup SVG code
Diffstat (limited to 'src/CGALEvaluator.cc')
-rw-r--r--src/CGALEvaluator.cc78
1 files changed, 14 insertions, 64 deletions
diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc
index b0984ce..a5a9d65 100644
--- a/src/CGALEvaluator.cc
+++ b/src/CGALEvaluator.cc
@@ -185,13 +185,6 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node)
// Based on resize() in Giles Bathgate's RapCAD
CGAL_Nef_polyhedron N;
N = applyToChildren(node, CGE_UNION);
- if (N.isNull()) {
- PRINT("WARNING: resize() of null polyhedron");
- return N;
- }
-
- int dim = N.dim;
- if (dim==2) N.convertTo3d();
CGAL_Iso_cuboid_3 bb = bounding_box( *N.p3 );
Eigen::Matrix<NT,3,1> scale, bbox_size;
@@ -200,13 +193,18 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node)
for (int i=0;i<3;i++)
if (node.newsize[i] && bbox_size[i]!=NT(0))
scale[i] = NT(node.newsize[i]) / NT(bbox_size[i]);
- CGAL_Aff_transformation t( scale[0], 0, 0, 0,
- 0, scale[1], 0, 0,
- 0, 0, scale[2], 0, 1);
- N.p3->transform( t );
-
- if (dim==2) N.convertTo2d();
-
+ NT autoscale = scale.maxCoeff();
+ if (node.autosize)
+ for (int i=0;i<3;i++)
+ 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;
+
+ N.transform( Transform3d( t ) );
return N;
}
@@ -286,56 +284,8 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node)
PRINT("Warning: Transformation matrix contains Not-a-Number and/or Infinity - removing object.");
N.reset();
}
-
- // Then apply transform
- // If there is no geometry under the transform, N will be empty
- // just silently ignore such nodes
- if (!N.isNull()) {
- if (N.dim == 2) {
- // Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2
- // objects. So we convert in to our internal 2d data format, transform it,
- // tesselate it and create a new CGAL_Nef_polyhedron2 from it.. What a hack!
-
- Eigen::Matrix2f testmat;
- testmat << node.matrix(0,0), node.matrix(0,1), node.matrix(1,0), node.matrix(1,1);
- if (testmat.determinant() == 0) {
- PRINT("Warning: Scaling a 2D object with 0 - removing object");
- N.reset();
- }
- else {
- CGAL_Aff_transformation2 t(
- node.matrix(0,0), node.matrix(0,1), node.matrix(0,3),
- node.matrix(1,0), node.matrix(1,1), node.matrix(1,3), node.matrix(3,3));
-
- DxfData *dd = N.convertToDxfData();
- for (size_t 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());
- }
-
- PolySet ps;
- ps.is2d = true;
- dxf_tesselate(&ps, *dd, 0, true, false, 0);
-
- N = evaluateCGALMesh(ps);
- delete dd;
- }
- }
- else if (N.dim == 3) {
- if (node.matrix.matrix().determinant() == 0) {
- PRINT("Warning: Scaling a 3D object with 0 - removing object");
- N.reset();
- }
- else {
- CGAL_Aff_transformation t(
- node.matrix(0,0), node.matrix(0,1), node.matrix(0,2), node.matrix(0,3),
- node.matrix(1,0), node.matrix(1,1), node.matrix(1,2), node.matrix(1,3),
- node.matrix(2,0), node.matrix(2,1), node.matrix(2,2), node.matrix(2,3), node.matrix(3,3));
- N.p3->transform(t);
- }
- }
+ else {
+ N.transform( node.matrix );
}
}
else {
contact: Jan Huwald // Impressum