using System.Text.RegularExpressions ;
using NUnit.Framework ;
using Unity.Mathematics ;
using UnityEditorInternal ;
using UnityEngine ;
using UnityEngine.Perception.GroundTruth ;
using UnityEngine.Perception.GroundTruth.DataModel ;
internal SimulationStateTestHelper ( )
{
DatasetCapture . Instance . automaticShutdown = false ;
m_State = DatasetCapture . Instance . currentSimulation ;
var bindingFlags = BindingFlags . NonPublic | BindingFlags . Instance ;
m_SequenceTimeOfNextCaptureMethod = m_State . GetType ( ) . GetMethod ( "GetSequenceTimeOfNextCapture" , bindingFlags ) ;
DatasetCapture . Instance . ResetSimulation ( ) ;
}
SensorDefinition CreateSensorDefinition ( string id , string modality , string def , int firstFrame , CaptureTriggerMode mode , float deltaTime , int framesBetween )
SensorDefinition CreateSensorDefinition ( string id , string modality , string def , int firstFrame , CaptureTriggerMode mode , float deltaTime , int framesBetween , bool manualSensorAffectSimulationTiming = false )
{
return new SensorDefinition ( id , modality , def )
{
framesBetweenCaptures = framesBetween
framesBetweenCaptures = framesBetween ,
manualSensorsAffectTiming = manualSensorAffectSimulationTiming
} ;
}
DatasetCapture . Instance . ResetSimulation ( ) ;
Assert . AreEqual ( 0 , Time . captureDeltaTime ) ;
}
#if fals e
#if tru e
[UnityTest]
public IEnumerator ShouldCaptureFlagsAndRenderTimesAreCorrectWithMultipleSensors ( )
{
//Third sensor is a manually triggered one. All it does in this test is affect delta times.
var simDeltaTime3 = 5 ;
var sensor3 = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam3" , "" , "" , 0 , CaptureTriggerMode . Manual , simDeltaTime3 , 0 ) ) ; // why is there a true on this one
var sensor3 = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam3" , "" , "" , 0 , CaptureTriggerMode . Manual , simDeltaTime3 , 0 , true ) ) ;
( float deltaTime , bool sensor1ShouldCapture , bool sensor2ShouldCapture , bool sensor3ShouldCapture ) [ ] samplesExpected =
{
[TestCase(235, 10, 2350, 2585, 2820, 3055, ExpectedResult = (IEnumerator)null)]
public IEnumerator SequenceTimeOfNextCapture_ReportsCorrectTime_VariedDeltaTimesAndStartFrames ( float simulationDeltaTime , int firstCaptureFrame , float firstCaptureTime , float secondCaptureTime , float thirdCaptureTime , float fourthCaptureTime )
{
var sensorHandle = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam" , "" , "" , firstCaptureFrame , CaptureTriggerMode . Scheduled , simulationDeltaTime , 0 ) ) ;
float [ ] sequenceTimesExpected =
Assert . AreEqual ( sequenceTimesExpected [ i ] , sequenceTimeActual , 0.0001f ) ;
yield return null ;
}
// DatasetCapture.Instance.ResetSimulation();
// var dcWatcher = new DatasetCapture.WaitUntilComplete();
// yield return dcWatcher;
#if false
#if true
var sensorHandle = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam" , "" , "" , 0 , CaptureTriggerMode . Manual , 0 , 0 ) ) ; // why is there supposed to be a falise at the end of this
var sensorHandle = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam" , "" , "" , 0 , CaptureTriggerMode . Manual , 0 , 0 , false ) ) ;
var framesToCaptureOn = new List < int > ( ) ;
var elapsed = Time . time - startTime ;
Assert . AreEqual ( elapsed , sequenceTimeActual , 0.0001f ) ;
}
if ( Time . frameCount > 1 0 0 0 )
{
Debug . Log ( "Pulling the eject handle" ) ;
yield break ;
}
yield return null ;
}
#if false
#if true
var sensorHandle = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam" , "" , "" , 0 , CaptureTriggerMode . Manual , simulationDeltaTime , 0 ) ) ; // why was there a true here...
var sensorHandle = DatasetCapture . Instance . RegisterSensor ( CreateSensorDefinition ( "cam" , "" , "" , 0 , CaptureTriggerMode . Manual , simulationDeltaTime , 0 , true ) ) ;
var framesToCaptureOn = new List < int > ( ) ;
Assert . AreEqual ( sequenceTimesExpected [ frameIndex ] , sequenceTimeActual , 0.0001f ) ;
frameIndex + + ;
}
if ( Time . frameCount > 1 0 0 0 )
{
Debug . Log ( "Pulling the eject handle" ) ;
yield break ;
}
yield return null ;
}
Assert . AreEqual ( frameIndex , framesToCaptureOn . Count , 0.0001f ) ;