浏览代码

Adding tests for visualization init and destroy.

/aisv647_visualizations
Jon Hogins 4 年前
当前提交
3424bf30
共有 7 个文件被更改,包括 175 次插入110 次删除
  1. 3
      .gitignore
  2. 69
      TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity
  3. 5
      TestProjects/PerceptionURP/ProjectSettings/EditorBuildSettings.asset
  4. 101
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  5. 96
      com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs
  6. 3
      com.unity.perception/Tests/Runtime/GroundTruthTests/VisualizationTests.cs.meta
  7. 8
      com.unity.perception/Runtime/GroundTruth/Labelers/Resources.meta

3
.gitignore


**/.bin
CodeCoverage
/.download
/TestProjects/PerceptionURP/Build
**/Build/**
**/Builds/**

69
TestProjects/PerceptionURP/Assets/Scenes/SampleScene.unity


m_TrainingDataDestination: TrainingData
m_LightProbeSampleCountMultiplier: 4
m_LightingDataAsset: {fileID: 0}
m_UseShadowmask: 1
m_UseShadowmask: 0
--- !u!196 &4
NavMeshSettings:
serializedVersion: 2

debug:
m_Flags: 0
m_NavMeshData: {fileID: 0}
--- !u!1 &334211407
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 334211410}
- component: {fileID: 334211409}
- component: {fileID: 334211408}
m_Layer: 0
m_Name: EventSystem
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!114 &334211408
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 334211407}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 4f231c4fb786f3946a6b90b886c48677, type: 3}
m_Name:
m_EditorClassIdentifier:
m_HorizontalAxis: Horizontal
m_VerticalAxis: Vertical
m_SubmitButton: Submit
m_CancelButton: Cancel
m_InputActionsPerSecond: 10
m_RepeatDelay: 0.5
m_ForceModuleActive: 0
--- !u!114 &334211409
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 334211407}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 76c392e42b5098c458856cdf6ecaaaa1, type: 3}
m_Name:
m_EditorClassIdentifier:
m_FirstSelected: {fileID: 0}
m_sendNavigationEvents: 1
m_DragThreshold: 10
--- !u!4 &334211410
Transform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 334211407}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 0}
m_RootOrder: 5
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!1 &411238276
GameObject:
m_ObjectHideFlags: 0

- id: 1
- id: 2
- id: 3
m_VisualizationEnabled: 1
references:
version: 1
00000000:

5
TestProjects/PerceptionURP/ProjectSettings/EditorBuildSettings.asset


EditorBuildSettings:
m_ObjectHideFlags: 0
serializedVersion: 2
m_Scenes: []
m_Scenes:
- enabled: 1
path: Assets/Scenes/SampleScene.unity
guid: 9fc0d4010bbf28b4594072e72b8655ab
m_configObjects: {}

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


List<CameraLabeler> m_Labelers = new List<CameraLabeler>();
Dictionary<string, object> m_PersistentSensorData = new Dictionary<string, object>();
#if URP_PRESENT
internal List<ScriptableRenderPass> passes = new List<ScriptableRenderPass>();
public void AddScriptableRenderPass(ScriptableRenderPass pass)
{
passes.Add(pass);
}
#endif
private static Camera visualizationCamera;
static PerceptionCamera s_VisualizedPerceptionCamera;
static GameObject s_VisualizationCamera;
static GameObject s_VisualizationCanvas;
/// <summary>
/// Should the labeling visualization routines run for this camera. This will only

bool m_VisualizationBlocked = false;
[SerializeField]
public bool visualizationEnabled
{
public bool visualizationEnabled
{
return m_VisualizationEnabled;
return !m_VisualizationBlocked && m_VisualizationEnabled;
}
set
{
if (m_VisualizationBlocked)
return;
m_VisualizationEnabled = value;
}
}

public SensorHandle SensorHandle { get; private set; }
static ProfilerMarker s_WriteFrame = new ProfilerMarker("Write Frame (PerceptionCamera)");
static ProfilerMarker s_FlipY = new ProfilerMarker("Flip Y (PerceptionCamera)");
#if URP_PRESENT
internal List<ScriptableRenderPass> passes = new List<ScriptableRenderPass>();
public void AddScriptableRenderPass(ScriptableRenderPass pass)
{
passes.Add(pass);
}
#endif
/// <summary>
/// Add a data object which will be added to the dataset with each capture. Overrides existing sensor data associated with the given key.

SensorHandle = DatasetCapture.RegisterSensor(ego, "camera", description, period, startTime);
SetupInstanceSegmentation();
var cam = GetComponent<Camera>();
SetupVisualizationCamera(cam);
DatasetCapture.SimulationEnding += OnSimulationEnding;
}
void OnEnable()
{
DatasetCapture.SimulationEnding += OnSimulationEnding;
}
void Start()

SetupVisualizationCamera(cam);
if (visualizationCamera != null)
if (s_VisualizedPerceptionCamera != null)
Debug.LogWarning("Currently only support one visualization camera at a time. User should switch main camera in project hierarchy to visualize a different camera");
Debug.LogWarning($"Currently only one PerceptionCamera may be visualized at a time. Disabling visualization on {gameObject.name}.");
m_VisualizationBlocked = true;
s_VisualizedPerceptionCamera = this;
// set up to render to a render texture instead of the screen
var visualizationRenderTexture = new RenderTexture(new RenderTextureDescriptor(cam.pixelWidth, cam.pixelHeight, UnityEngine.Experimental.Rendering.GraphicsFormat.R8G8B8A8_UNorm, 8));

// set up to not render the UI layer
s_VisualizationCamera = new GameObject(cam.name + "_VisualizationCamera");
var visualizationCameraComponent = s_VisualizationCamera.AddComponent<Camera>();
cam.cullingMask = ~layerMask;
visualizationCameraComponent.cullingMask = layerMask;
var camera2 = new GameObject(cam.name + "_VisualizationCamera");
visualizationCamera = camera2.AddComponent<Camera>();
visualizationCamera.cullingMask = layerMask;
s_VisualizationCanvas = new GameObject(cam.name + "_VisualizationCanvas");
var canvas = s_VisualizationCanvas.AddComponent<Canvas>();
s_VisualizationCanvas.AddComponent<CanvasScaler>();
s_VisualizationCanvas.AddComponent<GraphicRaycaster>();
var canvasObj = new GameObject(cam.name + "_VisualizationImageUI");
var canvas = canvasObj.AddComponent<Canvas>();
canvasObj.AddComponent<CanvasScaler>();
canvasObj.AddComponent<GraphicRaycaster>();
canvas.renderMode = RenderMode.ScreenSpaceOverlay;
canvas.renderMode = RenderMode.ScreenSpaceCamera;
canvas.worldCamera = visualizationCameraComponent;
var imgObj = new GameObject(cam.name + "_Image");
var img = imgObj.AddComponent<RawImage>();

rect.SetParent(canvasObj.transform, false);
rect.SetParent(s_VisualizationCanvas.transform, false);
rect.anchorMin = new Vector2(0, 0);
rect.anchorMax = new Vector2(1, 1);
rect.pivot = new Vector2(0.5f, 0.5f);

using (s_WriteFrame.Auto())
{
var dataColorBuffer = (byte[])r.data.colorBuffer;
byte[] encodedData;
using (s_EncodeAndSave.Auto())
{

return camera.targetTexture != null || hdAdditionalCameraData.flipYMode == HDAdditionalCameraData.FlipYMode.ForceFlipY || camera.cameraType == CameraType.Game;
#elif URP_PRESENT
return (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Direct3D11 || SystemInfo.graphicsDeviceType == GraphicsDeviceType.Metal) &&
(camera.targetTexture != null || camera.cameraType == CameraType.Game);
(camera.targetTexture == null && camera.cameraType == CameraType.Game);
#else
return false;
#endif

void OnDisable()
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
RenderPipelineManager.endCameraRendering -= CheckForRendererFeature;
}
void OnDestroy()
{
RenderPipelineManager.beginCameraRendering -= OnBeginCameraRendering;
CleanupVisualization();
}
void CleanupVisualization()
{
if (s_VisualizedPerceptionCamera == this)
{
Destroy(s_VisualizationCamera);
Destroy(s_VisualizationCanvas);
s_VisualizedPerceptionCamera = null;
s_VisualizationCamera = null;
s_VisualizationCanvas = null;
}
}
/// <summary>

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


using System.Collections;
using System.Text.RegularExpressions;
using NUnit.Framework;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.TestTools;
namespace GroundTruthTests
{
[TestFixture]
public class VisualizationTests : GroundTruthTestBase
{
[Test]
public void VisualizedCamera_SetsUpCanvasAndSecondCamera()
{
var object1 = new GameObject();
object1.name = nameof(VisualizedCamera_SetsUpCanvasAndSecondCamera);
object1.SetActive(false);
var camera = object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);
Assert.IsNotNull(camera.targetTexture);
Assert.IsNotNull(GameObject.Find(nameof(VisualizedCamera_SetsUpCanvasAndSecondCamera) + "_VisualizationCamera"));
Assert.IsNotNull(GameObject.Find(nameof(VisualizedCamera_SetsUpCanvasAndSecondCamera) + "_VisualizationCanvas"));
}
[Test]
public void TwoCamerasVisualizing_CausesWarningAndDisablesVisualization()
{
var object1 = new GameObject();
object1.name = nameof(TwoCamerasVisualizing_CausesWarningAndDisablesVisualization);
object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
AddTestObjectForCleanup(object1);
var object2 = new GameObject();
object2.SetActive(false);
object2.name = nameof(TwoCamerasVisualizing_CausesWarningAndDisablesVisualization) + "2";
object2.AddComponent<Camera>();
var perceptionCamera2 = object2.AddComponent<PerceptionCamera>();
perceptionCamera2.visualizationEnabled = true;
AddTestObjectForCleanup(object2);
object1.SetActive(true);
LogAssert.Expect(LogType.Warning, $"Currently only one PerceptionCamera may be visualized at a time. Disabling visualization on {nameof(TwoCamerasVisualizing_CausesWarningAndDisablesVisualization)}2.");
object2.SetActive(true);
}
[UnityTest]
public IEnumerator DestroyCamera_RemovesVisualization()
{
var object1 = new GameObject();
object1.name = nameof(DestroyCamera_RemovesVisualization);
object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);
Assert.IsNotNull(GameObject.Find(nameof(DestroyCamera_RemovesVisualization) + "_VisualizationCamera"));
Object.DestroyImmediate(object1);
//wait a frame to allow objects destroyed via Destroy() to be cleaned up
yield return null;
Assert.IsNull(GameObject.Find(nameof(DestroyCamera_RemovesVisualization) + "_VisualizationCamera"));
}
[Test]
public void DestroyAndRecreateCamera_ProperlyVisualizes()
{
var object1 = new GameObject();
object1.name = nameof(DestroyAndRecreateCamera_ProperlyVisualizes);
object1.SetActive(false);
object1.AddComponent<Camera>();
var perceptionCamera1 = object1.AddComponent<PerceptionCamera>();
perceptionCamera1.visualizationEnabled = true;
object1.SetActive(true);
AddTestObjectForCleanup(object1);
Object.DestroyImmediate(object1);
var object2 = new GameObject();
object2.name = nameof(DestroyAndRecreateCamera_ProperlyVisualizes) + "2";
object2.SetActive(false);
var camera2 = object2.AddComponent<Camera>();
var perceptionCamera2 = object2.AddComponent<PerceptionCamera>();
perceptionCamera2.visualizationEnabled = true;
object2.SetActive(true);
AddTestObjectForCleanup(object2);
Assert.IsNotNull(camera2.targetTexture);
Assert.IsNotNull(GameObject.Find(nameof(DestroyAndRecreateCamera_ProperlyVisualizes) + "2_VisualizationCamera"));
}
}
}

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


fileFormatVersion: 2
guid: 2bac8a8673454861a0532ef0a7ee968f
timeCreated: 1596035114

8
com.unity.perception/Runtime/GroundTruth/Labelers/Resources.meta


fileFormatVersion: 2
guid: 3be4f06c14c9249b1889791b25cb15f4
folderAsset: yes
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存