浏览代码

Labeling UI almost done

/main
Mohsen Kamalzadeh 4 年前
当前提交
228e2ab6
共有 14 个文件被更改,包括 386 次插入197 次删除
  1. 153
      com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs
  2. 8
      com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs
  3. 207
      com.unity.perception/Editor/GroundTruth/LabelingEditor.cs
  4. 12
      com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor.cs
  5. 71
      com.unity.perception/Editor/GroundTruth/Uss/Styles.uss
  6. 10
      com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml
  7. 10
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementForAddingLabelsFrom.uxml
  8. 3
      com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml
  9. 9
      com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml
  10. 22
      com.unity.perception/Runtime/GroundTruth/Labeling/IdLabelConfig.cs
  11. 34
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs
  12. 34
      com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationLabelConfig.cs
  13. 7
      com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml
  14. 3
      com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml.meta

153
com.unity.perception/Editor/GroundTruth/AddToConfigWindow.cs


private static string m_LabelValue;
private static Label m_TitleLabel;
private List<string> m_AllLabelConfigGuids = new List<string>();
private List<Type> m_LabelConfigTypes = new List<Type>();
window.minSize = new Vector2(400, 500);
window.minSize = new Vector2(350, 385);
window.maxSize = new Vector2(350, 385);
window.titleContent = new GUIContent("Manage Label");
window.Init();
window.Show();
}

m_ConfigsContainingLabel.Clear();
if(m_TitleLabel != null)
m_TitleLabel.text = "Add " + m_LabelValue + "to Label Configurations";
m_TitleLabel.text = "Label: \"" + m_LabelValue + "\"";
Refresh();
m_LabelConfigTypes = FindAllSubTypes(typeof(LabelConfig<>));
RefreshConfigAssets();
CheckInclusionInConfigs(m_AllLabelConfigGuids, m_LabelConfigTypes, m_LabelValue, this);
SetupListViews();
void Refresh()
void RefreshConfigAssets()
var types = FindAllRelevant();
List<string> labelConfigGuids = new List<string>();
foreach (var type in types)
m_AllLabelConfigGuids.Clear();
foreach (var type in m_LabelConfigTypes)
labelConfigGuids.AddRange(AssetDatabase.FindAssets("t:"+type.Name));
m_AllLabelConfigGuids.AddRange(AssetDatabase.FindAssets("t:"+type.Name));
}
CheckInclusionInConfigs(labelConfigGuids, types, m_LabelValue, this);
Func<VisualElement> makeItem = () => new ConfigElementLabelPresent(m_LabelValue);
void SetupListViews()
{
//configs containing label
m_PresentConfigsListview.itemsSource = m_ConfigsContainingLabel;
VisualElement MakeItem1() => new ConfigElementLabelPresent(this, m_LabelValue);
void BindItem(VisualElement e, int i)
void BindItem1(VisualElement e, int i)
{
if (e is ConfigElementLabelPresent element)
{

}
m_PresentConfigsListview.itemHeight = 30;
m_PresentConfigsListview.itemsSource = m_ConfigsContainingLabel;
m_PresentConfigsListview.bindItem = BindItem1;
m_PresentConfigsListview.makeItem = MakeItem1;
m_PresentConfigsListview.selectionType = SelectionType.None;
m_PresentConfigsListview.bindItem = BindItem;
m_PresentConfigsListview.makeItem = makeItem;
//Configs not containing label
m_NonPresentConfigsListview.itemsSource = m_ConfigsNotContainingLabel;
VisualElement MakeItem2() => new ConfigElementLabelNotPresent(this, m_LabelValue);
void BindItem2(VisualElement e, int i)
{
if (e is ConfigElementLabelNotPresent element)
{
element.m_Label.text = m_ConfigsNotContainingLabel[i].name;
element.m_LabelConfig = m_ConfigsNotContainingLabel[i];
}
}
// Func<VisualElement> makeItem1 = () => new Label();
// Action<VisualElement, int> bindItem1 = (e, i) => (e as Label).text = m_ConfigsNotContainingLabel[i];
//
// m_NonPresentConfigsListview.itemHeight = 30;
// m_NonPresentConfigsListview.itemsSource = m_ConfigsNotContainingLabel;
//
// m_NonPresentConfigsListview.bindItem = bindItem1;
// m_NonPresentConfigsListview.makeItem = makeItem1;
m_NonPresentConfigsListview.itemHeight = 30;
m_NonPresentConfigsListview.bindItem = BindItem2;
m_NonPresentConfigsListview.makeItem = MakeItem2;
m_NonPresentConfigsListview.selectionType = SelectionType.None;
public void RefreshLists()
{
CheckInclusionInConfigs(m_AllLabelConfigGuids, m_LabelConfigTypes, m_LabelValue, this);
m_PresentConfigsListview.Refresh();
m_NonPresentConfigsListview.Refresh();
}
void OnEnable()
{
m_UxmlPath = m_UxmlDir + "AddToConfigWindow.uxml";

void CheckInclusionInConfigs(List<string> configGuids, List<Type> configTypes, string label, AddToConfigWindow window)
{
m_ConfigsContainingLabel.Clear();
m_ConfigsNotContainingLabel.Clear();
var methodInfo = asset.GetType().GetMethod("DoesLabelMatchAnyEntries");
var methodInfo = asset.GetType().GetMethod(IdLabelConfig.DoesLabelMatchAnEntryName);
if (methodInfo == null)
continue;

}
}
public T Cast<T>(object o)
public static List<Type> FindAllSubTypes(Type superType)
return (T) o;
}
List<Type> FindAllRelevant()
{
Type superType = typeof(LabelConfig<>);
}
bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != null && toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur) {
return true;
bool IsSubclassOfRawGeneric(Type generic, Type toCheck) {
while (toCheck != null && toCheck != typeof(object)) {
var cur = toCheck.IsGenericType ? toCheck.GetGenericTypeDefinition() : toCheck;
if (generic == cur) {
return true;
}
toCheck = toCheck.BaseType;
toCheck = toCheck.BaseType;
return false;
return false;
}
}

private VisualElement m_Root;
private Button m_RemoveButton;
private ObjectField m_ConfigObjectField;
public ConfigElementLabelPresent(string targetLabel)
public ConfigElementLabelPresent(AddToConfigWindow window, string targetLabel)
m_ConfigObjectField = this.Q<ObjectField>("config-object");
m_ConfigObjectField.v\alue = m_LabelConfig;
m_ConfigObjectField.objectType = typeof(ScriptableObject);
this.MarkDirtyRepaint();
m_RemoveButton.text = "Remove Label";
//var methodInfo = m_LabelConfig.GetType().GetMethod("DoesLabelMatchAnyEntries");
if (m_LabelConfig is IdLabelConfig idLabelConfig)
var methodInfo = m_LabelConfig.GetType().GetMethod(IdLabelConfig.RemoveLabelName);
if (methodInfo != null)
idLabelConfig.RemoveLabel(targetLabel);
object[] parametersArray = new object[1];
parametersArray[0] = targetLabel;
methodInfo.Invoke(m_LabelConfig, parametersArray);
EditorUtility.SetDirty(m_LabelConfig);
window.RefreshLists();
}
}

private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private VisualElement m_Root;
private Button m_AddButton;
private ObjectField m_ConfigObjectField;
public Label m_Label;
public ScriptableObject m_LabelConfig;
public ConfigElementLabelNotPresent(AddToConfigWindow window, string targetLabel)
{
m_UxmlPath = m_UxmlDir + "ConfigElementLabelPresent.uxml";
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree(this);
m_Label = this.Q<Label>("config-name");
m_AddButton = this.Q<Button>("remove-from-config-button");
m_AddButton.text = "Add Label";
m_AddButton.clicked += () =>
{
var methodInfo = m_LabelConfig.GetType().GetMethod(IdLabelConfig.AddLabelName);
if (methodInfo != null)
{
object[] parametersArray = new object[1];
parametersArray[0] = targetLabel;
methodInfo.Invoke(m_LabelConfig, parametersArray);
EditorUtility.SetDirty(m_LabelConfig);
window.RefreshLists();
}
};
}
}
}

8
com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs


m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
m_LabelsList.onReorderCallbackWithDetails += OnReorder;
if (autoAssign)
{
AutoAssignIds();
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
}
void OnReorder(ReorderableList list, int oldIndex, int newIndex)

207
com.unity.perception/Editor/GroundTruth/LabelingEditor.cs


#define ENABLED
#if ENABLED
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics.Contracts;
using System.Linq;

private ListView m_CurrentLabelsListView;
private ListView m_SuggestLabelsListView_FromName;
private ListView m_SuggestLabelsListView_FromPath;
private ListView m_SuggestLabelsListView_FromDB;
private ScrollView m_LabelConfigsScrollView;
private Button m_AddButton;

private List<string> m_CommonLabels = new List<string>(); //labels that are common between all selected Labeling objects (for multi editing)
public List<string> CommonLabels => m_CommonLabels;
public Dictionary<int, int> CommonsIndexToLabelsIndex => m_CommonsIndexToLabelsIndex;
private List<Type> m_LabelConfigTypes = new List<Type>();
private List<ScriptableObject> m_AllLabelConfigsInProject = new List<ScriptableObject>();
m_LabelConfigTypes = AddToConfigWindow.FindAllSubTypes(typeof(LabelConfig<>));
var mySerializedObject = new SerializedObject(serializedObject.targetObjects[0]);
m_SerializedLabelsArray = mySerializedObject.FindProperty("labels");

m_CurrentLabelsListView = m_Root.Q<ListView>("current-labels-listview");
m_SuggestLabelsListView_FromName = m_Root.Q<ListView>("suggested-labels-name-listview");
m_SuggestLabelsListView_FromPath = m_Root.Q<ListView>("suggested-labels-path-listview");
m_SuggestLabelsListView_FromDB = m_Root.Q<ListView>("suggested-labels-db-listview");
m_LabelConfigsScrollView = m_Root.Q<ScrollView>("label-configs-scrollview");
m_AddButton = m_Root.Q<Button>("add-label");

}
}
RefreshData();
//RefreshUi();
};
}

result.UnionWith(labeling.labels);
}
}
return result;
}
string FindNewLabelValue(HashSet<string> labels)

m_SerializedLabelsArray = mySerializedObject.FindProperty("labels");
RefreshCommonLabels();
RefreshSuggestedLabelLists();
SetupListViews();
RefreshLabelConfigsList();
SetupListsAndScrollers();
void RefreshLabelConfigsList()
{
List<string> labelConfigGuids = new List<string>();
foreach (var type in m_LabelConfigTypes)
{
labelConfigGuids.AddRange(AssetDatabase.FindAssets("t:"+type.Name));
}
m_AllLabelConfigsInProject.Clear();
foreach (var configGuid in labelConfigGuids)
{
var asset = AssetDatabase.LoadAssetAtPath<ScriptableObject>(AssetDatabase.GUIDToAssetPath(configGuid));
m_AllLabelConfigsInProject.Add(asset);
}
}
public void RemoveAddedLabelsFromSuggestedLists()
{
m_SuggestedLabelsBasedOnName.RemoveAll(s => m_CommonLabels.Contains(s));

RemoveAddedLabelsFromSuggestedLists();
Debug.Log("list update, source list count is:" + m_SuggestedLabelsBasedOnPath.Count);
//Debug.Log("list update, source list count is:" + m_SuggestedLabelsBasedOnPath.Count);
}
public void RefreshData()

SetupCurrentLabelsListView();
}
void SetupListViews()
void SetupListsAndScrollers()
//Add labels from Label Configs present in project
SetupLabelConfigsScrollView();
}
void RefreshCommonLabels()

m_CurrentLabelsListView.itemHeight = itemHeight;
m_CurrentLabelsListView.itemsSource = m_CommonLabels;
m_CurrentLabelsListView.selectionType = SelectionType.None;
//m_CurrentLabelsListView.reorderable = true;
//m_CurrentLabelsListView.selectionType = SelectionType.Multiple;

labelsListView.itemHeight = itemHeight;
labelsListView.selectionType = SelectionType.None;
}
// void SetupSuggestedBasedOnPathLabelsListView()
// {
// m_SuggestLabelsListView_FromPath.itemsSource = m_SuggestedLabelsBasedOnPath;
//
// VisualElement MakeItem() => new SuggestedLabelElement(this);
//
// void BindItem(VisualElement e, int i)
// {
// if (e is SuggestedLabelElement suggestedLabel)
// {
// Debug.Log("bind, source list count is:" + m_SuggestedLabelsBasedOnPath.Count);
// suggestedLabel.m_Label.text = m_SuggestedLabelsBasedOnPath[i];
// }
// }
//
// const int itemHeight = 32;
//
// m_SuggestLabelsListView_FromPath.bindItem = BindItem;
// m_SuggestLabelsListView_FromPath.makeItem = MakeItem;
// m_SuggestLabelsListView_FromPath.itemHeight = itemHeight;
// m_SuggestLabelsListView_FromPath.selectionType = SelectionType.None;
// }
//
// void SetupSuggestedBasedOnNameLabelsListView()
// {
// VisualElement MakeItem() => new SuggestedLabelElement(this);
//
// void BindItem(VisualElement e, int i)
// {
// if (e is SuggestedLabelElement suggestedLabel)
// {
// suggestedLabel.m_Label.text = m_SuggestedLabelsBasedOnName[i];
// }
// }
//
// const int itemHeight = 32;
//
// m_SuggestLabelsListView_FromName.bindItem = BindItem;
// m_SuggestLabelsListView_FromName.makeItem = MakeItem;
// m_SuggestLabelsListView_FromName.itemHeight = itemHeight;
// m_SuggestLabelsListView_FromName.itemsSource = m_SuggestedLabelsBasedOnName;
// m_SuggestLabelsListView_FromName.selectionType = SelectionType.None;
// }
void SetupLabelConfigsScrollView()
{
m_LabelConfigsScrollView.Clear();
foreach (var config in m_AllLabelConfigsInProject)
{
VisualElement configElement = new LabelConfigElement(this, config);
m_LabelConfigsScrollView.Add(configElement);
}
}
}

m_RemoveButton = this.Q<Button>("remove-button");
m_AddToConfigButton = this.Q<Button>("add-to-config-button");
// List<string> m_CommonLabels = new List<string>();
//
// m_CommonLabels.Clear();
// var firstTarget = editor.targets[0] as Labeling;
// m_CommonLabels.AddRange(firstTarget.labels);
//
// foreach (var obj in editor.targets)
// {
// m_CommonLabels = m_CommonLabels.Intersect(((Labeling) obj).labels).ToList();
// }
// Dictionary<int, int> commonsIndexToLabelsIndex = new Dictionary<int, int>();
//
// for (int i = 0; i < labeling.labels.Count; i++)
// {
// string label = labeling.labels[i];
//
// for (int j = 0; j < editor.CommonLabels.Count; j++)
// {
// string label2 = editor.CommonLabels[j];
//
// if (String.Equals(label, label2) && !commonsIndexToLabelsIndex.ContainsKey(j))
// {
// commonsIndexToLabelsIndex.Add(j, i);
// }
// }
// }
var indexToModifyInTargetLabelList =
labeling.labels.IndexOf(editor.CommonLabels[m_IndexInList]);

m_RemoveButton.clicked += () =>
{
// labelsArrayProperty.DeleteArrayElementAtIndex(m_IndexInList);
// serializedLabelingObject.ApplyModifiedProperties();
// editor.UpdateSuggestedLabelLists();
// editor.RefreshUi();
// listView.Refresh();
List<string> m_CommonLabels = new List<string>();
m_CommonLabels.Clear();

}
editor.serializedObject.SetIsDifferentCacheDirty();
editor.RefreshData();
//editor.RefreshUi();
};
}

editor.RefreshData();
//editor.RefreshUi();
};
}
}
class LabelConfigElement : VisualElement
{
private string m_UxmlDir = "Packages/com.unity.perception/Editor/GroundTruth/Uxml/";
private string m_UxmlPath;
private bool m_Collapsed = true;
private ListView m_LabelsListView;
private Label m_ConfigName;
private VisualElement m_CollapseToggle;
//private Toggle m_HiddenCollapsedToggle;
public LabelConfigElement(LabelingEditor editor, ScriptableObject config)
{
m_UxmlPath = m_UxmlDir + "ConfigElementForAddingLabelsFrom.uxml";
AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(m_UxmlPath).CloneTree(this);
m_LabelsListView = this.Q<ListView>("label-config-contents-listview");
m_ConfigName = this.Q<Label>("config-name");
m_ConfigName.text = config.name;
m_CollapseToggle = this.Q<VisualElement>("collapse-toggle");
var propertyInfo = config.GetType().GetProperty(IdLabelConfig.publicLabelEntriesFieldName);
if (propertyInfo != null)
{
var objectList = (IEnumerable) propertyInfo.GetValue(config);
var labelEntryList = objectList.Cast<ILabelEntry>().ToList();
var labelList = labelEntryList.Select(entry => entry.label).ToList();
m_LabelsListView.itemsSource = labelList;
VisualElement MakeItem()
{
var element = new SuggestedLabelElement(editor);
element.AddToClassList("label_add_from_config");
return element;
}
void BindItem(VisualElement e, int i)
{
if (e is SuggestedLabelElement suggestedLabel)
{
suggestedLabel.m_Label.text = labelList[i];
}
}
const int itemHeight = 27;
m_LabelsListView.bindItem = BindItem;
m_LabelsListView.makeItem = MakeItem;
m_LabelsListView.itemHeight = itemHeight;
m_LabelsListView.selectionType = SelectionType.None;
}
m_CollapseToggle.RegisterCallback<MouseUpEvent>(evt =>
{
m_Collapsed = !m_Collapsed;
ApplyCollapseState();
});
ApplyCollapseState();
}
void ApplyCollapseState()
{
if (m_Collapsed)
{
m_CollapseToggle.AddToClassList("collapsed-toggle-state");
m_LabelsListView.AddToClassList("collapsed");
}
else
{
m_CollapseToggle.RemoveFromClassList("collapsed-toggle-state");
m_LabelsListView.RemoveFromClassList("collapsed");
}
}
}
}

12
com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor.cs


ReorderableList m_LabelsList;
const float k_Margin = 5f;
static List<Color> s_StandardColors = new List<Color>()
{
Color.blue,
Color.green,
Color.red,
Color.white,
Color.yellow,
Color.gray
};
public void OnEnable()
{
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(IdLabelConfig.labelEntriesFieldName), true, false, true, true);

void OnAdd(ReorderableList list)
{
var standardColorList = new List<Color>(s_StandardColors);
var standardColorList = new List<Color>(SemanticSegmentationLabelConfig.s_StandardColors);
for (int i = 0; i < list.serializedProperty.arraySize; i++)
{
var item = list.serializedProperty.GetArrayElementAtIndex(i);

71
com.unity.perception/Editor/GroundTruth/Uss/Styles.uss


align-content: center;
}
.suggested-label {
margin: 3px 6px 3px 6px;
flex-direction: row;
align-content: center;
padding: 2px;
padding-left: 5px;
border-radius: 4px;
background-color: #313131;
}
.labeling__added-label-value {
width: auto;
flex-grow: 1;

border-width: 0px;
}
.suggested-label {
flex-direction: row;
align-content: center;
margin: 4px 6px 0 6px;
padding: 2px;
padding-left: 5px;
border-radius: 4px;
background-color: #313131;
}
.labeling__suggested-label-value {
width: auto;
flex-grow: 1;

border-radius: 4px;
margin: 6px;
padding: 6px;
padding-top: 6px;
border-bottom-right-radius: 0;
}

padding-top: 5px;
}
.outer-container-in-window{
padding: 7px;
}
.inner-container {
margin-top: 10px;
border-radius: 10px;

align-content: flex-start;
}
.inner-container .depth2{
background-color: rgb(60, 60, 60);
}
.labeling__add-to-list-button {
align-self: flex-end;
background-color: #505050;

margin-left: 3px;
width: 10px;
height: 10px;
align-self: center;
.collapsed .collapse-toggle {
.collapsed-toggle-state{
.randomization__collapse-toggle:hover {
.collapse-toggle:hover {
.label-config-header{
background-color: #272727;
flex-direction: row;
}
.suggested-label.label_add_from_config{
margin: 3px 3px 3px 3px;
}
.label-config-add-from{
border-radius: 4px;
margin: 2px 0 2px 0;
background-color: #272727;
padding: 3px 1px 3px 1px;
}
.labeling__config-name-label {
color: rgb(220, 220, 220);
width: auto;
flex-grow: 1;
align-self: center;
padding: 4px;
}
.collapsed {
display: none;
}
.config-label-present{
flex-direction: row;
align-content: center;
border-radius: 4px;
margin: 3px;
background-color: #272727;
}

10
com.unity.perception/Editor/GroundTruth/Uxml/AddToConfigWindow.uxml


<UXML xmlns="UnityEngine.UIElements">
<BindableElement class="outer-container" name="outer-container">
<BindableElement class="outer-container-in-window" name="outer-container">
<Label text="Currently Present In:"/>
<ListView name="current-configs-listview" class="labeling__configs-listview" style="height:150px"/>
<Label text="Other Label Configs in Project:"/>
<ListView name="other-configs-listview" class="labeling__configs-listview"/>
<Label text="Currently Present In:" style="margin: 10px 0 4px 0"/>
<ListView name="current-configs-listview" class="labeling__configs-listview" style="height:150px; margin: 0"/>
<Label text="Other Label Configs in Project:" style="margin: 10px 0 4px 0"/>
<ListView name="other-configs-listview" class="labeling__configs-listview" style="height:150px; margin: 0"/>
</BindableElement>
</UXML>

10
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementForAddingLabelsFrom.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-label">
<Toggle name="collapsed-state" style="display:none"/>
<VisualElement class="label-config-add-from">
<Label name="config-name" class="labeling__config-name-label"/>
<ListView name="label-config-contents-listview"/>
<VisualElement class="label-config-header">
<VisualElement name="collapse-toggle" class="collapse-toggle"/>
<Label name="config-name" class="labeling__config-name-label"/>
</VisualElement>
<ListView name="label-config-contents-listview" class="labeling__label-listview" style="height: 300px"/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/ConfigElementLabelPresent.uxml


<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements">
<VisualElement>
<VisualElement class="config-label-present">
<editor:ObjectField name="config-object"/>
<Label name="config-name" class="labeling__config-name-label"/>
<Button name="remove-from-config-button" class="labeling__addremove-config-button"/>
</VisualElement>

9
com.unity.perception/Editor/GroundTruth/Uxml/Labeling_Main.uxml


<Style src="../Uss/Styles.uss"/>
<VisualElement name="added-labels" class="inner-container" style="margin-top:0px">
<Label text="Added Labels" name="added-labels-title" class="title-label"/>
<ListView name="current-labels-listview" class="labeling__label-listview"/>
<ListView name="current-labels-listview" class="labeling__label-listview" style="margin-top: 5px"/>
<VisualElement name="from-label-configs" class="inner-container">
<VisualElement name="from-label-configs" class="inner-container depth2">
<VisualElement name="collapse" class="collapse-toggle collapsed"/>
<Toggle name="enabled"/>
<VisualElement name="suggested-labels" class="inner-container">
<VisualElement name="suggested-labels" class="inner-container depth2">
<Label text="Other Suggested Labels" class="title-label"/>
<VisualElement name="suggested-labels-from-name" style="padding-top: 10px;">
<Label text="Based on asset name" class="subtitle-label"/>

</VisualElement>
</VisualElement>
</VisualElement>
</BindableElement>
</UXML>

22
com.unity.perception/Runtime/GroundTruth/Labeling/IdLabelConfig.cs


return TryGetLabelEntryFromInstanceId(instanceId, out labelEntry, out var _);
}
public override void AddLabel(string labelToAdd)
{
m_LabelEntries.Add(new IdLabelEntry
{
label = labelToAdd
});
if (autoAssignIds)
{
AutoAssignIds();
}
}
AutoAssignIds();
var size = base.labelEntries.Count;
var size = m_LabelEntries.Count;
if (size == 0)
return;

//m_LabelEntries[i].id = nextId;
var labelEntry = m_LabelEntries[i];
labelEntry.id = nextId;
m_LabelEntries[i] = labelEntry;
nextId++;
}
}

34
com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs


[SerializeField]
protected List<T> m_LabelEntries = new List<T>();
/// <summary>
/// Name of the public accessor for the list of label entries, used for reflection purposes.
/// </summary>
public const string publicLabelEntriesFieldName = nameof(labelEntries);
/// <summary>
/// A sequence of <see cref="ILabelEntry"/> which defines the labels relevant for this configuration and their values.
/// </summary>

return TryGetMatchingConfigurationEntry(labeling, out labelEntry, out int _);
}
public bool DoesLabelMatchAnyEntries(string label)
/// <summary>
/// Name of the function that checks whether a string label is included in the config, used for reflection purposes.
/// </summary>
public const string DoesLabelMatchAnEntryName = nameof(DoesLabelMatchAnEntry);
public bool DoesLabelMatchAnEntry(string label)
/// <summary>
/// Name of label removal function with string argument, used for reflection purposes
/// </summary>
public const string RemoveLabelName = nameof(RemoveLabel);
/// <summary>
/// Remove the label entries matching the given string
/// </summary>
/// <param name="label"></param>
}
/// <summary>
/// Name of label adding function with string argument, used for reflection purposes
/// </summary>
public const string AddLabelName = nameof(AddLabel);
/// <summary>
/// To add a label carrying the given string
/// </summary>
/// <param name="label"></param>
public virtual void AddLabel(string label)
{
}
/// <summary>

34
com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationLabelConfig.cs


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
namespace UnityEngine.Perception.GroundTruth {
/// <summary>

public class SemanticSegmentationLabelConfig : LabelConfig<SemanticSegmentationLabelEntry>
{
public static readonly List<Color> s_StandardColors = new List<Color>()
{
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<Color>(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);
}
}
/// <summary>

7
com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml


<UXML xmlns="UnityEngine.UIElements">
<VisualElement class="added-config">
<Style src="../Uss/Styles.uss"/>
<Label name="config-name" class="labeling__config-name"/>
<Button name="remove-from-config-button" class="labeling__config-addremove-button"/>
</VisualElement>
</UXML>

3
com.unity.perception/Editor/GroundTruth/Uxml/AddedConfigElement.uxml.meta


fileFormatVersion: 2
guid: 4883c5b4a100149dabfe7832ca5a5ca6
timeCreated: 1603311500
正在加载...
取消
保存