fix crashbug 2d resize. add 2d tests. print offscreen warning better.

felipesanches-svg
don bright 2013-03-11 10:59:52 -05:00
parent 5559ae9a6a
commit 4e2965ac17
6 changed files with 86 additions and 7 deletions

View File

@ -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<NT,3,1> 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,

View File

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

View File

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

View File

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

View File

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

View File

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