浏览代码

update unit tests with new perception camera property captureFrameCount

/0.9.0.preview.1_staging
RuiyuZ 3 年前
当前提交
79ab5613
共有 5 个文件被更改,包括 37 次插入9 次删除
  1. 9
      com.unity.perception/Runtime/GroundTruth/PerceptionCamera.cs
  2. 2
      com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs
  3. 2
      com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs
  4. 27
      com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTests.cs
  5. 6
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs

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


static PerceptionCamera s_VisualizedPerceptionCamera;
/// <summary>
/// The number of capture-able frames that have been generated
/// </summary>
#if UNITY_EDITOR
public static int captureFrameCount => Time.frameCount - 2;
#else
public static int captureFrameCount => Time.frameCount - 1;
#endif
//TODO: Remove the Guid path when we have proper dataset merging in Unity Simulation and Thea
internal string rgbDirectory { get; } = $"RGB{Guid.NewGuid()}";
internal HUDPanel hudPanel;

2
com.unity.perception/Runtime/Randomization/Scenarios/PerceptionScenario.cs


MetricDefinition m_IterationMetricDefinition;
/// <inheritdoc/>
protected override bool isScenarioReadyToStart => Time.frameCount >= 1;
protected override bool isScenarioReadyToStart => PerceptionCamera.captureFrameCount >= 0;
/// <inheritdoc/>
protected override void OnAwake()

2
com.unity.perception/Runtime/Randomization/Scenarios/UnitySimulationScenario.cs


public abstract class UnitySimulationScenario<T> : PerceptionScenario<T>
where T : UnitySimulationScenarioConstants, new()
{
/// <inheritdoc/>
protected override bool isScenarioReadyToStart => !Application.isEditor || Configuration.Instance.IsSimulationRunningInCloud() || Time.frameCount > 1;
/// <inheritdoc/>
protected sealed override bool isScenarioComplete => currentIteration >= constants.totalIterations;

27
com.unity.perception/Tests/Runtime/Randomization/RandomizerTests/RandomizerTests.cs


using System.Collections;
using NUnit.Framework;
using RandomizationTests.ScenarioTests;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.Perception.Randomization.Randomizers;
using UnityEngine.Perception.Randomization.Scenarios;
using UnityEngine.TestTools;

}
// TODO: update this function once the perception camera doesn't skip the first frame
void CreateNewScenario(int totalIterations, int framesPerIteration)
IEnumerator CreateNewScenario(int totalIterations, int framesPerIteration, Randomizer[] randomizers = null)
if (randomizers != null)
{
foreach (var rnd in randomizers)
{
m_Scenario.AddRandomizer(rnd);
}
}
if (PerceptionCamera.captureFrameCount < 0)
{
yield return null;
}
}
[Test]

[UnityTest]
public IEnumerator OnUpdateExecutesEveryFrame()
{
CreateNewScenario(10, 1);
m_Scenario.AddRandomizer(new ExampleTransformRandomizer());
yield return CreateNewScenario(10, 1, new Randomizer[] { new ExampleTransformRandomizer() });
var transform = m_TestObject.transform;
var initialPosition = Vector3.zero;
transform.position = initialPosition;

[UnityTest]
public IEnumerator OnIterationStartExecutesEveryIteration()
{
CreateNewScenario(10, 2);
m_Scenario.AddRandomizer(new ExampleTransformRandomizer());
yield return CreateNewScenario(10, 2, new Randomizer[] { new ExampleTransformRandomizer() });
// Wait one frame so the next iteration can begin
yield return null;
yield return null;
Assert.AreNotEqual(initialRotation, transform.rotation);

6
com.unity.perception/Tests/Runtime/Randomization/ScenarioTests/ScenarioTests.cs


m_Scenario.AddRandomizer(rnd);
}
}
yield return null; // Skip first Update() frame
if (PerceptionCamera.captureFrameCount < 0)
{
yield return null;
}
}
[Test]

正在加载...
取消
保存