浏览代码

added generic seed generator apis to ScenarioBase

/main
Steven Leal 4 年前
当前提交
794ecb89
共有 4 个文件被更改,包括 36 次插入3 次删除
  1. 10
      com.unity.perception/Runtime/Randomization/Randomizers/AddRandomizerMenuAttribute.cs
  2. 2
      com.unity.perception/Runtime/Randomization/Randomizers/SampleRandomizers/Randomizers/BackgroundObjectPlacementRandomizer.cs
  3. 3
      com.unity.perception/Runtime/Randomization/Randomizers/SampleRandomizers/Randomizers/ForegroundObjectPlacementRandomizer.cs
  4. 24
      com.unity.perception/Runtime/Randomization/Scenarios/ScenarioBase.cs

10
com.unity.perception/Runtime/Randomization/Randomizers/AddRandomizerMenuAttribute.cs


namespace UnityEngine.Experimental.Perception.Randomization.Randomizers
{
/// <summary>
/// The AddRandomizerMenu attribute allows you to organize randomizers under different menu paths
/// </summary>
/// <summary>
/// The assigned randomizer menu path. Path directories should be separated using forward slash characters.
/// </summary>
/// <summary>
/// Add a randomizer to the AddRandomizerMenus
/// </summary>
/// <param name="menuPath">The assigned randomizer menu path</param>
public AddRandomizerMenuAttribute(string menuPath)
{
this.menuPath = menuPath;

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


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

3
com.unity.perception/Runtime/Randomization/Randomizers/SampleRandomizers/Randomizers/ForegroundObjectPlacementRandomizer.cs


using System;
using System.Collections.Generic;
using UnityEngine.Experimental.Perception.Randomization.Parameters;
using UnityEngine.Experimental.Perception.Randomization.Samplers;
namespace UnityEngine.Experimental.Perception.Randomization.Randomizers.SampleRandomizers
{

/// </summary>
protected override void OnIterationStart()
{
var seed = SamplerUtility.IterateSeed((uint)scenario.currentIteration, SamplerUtility.largePrime);
var seed = scenario.GenerateRandomSeed();
var placementSamples = PoissonDiskSampling.GenerateSamples(
placementArea.x, placementArea.y, separationDistance, seed);
var offset = new Vector3(placementArea.x, placementArea.y, 0f) * -0.5f;

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


using Unity.Simulation;
using UnityEngine;
using UnityEngine.Experimental.Perception.Randomization.Randomizers;
using UnityEngine.Experimental.Perception.Randomization.Samplers;
using UnityEngine.Perception.GroundTruth;
namespace UnityEngine.Experimental.Perception.Randomization.Scenarios

var randomizer = m_Randomizers[currentIndex];
m_Randomizers.RemoveAt(currentIndex);
m_Randomizers.Insert(nextIndex, randomizer);
}
/// <summary>
/// Generates a random seed by hashing the current scenario iteration with a given base random seed
/// </summary>
/// <param name="baseSeed">Used to offset the seed generator</param>
/// <returns>The generated random seed</returns>
public uint GenerateRandomSeed(uint baseSeed = SamplerUtility.largePrime)
{
var seed = SamplerUtility.IterateSeed((uint)currentIteration, baseSeed);
return SamplerUtility.IterateSeed((uint)currentIteration, seed);
}
/// <summary>
/// Generates a random seed by hashing three values together: an arbitrary iteration value,
/// the current scenario iteration, and a base random seed
/// </summary>
/// <param name="iteration">An offset value hashed inside the seed generator</param>
/// <param name="baseSeed">An offset value hashed inside the seed generator</param>
/// <returns>The generated random seed</returns>
public uint GenerateIterativeRandomSeed(int iteration, uint baseSeed = SamplerUtility.largePrime)
{
return SamplerUtility.IterateSeed((uint)iteration, baseSeed);
}
void ValidateParameters()

正在加载...
取消
保存