浏览代码

addressed PR feedback

/main
sleal-unity 4 年前
当前提交
df4ca74d
共有 4 个文件被更改,包括 12 次插入104 次删除
  1. 22
      com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs
  2. 1
      com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs
  3. 48
      com.unity.perception/Runtime/GroundTruth/SimulationState.cs
  4. 45
      com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs

22
com.unity.perception/Runtime/GroundTruth/Labeling/LabelManager.cs


/// <summary>
/// Registers a labeling component
/// </summary>
/// <param name="labeledObject">the component to register</param>
internal void Register(Labeling labeledObject)
/// <param name="labeling">the component to register</param>
internal void Register(Labeling labeling)
m_LabelsPendingRegistration.Add(labeledObject);
m_LabelsPendingRegistration.Add(labeling);
/// <param name="labeledObject">the component to unregister</param>
internal void Unregister(Labeling labeledObject)
/// <param name="labeling">the component to unregister</param>
internal void Unregister(Labeling labeling)
m_LabelsPendingRegistration.Remove(labeledObject);
m_RegisteredLabels.Remove(labeledObject);
m_LabelsPendingRegistration.Remove(labeling);
m_RegisteredLabels.Remove(labeling);
}
/// <summary>

/// <param name="labeledObject">the component to refresh</param>
internal void RefreshLabeling(Labeling labeledObject)
/// <param name="labeling">the component to refresh</param>
internal void RefreshLabeling(Labeling labeling)
m_RegisteredLabels.Remove(labeledObject);
m_LabelsPendingRegistration.Add(labeledObject);
m_RegisteredLabels.Remove(labeling);
m_LabelsPendingRegistration.Add(labeling);
}
/// <summary>

1
com.unity.perception/Runtime/GroundTruth/PerceptionUpdater.cs


/// PerceptionUpdater is automatically spawned when the player starts and is used to coordinate and maintain
/// static perception lifecycle behaviours.
/// </summary>
[DefaultExecutionOrder(5)]
class PerceptionUpdater : MonoBehaviour
{
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]

48
com.unity.perception/Runtime/GroundTruth/SimulationState.cs


ReportAsyncAnnotationResult(asyncAnnotation, filename, jArray);
}
[SuppressMessage("ReSharper", "PossibleInvalidOperationException")]
public class QuaternionConverter : JsonConverter<Quaternion>
{
public override void WriteJson(JsonWriter writer, Quaternion quaternion, JsonSerializer serializer)
{
writer.WriteStartArray();
writer.WriteValue(quaternion.x);
writer.WriteValue(quaternion.y);
writer.WriteValue(quaternion.z);
writer.WriteValue(quaternion.w);
writer.WriteEndArray();
}
public override Quaternion ReadJson(JsonReader reader, Type objectType, Quaternion existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var q = Quaternion.identity;
reader.Read(); // open [ token
q.x = (float)reader.ReadAsDecimal();
q.y = (float)reader.ReadAsDecimal();
q.z = (float)reader.ReadAsDecimal();
q.w = (float)reader.ReadAsDecimal();
reader.Read(); // close ] token
return q;
}
}
[SuppressMessage("ReSharper", "PossibleInvalidOperationException")]
public class Vector3Converter : JsonConverter<Vector3>
{
public override void WriteJson(JsonWriter writer, Vector3 value, JsonSerializer serializer)
{
writer.WriteStartArray();
writer.WriteValue(value.x);
writer.WriteValue(value.y);
writer.WriteValue(value.z);
writer.WriteEndArray();
}
public override Vector3 ReadJson(JsonReader reader, Type objectType, Vector3 existingValue, bool hasExistingValue, JsonSerializer serializer)
{
var outVector = new Vector3();
reader.Read(); // open array token
outVector.x = (float)reader.ReadAsDecimal();
outVector.y = (float)reader.ReadAsDecimal();
outVector.z = (float)reader.ReadAsDecimal();
reader.Read(); // close array token
return outVector;
}
}
public void ReportAsyncAnnotationResult<T>(AsyncAnnotation asyncAnnotation, string filename = null, IEnumerable<T> values = null)
{
JArray jArray = null;

45
com.unity.perception/Tests/Runtime/GroundTruthTests/DatasetJsonUtilityTests.cs


var jsonActual = DatasetJsonUtility.ToJToken(o).ToString();
Assert.AreEqual(TestHelper.NormalizeJson(jsonExpected), TestHelper.NormalizeJson(jsonActual));
}
[Test]
[TestCase(1,2,3)]
[TestCase(0,0,0)]
[TestCase(1000, 13000,700)]
[TestCase(1.23f, 4.56f, 7.89f)]
[TestCase(-100, 27.33f, -501.78f)]
public void Vector3Converter_ConvertsProperly(float x, float y, float z)
{
var converter = new SimulationState.Vector3Converter();
var testCase = new Vector3(x,y,z);
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var serializer = JsonSerializer.CreateDefault();
converter.WriteJson(new JsonTextWriter(sw), testCase, serializer);
var str = sb.ToString();
var sr = new StringReader(str);
var converted = converter.ReadJson(new JsonTextReader(sr), typeof(Vector3), Vector3.zero, false, serializer);
Assert.AreEqual(testCase, converted);
}
[Test]
[TestCase(1,2,3, 4)]
[TestCase(0,0,0, 1)]
[TestCase(0, 0.6502878f, 0, -0.7596879f)]
[TestCase(-0.3670137f, -0.1835069f, 0.1223379f, -0.9036922f)]
public void QuaternionConverter_ConvertsProperly(float x, float y, float z, float w)
{
var converter = new SimulationState.QuaternionConverter();
var testCase = new Quaternion(x, y, z, w);
var sb = new StringBuilder();
var sw = new StringWriter(sb);
var serializer = JsonSerializer.CreateDefault();
converter.WriteJson(new JsonTextWriter(sw), testCase, serializer);
var str = sb.ToString();
var sr = new StringReader(str);
var converted = converter.ReadJson(new JsonTextReader(sr), typeof(Quaternion), Quaternion.identity, false, serializer);
Assert.AreEqual(testCase, converted);
}
}
}
正在加载...
取消
保存