Mohsen Kamalzadeh
4 年前
当前提交
9feaf706
共有 10 个文件被更改,包括 2 次插入 和 426 次删除
-
4com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor.cs
-
5com.unity.perception/Editor/GroundTruth/LabelConfigEditor.cs
-
10com.unity.perception/Runtime/GroundTruth/Labeling/LabelConfig.cs
-
32com.unity.perception/Runtime/GroundTruth/Labeling/SemanticSegmentationLabelConfig.cs
-
127com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs
-
3com.unity.perception/Editor/GroundTruth/LabelingEditor_OLD.cs.meta
-
157com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs
-
3com.unity.perception/Editor/GroundTruth/IdLabelConfigEditor_OLD.cs.meta
-
84com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs
-
3com.unity.perception/Editor/GroundTruth/SemanticSegmentationLabelConfigEditor_OLD.cs.meta
|
|||
//#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
|
|
|||
fileFormatVersion: 2 |
|||
guid: 2e725508a34c40a0938c8d891b371980 |
|||
timeCreated: 1585933334 |
|
|||
//#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
|
|
|||
fileFormatVersion: 2 |
|||
guid: 910dd3186e1c4fad8eb6aca9b9ee0f48 |
|||
timeCreated: 1585940009 |
|
|||
//#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
|
|
|||
fileFormatVersion: 2 |
|||
guid: e8cb4fead5b34d41884c1c9a77308c72 |
|||
timeCreated: 1593454492 |
撰写
预览
正在加载...
取消
保存
Reference in new issue