From 3cf6c24d834295eb9f409cece0b9aec8f2296fa2 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 9 Mar 2013 20:28:43 -0600 Subject: beginning of resize() command implementation. diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 4deb3b3..b0984ce 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -179,6 +179,39 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) return N; } + +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 scale, bbox_size; + scale << 1,1,1; + bbox_size << bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin(), bb.zmax()-bb.zmin(); + 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(); + + return N; +} + + + /* Typical visitor behavior: o In prefix: Check if we're cached -> prune @@ -358,6 +391,9 @@ Response CGALEvaluator::visit(State &state, const CgaladvNode &node) case HULL: N = applyHull(node); break; + case RESIZE: + N = applyResize(node); + break; } } else { diff --git a/src/CGALEvaluator.h b/src/CGALEvaluator.h index 42af5a1..818f520 100644 --- a/src/CGALEvaluator.h +++ b/src/CGALEvaluator.h @@ -34,6 +34,7 @@ private: void process(CGAL_Nef_polyhedron &target, const CGAL_Nef_polyhedron &src, CGALEvaluator::CsgOp op); CGAL_Nef_polyhedron applyToChildren(const AbstractNode &node, CGALEvaluator::CsgOp op); CGAL_Nef_polyhedron applyHull(const CgaladvNode &node); + CGAL_Nef_polyhedron applyResize(const CgaladvNode &node); std::string currindent; typedef std::pair ChildItem; diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h index d949a2a..03eaaa6 100644 --- a/src/CGAL_Nef_polyhedron.h +++ b/src/CGAL_Nef_polyhedron.h @@ -27,6 +27,8 @@ public: int weight() const; class PolySet *convertToPolyset(); class DxfData *convertToDxfData() const; + void convertTo2d(); + void convertTo3d(); int dim; shared_ptr p2; diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index 0d0b8f0..e642612 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -29,7 +29,6 @@ #include "CGAL_Nef_polyhedron.h" #include "cgal.h" #include "cgalutils.h" -#include "svg.h" #ifdef ENABLE_CGAL @@ -89,4 +88,85 @@ std::string CGAL_Nef_polyhedron::dump() const return std::string("Nef Polyhedron with dimension != 2 or 3"); } +// use a try/catch block around any calls to this +void CGAL_Nef_polyhedron::convertTo2d() +{ + logstream log(5); + if (dim!=3) return; + assert(this->p3); + ZRemover zremover; + CGAL_Nef_polyhedron3::Volume_const_iterator i; + CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; + CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; + for ( i = this->p3->volumes_begin(); i != this->p3->volumes_end(); ++i ) { + log << "\n"; + for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { + log << "\n"; + sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); + this->p3->visit_shell_objects( sface_handle , zremover ); + log << "\n"; + } + log << "\n"; + } + this->p3.reset(); + this->p2 = zremover.output_nefpoly2d; + this->dim = 2; +} + + +std::vector face2to3( + CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1, + CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2, + CGAL_Nef_polyhedron2::Explorer explorer ) +{ + std::vector result; + CGAL_For_all(c1, c2) { + if ( explorer.is_standard( explorer.target(c1) ) ) { + //CGAL_Point_2e source = explorer.point( explorer.source( c1 ) ); + CGAL_Point_2e target = explorer.point( explorer.target( c1 ) ); + if (c1->mark()) { + CGAL_Point_3 tmp( target.x(), target.y(), 0 ); + result.push_back( tmp ); + } + } + } + return result; +} + + +// use a try/catch block around any calls to this +void CGAL_Nef_polyhedron::convertTo3d() +{ + if (dim!=2) return; + assert(this->p2); + CGAL_Nef_polyhedron2::Explorer explorer = this->p2->explorer(); + CGAL_Nef_polyhedron2::Explorer::Face_const_iterator i; + + this->p3.reset( new CGAL_Nef_polyhedron3() ); + + for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) { + + CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1 + = explorer.face_cycle( i ), c2 ( c1 ); + std::vector body_pts = face2to3( c1, c2, explorer ); + CGAL_Nef_polyhedron3 body( body_pts.begin(), body_pts.end() ); + + CGAL_Nef_polyhedron3 holes; + CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j; + for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) { + CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 ); + std::vector hole_pts = face2to3( c3, c4, explorer ); + CGAL_Nef_polyhedron3 hole( hole_pts.begin(), hole_pts.end() ); + holes = holes.join( hole ); + } + + body = body.difference( holes ); + *(this->p3) = this->p3->join( body ); + } + + this->p2.reset(); + this->dim = 3; +} + + #endif // ENABLE_CGAL diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 224e657..0aa9e9e 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -20,104 +20,6 @@ #include #include -/* - -ZRemover - -This class converts one or more already 'flat' Nef3 polyhedra into a Nef2 -polyhedron by stripping off the 'z' coordinates from the vertices. The -resulting Nef2 poly is accumulated in the 'output_nefpoly2d' member variable. - -The 'z' coordinates will either be all 0s, for an xy-plane intersected Nef3, -or, they will be a mixture of -eps and +eps, for a thin-box intersected Nef3. - -Notes on CGAL's Nef Polyhedron2: - -1. The 'mark' on a 2d Nef face is important when doing unions/intersections. - If the 'mark' of a face is wrong the resulting nef2 poly will be unexpected. -2. The 'mark' can be dependent on the points fed to the Nef2 constructor. - This is why we iterate through the 3d faces using the halfedge cycle - source()->target() instead of the ordinary source()->source(). The - the latter can generate sequences of points that will fail the - the CGAL::is_simple_2() test, resulting in improperly marked nef2 polys. -3. 3d facets have 'two sides'. we throw out the 'down' side to prevent dups. - -The class uses the 'visitor' pattern from the CGAL manual. See also -http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html -http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3_ref/Class_Nef_polyhedron3.html -OGL_helper.h -*/ - -class ZRemover { -public: - logstream log; - CGAL_Nef_polyhedron2::Boundary boundary; - shared_ptr tmpnef2d; - shared_ptr output_nefpoly2d; - CGAL::Direction_3 up; - ZRemover() - { - output_nefpoly2d.reset( new CGAL_Nef_polyhedron2() ); - boundary = CGAL_Nef_polyhedron2::INCLUDED; - up = CGAL::Direction_3(0,0,1); - log = logstream(5); - } - void visit( CGAL_Nef_polyhedron3::Vertex_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { - log << " \n"; - if ( hfacet->plane().orthogonal_direction() != this->up ) { - log << " \n"; - log << " \n"; - return; - } - - // possible optimization - throw out facets that are 'side facets' between - // the top & bottom of the big thin box. (i.e. mixture of z=-eps and z=eps) - - CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator fci; - int contour_counter = 0; - CGAL_forall_facet_cycles_of( fci, hfacet ) { - if ( fci.is_shalfedge() ) { - CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(fci), cend(c1); - std::vector contour; - CGAL_For_all( c1, cend ) { - CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->target()->point(); - CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); - contour.push_back( point2d ); - } - - if (contour.size()==0) continue; - - log << " \n"; - - tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); - - if ( contour_counter == 0 ) { - log << " \n" ; - *(output_nefpoly2d) += *(tmpnef2d); - } else { - log << " \n"; - *(output_nefpoly2d) *= *(tmpnef2d); - } - - log << "\n\n" - << OpenSCAD::dump_svg( *tmpnef2d ) << "\n" - << "\n\n" - << OpenSCAD::dump_svg( *output_nefpoly2d ) << "\n"; - - contour_counter++; - } else { - log << " \n"; - } - } // next facet cycle (i.e. next contour) - log << " \n"; - } // visit() -}; - PolySetCGALEvaluator::PolySetCGALEvaluator(CGALEvaluator &cgalevaluator) : PolySetEvaluator(cgalevaluator.getTree()), cgalevaluator(cgalevaluator) { @@ -186,24 +88,10 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) return NULL; } - // remove z coordinates to make CGAL_Nef_polyhedron2 log << OpenSCAD::svg_header( 480, 100000 ) << "\n"; try { - ZRemover zremover; - CGAL_Nef_polyhedron3::Volume_const_iterator i; - CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; - CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; - for ( i = sum.p3->volumes_begin(); i != sum.p3->volumes_end(); ++i ) { - log << "\n"; - for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { - log << "\n"; - sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); - sum.p3->visit_shell_objects( sface_handle , zremover ); - log << "\n"; - } - log << "\n"; - } - nef_poly.p2 = zremover.output_nefpoly2d; + sum.convertTo2d(); + nef_poly.p2 = sum.p2; } catch (const CGAL::Failure_exception &e) { PRINTB("CGAL error in projection node while flattening: %s", e.what()); } diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 1773a90..073a908 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -58,6 +58,9 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat if (type == SUBDIV) argnames += "type", "level", "convexity"; + if (type == RESIZE) + argnames += "newsize"; + Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); @@ -78,6 +81,17 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat level = c.lookup_variable("level", true); } + if (type == RESIZE) { + Value ns = c.lookup_variable("newsize"); + node->newsize << 0,0,0; + if ( ns.type() == Value::VECTOR ) { + Value::VectorType v = ns.toVector(); + if ( v.size() >= 1 ) node->newsize[0] = v[0].toDouble(); + if ( v.size() >= 2 ) node->newsize[1] = v[1].toDouble(); + if ( v.size() >= 3 ) node->newsize[2] = v[2].toDouble(); + } + } + node->convexity = (int)convexity.toDouble(); node->path = path; node->subdiv_type = subdiv_type.toString(); @@ -112,6 +126,9 @@ std::string CgaladvNode::name() const case HULL: return "hull"; break; + case RESIZE: + return "resize"; + break; default: assert(false); } @@ -135,6 +152,9 @@ std::string CgaladvNode::toString() const case HULL: stream << "()"; break; + case RESIZE: + stream << "(newsize = " << this->newsize << ")"; + break; default: assert(false); } @@ -148,4 +168,5 @@ void register_builtin_cgaladv() Builtins::init("glide", new CgaladvModule(GLIDE)); Builtins::init("subdiv", new CgaladvModule(SUBDIV)); Builtins::init("hull", new CgaladvModule(HULL)); + Builtins::init("resize", new CgaladvModule(RESIZE)); } diff --git a/src/cgaladvnode.h b/src/cgaladvnode.h index 8e769bf..097d2b4 100644 --- a/src/cgaladvnode.h +++ b/src/cgaladvnode.h @@ -4,12 +4,14 @@ #include "node.h" #include "visitor.h" #include "value.h" +#include "linalg.h" enum cgaladv_type_e { MINKOWSKI, GLIDE, SUBDIV, - HULL + HULL, + RESIZE }; class CgaladvNode : public AbstractNode @@ -29,6 +31,7 @@ public: Value path; std::string subdiv_type; int convexity, level; + Vector3d newsize; cgaladv_type_e type; }; diff --git a/src/cgalutils.cc b/src/cgalutils.cc index 51838df..66d4b18 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -147,7 +147,7 @@ CGAL_Polyhedron *createPolyhedronFromPolySet(const PolySet &ps) CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) { - CGAL_Iso_cuboid_3 result(-1,-1,-1,1,1,1); + CGAL_Iso_cuboid_3 result(0,0,0,0,0,0); CGAL_Nef_polyhedron3::Vertex_const_iterator vi; std::vector points; // can be optimized by rewriting bounding_box to accept vertices @@ -160,7 +160,7 @@ CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ) CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ) { - CGAL_Iso_rectangle_2e result(-1,-1,1,1); + CGAL_Iso_rectangle_2e result(0,0,0,0); CGAL_Nef_polyhedron2::Explorer explorer = N.explorer(); CGAL_Nef_polyhedron2::Explorer::Vertex_const_iterator vi; std::vector points; diff --git a/src/cgalutils.h b/src/cgalutils.h index 9093c3f..8f10519 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -2,10 +2,111 @@ #define CGALUTILS_H_ #include - class PolySet *createPolySetFromPolyhedron(const CGAL_Polyhedron &p); CGAL_Polyhedron *createPolyhedronFromPolySet(const class PolySet &ps); CGAL_Iso_cuboid_3 bounding_box( const CGAL_Nef_polyhedron3 &N ); CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ); +#include "svg.h" +#include "printutils.h" + +/* + +ZRemover + +This class converts one or more Nef3 polyhedra into a Nef2 polyhedron by +stripping off the 'z' coordinates from the vertices. The resulting Nef2 +poly is accumulated in the 'output_nefpoly2d' member variable. + +The 'z' coordinates will either be all 0s, for an xy-plane intersected Nef3, +or, they will be a mixture of -eps and +eps, for a thin-box intersected Nef3. + +Notes on CGAL's Nef Polyhedron2: + +1. The 'mark' on a 2d Nef face is important when doing unions/intersections. + If the 'mark' of a face is wrong the resulting nef2 poly will be unexpected. +2. The 'mark' can be dependent on the points fed to the Nef2 constructor. + This is why we iterate through the 3d faces using the halfedge cycle + source()->target() instead of the ordinary source()->source(). The + the latter can generate sequences of points that will fail the + the CGAL::is_simple_2() test, resulting in improperly marked nef2 polys. +3. 3d facets have 'two sides'. we throw out the 'down' side to prevent dups. + +The class uses the 'visitor' pattern from the CGAL manual. See also +http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3/Chapter_main.html +http://www.cgal.org/Manual/latest/doc_html/cgal_manual/Nef_3_ref/Class_Nef_polyhedron3.html +OGL_helper.h +*/ + +class ZRemover { +public: + logstream log; + CGAL_Nef_polyhedron2::Boundary boundary; + boost::shared_ptr tmpnef2d; + boost::shared_ptr output_nefpoly2d; + CGAL::Direction_3 up; + ZRemover() + { + output_nefpoly2d.reset( new CGAL_Nef_polyhedron2() ); + boundary = CGAL_Nef_polyhedron2::INCLUDED; + up = CGAL::Direction_3(0,0,1); + log = logstream(5); + } + void visit( CGAL_Nef_polyhedron3::Vertex_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::Halfedge_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} + void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { + log << " \n"; + if ( hfacet->plane().orthogonal_direction() != this->up ) { + log << " \n"; + log << " \n"; + return; + } + + // possible optimization - throw out facets that are 'side facets' between + // the top & bottom of the big thin box. (i.e. mixture of z=-eps and z=eps) + + CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator fci; + int contour_counter = 0; + CGAL_forall_facet_cycles_of( fci, hfacet ) { + if ( fci.is_shalfedge() ) { + CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(fci), cend(c1); + std::vector contour; + CGAL_For_all( c1, cend ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->target()->point(); + CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); + contour.push_back( point2d ); + } + + if (contour.size()==0) continue; + + log << " \n"; + + tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); + + if ( contour_counter == 0 ) { + log << " \n" ; + *(output_nefpoly2d) += *(tmpnef2d); + } else { + log << " \n"; + *(output_nefpoly2d) *= *(tmpnef2d); + } + + log << "\n\n" + << OpenSCAD::dump_svg( *tmpnef2d ) << "\n" + << "\n\n" + << OpenSCAD::dump_svg( *output_nefpoly2d ) << "\n"; + + contour_counter++; + } else { + log << " \n"; + } + } // next facet cycle (i.e. next contour) + log << " \n"; + } // visit() +}; + + #endif diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad new file mode 100644 index 0000000..f2e9148 --- /dev/null +++ b/testdata/scad/features/resize-tests.scad @@ -0,0 +1,42 @@ +// bottom row = reference +// middle row = should match reference +// top row = should be inscribed in middle row in 'top' view + +$fn=10; + +color("red") { +translate([0, 0,-10]) cube(); +translate([0,10,-10]) cube([5,1,1]); +translate([0,20,-10]) cube([1,6,1]); +translate([0,30,-10]) cube([1,1,7]); +translate([0,40,-10]) cube([5,6,1]); +translate([0,60,-10]) cube([1,6,7]); +translate([0,50,-10]) cube([5,1,7]); +translate([0,70,-10]) cube([8,9,1]); +translate([0,80,-10]) cube([9,1,1]); +translate([0,90,-10]) cube([5,6,1]); +} + +translate([0, 0,0]) cube(); +translate([0,10,0]) resize([5,0,0]) cube(); +translate([0,20,0]) resize([0,6,0]) cube(); +translate([0,30,0]) resize([0,0,7]) cube(); +translate([0,40,0]) resize([5,6,0]) cube(); +translate([0,60,0]) resize([0,6,7]) cube(); +translate([0,50,0]) resize([5,0,7]) cube(); +translate([0,70,0]) resize([8,9]) cube(); +translate([0,80,0]) resize([9]) cube(); +translate([0,90,0]) resize([5,6,7]) cube(); + +color("blue"){ +translate([0, 0,10]) cube(); +translate([2.5,10.5,10]) resize([5,0,0]) sphere(0.5); +translate([0.5,23,10]) resize([0,6,0]) sphere(0.5); +translate([0.5,30.5,10]) resize([0,0,7]) sphere(0.5); +translate([2.5,43,10]) resize([5,6,0]) sphere(0.5); +translate([0.5,63,10]) resize([0,6,7]) sphere(0.5); +translate([2.5,50.5,10]) resize([5,0,7]) sphere(0.5); +translate([4,74.5,10]) resize([8,9]) sphere(0.5); +translate([4.5,80.5,10]) resize([9]) sphere(0.5); +translate([2.5,93,10]) resize([5,6,7]) sphere(0.5); +} \ No newline at end of file -- cgit v0.10.1 From 33a54b52f2c54c4ac66881d63b852b472f5589f1 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 9 Mar 2013 20:36:35 -0600 Subject: test output for resize() diff --git a/tests/regression/cgalpngtest/resize-tests-expected.png b/tests/regression/cgalpngtest/resize-tests-expected.png new file mode 100644 index 0000000..b9f7792 Binary files /dev/null and b/tests/regression/cgalpngtest/resize-tests-expected.png differ diff --git a/tests/regression/dumptest/resize-tests-expected.txt b/tests/regression/dumptest/resize-tests-expected.txt new file mode 100644 index 0000000..4ba8925 --- /dev/null +++ b/tests/regression/dumptest/resize-tests-expected.txt @@ -0,0 +1,167 @@ + color([1, 0, 0, 1]) { + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [1, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 10], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [5, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 20], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [1, 6, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 30], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [1, 1, 7], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 40], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [5, 6, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 60], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [1, 6, 7], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 50], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [5, 1, 7], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 70], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [8, 9, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 80], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [9, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 90], [0, 0, 1, -10], [0, 0, 0, 1]]) { + cube(size = [5, 6, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + cube(size = [1, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 5 +0 +0) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 20], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 0 +6 +0) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 30], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 0 +0 +7) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 40], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 5 +6 +0) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 60], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 0 +6 +7) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 50], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 5 +0 +7) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 70], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 8 +9 +0) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 80], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 9 +0 +0) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 90], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = 5 +6 +7) { + cube(size = [1, 1, 1], center = false); + } + } + color([0, 0, 1, 1]) { + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 10], [0, 0, 0, 1]]) { + cube(size = [1, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 10.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 5 +0 +0) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 23], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 0 +6 +0) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 30.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 0 +0 +7) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 43], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 5 +6 +0) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 63], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 0 +6 +7) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 50.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 5 +0 +7) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 4], [0, 1, 0, 74.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 8 +9 +0) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 4.5], [0, 1, 0, 80.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 9 +0 +0) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 93], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = 5 +6 +7) { + sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + } + } + } + diff --git a/tests/regression/opencsgtest/resize-tests-expected.png b/tests/regression/opencsgtest/resize-tests-expected.png new file mode 100644 index 0000000..c8b1356 Binary files /dev/null and b/tests/regression/opencsgtest/resize-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-tests-expected.png b/tests/regression/throwntogethertest/resize-tests-expected.png new file mode 100644 index 0000000..3895f88 Binary files /dev/null and b/tests/regression/throwntogethertest/resize-tests-expected.png differ -- cgit v0.10.1 From 5559ae9a6af459021c5b7ab4a823f491dce822a0 Mon Sep 17 00:00:00 2001 From: don bright Date: Sun, 10 Mar 2013 21:35:30 -0500 Subject: move transform from CGALEvaluator to Nef_polyhedron - reuse in resize(). also move ZRemover code to cgalutils, also cleanup SVG code 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 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 { diff --git a/src/CGAL_Nef_polyhedron.h b/src/CGAL_Nef_polyhedron.h index 03eaaa6..cfab993 100644 --- a/src/CGAL_Nef_polyhedron.h +++ b/src/CGAL_Nef_polyhedron.h @@ -4,6 +4,7 @@ #include "cgalfwd.h" #include "memory.h" #include +#include "linalg.h" class CGAL_Nef_polyhedron { @@ -27,9 +28,7 @@ public: int weight() const; class PolySet *convertToPolyset(); class DxfData *convertToDxfData() const; - void convertTo2d(); - void convertTo3d(); - + void transform( const Transform3d &matrix ); int dim; shared_ptr p2; shared_ptr p3; diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index e642612..50a9952 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -29,6 +29,11 @@ #include "CGAL_Nef_polyhedron.h" #include "cgal.h" #include "cgalutils.h" +#include +#include "polyset.h" +#include "dxftess.h" +#include "CGALEvaluator.h" +#include "Tree.h" #ifdef ENABLE_CGAL @@ -88,85 +93,60 @@ std::string CGAL_Nef_polyhedron::dump() const return std::string("Nef Polyhedron with dimension != 2 or 3"); } -// use a try/catch block around any calls to this -void CGAL_Nef_polyhedron::convertTo2d() -{ - logstream log(5); - if (dim!=3) return; - assert(this->p3); - ZRemover zremover; - CGAL_Nef_polyhedron3::Volume_const_iterator i; - CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; - CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; - for ( i = this->p3->volumes_begin(); i != this->p3->volumes_end(); ++i ) { - log << "\n"; - for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { - log << "\n"; - sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); - this->p3->visit_shell_objects( sface_handle , zremover ); - log << "\n"; - } - log << "\n"; - } - this->p3.reset(); - this->p2 = zremover.output_nefpoly2d; - this->dim = 2; -} - -std::vector face2to3( - CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1, - CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2, - CGAL_Nef_polyhedron2::Explorer explorer ) +void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) { - std::vector result; - CGAL_For_all(c1, c2) { - if ( explorer.is_standard( explorer.target(c1) ) ) { - //CGAL_Point_2e source = explorer.point( explorer.source( c1 ) ); - CGAL_Point_2e target = explorer.point( explorer.target( c1 ) ); - if (c1->mark()) { - CGAL_Point_3 tmp( target.x(), target.y(), 0 ); - result.push_back( tmp ); + if (!this->isNull()) { + if (this->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 << matrix(0,0), matrix(0,1), matrix(1,0), matrix(1,1); + if (testmat.determinant() == 0) { + PRINT("Warning: Scaling a 2D object with 0 - removing object"); + this->reset(); } - } - } - return result; -} - - -// use a try/catch block around any calls to this -void CGAL_Nef_polyhedron::convertTo3d() -{ - if (dim!=2) return; - assert(this->p2); - CGAL_Nef_polyhedron2::Explorer explorer = this->p2->explorer(); - CGAL_Nef_polyhedron2::Explorer::Face_const_iterator i; - - this->p3.reset( new CGAL_Nef_polyhedron3() ); - - for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) { + else { + CGAL_Aff_transformation2 t( + matrix(0,0), matrix(0,1), matrix(0,3), + matrix(1,0), matrix(1,1), matrix(1,3), matrix(3,3)); + + DxfData *dd = this->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()); + } - CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1 - = explorer.face_cycle( i ), c2 ( c1 ); - std::vector body_pts = face2to3( c1, c2, explorer ); - CGAL_Nef_polyhedron3 body( body_pts.begin(), body_pts.end() ); + PolySet ps; + ps.is2d = true; + dxf_tesselate(&ps, *dd, 0, true, false, 0); - CGAL_Nef_polyhedron3 holes; - CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j; - for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) { - CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 ); - std::vector hole_pts = face2to3( c3, c4, explorer ); - CGAL_Nef_polyhedron3 hole( hole_pts.begin(), hole_pts.end() ); - holes = holes.join( hole ); + Tree nulltree; + CGALEvaluator tmpeval(nulltree); + CGAL_Nef_polyhedron N = tmpeval.evaluateCGALMesh(ps); + this->p2.reset(); + *(this->p2) = *(N.p2); + delete dd; + } } - - body = body.difference( holes ); - *(this->p3) = this->p3->join( body ); - } - - this->p2.reset(); - this->dim = 3; + else if (this->dim == 3) { + if (matrix.matrix().determinant() == 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); + } + } + } } - #endif // ENABLE_CGAL diff --git a/src/PolySetCGALEvaluator.cc b/src/PolySetCGALEvaluator.cc index 0aa9e9e..5976daf 100644 --- a/src/PolySetCGALEvaluator.cc +++ b/src/PolySetCGALEvaluator.cc @@ -90,8 +90,21 @@ PolySet *PolySetCGALEvaluator::evaluatePolySet(const ProjectionNode &node) log << OpenSCAD::svg_header( 480, 100000 ) << "\n"; try { - sum.convertTo2d(); - nef_poly.p2 = sum.p2; + ZRemover zremover; + CGAL_Nef_polyhedron3::Volume_const_iterator i; + CGAL_Nef_polyhedron3::Shell_entry_const_iterator j; + CGAL_Nef_polyhedron3::SFace_const_handle sface_handle; + for ( i = sum.p3->volumes_begin(); i != sum.p3->volumes_end(); ++i ) { + log << "\n"; + for ( j = i->shells_begin(); j != i->shells_end(); ++j ) { + log << "\n"; + sface_handle = CGAL_Nef_polyhedron3::SFace_const_handle( j ); + sum.p3->visit_shell_objects( sface_handle , zremover ); + log << "\n"; + } + log << "\n"; + } + nef_poly.p2 = zremover.output_nefpoly2d; } catch (const CGAL::Failure_exception &e) { PRINTB("CGAL error in projection node while flattening: %s", e.what()); } diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 073a908..276b59c 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -59,7 +59,7 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat argnames += "type", "level", "convexity"; if (type == RESIZE) - argnames += "newsize"; + argnames += "newsize", "auto"; Context c(ctx); c.args(argnames, argexpr, inst->argnames, inst->argvalues); @@ -90,6 +90,8 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat if ( v.size() >= 2 ) node->newsize[1] = v[1].toDouble(); if ( v.size() >= 3 ) node->newsize[2] = v[2].toDouble(); } + Value autosize = c.lookup_variable("auto"); + node->autosize = autosize.toBool(); } node->convexity = (int)convexity.toDouble(); diff --git a/src/cgaladvnode.h b/src/cgaladvnode.h index 097d2b4..22285da 100644 --- a/src/cgaladvnode.h +++ b/src/cgaladvnode.h @@ -32,6 +32,7 @@ public: std::string subdiv_type; int convexity, level; Vector3d newsize; + bool autosize; cgaladv_type_e type; }; diff --git a/src/cgalutils.cc b/src/cgalutils.cc index 66d4b18..8b4c476 100644 --- a/src/cgalutils.cc +++ b/src/cgalutils.cc @@ -173,5 +173,56 @@ CGAL_Iso_rectangle_2e bounding_box( const CGAL_Nef_polyhedron2 &N ) return result; } +void ZRemover::visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) +{ + log << " \n"; + if ( hfacet->plane().orthogonal_direction() != this->up ) { + log << " \n"; + log << " \n"; + return; + } + + // possible optimization - throw out facets that are vertically oriented + + CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator fci; + int contour_counter = 0; + CGAL_forall_facet_cycles_of( fci, hfacet ) { + if ( fci.is_shalfedge() ) { + log << " \n"; + CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(fci), cend(c1); + std::vector contour; + CGAL_For_all( c1, cend ) { + CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->target()->point(); + CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); + contour.push_back( point2d ); + } + if (contour.size()==0) continue; + + log << " \n"; + + tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); + + if ( contour_counter == 0 ) { + log << " \n" ; + *(output_nefpoly2d) += *(tmpnef2d); + } else { + log << " \n"; + *(output_nefpoly2d) *= *(tmpnef2d); + } + + /*log << "\n\n" + << OpenSCAD::dump_svg( *tmpnef2d ) << "\n" + << "\n\n" + << OpenSCAD::dump_svg( *output_nefpoly2d ) << "\n";*/ + + contour_counter++; + } else { + log << " \n"; + } + log << " \n"; + } + log << " \n"; +} + #endif /* ENABLE_CGAL */ diff --git a/src/cgalutils.h b/src/cgalutils.h index 8f10519..6ea7711 100644 --- a/src/cgalutils.h +++ b/src/cgalutils.h @@ -57,55 +57,7 @@ public: void visit( CGAL_Nef_polyhedron3::SHalfedge_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SHalfloop_const_handle ) {} void visit( CGAL_Nef_polyhedron3::SFace_const_handle ) {} - void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { - log << " \n"; - if ( hfacet->plane().orthogonal_direction() != this->up ) { - log << " \n"; - log << " \n"; - return; - } - - // possible optimization - throw out facets that are 'side facets' between - // the top & bottom of the big thin box. (i.e. mixture of z=-eps and z=eps) - - CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator fci; - int contour_counter = 0; - CGAL_forall_facet_cycles_of( fci, hfacet ) { - if ( fci.is_shalfedge() ) { - CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(fci), cend(c1); - std::vector contour; - CGAL_For_all( c1, cend ) { - CGAL_Nef_polyhedron3::Point_3 point3d = c1->source()->target()->point(); - CGAL_Nef_polyhedron2::Explorer::Point point2d( point3d.x(), point3d.y() ); - contour.push_back( point2d ); - } - - if (contour.size()==0) continue; - - log << " \n"; - - tmpnef2d.reset( new CGAL_Nef_polyhedron2( contour.begin(), contour.end(), boundary ) ); - - if ( contour_counter == 0 ) { - log << " \n" ; - *(output_nefpoly2d) += *(tmpnef2d); - } else { - log << " \n"; - *(output_nefpoly2d) *= *(tmpnef2d); - } - - log << "\n\n" - << OpenSCAD::dump_svg( *tmpnef2d ) << "\n" - << "\n\n" - << OpenSCAD::dump_svg( *output_nefpoly2d ) << "\n"; - - contour_counter++; - } else { - log << " \n"; - } - } // next facet cycle (i.e. next contour) - log << " \n"; - } // visit() + void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ); }; diff --git a/src/svg.cc b/src/svg.cc index 66e5797..c1231a5 100644 --- a/src/svg.cc +++ b/src/svg.cc @@ -2,13 +2,13 @@ #include "cgalutils.h" #include "svg.h" #include +#include #include namespace OpenSCAD { // SVG code // currently for debugging, not necessarily pretty or useful for users. (yet) -int svg_cursor_py = 0; int svg_px_width = SVG_PXW; int svg_px_height = SVG_PXH; @@ -27,6 +27,26 @@ std::string svg_label(std::string s) return out.str(); } +std::string svg_styleblock(std::string strokewidth) +{ + std::stringstream out; + // halfedge: f1/f0 = face mark, b1/b0 = body or hole, m1/m0 = halfedge mark + out << "\ + "; + std::string tmp = out.str(); + boost::replace_all( tmp, "__STROKEW__", strokewidth ); + return tmp; +} + std::string svg_border() { std::stringstream out; @@ -93,36 +113,27 @@ std::string dump_cgal_nef_polyhedron2_face_svg( CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1, CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c2, CGAL_Nef_polyhedron2::Explorer explorer, - std::string color, - bool mark, - CGAL_Iso_rectangle_2e bbox ) + bool facemark, bool body ) { + std::stringstream style; + style << "halfedge_f" << facemark << "_b" << body << "_m"; + std::string styleclass = style.str(); + std::stringstream out; CGAL_For_all(c1, c2) { if ( explorer.is_standard( explorer.target(c1) ) ) { CGAL_Point_2e source = explorer.point( explorer.source( c1 ) ); CGAL_Point_2e target = explorer.point( explorer.target( c1 ) ); - CGAL_Point_2e tp1 = project_svg_2to2( source, bbox ); - CGAL_Point_2e tp2 = project_svg_2to2( target, bbox ); - double mod=0; - if (color=="green") mod=10; - out << " \n"; - out << " \n"; - else out << " />\n"; - // crude "arrowhead" to indicate directionality - out << " \n"; + out << " \n"; + std::string he_mark = boost::lexical_cast(c1->mark()); + out << " \n"; } else { - out << " \n"; + out << " \n"; } } return out.str(); @@ -132,27 +143,27 @@ std::string dump_svg( const CGAL_Nef_polyhedron2 &N ) { std::stringstream out; CGAL_Nef_polyhedron2::Explorer explorer = N.explorer(); - CGAL_Iso_rectangle_2e bbox = bounding_box( N ); - CGAL_Nef_polyhedron2::Explorer::Face_const_iterator i; - out << " \n"; - out << svg_border() << "\n" << svg_axes() << "\n"; - svg_cursor_py += svg_px_height; + + std::string linewidth = "0.05"; + + out << "\n"; + out << svg_header() << "\n" << svg_styleblock( linewidth ) << "\n"; for ( i = explorer.faces_begin(); i!= explorer.faces_end(); ++i ) { out << " \n"; + out << " \n"; CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c1 = explorer.face_cycle( i ), c2 ( c1 ); - out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, "red", i->mark(), bbox ); + out << dump_cgal_nef_polyhedron2_face_svg( c1, c2, explorer, i->mark(), true ); + out << " \n"; CGAL_Nef_polyhedron2::Explorer::Hole_const_iterator j; for ( j = explorer.holes_begin( i ); j!= explorer.holes_end( i ); ++j ) { out << " \n"; CGAL_Nef_polyhedron2::Explorer::Halfedge_around_face_const_circulator c3( j ), c4 ( c3 ); - out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", j->mark(), bbox ); + out << dump_cgal_nef_polyhedron2_face_svg( c3, c4, explorer, "green", j->mark() ); out << " \n"; } out << " \n"; @@ -182,13 +193,13 @@ public: void visit( CGAL_Nef_polyhedron3::Halffacet_const_handle hfacet ) { int contour_count = 0; - out << " \n"; + out << " \n"; std::string color = "gold"; if (!(*hfacet).mark()) color = "green"; CGAL_Nef_polyhedron3::Halffacet_cycle_const_iterator i; CGAL_forall_facet_cycles_of( i, hfacet ) { CGAL_Nef_polyhedron3::SHalfloop_const_handle shl_handle; - out << " \n"; + out << " \n"; if ( contour_count == 0 ) { out << " \n"; } else { @@ -196,13 +207,15 @@ public: } CGAL_Nef_polyhedron3::SHalfedge_around_facet_const_circulator c1(i), c2(c1); CGAL_For_all( c1, c2 ) { - out << " source(), except thats what CGAL does internally CGAL_Point_3 source = c1->source()->source()->point(); CGAL_Point_3 target = c1->source()->target()->point(); CGAL_Point_2e tp1 = project_svg_3to2 ( source, bbox ); CGAL_Point_2e tp2 = project_svg_3to2 ( target, bbox ); - out << " " + out << " \n"; + out << " \n"; } contour_count++; - } // next facet cycle (i.e. next contour) - } // visit() - + out << " \n"; + } + out << " \n"; + } }; std::string dump_svg( const CGAL_Nef_polyhedron3 &N ) { std::stringstream out; - out << svg_header() << "\n" << svg_border() << "\n" << svg_axes() << "\n"; + std::string linewidth = "0.05"; out << "\n"; + out << svg_header() << "\n" << svg_border() << "\n"; + out << svg_styleblock( linewidth ) << "\n" << svg_axes() << "\n"; CGAL_Nef_polyhedron3::Volume_const_iterator c; CGAL_forall_volumes(c,N) { - out << " \n"; + out << " \n"; out << " \n"; CGAL_Nef_polyhedron3::Shell_entry_const_iterator it; CGAL_forall_shells_of(it,c) { - out << " \n"; + out << " \n"; NefPoly3_dumper_svg dumper_svg(N); N.visit_shell_objects(CGAL_Nef_polyhedron3::SFace_const_handle(it), dumper_svg ); out << dumper_svg.out.str(); - out << " \n"; + out << " \n"; } - out << " \n"; + out << " \n"; } out << "\n"; out << ""; -- cgit v0.10.1 From 4e2965ac17e4e8c64df327b3988bb0a4006f4357 Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 10:59:52 -0500 Subject: fix crashbug 2d resize. add 2d tests. print offscreen warning better. diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index a5a9d65..34f5bb6 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -185,8 +185,18 @@ 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); + CGAL_Iso_cuboid_3 bb; + + if ( N.dim == 2 ) { + CGAL_Iso_rectangle_2e bbox = bounding_box( *N.p2 ); + CGAL_Point_2e min2(bbox.min()), max2(bbox.max()); + CGAL_Point_3 min3(min2.x(),min2.y(),0), max3(max2.x(),max2.y(),0); + bb = CGAL_Iso_cuboid_3( min3, max3 ); + } + else { + bb = bounding_box( *N.p3 ); + } - CGAL_Iso_cuboid_3 bb = bounding_box( *N.p3 ); Eigen::Matrix scale, bbox_size; scale << 1,1,1; bbox_size << bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin(), bb.zmax()-bb.zmin(); @@ -197,7 +207,10 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) if (node.autosize) for (int i=0;i<3;i++) scale[i] = autoscale; - + std::cout << autoscale << " ascale \n"; + std::cout << scale[0] << ","; + std::cout << scale[1] << ","; + std::cout << scale[2] << " scalev \n"; Eigen::Matrix4d t; t << CGAL::to_double(scale[0]), 0, 0, 0, 0, CGAL::to_double(scale[1]), 0, 0, diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index 50a9952..8539e0e 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -96,17 +96,21 @@ std::string CGAL_Nef_polyhedron::dump() const void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) { + std::cout << matrix(0,0) << "," << matrix(1,0) << "," << matrix(2,0) << "," << matrix(3,0) << "\n"; + std::cout << matrix(0,1) << "," << matrix(1,1) << "," << matrix(2,1) << "," << matrix(3,1) << "\n"; + std::cout << matrix(0,2) << "," << matrix(1,2) << "," << matrix(2,2) << "," << matrix(3,2) << "\n"; + std::cout << matrix(0,3) << "," << matrix(1,3) << "," << matrix(2,3) << "," << matrix(3,3) << "\n"; if (!this->isNull()) { if (this->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 << matrix(0,0), matrix(0,1), matrix(1,0), matrix(1,1); if (testmat.determinant() == 0) { PRINT("Warning: Scaling a 2D object with 0 - removing object"); this->reset(); + return; } else { CGAL_Aff_transformation2 t( @@ -128,8 +132,7 @@ void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) Tree nulltree; CGALEvaluator tmpeval(nulltree); CGAL_Nef_polyhedron N = tmpeval.evaluateCGALMesh(ps); - this->p2.reset(); - *(this->p2) = *(N.p2); + this->p2.reset( new CGAL_Nef_polyhedron2( *N.p2 ) ); delete dd; } } diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc index 430d4ea..1e91f3d 100644 --- a/src/OffscreenView.cc +++ b/src/OffscreenView.cc @@ -23,7 +23,7 @@ OffscreenView::~OffscreenView() #ifdef ENABLE_OPENCSG void OffscreenView::display_opencsg_warning() { - fprintf(stderr, "OpenSCAD recommended OpenGL version is 2.0. \n"); + PRINT("OpenSCAD recommended OpenGL version is 2.0."); } #endif diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 276b59c..199ace2 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -155,7 +155,11 @@ std::string CgaladvNode::toString() const stream << "()"; break; case RESIZE: - stream << "(newsize = " << this->newsize << ")"; + stream << "(newsize = [" + << this->newsize[0] << "," + << this->newsize[1] << "," + << this->newsize[2] << "]" + << ", auto = " << this->autosize << ")"; break; default: assert(false); diff --git a/testdata/scad/features/resize-2d-tests.scad b/testdata/scad/features/resize-2d-tests.scad new file mode 100644 index 0000000..76da09e --- /dev/null +++ b/testdata/scad/features/resize-2d-tests.scad @@ -0,0 +1,45 @@ +// red = reference + +$fn=10; + +// two simple holes +module shape(){ + difference() { + square([5,5]); + translate([1,1]) square(); + translate([3,3]) circle(); + } +} + +// holes that have problems (duplicate vertex) +module shape2(){ + difference() { + square([5,5]); + translate([1,1]) square(); + translate([2,2]) square(); + } +} + +// one square split into two by another +module shape3(){ + difference() { + square([5,5]); + translate([0,2.5]) square([5,1]); + } +} + +translate([0,0]) resize([15,15]) shape(); +translate([0,16]) resize([15,15,0]) shape2(); +translate([0,32]) resize([15,15]) shape3(); + +color("red") { +translate([-16,0]) scale([3,3]) shape(); +translate([-16,16]) scale([3,3]) shape2(); +translate([-16,32]) scale([3,3]) shape3(); +} + +color("green"){ +translate([16,0]) resize([15,0],auto=true) shape(); +translate([16,16]) resize([0,15],auto=true) shape2(); +translate([16,32]) resize([0,0,15],auto=true) shape3(); +} diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad index f2e9148..76f49ee 100644 --- a/testdata/scad/features/resize-tests.scad +++ b/testdata/scad/features/resize-tests.scad @@ -1,6 +1,7 @@ // bottom row = reference // middle row = should match reference // top row = should be inscribed in middle row in 'top' view +// back row = should be all cubes auto-scaled up $fn=10; @@ -39,4 +40,17 @@ translate([2.5,50.5,10]) resize([5,0,7]) sphere(0.5); translate([4,74.5,10]) resize([8,9]) sphere(0.5); translate([4.5,80.5,10]) resize([9]) sphere(0.5); translate([2.5,93,10]) resize([5,6,7]) sphere(0.5); +} + +color("green"){ +translate([10, 0, 0]) cube(); +translate([10,10,0]) resize([5,0,0],auto=true) cube(); +translate([10,20,0]) resize([0,6,0],auto=true) cube(); +translate([10,30,0]) resize([0,0,7],auto=true) cube(); +translate([10,40,0]) resize([5,6,0],true) cube(); +translate([10,60,0]) resize([0,6,7],auto=true) cube(); +translate([10,50,0]) resize([5,0,7],true) cube(); +translate([10,70,0]) resize([8,9],auto=true) cube(); +translate([10,80,0]) resize([9],true) cube(); +translate([10,90,0]) resize([5,6,7],auto=true) cube(); } \ No newline at end of file -- cgit v0.10.1 From 8bf53bc0199e7f6a24c9d88ad3eb0bf98d759d9c Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 11:02:01 -0500 Subject: replace fprintf with PRINT diff --git a/src/CsgInfo.h b/src/CsgInfo.h index 37fe0d0..fe953b5 100644 --- a/src/CsgInfo.h +++ b/src/CsgInfo.h @@ -57,7 +57,7 @@ public: if (this->root_norm_term) { this->root_chain = new CSGChain(); this->root_chain->import(this->root_norm_term); - fprintf(stderr, "Normalized CSG tree has %d elements", int(this->root_chain->polysets.size())); + PRINTB("Normalized CSG tree has %d elements", int(this->root_chain->polysets.size())); } else { this->root_chain = NULL; diff --git a/src/OffscreenView.cc b/src/OffscreenView.cc index 1e91f3d..2186eb1 100644 --- a/src/OffscreenView.cc +++ b/src/OffscreenView.cc @@ -6,6 +6,7 @@ #include #include #include +#include "printutils.h" OffscreenView::OffscreenView(size_t width, size_t height) { -- cgit v0.10.1 From 6d3089032ce12b09c2987d7f39b031cbe1a5db2b Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 12:00:15 -0500 Subject: allow resize's autosize to apply to individual dimensions diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 34f5bb6..b8ed0fc 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -179,10 +179,21 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) return N; } - +/* resize([x,y,z],auto=[x,y,z]|bool) + This will resize the child object to x,y,z. + If any of x,y,z is 0, then that dimension is left as-is in the child node. + If any of x,y,z is 0 and their corresponding 'auto' is true, then + they are auto-scaled up to match the ratio of the other dimensions (the max) + + Example - + resize([0,2]) cube() will make a cube([1,2,1]) + resize([0,2],auto=[true,false,false]) cube() will make a cube([2,2,1]) + resize([0,2],auto=true) cube() will make a cube([2,2,2]) + resize([0,0,3]) cube() will make a cube([1,1,3]) +*/ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) { - // Based on resize() in Giles Bathgate's RapCAD + // Based on resize() in Giles Bathgate's RapCAD (but not exactly) CGAL_Nef_polyhedron N; N = applyToChildren(node, CGE_UNION); CGAL_Iso_cuboid_3 bb; @@ -200,13 +211,19 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) Eigen::Matrix scale, bbox_size; scale << 1,1,1; bbox_size << bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin(), bb.zmax()-bb.zmin(); - 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]); + for (int i=0;i<3;i++) { + if (bbox_size[i]==NT(0)) bbox_size[i]=NT(1); + if (node.newsize[i]) scale[i] = NT(node.newsize[i]) / bbox_size[i]; + } NT autoscale = scale.maxCoeff(); - if (node.autosize) - for (int i=0;i<3;i++) + for (int i=0;i<3;i++) + if (node.autosize[i]) scale[i] = autoscale; + for (int i=0;i<3;i++) + if (scale[i]= 3 ) node->newsize[2] = v[2].toDouble(); } Value autosize = c.lookup_variable("auto"); - node->autosize = autosize.toBool(); + node->autosize << false, false, false; + if ( autosize.type() == Value::VECTOR ) { + Value::VectorType v = ns.toVector(); + if ( v.size() >= 1 ) node->autosize[0] = v[0].toBool(); + if ( v.size() >= 2 ) node->autosize[1] = v[1].toBool(); + if ( v.size() >= 3 ) node->autosize[2] = v[2].toBool(); + } + else if ( autosize.type() == Value::BOOL ) { + node->autosize << true, true, true; + } } node->convexity = (int)convexity.toDouble(); diff --git a/src/cgaladvnode.h b/src/cgaladvnode.h index 22285da..d3aa525 100644 --- a/src/cgaladvnode.h +++ b/src/cgaladvnode.h @@ -32,7 +32,7 @@ public: std::string subdiv_type; int convexity, level; Vector3d newsize; - bool autosize; + Eigen::Matrix autosize; cgaladv_type_e type; }; -- cgit v0.10.1 From 1726c26518cdc03cc1aff0438ccf4cdc93806eca Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 13:30:40 -0500 Subject: fix bug diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index b8ed0fc..8e72fff 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -224,7 +224,10 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) PRINT("WARNING: Cannot resize to a new size less than 0."); return N; } - std::cout << autoscale << " ascale \n"; + std::cout << autoscale << " autoscale\n"; + std::cout << node.autosize[0] << ","; + std::cout << node.autosize[1] << ","; + std::cout << node.autosize[2] << " node autosize \n"; std::cout << scale[0] << ","; std::cout << scale[1] << ","; std::cout << scale[2] << " scalev \n"; diff --git a/src/cgaladv.cc b/src/cgaladv.cc index 94f84fd..fb0bfaf 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -85,18 +85,20 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat Value ns = c.lookup_variable("newsize"); node->newsize << 0,0,0; if ( ns.type() == Value::VECTOR ) { - Value::VectorType v = ns.toVector(); - if ( v.size() >= 1 ) node->newsize[0] = v[0].toDouble(); - if ( v.size() >= 2 ) node->newsize[1] = v[1].toDouble(); - if ( v.size() >= 3 ) node->newsize[2] = v[2].toDouble(); + Value::VectorType vs = ns.toVector(); + if ( vs.size() >= 1 ) node->newsize[0] = vs[0].toDouble(); + if ( vs.size() >= 2 ) node->newsize[1] = vs[1].toDouble(); + if ( vs.size() >= 3 ) node->newsize[2] = vs[2].toDouble(); } Value autosize = c.lookup_variable("auto"); node->autosize << false, false, false; if ( autosize.type() == Value::VECTOR ) { - Value::VectorType v = ns.toVector(); - if ( v.size() >= 1 ) node->autosize[0] = v[0].toBool(); - if ( v.size() >= 2 ) node->autosize[1] = v[1].toBool(); - if ( v.size() >= 3 ) node->autosize[2] = v[2].toBool(); + Value::VectorType va = autosize.toVector(); + if ( va.size() >= 1 ) node->autosize[0] = va[0].toBool(); + if ( va.size() >= 2 ) node->autosize[1] = va[1].toBool(); + if ( va.size() >= 3 ) node->autosize[2] = va[2].toBool(); + std::cout << "adv.cc: " << va << "\n"; + std::cout << "adv.cc as: " << node->autosize << "\n"; } else if ( autosize.type() == Value::BOOL ) { node->autosize << true, true, true; -- cgit v0.10.1 From fc257c93835470181f73d27e1867057d24a43c1e Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 17:23:53 -0500 Subject: make resize of flat objects fail in the direction normal to the flat. also fail on resize to negative size. update tests diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 8e72fff..406614f 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -179,23 +179,19 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) return N; } -/* resize([x,y,z],auto=[x,y,z]|bool) - This will resize the child object to x,y,z. - If any of x,y,z is 0, then that dimension is left as-is in the child node. - If any of x,y,z is 0 and their corresponding 'auto' is true, then - they are auto-scaled up to match the ratio of the other dimensions (the max) - - Example - - resize([0,2]) cube() will make a cube([1,2,1]) - resize([0,2],auto=[true,false,false]) cube() will make a cube([2,2,1]) - resize([0,2],auto=true) cube() will make a cube([2,2,2]) - resize([0,0,3]) cube() will make a cube([1,1,3]) -*/ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) { - // Based on resize() in Giles Bathgate's RapCAD (but not exactly) + // Based on resize() in Giles Bathgate's RapCAD (but not exactly) CGAL_Nef_polyhedron N; N = applyToChildren(node, CGE_UNION); + + for (int i=0;i<3;i++) { + if (node.newsize[i]<0) { + PRINT("WARNING: Cannot resize to sizes less than 0."); + return N; + } + } + CGAL_Iso_cuboid_3 bb; if ( N.dim == 2 ) { @@ -212,25 +208,21 @@ CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) scale << 1,1,1; bbox_size << bb.xmax()-bb.xmin(), bb.ymax()-bb.ymin(), bb.zmax()-bb.zmin(); for (int i=0;i<3;i++) { - if (bbox_size[i]==NT(0)) bbox_size[i]=NT(1); - if (node.newsize[i]) scale[i] = NT(node.newsize[i]) / bbox_size[i]; + if (node.newsize[i]) { + if (bbox_size[i]==NT(0)) { + PRINT("WARNING: Cannot resize in direction normal to flat object"); + return N; + } + else { + scale[i] = NT(node.newsize[i]) / bbox_size[i]; + } + } } NT autoscale = scale.maxCoeff(); - for (int i=0;i<3;i++) - if (node.autosize[i]) - scale[i] = autoscale; - for (int i=0;i<3;i++) - if (scale[i]isNull()) { if (this->dim == 2) { // Unfortunately CGAL provides no transform method for CGAL_Nef_polyhedron2 diff --git a/src/cgaladv.cc b/src/cgaladv.cc index fb0bfaf..a4cb5ec 100644 --- a/src/cgaladv.cc +++ b/src/cgaladv.cc @@ -97,8 +97,6 @@ AbstractNode *CgaladvModule::evaluate(const Context *ctx, const ModuleInstantiat if ( va.size() >= 1 ) node->autosize[0] = va[0].toBool(); if ( va.size() >= 2 ) node->autosize[1] = va[1].toBool(); if ( va.size() >= 3 ) node->autosize[2] = va[2].toBool(); - std::cout << "adv.cc: " << va << "\n"; - std::cout << "adv.cc as: " << node->autosize << "\n"; } else if ( autosize.type() == Value::BOOL ) { node->autosize << true, true, true; @@ -167,10 +165,10 @@ std::string CgaladvNode::toString() const break; case RESIZE: stream << "(newsize = [" - << this->newsize[0] << "," - << this->newsize[1] << "," - << this->newsize[2] << "]" - << ", auto = " << this->autosize << ")"; + << this->newsize[0] << "," << this->newsize[1] << "," << this->newsize[2] << "]" + << ", auto = [" + << this->autosize[0] << "," << this->autosize[1] << "," << this->autosize[2] << "]" + << ")"; break; default: assert(false); diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad index 76f49ee..5853980 100644 --- a/testdata/scad/features/resize-tests.scad +++ b/testdata/scad/features/resize-tests.scad @@ -1,9 +1,11 @@ -// bottom row = reference -// middle row = should match reference -// top row = should be inscribed in middle row in 'top' view -// back row = should be all cubes auto-scaled up +// bottom row (red) = reference +// middle row (gold) = should match reference +// top row (blue) = should be inscribed in middle row in 'top' view +// back row (green) = should be all cubes auto-scaled up +// back top (purple) = uses 'auto' feature +// pink = recursive resize -$fn=10; +$fn=8; color("red") { translate([0, 0,-10]) cube(); @@ -35,8 +37,8 @@ translate([2.5,10.5,10]) resize([5,0,0]) sphere(0.5); translate([0.5,23,10]) resize([0,6,0]) sphere(0.5); translate([0.5,30.5,10]) resize([0,0,7]) sphere(0.5); translate([2.5,43,10]) resize([5,6,0]) sphere(0.5); -translate([0.5,63,10]) resize([0,6,7]) sphere(0.5); translate([2.5,50.5,10]) resize([5,0,7]) sphere(0.5); +translate([0.5,63,10]) resize([0,6,7]) sphere(0.5); translate([4,74.5,10]) resize([8,9]) sphere(0.5); translate([4.5,80.5,10]) resize([9]) sphere(0.5); translate([2.5,93,10]) resize([5,6,7]) sphere(0.5); @@ -48,9 +50,25 @@ translate([10,10,0]) resize([5,0,0],auto=true) cube(); translate([10,20,0]) resize([0,6,0],auto=true) cube(); translate([10,30,0]) resize([0,0,7],auto=true) cube(); translate([10,40,0]) resize([5,6,0],true) cube(); -translate([10,60,0]) resize([0,6,7],auto=true) cube(); translate([10,50,0]) resize([5,0,7],true) cube(); +translate([10,60,0]) resize([0,6,7],auto=true) cube(); translate([10,70,0]) resize([8,9],auto=true) cube(); translate([10,80,0]) resize([9],true) cube(); translate([10,90,0]) resize([5,6,7],auto=true) cube(); +} + +color("purple"){ +translate([10, 0, 10]) cube(); +translate([10,10,10]) resize([5,0,0],auto=[true,true,false]) cube(); +translate([10,20,10]) resize([6,0,0],auto=[true,true,true]) cube(); +translate([13.5,33.5,10]) resize([7,0,0],auto=[true,false,false]) sphere(); +translate([10,40,10]) resize([6,0,0],auto=[true,false,true]) cube(); +translate([10,50,10]) resize([7,0,7],auto=[false,true,true]) cube(); +translate([13.5,63.5,10]) resize([7,0,0],auto=[false,true,false]) sphere(); translate([10,70,10]) resize([8,0,0],auto=[false,false,false]) cube(); +translate([10,80,10]) resize([9,0,0],auto=[false,false,true]) cube(); +translate([10,90,10]) resize([-5,0,0]) cube(); +} + +color("pink"){ +translate([10,0,-10]) resize([4,4,4]) resize([5000,100,1000]) cube(); } \ No newline at end of file -- cgit v0.10.1 From 79ce1e47d0ff250aed46ddc3058ea4f694900bb0 Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 17:59:02 -0500 Subject: add new test results and updated versions of old ones diff --git a/tests/regression/cgalpngtest/resize-2d-tests-expected.png b/tests/regression/cgalpngtest/resize-2d-tests-expected.png new file mode 100644 index 0000000..1b0cc8a Binary files /dev/null and b/tests/regression/cgalpngtest/resize-2d-tests-expected.png differ diff --git a/tests/regression/cgalpngtest/resize-tests-expected.png b/tests/regression/cgalpngtest/resize-tests-expected.png index b9f7792..0c82744 100644 Binary files a/tests/regression/cgalpngtest/resize-tests-expected.png and b/tests/regression/cgalpngtest/resize-tests-expected.png differ diff --git a/tests/regression/dumptest/resize-2d-tests-expected.txt b/tests/regression/dumptest/resize-2d-tests-expected.txt new file mode 100644 index 0000000..9d5d3ae --- /dev/null +++ b/tests/regression/dumptest/resize-2d-tests-expected.txt @@ -0,0 +1,131 @@ + multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [15,15,0], auto = [0,0,0]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 3], [0, 1, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]]) { + circle($fn = 10, $fa = 12, $fs = 2, r = 1); + } + } + } + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [15,15,0], auto = [0,0,0]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 2], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + } + } + } + } + multmatrix([[1, 0, 0, 0], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [15,15,0], auto = [0,0,0]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [5, 1], center = false); + } + } + } + } + } + color([1, 0, 0, 1]) { + multmatrix([[1, 0, 0, -16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 3], [0, 1, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]]) { + circle($fn = 10, $fa = 12, $fs = 2, r = 1); + } + } + } + } + } + multmatrix([[1, 0, 0, -16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 2], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + } + } + } + } + multmatrix([[1, 0, 0, -16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [5, 1], center = false); + } + } + } + } + } + } + color([0, 0.501961, 0, 1]) { + multmatrix([[1, 0, 0, 16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [15,0,0], auto = [1,1,1]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 3], [0, 1, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]]) { + circle($fn = 10, $fa = 12, $fs = 2, r = 1); + } + } + } + } + } + multmatrix([[1, 0, 0, 16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,15,0], auto = [1,1,1]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 2], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + } + } + } + } + multmatrix([[1, 0, 0, 16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,0,15], auto = [1,1,1]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [5, 1], center = false); + } + } + } + } + } + } + diff --git a/tests/regression/dumptest/resize-tests-expected.txt b/tests/regression/dumptest/resize-tests-expected.txt index 4ba8925..5fbbe4a 100644 --- a/tests/regression/dumptest/resize-tests-expected.txt +++ b/tests/regression/dumptest/resize-tests-expected.txt @@ -34,65 +34,47 @@ cube(size = [1, 1, 1], center = false); } multmatrix([[1, 0, 0, 0], [0, 1, 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 5 -0 -0) { + resize(newsize = [5,0,0], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 20], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 0 -6 -0) { + resize(newsize = [0,6,0], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 30], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 0 -0 -7) { + resize(newsize = [0,0,7], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 40], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 5 -6 -0) { + resize(newsize = [5,6,0], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 60], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 0 -6 -7) { + resize(newsize = [0,6,7], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 50], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 5 -0 -7) { + resize(newsize = [5,0,7], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 70], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 8 -9 -0) { + resize(newsize = [8,9,0], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 80], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 9 -0 -0) { + resize(newsize = [9,0,0], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 90], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = 5 -6 -7) { + resize(newsize = [5,6,7], auto = [0,0,0]) { cube(size = [1, 1, 1], center = false); } } @@ -101,66 +83,157 @@ cube(size = [1, 1, 1], center = false); } multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 10.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 5 -0 -0) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [5,0,0], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 23], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 0 -6 -0) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [0,6,0], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 30.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 0 -0 -7) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [0,0,7], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 43], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 5 -6 -0) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [5,6,0], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } - multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 63], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 0 -6 -7) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 50.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [5,0,7], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } - multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 50.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 5 -0 -7) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + multmatrix([[1, 0, 0, 0.5], [0, 1, 0, 63], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [0,6,7], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 4], [0, 1, 0, 74.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 8 -9 -0) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [8,9,0], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 4.5], [0, 1, 0, 80.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 9 -0 -0) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [9,0,0], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); } } multmatrix([[1, 0, 0, 2.5], [0, 1, 0, 93], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = 5 -6 -7) { - sphere($fn = 10, $fa = 12, $fs = 2, r = 0.5); + resize(newsize = [5,6,7], auto = [0,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 0.5); + } + } + } + color([0, 0.501961, 0, 1]) { + multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + cube(size = [1, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 10], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [5,0,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 20], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,6,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 30], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,0,7], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 40], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [5,6,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 50], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [5,0,7], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 60], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,6,7], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 70], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [8,9,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 80], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [9,0,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 90], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [5,6,7], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + } + color([0.501961, 0, 0.501961, 1]) { + multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, 10], [0, 0, 0, 1]]) { + cube(size = [1, 1, 1], center = false); + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 10], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [5,0,0], auto = [1,1,0]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 20], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [6,0,0], auto = [1,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 13.5], [0, 1, 0, 33.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [7,0,0], auto = [1,0,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 1); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 40], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [6,0,0], auto = [1,0,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 50], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [7,0,7], auto = [0,1,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 13.5], [0, 1, 0, 63.5], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [7,0,0], auto = [0,1,0]) { + sphere($fn = 8, $fa = 12, $fs = 2, r = 1); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 70], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [8,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 80], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [9,0,0], auto = [0,0,1]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 90], [0, 0, 1, 10], [0, 0, 0, 1]]) { + resize(newsize = [-5,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } + } + color([1, 0.752941, 0.796078, 1]) { + multmatrix([[1, 0, 0, 10], [0, 1, 0, 0], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [4,4,4], auto = [0,0,0]) { + resize(newsize = [5000,100,1000], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } } } } diff --git a/tests/regression/opencsgtest/resize-2d-tests-expected.png b/tests/regression/opencsgtest/resize-2d-tests-expected.png new file mode 100644 index 0000000..937de11 Binary files /dev/null and b/tests/regression/opencsgtest/resize-2d-tests-expected.png differ diff --git a/tests/regression/opencsgtest/resize-tests-expected.png b/tests/regression/opencsgtest/resize-tests-expected.png index c8b1356..fbe3e08 100644 Binary files a/tests/regression/opencsgtest/resize-tests-expected.png and b/tests/regression/opencsgtest/resize-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-2d-tests-expected.png b/tests/regression/throwntogethertest/resize-2d-tests-expected.png new file mode 100644 index 0000000..d896d8e Binary files /dev/null and b/tests/regression/throwntogethertest/resize-2d-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-tests-expected.png b/tests/regression/throwntogethertest/resize-tests-expected.png index 3895f88..7c6804c 100644 Binary files a/tests/regression/throwntogethertest/resize-tests-expected.png and b/tests/regression/throwntogethertest/resize-tests-expected.png differ -- cgit v0.10.1 From 4fa2338b267bdf6e08385ae103b5bafe7b4ee6e4 Mon Sep 17 00:00:00 2001 From: don bright Date: Mon, 11 Mar 2013 17:40:02 -0700 Subject: fix bug showed during circle test diff --git a/src/CGALEvaluator.cc b/src/CGALEvaluator.cc index 406614f..7c483cb 100644 --- a/src/CGALEvaluator.cc +++ b/src/CGALEvaluator.cc @@ -181,9 +181,11 @@ CGAL_Nef_polyhedron CGALEvaluator::applyHull(const CgaladvNode &node) CGAL_Nef_polyhedron CGALEvaluator::applyResize(const CgaladvNode &node) { - // Based on resize() in Giles Bathgate's RapCAD (but not exactly) + // Based on resize() in Giles Bathgate's RapCAD (but not exactly) CGAL_Nef_polyhedron N; - N = applyToChildren(node, CGE_UNION); + N = applyToChildren(node, CGE_UNION); + + if ( N.isNull() || N.isEmpty() ) return N; for (int i=0;i<3;i++) { if (node.newsize[i]<0) { @@ -309,9 +311,7 @@ Response CGALEvaluator::visit(State &state, const TransformNode &node) PRINT("Warning: Transformation matrix contains Not-a-Number and/or Infinity - removing object."); N.reset(); } - else { - N.transform( node.matrix ); - } + N.transform( node.matrix ); } else { N = CGALCache::instance()->get(this->tree.getIdString(node)); diff --git a/src/CGAL_Nef_polyhedron_DxfData.cc b/src/CGAL_Nef_polyhedron_DxfData.cc index f7ff7f3..0388fe5 100644 --- a/src/CGAL_Nef_polyhedron_DxfData.cc +++ b/src/CGAL_Nef_polyhedron_DxfData.cc @@ -128,7 +128,7 @@ void CGAL_Nef_polyhedron::transform( const Transform3d &matrix ) Tree nulltree; CGALEvaluator tmpeval(nulltree); CGAL_Nef_polyhedron N = tmpeval.evaluateCGALMesh(ps); - this->p2.reset( new CGAL_Nef_polyhedron2( *N.p2 ) ); + if ( N.p2 ) this->p2.reset( new CGAL_Nef_polyhedron2( *N.p2 ) ); delete dd; } } -- cgit v0.10.1 From eb9139b34ee8e0c5ac9f94f93078165c6e5edd56 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Tue, 12 Mar 2013 01:13:59 -0400 Subject: sync diff --git a/RELEASE_NOTES b/RELEASE_NOTES index 9e2da81..308bbe9 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -20,6 +20,7 @@ o Changed multmatrix floating-point output to improve dumptest portability o Regression test auto-starts & stops Xvfb / Xvnc if on headless unix machine o CGAL triangulation more lenient- enables partial rendering of 'bad' DXF data o Fixes problem where local changes are overwritten on automatic reload when included files has changed. +o Non-ascii filenames are now allowed OpenSCAD 2013.01 ================ -- cgit v0.10.1 From 9891d8c86cbd567308575a0d4ec4b0d2f35776c8 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 16 Mar 2013 13:04:32 -0500 Subject: fix 3d test bug, improve 2d test, update release note diff --git a/RELEASE_NOTES b/RELEASE_NOTES index d1a02ed..7e4288a 100644 --- a/RELEASE_NOTES +++ b/RELEASE_NOTES @@ -7,6 +7,7 @@ o Added basic syntax highlighting in the editor o Mac: Added document icon o Mac: Added auto-update check o Commandline output to PNG, with various camera and rendering settings +o resize() command introduced o Regression test now creates single monolithic .html file for easier uploading Bugfixes: diff --git a/testdata/scad/features/resize-2d-tests.scad b/testdata/scad/features/resize-2d-tests.scad index 76da09e..911a4cd 100644 --- a/testdata/scad/features/resize-2d-tests.scad +++ b/testdata/scad/features/resize-2d-tests.scad @@ -1,4 +1,7 @@ // red = reference +// gold = basic resize +// green = auto resize +// pink = errors, wrong syntax, trying to resize in 3rd dimension, etc $fn=10; @@ -28,18 +31,25 @@ module shape3(){ } } -translate([0,0]) resize([15,15]) shape(); -translate([0,16]) resize([15,15,0]) shape2(); -translate([0,32]) resize([15,15]) shape3(); - color("red") { translate([-16,0]) scale([3,3]) shape(); translate([-16,16]) scale([3,3]) shape2(); translate([-16,32]) scale([3,3]) shape3(); } +translate([0,0]) resize([15,15]) shape(); +translate([0,16]) resize([15,15,0]) shape2(); +translate([0,32]) resize([15,15]) shape3(); + color("green"){ translate([16,0]) resize([15,0],auto=true) shape(); translate([16,16]) resize([0,15],auto=true) shape2(); -translate([16,32]) resize([0,0,15],auto=true) shape3(); +translate([16,32]) resize([0,15],auto=[true,false]) shape3(); } + +color("pink"){ +translate([32,0]) resize([0,0],auto=[false,true]) shape(); +translate([32,16]) resize([0,0,15],auto=true) shape2(); +translate([32,32]) resize([0,0,15]) shape3(); +} + diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad index 5853980..67e2535 100644 --- a/testdata/scad/features/resize-tests.scad +++ b/testdata/scad/features/resize-tests.scad @@ -1,9 +1,10 @@ // bottom row (red) = reference // middle row (gold) = should match reference -// top row (blue) = should be inscribed in middle row in 'top' view +// top row (blue) = should be 'spherical' versions of gold row, +// and should be inscribed in gold row in 'top' view // back row (green) = should be all cubes auto-scaled up // back top (purple) = uses 'auto' feature -// pink = recursive resize +// pink = recursive resize, negative, wrong syntax, etc $fn=8; @@ -17,7 +18,7 @@ translate([0,60,-10]) cube([1,6,7]); translate([0,50,-10]) cube([5,1,7]); translate([0,70,-10]) cube([8,9,1]); translate([0,80,-10]) cube([9,1,1]); -translate([0,90,-10]) cube([5,6,1]); +translate([0,90,-10]) cube([5,6,7]); } translate([0, 0,0]) cube(); @@ -66,9 +67,13 @@ translate([10,40,10]) resize([6,0,0],auto=[true,false,true]) cube(); translate([10,50,10]) resize([7,0,7],auto=[false,true,true]) cube(); translate([13.5,63.5,10]) resize([7,0,0],auto=[false,true,false]) sphere(); translate([10,70,10]) resize([8,0,0],auto=[false,false,false]) cube(); translate([10,80,10]) resize([9,0,0],auto=[false,false,true]) cube(); -translate([10,90,10]) resize([-5,0,0]) cube(); +translate([10,90,10]) resize([0,0,7],auto=[true,true,false]) cube(); } color("pink"){ translate([10,0,-10]) resize([4,4,4]) resize([5000,100,1000]) cube(); +translate([10,10,-10]) resize([-5,0,0]) cube(); +translate([10,20,-10]) resize([-5,0,0],auto=3) cube(); +translate([10,30,-10]) resize(-5,0,0,auto=3) cube(); +translate([10,40,-10]) resize(5,0,0) cube(); } \ No newline at end of file -- cgit v0.10.1 From c46fb24bf2890fd6e7c7e93b67e584c56a264d72 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 16 Mar 2013 13:18:10 -0500 Subject: update regression test results diff --git a/tests/regression/cgalpngtest/resize-2d-tests-expected.png b/tests/regression/cgalpngtest/resize-2d-tests-expected.png index 1b0cc8a..44e9598 100644 Binary files a/tests/regression/cgalpngtest/resize-2d-tests-expected.png and b/tests/regression/cgalpngtest/resize-2d-tests-expected.png differ diff --git a/tests/regression/cgalpngtest/resize-tests-expected.png b/tests/regression/cgalpngtest/resize-tests-expected.png index 0c82744..3023c51 100644 Binary files a/tests/regression/cgalpngtest/resize-tests-expected.png and b/tests/regression/cgalpngtest/resize-tests-expected.png differ diff --git a/tests/regression/dumptest/resize-2d-tests-expected.txt b/tests/regression/dumptest/resize-2d-tests-expected.txt index 9d5d3ae..0bbdd66 100644 --- a/tests/regression/dumptest/resize-2d-tests-expected.txt +++ b/tests/regression/dumptest/resize-2d-tests-expected.txt @@ -1,3 +1,47 @@ + color([1, 0, 0, 1]) { + multmatrix([[1, 0, 0, -16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 3], [0, 1, 0, 3], [0, 0, 1, 0], [0, 0, 0, 1]]) { + circle($fn = 10, $fa = 12, $fs = 2, r = 1); + } + } + } + } + } + multmatrix([[1, 0, 0, -16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 1], [0, 1, 0, 1], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + multmatrix([[1, 0, 0, 2], [0, 1, 0, 2], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [1, 1], center = false); + } + } + } + } + } + multmatrix([[1, 0, 0, -16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + group() { + difference() { + square(size = [5, 5], center = false); + multmatrix([[1, 0, 0, 0], [0, 1, 0, 2.5], [0, 0, 1, 0], [0, 0, 0, 1]]) { + square(size = [5, 1], center = false); + } + } + } + } + } + } multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { resize(newsize = [15,15,0], auto = [0,0,0]) { group() { @@ -40,9 +84,9 @@ } } } - color([1, 0, 0, 1]) { - multmatrix([[1, 0, 0, -16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + color([0, 0.501961, 0, 1]) { + multmatrix([[1, 0, 0, 16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [15,0,0], auto = [1,1,1]) { group() { difference() { square(size = [5, 5], center = false); @@ -56,8 +100,8 @@ } } } - multmatrix([[1, 0, 0, -16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { - multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[1, 0, 0, 16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,15,0], auto = [1,1,1]) { group() { difference() { square(size = [5, 5], center = false); @@ -71,8 +115,8 @@ } } } - multmatrix([[1, 0, 0, -16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { - multmatrix([[3, 0, 0, 0], [0, 3, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + multmatrix([[1, 0, 0, 16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,15,0], auto = [1,0,0]) { group() { difference() { square(size = [5, 5], center = false); @@ -84,9 +128,9 @@ } } } - color([0, 0.501961, 0, 1]) { - multmatrix([[1, 0, 0, 16], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = [15,0,0], auto = [1,1,1]) { + color([1, 0.752941, 0.796078, 1]) { + multmatrix([[1, 0, 0, 32], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,0,0], auto = [0,1,0]) { group() { difference() { square(size = [5, 5], center = false); @@ -100,8 +144,8 @@ } } } - multmatrix([[1, 0, 0, 16], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = [0,15,0], auto = [1,1,1]) { + multmatrix([[1, 0, 0, 32], [0, 1, 0, 16], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,0,15], auto = [1,1,1]) { group() { difference() { square(size = [5, 5], center = false); @@ -115,8 +159,8 @@ } } } - multmatrix([[1, 0, 0, 16], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { - resize(newsize = [0,0,15], auto = [1,1,1]) { + multmatrix([[1, 0, 0, 32], [0, 1, 0, 32], [0, 0, 1, 0], [0, 0, 0, 1]]) { + resize(newsize = [0,0,15], auto = [0,0,0]) { group() { difference() { square(size = [5, 5], center = false); diff --git a/tests/regression/dumptest/resize-tests-expected.txt b/tests/regression/dumptest/resize-tests-expected.txt index 5fbbe4a..e806250 100644 --- a/tests/regression/dumptest/resize-tests-expected.txt +++ b/tests/regression/dumptest/resize-tests-expected.txt @@ -27,7 +27,7 @@ cube(size = [9, 1, 1], center = false); } multmatrix([[1, 0, 0, 0], [0, 1, 0, 90], [0, 0, 1, -10], [0, 0, 0, 1]]) { - cube(size = [5, 6, 1], center = false); + cube(size = [5, 6, 7], center = false); } } multmatrix([[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]]) { @@ -223,7 +223,7 @@ } } multmatrix([[1, 0, 0, 10], [0, 1, 0, 90], [0, 0, 1, 10], [0, 0, 0, 1]]) { - resize(newsize = [-5,0,0], auto = [0,0,0]) { + resize(newsize = [0,0,7], auto = [1,1,0]) { cube(size = [1, 1, 1], center = false); } } @@ -236,5 +236,25 @@ } } } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 10], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [-5,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 20], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [-5,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 30], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [0,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 40], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [0,0,0], auto = [0,0,0]) { + cube(size = [1, 1, 1], center = false); + } + } } diff --git a/tests/regression/opencsgtest/resize-2d-tests-expected.png b/tests/regression/opencsgtest/resize-2d-tests-expected.png index 937de11..d3bda96 100644 Binary files a/tests/regression/opencsgtest/resize-2d-tests-expected.png and b/tests/regression/opencsgtest/resize-2d-tests-expected.png differ diff --git a/tests/regression/opencsgtest/resize-tests-expected.png b/tests/regression/opencsgtest/resize-tests-expected.png index fbe3e08..77b0544 100644 Binary files a/tests/regression/opencsgtest/resize-tests-expected.png and b/tests/regression/opencsgtest/resize-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-2d-tests-expected.png b/tests/regression/throwntogethertest/resize-2d-tests-expected.png index d896d8e..4737cf7 100644 Binary files a/tests/regression/throwntogethertest/resize-2d-tests-expected.png and b/tests/regression/throwntogethertest/resize-2d-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-tests-expected.png b/tests/regression/throwntogethertest/resize-tests-expected.png index 7c6804c..19d6881 100644 Binary files a/tests/regression/throwntogethertest/resize-tests-expected.png and b/tests/regression/throwntogethertest/resize-tests-expected.png differ -- cgit v0.10.1 From eb8772539cb38691e11ca85215bd2ea16bdddb62 Mon Sep 17 00:00:00 2001 From: don bright Date: Sat, 16 Mar 2013 13:34:47 -0500 Subject: update test results diff --git a/testdata/scad/features/resize-tests.scad b/testdata/scad/features/resize-tests.scad index 67e2535..659848b 100644 --- a/testdata/scad/features/resize-tests.scad +++ b/testdata/scad/features/resize-tests.scad @@ -4,7 +4,7 @@ // and should be inscribed in gold row in 'top' view // back row (green) = should be all cubes auto-scaled up // back top (purple) = uses 'auto' feature -// pink = recursive resize, negative, wrong syntax, etc +// pink = recursive resize, negative, <1, wrong syntax, etc $fn=8; @@ -76,4 +76,6 @@ translate([10,10,-10]) resize([-5,0,0]) cube(); translate([10,20,-10]) resize([-5,0,0],auto=3) cube(); translate([10,30,-10]) resize(-5,0,0,auto=3) cube(); translate([10,40,-10]) resize(5,0,0) cube(); +translate([10,50,-10]) resize([0.5,0,7]) cube([0.5,1,1000]); +translate([10,60,-10]) resize([0,0,0.5]) cube([6,6,10000000000]); } \ No newline at end of file diff --git a/tests/regression/cgalpngtest/resize-tests-expected.png b/tests/regression/cgalpngtest/resize-tests-expected.png index 3023c51..8f994bf 100644 Binary files a/tests/regression/cgalpngtest/resize-tests-expected.png and b/tests/regression/cgalpngtest/resize-tests-expected.png differ diff --git a/tests/regression/dumptest/resize-tests-expected.txt b/tests/regression/dumptest/resize-tests-expected.txt index e806250..f31290c 100644 --- a/tests/regression/dumptest/resize-tests-expected.txt +++ b/tests/regression/dumptest/resize-tests-expected.txt @@ -256,5 +256,15 @@ cube(size = [1, 1, 1], center = false); } } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 50], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [0.5,0,7], auto = [0,0,0]) { + cube(size = [0.5, 1, 1000], center = false); + } + } + multmatrix([[1, 0, 0, 10], [0, 1, 0, 60], [0, 0, 1, -10], [0, 0, 0, 1]]) { + resize(newsize = [0,0,0.5], auto = [0,0,0]) { + cube(size = [6, 6, 1e+10], center = false); + } + } } diff --git a/tests/regression/opencsgtest/resize-tests-expected.png b/tests/regression/opencsgtest/resize-tests-expected.png index 77b0544..0334ba6 100644 Binary files a/tests/regression/opencsgtest/resize-tests-expected.png and b/tests/regression/opencsgtest/resize-tests-expected.png differ diff --git a/tests/regression/throwntogethertest/resize-tests-expected.png b/tests/regression/throwntogethertest/resize-tests-expected.png index 19d6881..7445c1c 100644 Binary files a/tests/regression/throwntogethertest/resize-tests-expected.png and b/tests/regression/throwntogethertest/resize-tests-expected.png differ -- cgit v0.10.1 From 8ea615c7cf23cf32e3c3ab1acaaa5f2b20ffbe03 Mon Sep 17 00:00:00 2001 From: Marius Kintel Date: Fri, 22 Mar 2013 10:48:30 -0300 Subject: Mention cmake dependency on Mac diff --git a/README.md b/README.md index c3e2e36..c2acded 100644 --- a/README.md +++ b/README.md @@ -113,8 +113,11 @@ To pull the MCAD library (http://reprap.org/wiki/MCAD), do the following: ### Building for Mac OS X -First, make sure that you have XCode installed to get GCC. Then after -you've cloned this git repository, run the script that sets up the +Prerequisites: +* XCode, including XCode command-line tools (install from XCode Preferences). +* [CMake](http://cmake.org), which can be installed manually or through MacPorts/homebrew. + +Then after you've cloned this git repository, run the script that sets up the environment variables. source setenv_mjau.sh -- cgit v0.10.1 From 894c9fe561e9178b3d4004c1370c3a45a945c507 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Sat, 23 Mar 2013 12:36:10 -0700 Subject: Make OpenSCAD look better on retina displays. Apps need an NSPrincipalClass entry in Info.plist to look good on retina displays, see "Framework-Scaled Mode Provides Automatic Scaling" in http://developer.apple.com/library/mac/#documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/Explained/Explained.html It's also what we did in Chromium ( https://codereview.chromium.org/10069029 ) and what was suggested in openscad issue #279. This only makes the window decoration and all text pretty. The 3d view is still pixel-doubled: OpenGL is a pixel-based API and needs an explicit opt-in. This can be addressed in a future patch. While here, also consistently use tabs instead of spaces. diff --git a/Info.plist b/Info.plist index 144dd69..506bab7 100644 --- a/Info.plist +++ b/Info.plist @@ -35,15 +35,17 @@ Editor CFBundleTypeIconFile SCAD.icns - LSIsAppleDefaultForType + LSIsAppleDefaultForType NSAppleScriptEnabled - + + NSPrincipalClass + NSApplication OSAScriptingDefinition OpenSCAD.sdef - SUPublicDSAKeyFile - dsa_pub.pem + SUPublicDSAKeyFile + dsa_pub.pem -- cgit v0.10.1