void BallTree<_Scalar>::buildNode(Node& node, std::vector<int>& indices, AxisAlignedBoxType aabb, int level) { Scalar avgradius = 0.; for (std::vector<int>::const_iterator it=indices.begin(), end=indices.end() ; it!=end ; ++it) avgradius += mRadii[*it]; avgradius = mRadiusScale * avgradius / Scalar(indices.size()); VectorType diag = aabb.max - aabb.min; if (int(indices.size())<mTargetCellSize || avgradius*0.9 > std::max(std::max(diag.X(), diag.Y()), diag.Z()) || int(level)>=mMaxTreeDepth) { node.leaf = true; node.size = indices.size(); node.indices = new unsigned int[node.size]; for (unsigned int i=0 ; i<node.size ; ++i) node.indices[i] = indices[i]; return; } unsigned int dim = vcg::MaxCoeffId(diag); node.dim = dim; node.splitValue = Scalar(0.5*(aabb.max[dim] + aabb.min[dim])); node.leaf = 0; AxisAlignedBoxType aabbLeft=aabb, aabbRight=aabb; aabbLeft.max[dim] = node.splitValue; aabbRight.min[dim] = node.splitValue; std::vector<int> iLeft, iRight; split(indices, aabbLeft, aabbRight, iLeft,iRight); // we don't need the index list anymore indices.clear(); { // left child //mNodes.resize(mNodes.size()+1); Node* pChild = new Node(); node.children[0] = pChild; buildNode(*pChild, iLeft, aabbLeft, level+1); } { // right child //mNodes.resize(mNodes.size()+1); Node* pChild = new Node(); node.children[1] = pChild; buildNode(*pChild, iRight, aabbRight, level+1); } }
void Rectangle::Inflate(const VectorType &size) noexcept { Inflate(size.X(), size.Y()); }
void Rectangle::Offest(const VectorType &vec) noexcept { Offest(vec.X(), vec.Y()); }