QString printBounding(const Eigen::AlignedBox3d& box){ QString retval; QTextStream sout(&retval); Vector3 c = box.center(); Vector3 s = box.diagonal(); sout << "Center[" << c.x() << " " << c.y() << " " << c.z() << "]" << " Size[" << s.x() << " " << s.y() << " " << s.z() << "]"; return retval; }
Eigen::AlignedBox3d Sheet::bbox(double scaling) { Eigen::AlignedBox3d box; foreach(std::vector<Vector3d> cps, surface.mCtrlPoint) foreach(Vector3d cp, cps) box = box.merged( Eigen::AlignedBox3d(cp, cp) ); // Scaling Eigen::Vector3d diagonal = box.diagonal() * 0.5; Eigen::Vector3d a = box.center() + (diagonal * scaling); Eigen::Vector3d b = box.center() - (diagonal * scaling); box = box.merged( Eigen::AlignedBox3d(a,a) ); box = box.merged( Eigen::AlignedBox3d(b,b) ); return box; }
void surfacemesh_filter_normalize::applyFilter(RichParameterSet*){ qDebug() << "Old bounding box: " << printBounding(mesh()->bbox()); /// Just to be sure... update it mesh()->updateBoundingBox(); Eigen::AlignedBox3d bbox = mesh()->bbox(); Vector3 offset = bbox.center(); /// Normalize to have longest side size = 1 Vector3 s = bbox.diagonal(); Scalar scale = qMax(s.x(),qMax(s.y(),s.z())); Vector3VertexProperty points = mesh()->vertex_coordinates(); foreach(Vertex v, mesh()->vertices()){ Point& p = points[v]; p.x() -= offset.x(); p.y() -= offset.y(); p.z() -= offset.z(); p.x() /= scale; p.y() /= scale; p.z() /= scale; }