public bool AddLeaf(OctreeLeaf leaf) { double x = leaf.getX(); double y = leaf.getY(); double z = leaf.getZ(); if (!this._bounds.InBound(x, y, z)) { return(false); } if (this._leafs.Count + 1 > this._capacity) { this._divide(); } if (this._innerNode) { for (int i = 0; i < 8; i++) { if (this._childs[i].AddLeaf(leaf)) { break; } } } else { this._leafs.Add(leaf); } return(true); }
public double getDistanceToCenter(OctreeLeaf oL) { double sum = 0.0d; sum += Math.Pow(oL.getX() - this.getXCenter(), 2); sum += Math.Pow(oL.getY() - this.getYCenter(), 2); sum += Math.Pow(oL.getZ() - this.getZCenter(), 2); return(Math.Sqrt(sum)); }
private OctreeLeaf getCentroid() { double min = double.MaxValue; OctreeLeaf representation = null; for (int i = 0; i < this._leafs.Count; i++) { double dist = this._bounds.getDistanceToCenter(this._leafs[i]); if (dist < min) { min = dist; representation = this._leafs[i]; } } return(representation); }
public List <OctreeLeaf> getRepresentation() { if (this._innerNode) { List <OctreeLeaf> ret = new List <OctreeLeaf>(); for (int i = 0; i < 8; i++) { ret.AddRange(this._childs[i].getRepresentation()); } return(ret); } else { OctreeLeaf representation = getMedoid(); List <OctreeLeaf> ret = new List <OctreeLeaf>(); ret.Add(representation); return(ret); } }
private OctreeLeaf getMedoid() { double x = 0, y = 0, z = 0, w = 0; for (int i = 0; i < this._leafs.Count; i++) { x += this._leafs[i].getX(); y += this._leafs[i].getY(); z += this._leafs[i].getZ(); w += this._leafs[i].getW(); } x = x / this._leafs.Count; y = y / this._leafs.Count; z = z / this._leafs.Count; w = w / this._leafs.Count; double min = double.MaxValue; OctreeLeaf representation = null; for (int i = 0; i < this._leafs.Count; i++) { double sum = 0.0d; sum += Math.Pow(this._leafs[i].getX() - x, 2); sum += Math.Pow(this._leafs[i].getY() - y, 2); sum += Math.Pow(this._leafs[i].getZ() - z, 2); sum += Math.Pow(this._leafs[i].getW() - w, 2); double dist = Math.Sqrt(sum); if (dist < min) { min = dist; representation = this._leafs[i]; } } return(representation); }