bool IOctTreeInsertable.HitTest(ref BoundingCube cube, double precision) { return(cube.Contains(position, precision)); }
/// <summary> /// Overrides <see cref="CADability.GeoObject.IGeoObjectImpl.HitTest (ref BoundingCube, double)"/> /// </summary> /// <param name="cube"></param> /// <param name="precision"></param> /// <returns></returns> public override bool HitTest(ref BoundingCube cube, double precision) { return(cube.Contains(location)); }
/// <summary> /// Creates the voxel representation of the provided <paramref name="obj"/> (only GetExtent and HitTest are beeing used) /// </summary> /// <param name="obj">the object for which the voxel represenation is to be created</param> /// <param name="precision">the precision, size of the smallest voxel</param> public VoxelTree(IOctTreeInsertable obj, double precision) { BoundingCube ext = obj.GetExtent(precision); BoundingCube unit = new BoundingCube(-1, 1, -1, 1, -1, 1); baseCube = 1; double size = 1; while (unit.Contains(ext)) { size /= 2; baseCube--; unit.Set(-size, size, -size, size, -size, size); } if (baseCube == 1) { // ext is not contained in -1..1 size = 2; unit.Set(-2, 2, -2, 2, -2, 2); while (!unit.Contains(ext)) { size *= 2; baseCube++; unit.Set(-size, size, -size, size, -size, size); } } if (baseCube >= 0) { size = 1 << baseCube; } else { size = 1.0 / (1 << -baseCube); } unit.Set(-size, size, -size, size, -size, size); // this BoundingCube contains the whole object List <byte> startCubesList = new List <byte>(); do { byte found = 255; BoundingCube[] sc = subCubes(unit); for (byte i = 0; i < 8; i++) { if (sc[i].Contains(ext)) { if (found == 255) { found = i; } else { // two different cubes contain ext, so we must stop here found = 255; break; } } } if (found != 255) { startCubesList.Add(found); unit = sc[found]; } else { break; } } while (true); startCube = startCubesList.ToArray(); List <byte> voxelList = new List <byte>(); Add(voxelList, unit, obj, precision); voxels = voxelList.ToArray(); }