浏览代码

Merge branch 'aisv647_visualizations' of https://github.com/Unity-Technologies/com.unity.perception into aisv647_visualizations

/aisv647_visualizations
Jon Hogins 4 年前
当前提交
1adf9d68
共有 5 个文件被更改,包括 95 次插入61 次删除
  1. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  2. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  3. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
  4. 70
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/ControlPanel.cs
  5. 72
      com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs

2
com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs


objectPool.Add(boundingBoxObject);
var rectTransform = (RectTransform)boundingBoxObject.transform;
rectTransform.localScale = Vector3.one;
rectTransform.parent = visualizationHolder.transform;
rectTransform.SetParent(visualizationHolder.transform);
}
if (!objectPool[i].activeSelf) objectPool[i].SetActive(true);

6
com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs


m_ClassCountValues = new ClassCountValue[entries.Count];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
if (visualize && vizEntries == null)
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
vizEntries = new List<string>();
}
for (var i = 0; i < entries.Count; i++)

6
com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs


m_VisiblePixelsValues = new RenderedObjectInfoValue[renderedObjectInfos.Length];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
if (visualize)
if (visualize && vizEntries == null)
if (vizEntries == null) vizEntries = new List<string>();
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
vizEntries = new List<string>();
}
for (var i = 0; i < renderedObjectInfos.Length; i++)

70
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/ControlPanel.cs


using System.Collections;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.Events;
using UnityEngine.UI;

/// </summary>
public class ControlPanel : MonoBehaviour
{
Dictionary<string, GameObject> controlMap = new Dictionary<string, GameObject>();
HashSet<GameObject> m_Controls = new HashSet<GameObject>();
/// Adds a new UI control to the control panel. If the panel already contains an elment with the
/// passed in name, the UI element will not be added and the method will return false. Also, all
/// UI elements must have a LayoutElement component and if they do not, this method will reject
/// the new element, and return false.
/// Retrieves a list of the current controls in the control panel.
/// </summary>
public List<GameObject> controls
{
get
{
return m_Controls.ToList<GameObject>();
}
}
/// <summary>
/// Adds a new UI control to the control panel. If the control cannot be added and the method will
/// return false. Also, all UI elements must have a LayoutElement component and if they do not,
/// this method will reject the new element, and return false.
public bool AddNewControl(string name, GameObject uiControl)
public bool AddNewControl(GameObject uiControl)
{
if (uiControl.GetComponent<RectTransform>() == null)
{

return false;
}
if (controlMap.ContainsKey(name))
if (m_Controls.Add(uiControl))
Debug.LogWarning("A control with the name: " + name + " has already been registered with the control panel.");
return false;
uiControl.transform.SetParent(this.transform, false);
return true;
controlMap[name] = uiControl;
uiControl.transform.SetParent(this.transform, false);
return true;
return false;
/// Removes the component with the passed in name from the control panel. Returns
/// Removes the passed in component from the control panel. Returns
/// The caller is responsible for destroying the control.
public bool RemoveControl(string name)
public bool RemoveControl(GameObject uiControl)
if (!controlMap.ContainsKey(name))
if (m_Controls.Remove(uiControl))
Debug.LogWarning(name + " does not exist in control panel, cannot remove.");
return false;
}
uiControl.transform.SetParent(null);
var control = controlMap[name];
controlMap.Remove(name);
control.transform.SetParent(null);
GameObject.Destroy(control.gameObject);
return true;
return true;
}
return false;
}
/// <summary>

/// </summary>
public GameObject AddToggleControl(string name, UnityAction<bool> listener)
{
if (controlMap.ContainsKey(name))
{
Debug.LogWarning("A control with the name: " + name + " has already been registered with the control panel.");
return null;
}
if (listener == null)
{
Debug.LogWarning("Adding toggle to control panel without a listener, nothing will respond to user's clicks");

toggle.GetComponentInChildren<Text>().text = name;
toggle.GetComponent<Toggle>().onValueChanged.AddListener(listener);
controlMap[name] = toggle;
m_Controls.Add(toggle);
return toggle;
}

/// </summary>
public GameObject AddSliderControl(string name, float defaultValue, UnityAction<float> listener)
{
if (controlMap.ContainsKey(name))
{
Debug.LogWarning("A control with the name: " + name + " has already been registered with the control panel.");
return null;
}
if (listener == null)
{
Debug.LogWarning("Adding slider to control panel without a listener, nothing will respond to user's interactions");

slider.value = defaultValue;
slider.onValueChanged.AddListener(listener);
controlMap[name] = gameObject;
m_Controls.Add(gameObject);
return gameObject;
}

72
com.unity.perception/Runtime/GroundTruth/Labelers/Visualization/HUDPanel.cs


namespace UnityEngine.Perception.GroundTruth
{
/// <summary>
/// Heads up display panel used to publish a key value pair on the screen.
/// Heads up display panel used to publish a key value pair on the screen. Items added to this need
/// to have their values updated every frame, or else, they will be determined to be stale and removed
/// from the view and re-used for a new entry.
Dictionary<string, KeyValuePanel> entries = new Dictionary<string, KeyValuePanel>();
Dictionary<string, (bool, KeyValuePanel)> entries = new Dictionary<string, (bool, KeyValuePanel)>();
Stack<KeyValuePanel> orphans = new Stack<KeyValuePanel>();
public GameObject contentPanel = null;
public ScrollRect scrollRect = null;
public Image img = null;

i.enabled = scrollRect.enabled;
}
}
}
// TODO object pooling
// Go through everyone that has not been updated and remove them and
// if they have been updated mark them dirty for next round
var keys = new List<string>(entries.Keys);
foreach (var key in keys)
{
var entry = entries[key];
if (!entry.Item1)
{
entry.Item2.gameObject.SetActive(false);
orphans.Push(entry.Item2);
}
else
{
entry.Item1 = false;
entries[key] = entry;
}
}
}
/// <summary>
/// Updates (or creates) an entry with the passed in key value pair

(bool, KeyValuePanel) val;
entries[key] = GameObject.Instantiate(Resources.Load<GameObject>("KeyValuePanel")).GetComponent<KeyValuePanel>();
entries[key].SetKey(key);
entries[key].transform.SetParent(contentPanel.transform, false);
if (orphans.Any())
{
val = (true, orphans.Pop());
val.Item2.gameObject.SetActive(true);
}
else
{
val = (true, GameObject.Instantiate(Resources.Load<GameObject>("KeyValuePanel")).GetComponent<KeyValuePanel>());
val.Item2.transform.SetParent(contentPanel.transform, false);
}
val.Item2.SetKey(key);
entries[key].SetValue(value);
else
{
val = entries[key];
val.Item1 = true;
}
val.Item2.SetValue(value);
entries[key] = val;
}
/// <summary>

{
if (entries.ContainsKey(key))
{
var pair = entries[key];
var entry = entries[key];
entry.Item2.gameObject.SetActive(false);
pair.transform.SetParent(null);
Destroy(pair.gameObject);
orphans.Push(entry.Item2);
/// Removes all of the list of keys from the HUD
/// Removes all of the passed in entries from the HUD
{
foreach (var k in keys) RemoveEntry(k);
}
/// <summary>
/// Removes all of the passed in entries from the HUD
/// </summary>
public void RemoveEntries(string[] keys)
{
foreach (var k in keys) RemoveEntry(k);
}
正在加载...
取消
保存