Пример #1
0
        private BinaryMask GetInterpolatedMask(double z)
        {
            if (sliceDictionary.ContainsKey(z))
            {
                return(sliceDictionary[z].BinaryMask);
            }

            RegionOfInterestSlice slice1 = GetClosestSlicePrevious(z);
            RegionOfInterestSlice slice2 = GetClosestSliceNext(z);
            double     z1 = slice1?.ZCoord ?? 0, z2 = slice2?.ZCoord ?? 0;
            BinaryMask mask1 = slice1?.BinaryMask;
            BinaryMask mask2 = slice2?.BinaryMask;

            if (mask1 == null)
            {
                mask1 = new BinaryMask(XRange, YRange);
                z1    = slice2 != null ? slice2.ZCoord - 2 : z - 2;
            }
            if (mask2 == null)
            {
                mask2 = new BinaryMask(XRange, YRange);
                z2    = slice2 != null ? slice2.ZCoord + 2 : z + 2;
            }
            double     frac     = (z - z1) / (z2 - z1);
            BinaryMask interped = mask1.InterpolateWith(mask2, frac);

            return(interped);
        }
Пример #2
0
        /// <summary>
        /// Finds whether a point is inside the ROI, not interpolating between ROI slices
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public bool ContainsPointNonInterpolated(double x, double y, double z)
        {
            RegionOfInterestSlice slice = GetClosestSlice(z);

            if (slice == null)
            {
                return(false);
            }

            return(slice.ContainsPoint(x, y));
        }
Пример #3
0
 public void AddSlice(RegionOfInterestSlice slice, double coordinate)
 {
     if (!sliceDictionary.ContainsKey(coordinate))
     {
         // Add the ROIs to arrays but ensure they are sorted by z coord
         int insertIndex = BinaryMath.BinarySearchClosest(coordinate, roiZCoordinates);
         if (insertIndex < 0)
         {
             insertIndex = ~insertIndex;
         }
         RegionOfInterestSlices.Insert(insertIndex, slice);
         roiZCoordinates.Insert(insertIndex, coordinate);
         sliceDictionary.Add(coordinate, slice);
     }
 }
Пример #4
0
        /// <summary>
        /// Returns the closest slice with
        /// </summary>
        /// <param name="z"></param>
        /// <returns></returns>
        public RegionOfInterestSlice GetClosestSlice(double z)
        {
            if (!ZRange.Contains(z))
            {
                return(null);
            }

            if (sliceDictionary.ContainsKey(z))
            {
                return(sliceDictionary[z]);
            }

            int index = BinaryMath.BinarySearchClosest(z, roiZCoordinates);
            RegionOfInterestSlice slice1 = null;
            RegionOfInterestSlice slice2 = null;

            if (!(index - 1 > RegionOfInterestSlices.Count - 1) && !(index - 1 < 0))
            {
                slice1 = RegionOfInterestSlices[index - 1];
            }
            if (!(index > RegionOfInterestSlices.Count - 1) && !(index < 0))
            {
                slice2 = RegionOfInterestSlices[index];
            }

            if (slice2 == null)
            {
                return(slice1);
            }
            if (slice1 == null)
            {
                return(slice2);
            }

            if (Math.Abs((slice1.ZCoord - z)) <= Math.Abs((slice2.ZCoord - z)))
            {
                return(slice1);
            }
            else
            {
                return(slice2);
            }
        }