using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
namespace UnityEngine.Perception.GroundTruth {
///
/// A definition for how a should be resolved to a single label and color for semantic segmentation generation.
///
[CreateAssetMenu(fileName = "SemanticSegmentationLabelConfig", menuName = "Perception/Semantic Segmentation Label Config", order = 1)]
public class SemanticSegmentationLabelConfig : LabelConfig
{
public static readonly List s_StandardColors = new List()
{
Color.blue,
Color.green,
Color.red,
Color.white,
Color.yellow,
Color.gray
};
public override void AddLabel(string labelToAdd)
{
m_LabelEntries.Add(new SemanticSegmentationLabelEntry
{
label = labelToAdd,
color = FindNewColor()
});
}
Color FindNewColor()
{
var standardColorList = new List(s_StandardColors);
foreach (var item in m_LabelEntries)
{
standardColorList.Remove(item.color);
}
if (standardColorList.Any())
return standardColorList.First();
return Random.ColorHSV(0, 1, .5f, 1, 1, 1);
}
}
///
/// LabelEntry for . Maps a label to a color.
///
[Serializable]
public struct SemanticSegmentationLabelEntry : ILabelEntry
{
string ILabelEntry.label => this.label;
///
/// The label this entry should match.
///
public string label;
///
/// The color to be drawn in the semantic segmentation image
///
public Color color;
}
}