using System;
using System.Collections.Generic;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth
{
[Serializable]
public struct IdLabelEntry : ILabelEntry
{
string ILabelEntry.label => this.label;
public string label;
public int id;
}
///
/// A definition for how a should be resolved to a single label and id for ground truth generation.
///
[CreateAssetMenu(fileName = "IdLabelingConfiguration", menuName = "Perception/ID Labeling Configuration", order = 1)]
public class IdLabelConfig : LabelingConfiguration2
{
}
[Serializable]
public struct SemanticSegmentationLabelEntry : ILabelEntry
{
string ILabelEntry.label => this.label;
public string label;
public int pixelValue;
}
///
/// A definition for how a should be resolved to a single label and id for ground truth generation.
///
[CreateAssetMenu(fileName = "SemanticSegmentationLabelingConfiguration", menuName = "Perception/Semantic Segmentation Label Config", order = 1)]
public class SemanticSegmentationLabelConfig : LabelingConfiguration2
{
///
/// Whether the inspector will auto-assign ids based on the id of the first element.
///
public bool AutoAssignIds = true;
///
/// Whether the inspector will start label ids at zero or one when is enabled.
///
public StartingLabelId StartingLabelId = StartingLabelId.One;
}
///
/// A definition for how a should be resolved to a single label and id for ground truth generation.
///
[CreateAssetMenu(fileName = "LabelingConfiguration2", menuName = "Perception/Labeling Configuration 2", order = 1)]
public class LabelingConfiguration2 : ScriptableObject where T : ILabelEntry
{
///
/// A sequence of which defines the labels relevant for this configuration and their values.
///
[FormerlySerializedAs("LabelingConfigurations")]
[SerializeField]
public List LabelEntries = new List();
///
/// Attempts to find the matching index in for the given .
///
///
/// The matching index is the first class name in the given Labeling which matches an entry in .
///
/// The to match
/// When this method returns, contains the matching , or default
if no match was found.
/// Returns true if a match was found. False if not.
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out T labelEntry)
{
return TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _);
}
///
/// Attempts to find the matching index in for the given .
///
///
/// The matching index is the first class name in the given Labeling which matches an entry in .
///
/// The to match
/// When this method returns, contains the matching , or default
if no match was found.
/// When this method returns, contains the index of the matching , or -1
if no match was found.
/// Returns true if a match was found. False if not.
public bool TryGetMatchingConfigurationEntry(Labeling labeling, out T labelEntry, out int labelEntryIndex)
{
foreach (var labelingClass in labeling.labels)
{
for (var i = 0; i < LabelEntries.Count; i++)
{
var entry = LabelEntries[i];
if (string.Equals(entry, labelingClass))
{
labelEntry = LabelEntries[i];
labelEntryIndex = i;
return true;
}
}
}
labelEntryIndex = -1;
labelEntry = default;
return false;
}
}
public interface ILabelEntry
{
string label { get; }
}
}