Commit 32aea1fb authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Rework relative translation filter and test

parent e98d1c87
......@@ -29,7 +29,7 @@ namespace ITA
///
enum class TranslationModes
{
relative, ///< In this mode, the translation relative to the opposite element is considered.
relative, ///< In this mode, the distance relative to previous distance is considered.
absolute ///< In this mode, only the absolute translation of source and receiver is considered.
};
......@@ -40,7 +40,7 @@ namespace ITA
{
explicit TranslationFilterConfig ( );
double dMinimumTranslation = 5.0;
double dThreshold = 5.0;
TranslationModes eMode = TranslationModes::absolute;
......@@ -63,8 +63,8 @@ namespace ITA
///
/// \brief Check if the change between \p previousState and \p newUpdate is audible.
///
/// The change between \p previousState and \p newUpdate in absolute mode is audible when the length of the translation vector of source or receiver is larger than the configured minimum.
/// The change between \p previousState and \p newUpdate in relative mode is audible when the difference of the distances between source and receiver is larger than the configured minimum.
/// The change between \p previousState and \p newUpdate in absolute mode is audible when the length of the translation vector of source or receiver is larger than the configured threshold.
/// The change between \p previousState and \p newUpdate in relative mode is audible when the quotient of the new and previous distance between source and receiver is larger than the configured threshold.
/// \param previousState the previous state of the scene to check against.
/// \param newUpdate the CUpdateScene to check for audibility.
/// \return true if the change between \p previousState and \p newUpdate is audible, else false.
......@@ -87,7 +87,7 @@ namespace ITA
///
/// \brief The minimum translation, above which the filter deems the update audible.
///
double m_dMinimumTranslation = 1.0;
double m_dThreshold = 1.0;
///
/// \brief Mode in which the translation should be evaluated.
......
......@@ -21,7 +21,7 @@ namespace ITA
{
auto oProperties = AudibilityFilterConfig::Store ( );
oProperties.SetValue ( translationFilterMinimumTranslationKey, dMinimumTranslation );
oProperties.SetValue ( translationFilterThresholdKey, dThreshold );
oProperties.SetValue ( translationFilterTranslationModeKey, AsInteger ( eMode ) );
return oProperties;
......@@ -31,13 +31,13 @@ namespace ITA
{
AudibilityFilterConfig::Load ( oProperties );
oProperties.GetValue ( translationFilterMinimumTranslationKey, dMinimumTranslation );
oProperties.GetValue ( translationFilterThresholdKey, dThreshold );
eMode = static_cast< TranslationModes >( oProperties.GetValue <int> ( translationFilterTranslationModeKey ) );
}
CTranslationFilter::CTranslationFilter ( const TranslationFilterConfig& oConfig )
{
m_dMinimumTranslation = oConfig.dMinimumTranslation;
m_dThreshold = oConfig.dThreshold;
m_eTranslationMode = oConfig.eMode;
}
......@@ -54,7 +54,7 @@ namespace ITA
const auto receiverTranslationLength = ( previousSourceReceiverPair.receiver->GetPosition ( ) - newSourceReceiverPair.receiver->GetPosition ( ) ).GetLength ( );
const auto sourceTranslationLength = ( previousSourceReceiverPair.source->GetPosition ( ) - newSourceReceiverPair.source->GetPosition ( ) ).GetLength ( );
return receiverTranslationLength >= m_dMinimumTranslation || sourceTranslationLength >= m_dMinimumTranslation;
return receiverTranslationLength >= m_dThreshold || sourceTranslationLength >= m_dThreshold;
}
if ( m_eTranslationMode == TranslationModes::relative )
......@@ -62,7 +62,12 @@ namespace ITA
const auto previousDistance = previousSourceReceiverPair.source->GetPosition ( ) - previousSourceReceiverPair.receiver->GetPosition ( );
const auto newDistance = newSourceReceiverPair.source->GetPosition ( ) - newSourceReceiverPair.receiver->GetPosition ( );
return std::abs ( previousDistance.GetLength ( ) - newDistance.GetLength ( ) ) > m_dMinimumTranslation;
auto distanceQuotient = newDistance.GetLength ( ) / previousDistance.GetLength ( );
if ( distanceQuotient < 1 )
distanceQuotient = 1 / distanceQuotient;
return distanceQuotient > m_dThreshold;
}
}
......
......@@ -43,7 +43,7 @@ namespace ITA
namespace AudibilityFilter
{
const std::string translationFilterTranslationModeKey = "@TranslationMode";
const std::string translationFilterMinimumTranslationKey = "@MinimumTranslation";
const std::string translationFilterThresholdKey = "@Threshold";
const std::string rotationFilterSourceThresholdKey = "@SourceThreshold";
const std::string rotationFilterReceiverThresholdKey = "@ReceiverThreshold";
......
......@@ -92,7 +92,7 @@ TEST ( ZoneFilter, correctResult )
TEST ( TranslationFilter, correctResultAbsolut )
{
auto conf = CTranslationFilter::TranslationFilterConfig ( ); // min trans = 1m
conf.dMinimumTranslation = 1;
conf.dThreshold = 1;
CTranslationFilter filter ( conf );
......@@ -385,7 +385,7 @@ INSTANTIATE_TEST_CASE_P ( PerceptiveRotationFilterTest, PerceptiveRotationFilter
TEST ( TranslationFilter, correctResultRelative )
{
auto conf = CTranslationFilter::TranslationFilterConfig ( ); // min trans = 1m
conf.dMinimumTranslation = 1;
conf.dThreshold = 3;
conf.eMode = CTranslationFilter::TranslationModes::relative;
CTranslationFilter filter ( conf );
......@@ -395,7 +395,7 @@ TEST ( TranslationFilter, correctResultRelative )
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 1 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
......@@ -404,32 +404,51 @@ TEST ( TranslationFilter, correctResultRelative )
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 2 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
EXPECT_FALSE ( filter.ChangeIsAudible ( prevUpdate, newUpdate ) );
newUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 1, 0, 0 ),
newUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 3 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
EXPECT_FALSE ( filter.ChangeIsAudible ( prevUpdate, newUpdate ) );
newUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 1.1 ),
newUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 3.1 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
EXPECT_TRUE ( filter.ChangeIsAudible ( prevUpdate, newUpdate ) );
newUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 1 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
prevUpdate.SetSourceReceiverPair ( std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 3.1 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
EXPECT_TRUE ( filter.ChangeIsAudible ( prevUpdate, newUpdate ) );
}
\ No newline at end of file
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment