make resize of flat objects fail in the direction normal to the flat.

also fail on resize to negative size.
update tests
felipesanches-svg
don bright 2013-03-11 17:23:53 -05:00
parent 1726c26518
commit fc257c9383
4 changed files with 51 additions and 47 deletions

View File

@ -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]<NT(0)) {
PRINT("WARNING: Cannot resize to a new size less than 0.");
return 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";
for (int i=0;i<3;i++) {
if (node.autosize[i]) scale[i] = autoscale;
}
Eigen::Matrix4d t;
t << CGAL::to_double(scale[0]), 0, 0, 0,
0, CGAL::to_double(scale[1]), 0, 0,

View File

@ -96,10 +96,6 @@ 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

View File

@ -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);

View File

@ -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();
}