浏览代码

updated and fixed the categorical parameter UI

/main
Steven Leal 4 年前
当前提交
2b29bed1
共有 5 个文件被更改,包括 70 次插入14 次删除
  1. 5
      com.unity.perception/CHANGELOG.md
  2. 12
      com.unity.perception/Editor/Randomization/VisualElements/Parameter/CategoricalOptionElement.cs
  3. 44
      com.unity.perception/Editor/Randomization/VisualElements/Parameter/ParameterElement.cs
  4. 12
      com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs
  5. 11
      com.unity.perception/Tests/Runtime/Randomization/ParameterTests/CategoricalParameterTests.cs

5
com.unity.perception/CHANGELOG.md


* Can now render intermediate frames between captures.
* Capture can now be triggered manually using a function call, instead of automatic capturing on a schedule.
Categorical Parameters will now validate that their specified options are unique at runtime
### Changed
Randomizers now access their parent scenario through the static activeScenario property

Semantic Segmentation Labeler now places data in folders with randomized filenames
The uniform toggle on Categorical Parameters will now reset the parameter's probability weights to be uniform
### Deprecated

Semantic Segmentation Labeler now produces output in the proper form for distributed data generation on Unity Simulation by placing output in randomized directory names
Texture Randomizer is now compatible with HDRP
Categorical Parameters no longer error when deleting items from long options lists
## [0.6.0-preview.1] - 2020-12-03

12
com.unity.perception/Editor/Randomization/VisualElements/Parameter/CategoricalOptionElement.cs


{
m_CategoryProperty = categoryProperty;
m_ProbabilitiesProperty = probabilitiesProperty;
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/Parameter/CategoricalOptionElement.uxml");
template.CloneTree(this);
// Reset this categorical item's UI
Clear();
var template = AssetDatabase.LoadAssetAtPath<VisualTreeAsset>(
$"{StaticData.uxmlDir}/Parameter/CategoricalOptionElement.uxml");
template.CloneTree(this);
m_Index = i;
var indexLabel = this.Q<Label>("index-label");
indexLabel.text = $"[{m_Index}]";

option.BindProperty(optionProperty);
// Remove the redundant element label to save space
var label = option.Q<Label>();
label.parent.Remove(label);

44
com.unity.perception/Editor/Randomization/VisualElements/Parameter/ParameterElement.cs


{
probabilitiesProperty.arraySize++;
optionsProperty.arraySize++;
var newOption = optionsProperty.GetArrayElementAtIndex(optionsProperty.arraySize - 1);
switch (newOption.propertyType)
{
case SerializedPropertyType.ObjectReference:
newOption.objectReferenceValue = null;
break;
case SerializedPropertyType.String:
newOption.stringValue = string.Empty;
break;
}
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
listView.itemsSource = categoricalParameter.probabilities;
listView.Refresh();

var uniformToggle = template.Q<Toggle>("uniform");
var uniformProperty = m_SerializedProperty.FindPropertyRelative("uniform");
uniformToggle.BindProperty(uniformProperty);
void ToggleProbabilityFields(bool toggle)
{
if (toggle)
listView.AddToClassList("collapsed");
else
listView.RemoveFromClassList("collapsed");
}
ToggleProbabilityFields(uniformToggle.value);
if (uniformToggle.value)
listView.AddToClassList("collapsed");
else
listView.RemoveFromClassList("collapsed");
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt => ToggleProbabilityFields(evt.newValue));
{
uniformToggle.RegisterCallback<ChangeEvent<bool>>(evt =>
{
listView.ToggleInClassList("collapsed");
if (!evt.newValue)
return;
var numOptions = optionsProperty.arraySize;
var uniformProbabilityValue = 1f / numOptions;
for (var i = 0; i < numOptions; i++)
{
var probability = probabilitiesProperty.GetArrayElementAtIndex(i);
probability.floatValue = uniformProbabilityValue;
}
m_SerializedProperty.serializedObject.ApplyModifiedProperties();
listView.itemsSource = categoricalParameter.probabilities;
listView.Refresh();
});
}
m_PropertiesContainer.Add(template);
}

12
com.unity.perception/Runtime/Randomization/Parameters/CategoricalParameter.cs


public override void Validate()
{
base.Validate();
// Check for a non-zero amount of specified categories
// Check for duplicate categories
var uniqueCategories = new HashSet<T>();
foreach (var option in m_Categories)
if (uniqueCategories.Contains(option))
throw new ParameterValidationException("Duplicate categories");
else
uniqueCategories.Add(option);
// Check if the number of specified probabilities is different from the number of listed categories
if (!uniform)
{
if (probabilities.Count != m_Categories.Count)

11
com.unity.perception/Tests/Runtime/Randomization/ParameterTests/CategoricalParameterTests.cs


using NUnit.Framework;
using UnityEngine;
using UnityEngine.Experimental.Perception.Editor;
using UnityEngine.Experimental.Perception.Randomization.Parameters;
namespace RandomizationTests.ParameterTests

public void NegativeProbabilities()
{
var parameter = new StringParameter();
var optionsArray = new [] { ("option1", 1f), ("option1", -1f) };
var optionsArray = new [] { ("option1", 1f), ("option2", -1f) };
{
var parameter = new StringParameter();
var optionsArray = new [] { ("option1", 0f), ("option2", 0f) };
Assert.Throws<ParameterValidationException>(() => parameter.SetOptions(optionsArray));
}
[Test]
public void DuplicateCategoriesTest()
{
var parameter = new StringParameter();
var optionsArray = new [] { ("option1", 0f), ("option1", 0f) };

正在加载...
取消
保存