/// <summary> /// this method should only be used if no translation and no zoom /// </summary> /// <returns></returns> public List <TargetSelectionRegion> GetSelections() { var selections = new List <TargetSelectionRegion>(); foreach (var jayRectangle in _jayRectangles) { var selection = new TargetSelectionRegion(); var startY = Canvas.GetTop(jayRectangle.Rectangle); var startX = Canvas.GetLeft(jayRectangle.Rectangle); //If selection is out of the image bound, we move it so it will fit in the image boundaries var offsetY = startY < 0 ? Math.Abs(startY) : 0; // if selection is before image var offsetX = startX < 0 ? Math.Abs(startX) : 0; // if selection is before image selection.StartPixel = new SelectionPoint((int)(startX + offsetX), (int)(startY + offsetY)); var rectWidth = ((Rectangle)jayRectangle.Rectangle).ActualWidth; var rectHeight = ((Rectangle)jayRectangle.Rectangle).ActualHeight; var endX = Math.Round(rectWidth + startX + offsetX); var endY = Math.Round(rectHeight + startY + offsetY); selection.EndPixel = new SelectionPoint((int)endX, (int)endY); selections.Add(selection); } return(selections); }
/// <summary> /// Determines if the current selection is in the range of the current image slice /// </summary> /// <param name="i">The i.</param> /// <param name="j">The j.</param> /// <param name="selection">The selection.</param> /// <returns> /// <c>true</c> if the selection is in the slice; otherwise, <c>false</c>. /// </returns> private bool IsInRange(int i, int j, TargetSelectionRegion selection) { var sx = selection.StartPixel.X; var sy = selection.StartPixel.Y; var ex = selection.EndPixel.X; var ey = selection.EndPixel.Y; //settings var m = Settings.Default.ResizeMultiple; // https://stackoverflow.com/questions/13513932/algorithm-to-detect-overlapping-periods // Checking if the ranges are overlapping var inRange = i < ex && sx < i + m; var heightinRangeToo = j < ey && sy < j + m; if (!heightinRangeToo) { inRange = false; } return(inRange); }