Esempio n. 1
0
    public static void UpdateBin(string fileIn, string fileOut, string units, GridData.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, updateGrid);
                ParseBinProperties(br, fileIn, updateGrid);

                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
                updateGrid.units      = units;
                updateGrid.coloring   = coloring;
                updateGrid.metadata   = metadata;
                updateGrid.categories = categories;

                // Write
                WriteBinHeader(bw, updateGrid);
                WriteBinProperties(bw, updateGrid);
                bw.Write(bytes);
            }
        }
    }
Esempio n. 2
0
    public MultiGridData(MultiGridData other, bool withValues = true) : base(other)
    {
        if (other.categories != null)
        {
            int count = other.categories.Length;
            categories = new GridCategory[other.categories.Length];
            for (int i = 0; i < count; i++)
            {
                var c        = other.categories[i];
                var category = new GridCategory(c.name, new GridData(c.grid, withValues), c.color);
                category.grid.patch = patch;
                categories[i]       = category;
            }
        }

        gridFilter = other.gridFilter;
        coloring   = other.coloring;
    }
Esempio n. 3
0
    public MultiGridData(GridData other) : base(other)
    {
        coloring = other.coloring;

        if (other.categories != null && other.categories.Length > 0)
        {
            int count = other.categories.Length;
            categories = new GridCategory[count];

            for (int i = 0; i < count; i++)
            {
                var c        = other.categories[i];
                var category = new GridCategory(c.name, new GridData(other, false), c.color);
                category.grid.categories = null;
                category.grid.patch      = patch;
                categories[i]            = category;
            }
        }
    }
Esempio n. 4
0
    public static void AssignCategoryColors <T>(T[] categories, Color color, GridData.Coloring coloring) where T : Category
    {
        if (coloring == GridData.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 == GridData.Coloring.Single ||
            coloring == GridData.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 == GridData.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 == GridData.Coloring.Multi ||
                 coloring == GridData.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;
            }
        }
    }