浏览代码

cleanup

/main
Mohsen Kamalzadeh 4 年前
当前提交
9feaf706
共有 10 个文件被更改,包括 2 次插入426 次删除
  1. 4
      com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs
  2. 5
      com.unity.perception/Editor/GroundTruth/LabelConfigEditor.cs
  3. 10
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs
  4. 32
      com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationLabelConfig.cs
  5. 127
      com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs
  6. 3
      com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs.meta
  7. 157
      com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs
  8. 3
      com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs.meta
  9. 84
      com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs
  10. 3
      com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs.meta

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


using System;
using System.Collections.Generic;
using System.Linq;
using Unity.Mathematics;
using UnityEditor.UIElements;
using UnityEngine;

RefreshAddedLabels();
m_LabelListView.Refresh();
RefreshListViewHeight();
//AssetDatabase.SaveAssets();
}
}

RefreshAddedLabels();
m_LabelListView.Refresh();
RefreshListViewHeight();
//AssetDatabase.SaveAssets();
}
}

5
com.unity.perception/Editor/GroundTruth/LabelConfigEditor.cs


using System.Collections.Generic;
using System.IO;
using System.Linq;
using Newtonsoft.Json.Linq;
using Newtonsoft.Json.Linq;
using UnityEditor.UIElements;
namespace UnityEditor.Perception.GroundTruth

m_Root.schedule.Execute(() => { m_LabelListView.ScrollToItem(-1); })
.StartingIn(
10); //to circumvent the delay in the listview's internal scrollview updating its geometry (when new items are added).
10); //to circumvent the delay in listview's internal scrollview updating its geometry (when new items are added).
}
protected void RefreshAddedLabels()

public int m_IndexInList;
protected SerializedProperty m_LabelsArray;
protected LabelConfigEditor<T> m_LabelConfigEditor;

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


using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditor;
using UnityEngine.Serialization;
namespace UnityEngine.Perception.GroundTruth

public bool DoesLabelMatchAnEntry(string label)
{
return m_LabelEntries.Any(entry => string.Equals(entry.label, label));
}
/// <summary>
/// Remove the label entries matching the given string
/// </summary>
/// <param name="label"></param>
public virtual void RemoveLabel(string label)
{
m_LabelEntries.RemoveAll(entry => String.Equals(entry.label, label));
}
/// <summary>

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


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

Color.yellow,
Color.gray
};
/// <summary>
/// Add a string to the list of label entries in this label configuration. The color for this entry will be
/// a unique color not previously present in the config.
/// </summary>
/// <param name="labelToAdd"></param>
public void AddLabel(string labelToAdd)
{
if (DoesLabelMatchAnEntry(labelToAdd))
return;
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>

127
com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs


//#define ENABLED
#if ENABLED
using Unity.Entities;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(Labeling)), CanEditMultipleObjects]
class LabelingEditor : Editor
{
ReorderableList m_LabelsList;
public void OnEnable()
{
m_LabelsList = new ReorderableList(serializedObject, serializedObject.FindProperty(nameof(Labeling.labels)), true, false, true, true);
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
m_LabelsList.onRemoveCallback += OnRemove;
m_LabelsList.onReorderCallbackWithDetails += OnReordered;
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
{
var value = labeling.labels[list.index];
foreach (var t in targets)
{
((Labeling)t).labels.Remove(value);
}
}
}
Labeling labeling => (Labeling)target;
void OnAdd(ReorderableList list)
{
foreach (var t in targets)
{
var castedTarget = ((Labeling)t);
castedTarget.labels.Add("");
EditorUtility.SetDirty(castedTarget);
}
}
void OnReordered(ReorderableList list, int oldIndex, int newIndex)
{
var label = labeling.labels[newIndex];
foreach (var t in targets)
{
var l = (Labeling)t;
if (this.labeling == l) continue;
ReorderLabels(l, label, newIndex);
}
}
static void ReorderLabels(Labeling labeling, string label, int newIndex)
{
if (labeling.labels.Contains(label))
{
labeling.labels.Remove(label);
if (newIndex < labeling.labels.Count)
labeling.labels.Insert(newIndex, label);
else
labeling.labels.Add(label);
}
}
static void ReplaceLabel(Labeling labeling, string oldLabel, string newLabel)
{
var idx = labeling.labels.IndexOf(oldLabel);
if (idx == -1) return;
labeling.labels[idx] = newLabel;
}
private void ReplaceLabel(int index, string newLabel)
{
labeling.labels[index] = newLabel;
}
void ReplaceLabelAll(int index, string currentLabel)
{
var oldLabel = labeling.labels[index];
ReplaceLabel(index, currentLabel);
foreach (var t in targets)
{
var l = (Labeling)t;
if (this.labeling == l) continue;
ReplaceLabel(l, oldLabel, currentLabel);
}
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.x, rect.y, rect.width, rect.height);
var value = EditorGUI.DelayedTextField(contentRect, labeling.labels[index]);
if (change.changed)
{
ReplaceLabelAll(index, value);
if (PrefabUtility.IsPartOfAnyPrefab(target))
{
EditorUtility.SetDirty(target);
}
}
}
}
public override void OnInspectorGUI()
{
m_LabelsList.DoLayoutList();
}
}
}
#endif

3
com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs.meta


fileFormatVersion: 2
guid: 2e725508a34c40a0938c8d891b371980
timeCreated: 1585933334

157
com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs


//#define ENABLED
#if ENABLED
using System;
using Unity.Mathematics;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(IdLabelConfig))]
class IdLabelConfigEditor : Editor
{
ReorderableList m_LabelsList;
const float k_Margin = 5f;
public void OnEnable()
{
m_LabelsList = new ReorderableList(this.serializedObject,
this.serializedObject.FindProperty(IdLabelConfig.labelEntriesFieldName), true, false, true, true);
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + k_Margin;
m_LabelsList.drawElementCallback = DrawElement;
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)
{
if (!autoAssign)
return;
AutoAssignIds();
}
void OnRemove(ReorderableList list)
{
if (list.index != -1)
list.serializedProperty.DeleteArrayElementAtIndex(list.index);
if (autoAssign)
AutoAssignIds();
this.serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void OnAdd(ReorderableList list)
{
int maxLabel = Int32.MinValue;
if (list.serializedProperty.arraySize == 0)
maxLabel = -1;
for (int i = 0; i < list.serializedProperty.arraySize; i++)
{
var item = list.serializedProperty.GetArrayElementAtIndex(i);
maxLabel = math.max(maxLabel, item.FindPropertyRelative(nameof(IdLabelEntry.id)).intValue);
}
var index = list.serializedProperty.arraySize;
list.serializedProperty.InsertArrayElementAtIndex(index);
var element = list.serializedProperty.GetArrayElementAtIndex(index);
var idProperty = element.FindPropertyRelative(nameof(IdLabelEntry.id));
idProperty.intValue = maxLabel + 1;
var labelProperty = element.FindPropertyRelative(nameof(IdLabelEntry.label));
labelProperty.stringValue = "";
if (autoAssign)
AutoAssignIds();
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
var element = m_LabelsList.serializedProperty.GetArrayElementAtIndex(index);
var idProperty = element.FindPropertyRelative(nameof(IdLabelEntry.id));
var labelProperty = element.FindPropertyRelative(nameof(IdLabelEntry.label));
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
using (new EditorGUI.DisabledScope(autoAssign))
{
var newLabel = EditorGUI.IntField(contentRect, nameof(IdLabelEntry.id), idProperty.intValue);
if (change.changed)
{
idProperty.intValue = newLabel;
if (autoAssign)
AutoAssignIds();
}
}
}
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newLabel = EditorGUI.TextField(contentRect, nameof(IdLabelEntry.label), labelProperty.stringValue);
if (change.changed)
{
labelProperty.stringValue = newLabel;
}
}
}
bool autoAssign => serializedObject.FindProperty(nameof(IdLabelConfig.autoAssignIds)).boolValue;
public override void OnInspectorGUI()
{
serializedObject.Update();
var autoAssignIdsProperty = serializedObject.FindProperty(nameof(IdLabelConfig.autoAssignIds));
using (var change = new EditorGUI.ChangeCheckScope())
{
EditorGUILayout.PropertyField(autoAssignIdsProperty, new GUIContent("Auto Assign IDs"));
if (change.changed && autoAssignIdsProperty.boolValue)
AutoAssignIds();
}
if (autoAssignIdsProperty.boolValue)
{
using (var change = new EditorGUI.ChangeCheckScope())
{
var startingLabelIdProperty = serializedObject.FindProperty(nameof(IdLabelConfig.startingLabelId));
EditorGUILayout.PropertyField(startingLabelIdProperty, new GUIContent("Starting Label ID"));
if (change.changed)
AutoAssignIds();
}
}
m_LabelsList.DoLayoutList();
this.serializedObject.ApplyModifiedProperties();
}
void AutoAssignIds()
{
var serializedProperty = serializedObject.FindProperty(IdLabelConfig.labelEntriesFieldName);
var size = serializedProperty.arraySize;
if (size == 0)
return;
var startingLabelId = (StartingLabelId)serializedObject.FindProperty(nameof(IdLabelConfig.startingLabelId)).enumValueIndex;
var nextId = startingLabelId == StartingLabelId.One ? 1 : 0;
for (int i = 0; i < size; i++)
{
serializedProperty.GetArrayElementAtIndex(i).FindPropertyRelative(nameof(IdLabelEntry.id)).intValue = nextId;
nextId++;
}
}
}
}
#endif

3
com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs.meta


fileFormatVersion: 2
guid: 910dd3186e1c4fad8eb6aca9b9ee0f48
timeCreated: 1585940009

84
com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs


//#define ENABLED
#if ENABLED
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using Random = UnityEngine.Random;
namespace UnityEditor.Perception.GroundTruth
{
[CustomEditor(typeof(SemanticSegmentationLabelConfig))]
class SemanticSegmentationLabelConfigEditor : Editor
{
ReorderableList m_LabelsList;
const float k_Margin = 5f;
public void OnEnable()
{
m_LabelsList = new ReorderableList(this.serializedObject, this.serializedObject.FindProperty(IdLabelConfig.labelEntriesFieldName), true, false, true, true);
m_LabelsList.elementHeight = EditorGUIUtility.singleLineHeight * 2 + k_Margin;
m_LabelsList.drawElementCallback = DrawElement;
m_LabelsList.onAddCallback += OnAdd;
}
void OnAdd(ReorderableList list)
{
var standardColorList = new List<Color>(SemanticSegmentationLabelConfig.s_StandardColors);
for (int i = 0; i < list.serializedProperty.arraySize; i++)
{
var item = list.serializedProperty.GetArrayElementAtIndex(i);
standardColorList.Remove(item.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.color)).colorValue);
}
var index = list.serializedProperty.arraySize;
list.serializedProperty.InsertArrayElementAtIndex(index);
var element = list.serializedProperty.GetArrayElementAtIndex(index);
var labelProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.label));
labelProperty.stringValue = "";
var colorProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.color));
if (standardColorList.Any())
colorProperty.colorValue = standardColorList.First();
else
colorProperty.colorValue = Random.ColorHSV(0, 1, .5f, 1, 1, 1);
serializedObject.ApplyModifiedProperties();
EditorUtility.SetDirty(target);
}
void DrawElement(Rect rect, int index, bool isactive, bool isfocused)
{
var element = m_LabelsList.serializedProperty.GetArrayElementAtIndex(index);
var colorProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.color));
var labelProperty = element.FindPropertyRelative(nameof(SemanticSegmentationLabelEntry.label));
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position, new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newLabel = EditorGUI.TextField(contentRect, nameof(SemanticSegmentationLabelEntry.label), labelProperty.stringValue);
if (change.changed)
{
labelProperty.stringValue = newLabel;
}
}
using (var change = new EditorGUI.ChangeCheckScope())
{
var contentRect = new Rect(rect.position + new Vector2(0, EditorGUIUtility.singleLineHeight), new Vector2(rect.width, EditorGUIUtility.singleLineHeight));
var newLabel = EditorGUI.ColorField(contentRect, nameof(SemanticSegmentationLabelEntry.color), colorProperty.colorValue);
if (change.changed)
{
colorProperty.colorValue = newLabel;
}
}
}
public override void OnInspectorGUI()
{
serializedObject.Update();
m_LabelsList.DoLayoutList();
this.serializedObject.ApplyModifiedProperties();
}
}
}
#endif

3
com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs.meta


fileFormatVersion: 2
guid: e8cb4fead5b34d41884c1c9a77308c72
timeCreated: 1593454492
正在加载...
取消
保存