浏览代码

Sort of working enable/disable visualizations

/aisv647_visualizations
Jon Hogins 4 年前
当前提交
37bcc0b6
共有 9 个文件被更改,包括 68 次插入68 次删除
  1. 2
      com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs
  2. 7
      com.unity.perception/Runtime/GroundTruth/Labelers/BoundingBoxLabeler.cs
  3. 29
      com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs
  4. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/ObjectCountLabeler.cs
  5. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/RenderedObjectInfoLabeler.cs
  6. 2
      com.unity.perception/Runtime/GroundTruth/Labelers/SemanticSegmentationLabeler.cs
  7. 60
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  8. 12
      com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs
  9. 12
      com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs.meta

2
com.unity.perception/Editor/GroundTruth/PerceptionCameraEditor.cs


EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.description)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.period)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.startTime)));
EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(perceptionCamera.showVisualizations)));
serializedObject.ApplyModifiedProperties();
//EditorGUILayout.PropertyField(serializedObject.FindProperty(nameof(PerceptionCamera.labelers)));
m_LabelersList.DoLayoutList();

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


if (!CaptureOptions.useAsyncReadbackIfSupported && frameCount != Time.frameCount)
Debug.LogWarning("Not on current frame: " + frameCount + "(" + Time.frameCount + ")");
if (perceptionCamera.visualizationEnabled && visualizationEnabled)
if (visualizationEnabled)
{
Visualize();
}

var boundingBoxObject = GameObject.Instantiate(Resources.Load<GameObject>("BoundingBoxPrefab"));
objectPool.Add(boundingBoxObject);
var rectTransform = (RectTransform)boundingBoxObject.transform;
rectTransform.localScale = Vector3.one;
rectTransform.SetParent(visualizationHolder.transform);
rectTransform.SetParent(visualizationHolder.transform, false);
}
if (!objectPool[i].activeSelf) objectPool[i].SetActive(true);

var rectTrans = objectPool[i].transform as RectTransform;
rectTrans.localScale = Vector3.one;
rectTrans.localPosition = Vector3.zero;
rectTrans.anchoredPosition = new Vector2(boxVal.x, -boxVal.y);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal, boxVal.width);
rectTrans.SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, boxVal.height);

29
com.unity.perception/Runtime/GroundTruth/Labelers/CameraLabeler.cs


internal void InternalSetup() => Setup();
internal void InternalPopulateVisualizationPanel(GameObject panel) => PopulateVisualizationPanel(controlPanel);
internal void InternalVisualizerActiveStateChanged(bool enabled) => OnVisualizerEnabledChanged(enabled);
internal bool InternalVisualizationEnabled
{
get => visualizationEnabled;
set => visualizationEnabled = value;
}
private bool m_VisualizationEnabled = false;
private bool m_ShowVisualizations = false;
/// <summary>
/// Turns on/off the labeler's realtime visualization capability. If a labeler does not support realtime

{
get
{
return supportsVisualization && m_VisualizationEnabled;
return supportsVisualization && m_ShowVisualizations;
}
set
{

if (value != m_VisualizationEnabled)
if (value != m_ShowVisualizations)
m_VisualizationEnabled = value;
m_ShowVisualizations = value;
if (m_VisualizationEnabled)
activeVisualizers++;
else
activeVisualizers--;
if (activeVisualizers > 0)
CaptureOptions.useAsyncReadbackIfSupported = false;
else
CaptureOptions.useAsyncReadbackIfSupported = true;
OnVisualizerEnabledChanged(m_VisualizationEnabled);
OnVisualizerEnabledChanged(m_ShowVisualizations);
}
}
}

if (supportsVisualization && visualizationCanvas != null)
{
m_VisualizationEnabled = true;
m_ShowVisualizations = true;
InitVisualizationUI();
}
}

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


if (m_ClassCountValues == null || m_ClassCountValues.Length != entries.Count)
m_ClassCountValues = new ClassCountValue[entries.Count];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
bool visualize = visualizationEnabled;
if (visualize && vizEntries == null)
{
vizEntries = new List<string>();

classCountAsyncMetric.ReportValues(m_ClassCountValues);
}
}
/// <inheritdoc/>
protected override void PopulateVisualizationPanel(ControlPanel panel)
{

{
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
}
}
}
}

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


if (m_VisiblePixelsValues == null || m_VisiblePixelsValues.Length != renderedObjectInfos.Length)
m_VisiblePixelsValues = new RenderedObjectInfoValue[renderedObjectInfos.Length];
bool visualize = visualizationEnabled && perceptionCamera.visualizationEnabled;
bool visualize = visualizationEnabled;
if (visualize && vizEntries == null)
{
vizEntries = new List<string>();

}
}
bool TryGetLabelEntryFromInstanceId(uint instanceId, out IdLabelEntry labelEntry)
{

{
hudPanel.RemoveEntries(vizEntries);
vizEntries.Clear();
}
}
}
}
}

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


var asyncRequest = Manager.Instance.CreateRequest<AsyncRequest<AsyncSemanticSegmentationWrite>>();
if (visualizationEnabled && perceptionCamera.visualizationEnabled)
if (visualizationEnabled)
VisualizeSegmentationTexture(data, targetTexture);
imageReadback?.Invoke(new ImageReadbackEventArgs

60
com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs


using UnityEngine.Experimental.Rendering;
using UnityEngine.Profiling;
using UnityEngine.Rendering;
using UnityEngine.Serialization;
using UnityEngine.UI;
#if HDRP_PRESENT
using UnityEngine.Rendering.HighDefinition;

static GameObject s_VisualizationCamera;
static GameObject s_VisualizationCanvas;
/// <summary>
/// Should the labeling visualization routines run for this camera. This will only
/// be set to false if there is more than one camera in the scene, and this is
/// not considered the active camera.
/// </summary>
bool m_VisualizationAllowed = false;
bool m_VisualizationEnabled = true;
public bool visualizationEnabled
{
get
{
return m_VisualizationAllowed && m_VisualizationEnabled;
}
set
{
if (m_VisualizationAllowed)
return;
m_VisualizationEnabled = value;
}
}
public bool showVisualizations = true;
/// <summary>
/// The <see cref="SensorHandle"/> associated with this camera. Use this to report additional annotations and metrics at runtime.

}
#endif
VisualizationCanvas visualizationCanvas => m_VisualizationAllowed ? s_VisualizationCanvas.GetComponent<VisualizationCanvas>() : null;
VisualizationCanvas visualizationCanvas => isVisualizedPerceptionCamera ? s_VisualizationCanvas.GetComponent<VisualizationCanvas>() : null;
bool isVisualizedPerceptionCamera => s_VisualizedPerceptionCamera == this;
/// <summary>
/// Add a data object which will be added to the dataset with each capture. Overrides existing sensor data associated with the given key.

cam.enabled = false;
}
bool SetupVisualizationCamera(Camera cam)
void SetupVisualizationCamera(Camera cam)
if (s_VisualizedPerceptionCamera != null)
var visualizationAllowed = s_VisualizedPerceptionCamera == null;
if (!visualizationAllowed && showVisualizations)
m_VisualizationEnabled = false;
return false;
showVisualizations = false;
return;
if (!showVisualizations)
return;
m_VisualizationAllowed = true;
s_VisualizedPerceptionCamera = this;
// set up to render to a render texture instead of the screen

rect.pivot = new Vector2(0.5f, 0.5f);
rect.offsetMax = Vector2.zero;
rect.offsetMin = Vector2.zero;
return true;
}
void CheckForRendererFeature(ScriptableRenderContext context, Camera camera)

labeler.InternalOnUpdate();
}
//disable async readback when visualizations are enabled to ensure data is read and visualized in the same frame
if (showVisualizations)
CaptureOptions.useAsyncReadbackIfSupported = false;
if (isVisualizedPerceptionCamera)
{
s_VisualizationCanvas.SetActive(showVisualizations);
}
if (SensorHandle.ShouldCaptureThisFrame) cam.Render();
if (showVisualizations)
{
cam.enabled = false;
if (SensorHandle.ShouldCaptureThisFrame) cam.Render();
}
else
cam.enabled = SensorHandle.ShouldCaptureThisFrame;
}
void OnValidate()

12
com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs


object1.SetActive(false);
var camera = object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
perceptionCamera1.showVisualizations = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);

object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
perceptionCamera1.showVisualizations = true;
AddTestObjectForCleanup(object1);
var object2 = new GameObject();

var perceptionCamera2 = object2.AddComponent<PerceptionCamera>();
perceptionCamera2.visualizationEnabled = true;
perceptionCamera2.showVisualizations = true;
AddTestObjectForCleanup(object2);
object1.SetActive(true);

object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
perceptionCamera1.showVisualizations = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);

object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
perceptionCamera1.showVisualizations = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);
Object.DestroyImmediate(object1);

object2.SetActive(false);
var camera2 = object2.AddComponent<Camera>();
var perceptionCamera2 = object2.AddComponent<PerceptionCamera>();
perceptionCamera2.visualizationEnabled = true;
perceptionCamera2.showVisualizations = true;
object2.SetActive(true);
AddTestObjectForCleanup(object2);

12
com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs.meta


fileFormatVersion: 2
fileFormatVersion: 2
timeCreated: 1596035114
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存