浏览代码

Fixing issue with resizing buffers

/keypoint_self_occlusion
Jon Hogins 3 年前
当前提交
64327524
共有 3 个文件被更改,包括 47 次插入24 次删除
  1. 6
      com.unity.perception/Runtime/GroundTruth/Labelers/KeypointLabeler.cs
  2. 46
      com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs
  3. 19
      com.unity.perception/Tests/Runtime/GroundTruthTests/TestHelper.cs

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


private void SetupDepthCheckBuffers(int size)
{
var textureDimensions = TextureDimensions(size);
if (m_ResultsBuffer != null && textureDimensions.x * textureDimensions.y >= size)
if (m_ResultsBuffer != null &&
textureDimensions.x == m_ResultsBuffer.width &&
textureDimensions.y == m_ResultsBuffer.height)
return;

private static Vector2Int TextureDimensions(int keypointCount)
{
var width = Math.Max(k_MinTextureWidth, Mathf.NextPowerOfTwo((int)Math.Sqrt(keypointCount)));
var width = Math.Max(k_MinTextureWidth, Mathf.NextPowerOfTwo((int)Math.Ceiling(Math.Sqrt(keypointCount))));
var height = width;
var textureDimensions = new Vector2Int(width, height);

46
com.unity.perception/Tests/Runtime/GroundTruthTests/KeypointGroundTruthTests.cs


using System.Collections.Generic;
using System.Linq;
using NUnit.Framework;
using UnityEditorInternal;
using UnityEngine;
using UnityEngine.Perception.GroundTruth;
using UnityEngine.SceneManagement;

var labelerSelfOcclusionDistance = 0.5f;
var cam = SetupCamera(SetUpLabelConfig(), template, (frame, data) =>
{
incoming.Add(data);
incoming.Add(new List<KeypointLabeler.KeypointEntry>(data));
var count = new Vector2Int(50, 50);
Rect placementRect = new Rect(-2, -2, 4, 4);
for (int x = 0; x < count.x; x++)
void PlaceObjects(Rect rect, float z, Vector2Int count)
for (int y = 0; y < count.y; y++)
for (int x = 0; x < count.x; x++)
var cube = TestHelper.CreateLabeledCube(
scale: placementRect.width / count.x - .001f,
x: placementRect.width / count.x * x + placementRect.xMin,
y: placementRect.height / count.y * y + placementRect.yMin);
SetupCubeJoints(cube, template, .1f);
cube.SetActive(true);
AddTestObjectForCleanup(cube);
for (int y = 0; y < count.y; y++)
{
var cube = TestHelper.CreateLabeledCube(
scale: rect.width / count.x - .001f,
x: rect.width / count.x * x + rect.xMin,
y: rect.height / count.y * y + rect.yMin,
z: z);
SetupCubeJoints(cube, template, .1f);
cube.SetActive(true);
AddTestObjectForCleanup(cube);
}
PlaceObjects(new Rect(-2, -2, 2, 2), 0, new Vector2Int(10, 10));
//for (int i = 0; i < 10000; i++)
TestHelper.LoadAndStartRenderDocCapture();
yield return null;
PlaceObjects(new Rect(0, 0, 4, 4), 0, new Vector2Int(25, 25));
yield return null;
//force all async readbacks to complete

var testCase = incoming.Last();
Assert.AreEqual(count.x * count.y, testCase.Count);
TestHelper.EndCaptureRenderDoc();
Assert.AreEqual(2, incoming.Count);
Assert.AreEqual(10 * 10, incoming[0].Count);
Assert.AreEqual(10 * 10 + 25 * 25, incoming[1].Count);
foreach (var entry in testCase)
foreach (var entry in incoming[0].Concat(incoming[1]))
{
Assert.AreEqual(9, entry.keypoints.Length);

19
com.unity.perception/Tests/Runtime/GroundTruthTests/TestHelper.cs


using System.Diagnostics;
using System.Text.RegularExpressions;
using Unity.Collections;
using UnityEditor;
using UnityEngine;
using UnityEngine.Experimental.Rendering;
using UnityEngine.Perception.GroundTruth;

static class TestHelper
{
#if UNITY_EDITOR
private static EditorWindow s_GameView;
#endif
public static GameObject CreateLabeledPlane(float scale = 10, string label = "label")
{
GameObject planeObject;

callback(data);
}
#if UNITY_EDITOR
public static void LoadAndStartRenderDocCapture(out UnityEditor.EditorWindow gameView)
[Conditional("UNITY_EDITOR")]
public static void LoadAndStartRenderDocCapture()
gameView = UnityEditor.EditorWindow.GetWindow(type);
UnityEditorInternal.RenderDoc.BeginCaptureRenderDoc(gameView);
s_GameView = UnityEditor.EditorWindow.GetWindow(type);
UnityEditorInternal.RenderDoc.BeginCaptureRenderDoc(s_GameView);
}
[Conditional("UNITY_EDITOR")]
public static void EndCaptureRenderDoc()
{
UnityEditorInternal.RenderDoc.EndCaptureRenderDoc(s_GameView);
#endif
public static string NormalizeJson(string json, bool normalizeFormatting = false)
{
if (normalizeFormatting)

正在加载...
取消
保存