/// <summary> /// Returns the closest slice with a z value less than z /// </summary> /// <param name="z"></param> /// <returns></returns> public RegionOfInterestSlice GetClosestSlicePrevious(double z) { if (!ZRange.Contains(z)) { return(null); } if (sliceDictionary.ContainsKey(z)) { return(sliceDictionary[z]); } int index = BinaryMath.BinarySearchClosest(z, roiZCoordinates); if (!(index - 1 > RegionOfInterestSlices.Count - 1) && !(index - 1 < 0)) { return(RegionOfInterestSlices[index - 1]); } if (Math.Abs(RegionOfInterestSlices[0].ZCoord - z) <= 1) { return(RegionOfInterestSlices[0]); } if (Math.Abs(RegionOfInterestSlices[RegionOfInterestSlices.Count - 1].ZCoord - z) <= 1) { return(RegionOfInterestSlices[RegionOfInterestSlices.Count - 1]); } return(null); }
internal void AddFeature(uint id, Envelope geometry, Interval?zRange, Interval?mRange) { NumRecords++; XRange = XRange.ExpandedByInterval(Interval.Create(geometry.MinX, geometry.MaxX)); YRange = YRange.ExpandedByInterval(Interval.Create(geometry.MinY, geometry.MaxY)); ZRange = ZRange.ExpandedByInterval(zRange ?? Interval.Create()); MRange = MRange.ExpandedByInterval(mRange ?? Interval.Create()); }
public Range3Single Intersect(Range3Single other) { var xrange = XRange.Intersect(other.XRange); var yrange = YRange.Intersect(other.YRange); var zrange = ZRange.Intersect(other.ZRange); return(new Range3Single (new Vector3(xrange.Min, yrange.Min, zrange.Min), new Vector3(xrange.Max, yrange.Max, zrange.Max))); }
/// <summary> /// Finds whether a point is inside the ROI, by interpolating between ROI slices /// Only use this if you are checking a SINGLE point, otheriwse use ContainsXYCoordsInterpolated /// </summary> /// <param name="x"></param> /// <param name="y"></param> /// <param name="z"></param> /// <returns></returns> public bool ContainsPointInterpolated(double x, double y, double z) { if (!ZRange.Contains(z)) { return(false); } BinaryMask mask = GetInterpolatedMask(z); return(mask.ContainsPoint(x, y)); }
public long GetLength() { long size = 0; size += XYRange.GetLength(); size += sizeof(int); size += Util.GetArraySize(Points); size += ZRange.GetLength(); size += Util.GetArraySize(ZValues); size += MRange.GetLength(); size += Util.GetArraySize(MValues); return(size); }
void RenderXYFunc(double[,] data, bool booleanMode, Color trueColor) { if (HeatColors == null) { HeatColors = new Color[(ColorBands.Length - 1) * 16]; for (int band = 0; band < ColorBands.Length - 1; band++) { Color lo = ColorBands[band], hi = ColorBands[band + 1]; for (int hii = 0; hii < 16; hii++) { int loi = 16 - hii; HeatColors[band * 16 + hii] = Color.FromArgb((lo.R * loi + hi.R * hii) >> 4, (lo.G * loi + hi.G * hii) >> 4, (lo.B * loi + hi.B * hii) >> 4); } } } Color nanColor = Color.FromArgb(trueColor.R / 2 + 64, trueColor.G / 2 + 64, trueColor.B / 2 + 64); for (int y = 0; y < data.GetLength(0); y++) { for (int x = 0; x < data.GetLength(1); x++) { double d = data[y, x]; if (!booleanMode) { ZRange.PxCount = HeatColors.Length; double z = ZRange.ValueToPx(data[y, x]); Color c; if (double.IsNaN(z)) { c = Color.DarkGray; // which is lighter than "Gray" } else if (double.IsInfinity(z)) { c = Color.Purple; } else { int z2 = (int)G.PutInRange(ZRange.ValueToPx(data[y, x]), 0, HeatColors.Length - 1); c = HeatColors[z2]; } Bitmap.SetPixel(x, Bitmap.Height - 1 - y, c); } else if (!(d == 0)) { Bitmap.SetPixel(x, Bitmap.Height - 1 - y, double.IsNaN(d) ? nanColor : trueColor); } } } }
/// <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); } }
/// <summary> /// Returns the closest slice with a z value greater than z /// </summary> /// <param name="z"></param> /// <returns></returns> public RegionOfInterestSlice GetClosestSliceNext(double z) { if (!ZRange.Contains(z)) { return(null); } if (sliceDictionary.ContainsKey(z)) { return(sliceDictionary[z]); } int index = BinaryMath.BinarySearchClosest(z, roiZCoordinates); if (!(index > RegionOfInterestSlices.Count - 1) && !(index < 0)) { return(RegionOfInterestSlices[index]); } return(null); }
/// <summary> /// Converts the component z-order to the Adorner z-order. The adorner z-order /// is shifted by the minimal value for this level. Also there is a restriction /// about the maximal possible value for this level too /// </summary> /// <param name="zOrder">component z-order</param> /// <param name="level">component z-level</param> /// <returns></returns> private static int ComponentToAdorner(int zOrder, int level) { int res = zOrder; ZRange range = (ZRange)_ZRanges[level]; if (range != null) { //adjust the Z-order (shift it with the minimal value for this range) //that way the component does need to know the range for its type that is // set by the application. It always sets the z-order as it starts from 0 res += range.Min; if (res < range.Min) { res = range.Min; } if (res > range.Max) { res = range.Max; } } return(res); }
public bool ContainsPoint(double x, double y, double z) { return(XRange.Contains(x) && YRange.Contains(y) && ZRange.Contains(z)); }
public override void Interpolate(Point3d position, Voxel voxel) { voxel.Position.X = position.X; voxel.Position.Y = position.Y; voxel.Position.Z = position.Z; if (!XRange.Contains(position.X) || !YRange.Contains(position.Y) || !ZRange.Contains(position.Z)) { voxel.Value = DefaultPhysicalValue; } else { try { //float x0 = 0, x1 = 0, y0 = 0, y1 = 0, z0 = 0, z1 = 0; //int ix0 = 0, ix1 = 0, iy0 = 0, iy1 = 0, iz0 = 0, iz1 = 0; if (ConstantGridSpacing) { ix0 = (int)((position.X - XCoords[0]) / GridSpacing.X); if (ix0 >= XCoords.Length - 1) { ix1 = ix0 = XCoords.Length - 1; } else { ix1 = ix0 + 1; } x0 = XCoords[ix0]; x1 = XCoords[ix1]; iy0 = (int)((position.Y - YCoords[0]) / GridSpacing.Y); if (iy0 >= YCoords.Length - 1) { iy1 = iy0 = YCoords.Length - 1; } else { iy1 = iy0 + 1; } y0 = YCoords[iy0]; y1 = YCoords[iy1]; if (GridSpacing.Z != 0) { iz0 = (int)((position.Z - ZCoords[0]) / GridSpacing.Z); iz1 = iz0 + 1; if (iz0 >= ZCoords.Length - 1) { iz1 = iz0 = ZCoords.Length - 1; } else { iz1 = iz0 + 1; } z0 = ZCoords[iz0]; z1 = ZCoords[iz1]; } else { iz0 = 0; iz1 = 0; z0 = ZCoords[iz0]; z1 = ZCoords[iz1]; } } else { var xt = binarySearchForSurroundingCoords(position.X, XCoords); x0 = (float)xt.Item1; x1 = (float)xt.Item2; ix0 = xt.Item3; ix1 = xt.Item4; var yt = binarySearchForSurroundingCoords(position.Y, YCoords); y0 = (float)yt.Item1; y1 = (float)yt.Item2; iy0 = yt.Item3; iy1 = yt.Item4; var zt = binarySearchForSurroundingCoords(position.Z, ZCoords); z0 = (float)zt.Item1; z1 = (float)zt.Item2; iz0 = zt.Item3; iz1 = zt.Item4; } voxel.Value = Interpolation.TrilinearInterpolate( (float)position.X, (float)position.Y, (float)position.Z, x0, y0, z0, x1, y1, z1, Data[getIndex(ix0, iy0, iz0)], Data[getIndex(ix1, iy0, iz0)], Data[getIndex(ix0, iy0, iz1)], Data[getIndex(ix1, iy0, iz1)], Data[getIndex(ix0, iy1, iz0)], Data[getIndex(ix1, iy1, iz0)], Data[getIndex(ix0, iy1, iz1)], Data[getIndex(ix1, iy1, iz1)]); } #pragma warning disable CS0168 // The variable 'e' is declared but never used catch (Exception e) #pragma warning restore CS0168 // The variable 'e' is declared but never used { voxel.Value = DefaultPhysicalValue; } } }
// ---------------------------------------------------------------------------------------- #region WireframeDimensions public void UpdateDimensions(Single3 origin) { XRange = XRange.Add(origin.X); YRange = YRange.Add(origin.Y); ZRange = ZRange.Add(origin.Z); }
public double Distance2(Vector3 point) { return(_basePolygon.Distance2(point.XY) + ZRange.Distance2(point.Z)); }
public bool Contains(Vector3 point) { return(_basePolygon.Contains(point.XY) && ZRange.Contains(point.Z)); }
public override void Interpolate(Point3d position, Voxel voxel) { voxel.Position.X = position.X; voxel.Position.Y = position.Y; voxel.Position.Z = position.Z; if (!XRange.Contains(position.X) || !YRange.Contains(position.Y) || !ZRange.Contains(position.Z)) { voxel.Value = 0; } else { float x0 = 0, x1 = 0, y0 = 0, y1 = 0, z0 = 0, z1 = 0; int ix0 = 0, ix1 = 0, iy0 = 0, iy1 = 0, iz0 = 0, iz1 = 0; if (ConstantGridSpacing) { ix0 = (int)((position.X - XCoords[0]) / GridSpacing.X); ix1 = ix0 == XCoords.Length - 1 ? ix0 : ix0 + 1; x0 = (float)XCoords[ix0]; x1 = (float)XCoords[ix1]; iy0 = (int)((position.Y - YCoords[0]) / GridSpacing.Y); iy1 = iy0 == YCoords.Length - 1 ? iy0 : iy0 + 1; y0 = (float)YCoords[iy0]; y1 = (float)YCoords[iy1]; if (GridSpacing.Z != 0) { iz0 = (int)((position.Z - ZCoords[0]) / GridSpacing.Z); iz1 = iz0 == ZCoords.Length - 1 ? iz0 : iz0 + 1; z0 = (float)ZCoords[iz0]; z1 = (float)ZCoords[iz1]; } else { iz0 = 0; iz1 = 0; z0 = (float)ZCoords[iz0]; z1 = (float)ZCoords[iz1]; } } else { var xt = binarySearchForSurroundingCoords(position.X, XCoords); x0 = (float)xt.Item1; x1 = (float)xt.Item2; ix0 = xt.Item3; ix1 = xt.Item4; var yt = binarySearchForSurroundingCoords(position.Y, YCoords); y0 = (float)yt.Item1; y1 = (float)yt.Item2; iy0 = yt.Item3; iy1 = yt.Item4; var zt = binarySearchForSurroundingCoords(position.Z, ZCoords); z0 = (float)zt.Item1; z1 = (float)zt.Item2; iz0 = zt.Item3; iz1 = zt.Item4; } float xd; if (x1 == x0) { xd = 0; } else { xd = (float)(position.X - x0) / (x1 - x0); } double yd; if (y1 == y0) { yd = 0; } else { yd = (position.Y - y0) / (y1 - y0); } double zd; if (z1 == z0) { zd = 0; } else { zd = (position.Z - z0) / (z1 - z0); } float c00 = Data[ix0, iy0, iz0] * (1 - xd) + Data[ix1, iy0, iz0] * xd; float c01 = Data[ix0, iy0, iz1] * (1 - xd) + Data[ix1, iy0, iz1] * xd; float c10 = Data[ix0, iy1, iz0] * (1 - xd) + Data[ix1, iy1, iz0] * xd; float c11 = Data[ix0, iy1, iz1] * (1 - xd) + Data[ix1, iy1, iz1] * xd; float c0 = (float)(c00 * (1 - yd) + c10 * yd); float c1 = (float)(c01 * (1 - yd) + c11 * yd); float c = (float)(c0 * (1 - zd) + c1 * zd); voxel.Value = c; } }