public static void UpdateBin(string fileIn, string fileOut, string units, PointData.Coloring coloring, List <MetadataPair> metadata, IntCategory[] categories) { using (var br = new BinaryReader(File.Open(fileIn, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))) { using (var bw = new BinaryWriter(File.Open(fileOut, FileMode.Create))) { // Read original ParseBinHeader(br, fileIn, tempPointData); ParseBinProperties(br, fileIn, tempPointData); int readSize = (int)(br.BaseStream.Length - br.BaseStream.Position); var bytes = new byte[readSize]; int read = 0; if ((read = br.Read(bytes, 0, readSize)) != readSize) { Debug.LogError("Couldn't read all values. Expected (" + readSize + "), Read(" + read + ")"); return; } // Update properties tempPointData.units = units; tempPointData.coloring = coloring; tempPointData.metadata = metadata; tempPointData.categories = categories; // Write WriteBinHeader(bw, tempPointData); WriteBinProperties(bw, tempPointData); bw.Write(bytes); } } }
public static void AssignCategoryColors <T>(T[] categories, Color color, PointData.Coloring coloring) where T : Category { if (coloring == PointData.Coloring.Custom) { return; } int categoriesCount = categories.Length; if (categoriesCount <= 1) { if (categoriesCount == 1) { categories[0].color = color; categories[0].color.a = 1f; } return; } if (coloring == PointData.Coloring.Single || coloring == PointData.Coloring.ReverseSingle) { // Single hue progression Color.RGBToHSV(color, out float h, out float s, out float v); float start = 0.25f; // Start at 1/4 float k = (1f - start) / (categoriesCount - 1); if (coloring == PointData.Coloring.ReverseSingle) { start = 1; k = -k; } for (int i = 0; i < categoriesCount; ++i) { categories[i].color = Color.HSVToRGB(h, s, Mathf.Clamp01(start + i * k)); categories[i].color.a = 1f; } } else if (coloring == PointData.Coloring.Multi || coloring == PointData.Coloring.ReverseMulti) { // Spectral color progression Color.RGBToHSV(color, out float h, out float s, out float v); float hueRange = Mathf.Min(categoriesCount * 0.005f + 0.01f, 0.06f); float invCount = categoriesCount > 1 ? 1f / (categoriesCount - 1) : 0; for (int i = 0; i < categoriesCount; ++i) { var cat = categories[i]; float k = i * invCount; float h2 = h + hueRange * (2f * k - 1f); if (h2 < 0) { h2 += 1f; } else if (h2 > 1f) { h2 -= 1f; } float v2 = Math.Abs(categoriesCount < 3 || i % 2 == 0 ? v : v - 0.15f); cat.color = Color.HSVToRGB(h2, s, v2); cat.color.a = 1f; } } }