浏览代码

addressed PR feedback

/main
Steven Leal 4 年前
当前提交
8c18953c
共有 7 个文件被更改,包括 15 次插入13 次删除
  1. 2
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/BackgroundObjectPlacementRandomizer.cs
  2. 2
      com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs
  3. 4
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs
  4. 4
      com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs
  5. 6
      com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs
  6. 6
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs
  7. 4
      com.unity.perception/Tests/Runtime/Randomization/ScenarioTests.cs

2
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/BackgroundObjectPlacementRandomizer.cs


for (var i = 0; i < layerCount; i++)
{
var seed = scenario.NextRandomSeed();
var seed = scenario.NextRandomState();
var placementSamples = PoissonDiskSampling.GenerateSamples(
placementArea.x, placementArea.y, separationDistance, seed);
var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f;

2
com.unity.perception/Runtime/Randomization/Randomizers/RandomizerExamples/Randomizers/ForegroundObjectPlacementRandomizer.cs


if (m_SpawnedObjects == null)
m_SpawnedObjects = new List<GameObject>();
var seed = scenario.NextRandomSeed();
var seed = scenario.NextRandomState();
var placementSamples = PoissonDiskSampling.GenerateSamples(
placementArea.x, placementArea.y, separationDistance, seed);
var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f;

4
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/NormalSampler.cs


/// <returns>The generated sample</returns>
public float Sample()
{
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomSeed());
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomState());
return SamplerUtility.TruncatedNormalSample(
rng.NextFloat(), range.minimum, range.maximum, mean, standardDeviation);
}

max = range.maximum,
mean = mean,
standardDeviation = standardDeviation,
seed = ScenarioBase.activeScenario.NextRandomSeed(),
seed = ScenarioBase.activeScenario.NextRandomState(),
samples = samples
}.ScheduleBatch(sampleCount, SamplerUtility.samplingBatchSize);
return samples;

4
com.unity.perception/Runtime/Randomization/Samplers/SamplerTypes/UniformSampler.cs


/// <returns>The generated sample</returns>
public float Sample()
{
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomSeed());
var rng = new Unity.Mathematics.Random(ScenarioBase.activeScenario.NextRandomState());
return math.lerp(range.minimum, range.maximum, rng.NextFloat());
}

{
min = range.minimum,
max = range.maximum,
seed = ScenarioBase.activeScenario.NextRandomSeed(),
seed = ScenarioBase.activeScenario.NextRandomState(),
samples = samples
}.ScheduleBatch(sampleCount, SamplerUtility.samplingBatchSize);
return samples;

6
com.unity.perception/Runtime/Randomization/Samplers/SamplerUtility.cs


/// <param name="x">Unsigned integer to hash</param>
/// <returns>The calculated hash value</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static uint Hash32(uint x) {
public static uint Hash32(uint x)
{
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = ((x >> 16) ^ x) * 0x45d9f3b;
x = (x >> 16) ^ x;

/// <param name="x">64-bit value to hash</param>
/// <returns>The calculated hash value</returns>
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ulong Hash64(ulong x) {
public static ulong Hash64(ulong x)
{
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9ul;
x = (x ^ (x >> 27)) * 0x94d049bb133111ebul;
x ^= (x >> 31);

6
com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs


}
/// <summary>
/// Generates and returns a new random seed
/// Generates a new random state and overwrites the old random state with the newly generated value
/// <returns>The generated random seed</returns>
public uint NextRandomSeed()
/// <returns>The newly generated random state</returns>
public uint NextRandomState()
{
m_RandomState = SamplerUtility.Hash32(m_RandomState);
return m_RandomState;

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


yield return CreateNewScenario(3, 1);
var seeds = new uint[3];
for (var i = 0; i < 3; i++)
seeds[i] = m_Scenario.NextRandomSeed();
seeds[i] = m_Scenario.NextRandomState();
Assert.AreNotEqual(seeds[i], m_Scenario.NextRandomSeed());
Assert.AreNotEqual(seeds[i], m_Scenario.NextRandomState());
}
PerceptionCamera SetupPerceptionCamera()

正在加载...
取消
保存