public override IEnumerable <Vector2> GetPositionsToSample(Vector3 startPosition) { AxisAlignedBoundingBox aabb = printer.Bed.Aabb; var insets = printer.Settings.GetValue <Vector4>(SettingsKey.print_leveling_insets); aabb.MinXYZ.X += aabb.XSize * insets[0] / 100.0; aabb.MinXYZ.Y += aabb.YSize * insets[1] / 100.0; aabb.MaxXYZ.X -= aabb.XSize * insets[2] / 100.0; aabb.MaxXYZ.Y -= aabb.YSize * insets[3] / 100.0; if (printer.Settings.GetValue <BedShape>(SettingsKey.bed_shape) == BedShape.Circular) { // reduce the bed size by the ratio of the radius (square root of 2) so that the sample positions will fit on a circular bed aabb.Expand(aabb.XSize * .5 * (1 - Math.Sqrt(2)), aabb.YSize * .5 * (1 - Math.Sqrt(2)), 0); } if (printer.Settings.GetValue <bool>(SettingsKey.has_z_probe) && printer.Settings.GetValue <bool>(SettingsKey.use_z_probe)) { var probeOffset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset); if (probeOffset.X < 0) { // add the negative offset as the place we are going to probe cannot be the right edge (the nozzle can't get there) aabb.MaxXYZ.X += probeOffset.X; } else { // Where are we going to try to probe (this position will be offset with the probe later)? // We adjust the left side as we cannot put the probe on the left edge as it would require the nozzle to be too far left. aabb.MinXYZ.X += probeOffset.X; } if (probeOffset.Y < 0) { aabb.MaxXYZ.Y += probeOffset.Y; } else { aabb.MinXYZ.Y += probeOffset.Y; } } double xStep = aabb.XSize / (gridWidth - 1); double yStep = aabb.YSize / (gridHeight - 1); var allPositions = new List <Vector2>(gridWidth * gridHeight); for (int y = 0; y < gridHeight; y++) { // make it such that every other line is printed from right to left for (int x = 0; x < gridWidth; x++) { allPositions.Add(new Vector2 { X = aabb.MinXYZ.X + x * xStep, Y = aabb.MinXYZ.Y + y * yStep }); } } var currentPosition = new Vector2(startPosition); Vector2 ClosestPosition() { var closestIndex = 0; var closestDist = double.PositiveInfinity; for (int i = 0; i < allPositions.Count; i++) { var position = allPositions[i]; var dist = (currentPosition - position).Length; if (dist < closestDist) { closestDist = dist; closestIndex = i; } } currentPosition = allPositions[closestIndex]; allPositions.RemoveAt(closestIndex); return(currentPosition); } while (allPositions.Count > 0) { yield return(ClosestPosition()); } }
public override IEnumerable <Vector2> GetPositionsToSample(Vector3 startPosition) { AxisAlignedBoundingBox aabb = printer.Bed.Aabb; aabb.Expand(aabb.XSize * -.1, aabb.YSize * -.1, 0); if (printer.Settings.GetValue <BedShape>(SettingsKey.bed_shape) == BedShape.Circular) { // reduce the bed size by the ratio of the radius (square root of 2) so that the sample positions will fit on a circular bed aabb.Expand(aabb.XSize * .5 * (1 - Math.Sqrt(2)), aabb.YSize * .5 * (1 - Math.Sqrt(2)), 0); } if (printer.Settings.GetValue <bool>(SettingsKey.has_z_probe) && printer.Settings.GetValue <bool>(SettingsKey.use_z_probe)) { var probeOffset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset); if (probeOffset.X < 0) { aabb.MinXYZ.X -= probeOffset.X; } else { aabb.MaxXYZ.X -= probeOffset.X; } if (probeOffset.Y < 0) { aabb.MinXYZ.Y -= probeOffset.Y; } else { aabb.MaxXYZ.Y -= probeOffset.Y; } } double xStep = aabb.XSize / (gridWidth - 1); double yStep = aabb.YSize / (gridHeight - 1); var allPositions = new List <Vector2>(gridWidth * gridHeight); for (int y = 0; y < gridHeight; y++) { // make it such that every other line is printed from right to left for (int x = 0; x < gridWidth; x++) { int dirX = x; if ((y % 2) == 1) { dirX = (gridWidth - 1) - x; } allPositions.Add(new Vector2 { X = aabb.MinXYZ.X + dirX * xStep, Y = aabb.MinXYZ.Y + y * yStep }); } } var currentPosition = new Vector2(startPosition); Vector2 ClosestPosition() { var closestIndex = 0; var closestDist = double.PositiveInfinity; for (int i = 0; i < allPositions.Count; i++) { var position = allPositions[i]; var dist = (currentPosition - position).Length; if (dist < closestDist) { closestDist = dist; closestIndex = i; } } currentPosition = allPositions[closestIndex]; allPositions.RemoveAt(closestIndex); return(currentPosition); } while (allPositions.Count > 0) { yield return(ClosestPosition()); } }
public override IEnumerable <Vector2> GetPrintLevelPositionToSample() { AxisAlignedBoundingBox aabb = printer.Bed.Aabb; aabb.Expand(aabb.XSize * -.1, aabb.YSize * -.1, 0); if (printer.Settings.GetValue <BedShape>(SettingsKey.bed_shape) == BedShape.Circular) { // reduce the bed size by the ratio of the radius (square root of 2) so that the sample positions will fit on a circular bed aabb.Expand(aabb.XSize * .5 * (1 - Math.Sqrt(2)), aabb.YSize * .5 * (1 - Math.Sqrt(2)), 0); } if (printer.Settings.GetValue <bool>(SettingsKey.has_z_probe) && printer.Settings.GetValue <bool>(SettingsKey.use_z_probe)) { var probeOffset = printer.Settings.GetValue <Vector3>(SettingsKey.probe_offset); if (probeOffset.X < 0) { aabb.MinXYZ.X -= probeOffset.X; } else { aabb.MaxXYZ.X -= probeOffset.X; } if (probeOffset.Y < 0) { aabb.MinXYZ.Y -= probeOffset.Y; } else { aabb.MaxXYZ.Y -= probeOffset.Y; } } double xStep = aabb.XSize / (gridWidth - 1); double yStep = aabb.YSize / (gridHeight - 1); for (int y = 0; y < gridHeight; y++) { // make it such that every other line is printed from right to left for (int x = 0; x < gridWidth; x++) { int dirX = x; if ((y % 2) == 1) { dirX = (gridWidth - 1) - x; } var samplePosition = new Vector2 { X = aabb.MinXYZ.X + dirX * xStep, Y = aabb.MinXYZ.Y + y * yStep }; yield return(samplePosition); } } }
public static AxisAlignedBoundingBox GetWorldspaceAabbOfRenderAabb(AxisAlignedBoundingBox bounds, Matrix4X4 matrix, double lineWidth = 1, double extendLineLength = 0) { bounds = bounds.NewTransformed(matrix); bounds.Expand(extendLineLength); return(bounds); }