static Volume <byte> Scaled(Volume <byte> source, V2d scaleFactor, ImageInterpolation ip = ImageInterpolation.Cubic) { var targetSize = (new V2d(0.5, 0.5) + scaleFactor * (V2d)source.Size.XY).ToV2l(); var target = new V3l(targetSize.X, targetSize.Y, source.Size.Z).CreateImageVolume <byte>(); for (int c = 0; c < source.Size.Z; c++) { var targetMat = target.SubXYMatrixWindow(0); var sourceMat = source.SubXYMatrixWindow(0); switch (ip) { case ImageInterpolation.Near: targetMat.SetScaledNearest(sourceMat); break; case ImageInterpolation.Linear: targetMat.SetScaledLinear(sourceMat, (s, a, b) => (byte)s.Lerp(a, b), (s, a, b) => (byte)s.Lerp(a, b)); break; case ImageInterpolation.Cubic: targetMat.SetScaledCubic(sourceMat); break; case ImageInterpolation.Lanczos: targetMat.SetScaledLanczos(sourceMat); break; default: throw new NotImplementedException(); } } return(target); }
public static void CheckMatching(V3l v1, V3l v2) { if (v1 != v2) { throw new Exception("mismatch"); } }
public void Code(Type t, ref IArrayVolume value) { value = (IArrayVolume)FastObjectFactory.ObjectFactory(t)(); Array array = null; Code(value.ArrayType, ref array); value.Array = array; long origin = 0L; CodeLong(ref origin); value.Origin = origin; V3l length = default(V3l); CodeV3l(ref length); value.Size = length; V3l delta = default(V3l); CodeV3l(ref delta); value.Delta = delta; }
/// <summary> /// Creates a new image volume with a border of the supplied size /// around the supplied image volume. /// </summary> public static Volume <T> CopyWithBorder <T>(this Volume <T> volume, Border2l border) { var iv = new V3l(volume.SX + border.Min.X + border.Max.X, volume.SY + border.Min.Y + border.Max.Y, volume.SZ).CreateImageVolume <T>(); iv.SubCenter(border).Set(volume); return(iv); }
/// <summary> /// Creates a new image volume with a border of the supplied size /// around the supplied image volume. /// </summary> public static Volume <T1> MapWithBorder <T, T1>( this Volume <T> volume, Border2l border, Func <T, T1> item_fun) { var iv = new V3l(volume.SX + border.Min.X + border.Max.X, volume.SY + border.Min.Y + border.Max.Y, volume.SZ).CreateImageVolume <T1>(); iv.SubCenter(border).SetMap(volume, item_fun); return(iv); }
/// <summary> /// Calculates the sum for a given set of V3ls. /// </summary> public static V3l Sum(this V3l[] vectors) { V3l sum = V3l.Zero; for (var i = 0; i < vectors.Length; i++) { sum += vectors[i]; } return(sum); }
/// <summary> /// Calculates the sum for a given set of V3ls. /// </summary> public static V3l Sum(this IEnumerable <V3l> vectors) { V3l sum = V3l.Zero; foreach (var e in vectors) { sum += e; } return(sum); }
/// <summary> /// Returns an appropriate TileLayout value according to the 2d dimensions of a grid (z is ignored) /// </summary> public static TileLayout GetTileLayout(V3l dim) { if (dim.X >= 2 && dim.Y >= 2) { return(TileLayout.Full); } else if (dim.X == 1 && dim.Y == 1) { return(TileLayout.Single); } else if (dim.Y == 1) { return(TileLayout.Horizontal); } else if (dim.X == 1) { return(TileLayout.Vertical); } else { throw new Exception("TileLayout not handled"); } }
/// <summary> /// Cell with min corner at index*2^exponent and dimension 2^exponent. /// </summary> public Cell(V3l index, int exponent) : this(index.X, index.Y, index.Z, exponent) { }
public static Volume <T> CreateImageVolume <T>(this T[] data, V3l size) { return(new Volume <T>(data, 0L, size, new V3l(size.Z, size.Z * size.X, 1L))); }
public void Write(V3l x) { Write(x.X); Write(x.Y); Write(x.Z); }
public static void CheckMatching(V3l v1, V3l v2, V3l v3, V3l v4) { CheckMatching(v1, v2); CheckMatching(v1, v3); CheckMatching(v1, v4); }
private static ISg LodBoxHierarchy( int level, Volume <ISg> vgsVolume, LevelOfDetailSettings settings, int maxLevel) { int detailCount = 1; if (vgsVolume.SX > 1) { detailCount *= 2; } if (vgsVolume.SY > 1) { detailCount *= 2; } if (vgsVolume.SZ > 1) { detailCount *= 2; } //detail count is 1 when space is not dividable #region detailCount == 1 if (detailCount == 1) { //if level > 0 keep subsampling without subdivision if (level > 0) //|| ( level == 0 && (vgsVolume[0, 0, 0].TileSize.X > 256 || vgsVolume[0, 0, 0].TileSize.Y > 256))) { var detailNodeList = LodBoxHierarchy(level - 1, vgsVolume, settings, maxLevel).IntoList(); var dist = DistanceFunc(level - 1, settings); Report.Line("LOD.cs Level " + level + " " + dist); var box = new Sg.LodBox() { Name = "level" + level, DetailNodes = detailNodeList, Settings = new LodBoxSettings { Distance = dist, DeciderCombination = "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance", }, }; box["TileLayout"] = GetTileLayout(vgsVolume.Dim); return(box); } return(vgsVolume[0, 0, 0]); } #endregion var detailNodes = new List <ISg>(detailCount); for (int i = 0; i < 8; i++) { bool valid = true; V3l origin = V3l.Zero; V3l length = vgsVolume.Size; //compute splitting dimensions for each axis for (int dim = 0; dim < 3; dim++) { if ((i & (1 << dim)) == 0) { if (length[dim] > 1) { length[dim] /= 2; } } else { if (length[dim] > 1) { origin[dim] = length[dim] / 2; length[dim] = length[dim] - origin[dim]; } else { valid = false; } } } if (valid) { ISg detailNode = LodBoxHierarchy(level - 1, vgsVolume.SubVolume(origin, length), settings, maxLevel); detailNodes.Add(detailNode); } } { var dist = LevelOfDetail.DistanceFunc(level - 1, settings); //Report.Line("LOD.cs Level " + level + " " + dist); bool isMax = false; // level == maxLevel; var box = new Sg.LodBox() { Name = "level" + level, DetailNodes = detailNodes, Pinned = Sg.LodBox.PinnedOptions.Default, Settings = new LodBoxSettings { Distance = dist, DeciderCombination = !isMax ? "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => Distance" : "Distance, ScreenPixToTriSize, ScreenPixToTexPix, VisualImpact => false", }, }; // s_numOfBoxes++; box["TileLayout"] = GetTileLayout(vgsVolume.Dim); //Report.Line("DIM: " + vgsVolume.Dim.ToString() + " " // + box["TileLayout"].ToString() + " __lvl: " // + level + " Desc.: " + box.DetailNodes.Count()); var sg = Rsg.Apply( new ResourcePinningEnabledValue() { Value = level == maxLevel }, box); return(box); } }
/// <summary>Computes MD5 hash of given data.</summary> public static Guid ComputeMd5Hash(this V3l x) => ComputeMd5Hash(bw => { bw.Write(x.X); bw.Write(x.Y); bw.Write(x.Z); });