Steven Leal
4 年前
当前提交
a72ab433
共有 53 个文件被更改,包括 466 次插入 和 411 次删除
-
27com.unity.perception/Documentation~/Randomization/Parameters.md
-
22com.unity.perception/Documentation~/Randomization/Tutorial.md
-
32com.unity.perception/Editor/Randomization/CategoricalOptionElement.cs
-
5com.unity.perception/Editor/Randomization/ParameterConfigurationEditor.cs
-
24com.unity.perception/Editor/Randomization/ParameterElement.cs
-
2com.unity.perception/Editor/Randomization/RandomSeedField.cs
-
15com.unity.perception/Editor/Randomization/SamplerElement.cs
-
6com.unity.perception/Editor/Randomization/Uxml/CategoricalParameterTemplate.uxml
-
16com.unity.perception/Runtime/Randomization/Configuration/ParameterConfiguration.cs
-
86com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
-
4com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameterBase.cs
-
20com.unity.perception/Runtime/Randomization/Parameters/NumericParameter.cs
-
14com.unity.perception/Runtime/Randomization/Parameters/Parameter.cs
-
19com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/BooleanParameter.cs
-
48com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/ColorHsvaParameter.cs
-
15com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/FloatParameter.cs
-
17com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/IntegerParameter.cs
-
24com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector2Parameter.cs
-
28com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector3Parameter.cs
-
32com.unity.perception/Runtime/Randomization/Parameters/ParameterTypes/Vector4Parameter.cs
-
22com.unity.perception/Runtime/Randomization/Samplers/ISampler.cs
-
23com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/ConstantSampler.cs
-
39com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
-
38com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
-
12com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
-
2com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
-
16com.unity.perception/Tests/Runtime/Randomization/ParameterConfigurationTests.cs
-
6com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs
-
1com.unity.perception/Tests/Runtime/Randomization/TestValues.cs
-
9com.unity.perception/Tests/Runtime/Randomization/ParameterTests/CategoricalParameterTests.cs
-
10com.unity.perception/Tests/Runtime/Randomization/ParameterTests/GenericParameterTests.cs
-
7com.unity.perception/Tests/Runtime/Randomization/ParameterTests/StructParameterTests.cs
-
9com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs
-
3com.unity.perception/Runtime/Randomization/Samplers/IRandomRangedSampler.cs.meta
-
3com.unity.perception/Tests/Runtime/Randomization/ParameterTests.meta
-
3com.unity.perception/Tests/Runtime/Randomization/SamplerTests.meta
-
19com.unity.perception/Tests/Runtime/Randomization/SamplerTests/ConstantSamplerTests.cs
-
3com.unity.perception/Tests/Runtime/Randomization/SamplerTests/ConstantSamplerTests.cs.meta
-
14com.unity.perception/Tests/Runtime/Randomization/SamplerTests/NormalSamplerTests.cs
-
3com.unity.perception/Tests/Runtime/Randomization/SamplerTests/NormalSamplerTests.cs.meta
-
88com.unity.perception/Tests/Runtime/Randomization/SamplerTests/RangedSamplerTests.cs
-
14com.unity.perception/Tests/Runtime/Randomization/SamplerTests/UniformSamplerTests.cs
-
3com.unity.perception/Tests/Runtime/Randomization/SamplerTests/UniformSamplerTests.cs.meta
-
74com.unity.perception/Tests/Runtime/Randomization/SamplerTests.cs
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/CategoricalParameterTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/GenericParameterTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/Randomization/SamplerTests/RangedSamplerTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/StructParameterTests.cs.meta
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/CategoricalParameterTests.cs
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/GenericParameterTests.cs
-
0/com.unity.perception/Tests/Runtime/Randomization/ParameterTests/StructParameterTests.cs
|
|||
<UXML xmlns="UnityEngine.UIElements" xmlns:editor="UnityEditor.UIElements"> |
|||
<Toggle label="Uniform" name="uniform"/> |
|||
<editor:IntegerField label="Seed" name="seed"/> |
|||
<Button name="add-option" text="+ Add New Option" class="add-option-button"/> |
|||
<VisualElement style="flex-direction: row; justify-content: flex-end;"> |
|||
<Button name="add-option" text="Add New Option" class="add-option-button"/> |
|||
<Button name="clear-options" text="Clear Options" class="add-option-button"/> |
|||
</VisualElement> |
|||
</UXML> |
|
|||
namespace UnityEngine.Perception.Randomization.Samplers |
|||
{ |
|||
public interface IRandomRangedSampler |
|||
{ |
|||
uint baseSeed { get; set; } |
|||
uint state { get; set; } |
|||
FloatRange range { get; set; } |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 0f406605b3cb4d55b84b5955196c4911 |
|||
timeCreated: 1597419465 |
|
|||
fileFormatVersion: 2 |
|||
guid: d863105e5fa641dc893c604e733af0a0 |
|||
timeCreated: 1597426995 |
|
|||
fileFormatVersion: 2 |
|||
guid: f7c237ffad664023b7b65452426ea129 |
|||
timeCreated: 1597426125 |
|
|||
using NUnit.Framework; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace RandomizationTests.SamplerTests |
|||
{ |
|||
[TestFixture] |
|||
public class ConstantSamplerTests |
|||
{ |
|||
[Test] |
|||
public void ConstantSamplerGeneratesConstantValues() |
|||
{ |
|||
var constantSampler = new ConstantSampler(); |
|||
var samples = SamplerUtility.GenerateSamples(constantSampler, TestValues.TestSampleCount); |
|||
Assert.AreEqual(samples.Length, TestValues.TestSampleCount); |
|||
foreach (var sample in samples) |
|||
Assert.AreEqual(sample, constantSampler.value); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 1e969bf8899c46ce8bb9d5d1e32b3bb4 |
|||
timeCreated: 1597426149 |
|
|||
using NUnit.Framework; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace RandomizationTests.SamplerTests |
|||
{ |
|||
[TestFixture] |
|||
public class NormalSamplerTests : RangedSamplerTests<NormalSampler> |
|||
{ |
|||
public NormalSamplerTests() |
|||
{ |
|||
m_BaseSampler = new NormalSampler(-10f, 10f, 0f, 1f); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 8a4f678200ff4198af8d7a7f0c2e2766 |
|||
timeCreated: 1597426955 |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
using Unity.Jobs; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace RandomizationTests.SamplerTests |
|||
{ |
|||
public abstract class RangedSamplerTests<T> where T : struct, ISampler, IRandomRangedSampler |
|||
{ |
|||
const int k_TestSampleCount = 30; |
|||
protected T m_BaseSampler; |
|||
T m_Sampler; |
|||
|
|||
[SetUp] |
|||
public void Setup() |
|||
{ |
|||
m_Sampler = m_BaseSampler; |
|||
} |
|||
|
|||
[Test] |
|||
public void SamplesInRange() |
|||
{ |
|||
var samples = SamplerUtility.GenerateSamples(m_Sampler, k_TestSampleCount); |
|||
|
|||
Assert.AreEqual(samples.Length, k_TestSampleCount); |
|||
|
|||
foreach (var sample in samples) |
|||
{ |
|||
Assert.GreaterOrEqual(sample, m_Sampler.range.minimum); |
|||
Assert.LessOrEqual(sample, m_Sampler.range.maximum); |
|||
} |
|||
} |
|||
|
|||
[Test] |
|||
public void NativeSamplesInRange() |
|||
{ |
|||
var samples = m_Sampler.Samples(k_TestSampleCount, out var handle); |
|||
handle.Complete(); |
|||
Assert.AreEqual(samples.Length, k_TestSampleCount); |
|||
foreach (var sample in samples) |
|||
{ |
|||
Assert.GreaterOrEqual(sample, m_Sampler.range.minimum); |
|||
Assert.LessOrEqual(sample, m_Sampler.range.maximum); |
|||
} |
|||
samples.Dispose(); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConsecutiveSamplesChangesState() |
|||
{ |
|||
var state0 = m_Sampler.state; |
|||
m_Sampler.Sample(); |
|||
var state1 = m_Sampler.state; |
|||
m_Sampler.Sample(); |
|||
var state2 = m_Sampler.state; |
|||
|
|||
Assert.AreNotEqual(state0, state1); |
|||
Assert.AreNotEqual(state1, state2); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConsecutiveSampleBatchesChangesState() |
|||
{ |
|||
var state0 = m_Sampler.state; |
|||
var samples1 = m_Sampler.Samples(k_TestSampleCount, out var handle1); |
|||
var state1 = m_Sampler.state; |
|||
var samples2 = m_Sampler.Samples(k_TestSampleCount, out var handle2); |
|||
var state2 = m_Sampler.state; |
|||
|
|||
JobHandle.CombineDependencies(handle1, handle2).Complete(); |
|||
|
|||
Assert.AreEqual(samples1.Length, samples2.Length); |
|||
Assert.AreNotEqual(state0, state1); |
|||
Assert.AreNotEqual(state1, state2); |
|||
Assert.AreNotEqual(samples1[0], samples2[0]); |
|||
|
|||
samples1.Dispose(); |
|||
samples2.Dispose(); |
|||
} |
|||
|
|||
[Test] |
|||
public void InvalidRange() |
|||
{ |
|||
m_Sampler.range = new FloatRange(1, -1); |
|||
Assert.Throws<ArgumentException>(() => SamplerUtility.ValidateRange(m_Sampler)); |
|||
} |
|||
} |
|||
} |
|
|||
using NUnit.Framework; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace RandomizationTests.SamplerTests |
|||
{ |
|||
[TestFixture] |
|||
public class UniformSamplerTests : RangedSamplerTests<UniformSampler> |
|||
{ |
|||
public UniformSamplerTests() |
|||
{ |
|||
m_BaseSampler = new UniformSampler(0f, 1f); |
|||
} |
|||
} |
|||
} |
|
|||
fileFormatVersion: 2 |
|||
guid: 812592bf8d9f4243a88e209575bb6922 |
|||
timeCreated: 1597426939 |
|
|||
using System; |
|||
using NUnit.Framework; |
|||
using UnityEngine.Perception.Randomization.Samplers; |
|||
|
|||
namespace RandomizationTests |
|||
{ |
|||
[TestFixture] |
|||
public class SamplerTests |
|||
{ |
|||
const int k_ScenarioIteration = 0; |
|||
const int k_TestSampleCount = 30; |
|||
|
|||
static void SamplesInRange(ISampler sampler) |
|||
{ |
|||
var offsetSampler = sampler.CopyAndIterate(k_ScenarioIteration); |
|||
var samples = SamplerUtility.GenerateSamples(offsetSampler, k_TestSampleCount); |
|||
|
|||
Assert.AreEqual(samples.Length, k_TestSampleCount); |
|||
|
|||
foreach (var sample in samples) |
|||
{ |
|||
Assert.GreaterOrEqual(sample, sampler.range.minimum); |
|||
Assert.LessOrEqual(sample, sampler.range.maximum); |
|||
} |
|||
} |
|||
|
|||
static void NativeSamplesInRange(ISampler sampler) |
|||
{ |
|||
var samples = sampler.CopyAndIterate(k_ScenarioIteration).Samples(k_TestSampleCount, out var handle); |
|||
handle.Complete(); |
|||
Assert.AreEqual(samples.Length, k_TestSampleCount); |
|||
foreach (var sample in samples) |
|||
{ |
|||
Assert.GreaterOrEqual(sample, sampler.range.minimum); |
|||
Assert.LessOrEqual(sample, sampler.range.maximum); |
|||
} |
|||
samples.Dispose(); |
|||
} |
|||
|
|||
static void TestSamples(ISampler sampler) |
|||
{ |
|||
SamplesInRange(sampler); |
|||
NativeSamplesInRange(sampler); |
|||
} |
|||
|
|||
[Test] |
|||
public void UniformSamplesInRangeTest() |
|||
{ |
|||
TestSamples(new UniformSampler(0, 1)); |
|||
} |
|||
|
|||
[Test] |
|||
public void NormalSamplesInRangeTest() |
|||
{ |
|||
TestSamples(new NormalSampler(-1, 1, 0, 1)); |
|||
} |
|||
|
|||
[Test] |
|||
public void ConstantSamplerTest() |
|||
{ |
|||
var constantSampler = new ConstantSampler(); |
|||
var samples = SamplerUtility.GenerateSamples(constantSampler, k_TestSampleCount); |
|||
Assert.AreEqual(samples.Length, k_TestSampleCount); |
|||
foreach (var sample in samples) |
|||
Assert.AreEqual(sample, constantSampler.value); |
|||
} |
|||
|
|||
[Test] |
|||
public void CatchInvalidSamplerRangeTest() |
|||
{ |
|||
Assert.Throws<ArgumentException>(() => SamplerUtility.ValidateRange(new FloatRange(1, -1))); |
|||
} |
|||
} |
|||
} |
撰写
预览
正在加载...
取消
保存
Reference in new issue