Commit 45fe0ea8 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add relative translation mode and test

parent cde4f2d1
......@@ -24,6 +24,15 @@ namespace ITA
class ITA_SIMULATION_SCHEDULER_API CTranslationFilter : public IAudibilityFilter
{
public:
///
/// \brief Translation modes for the CTranslationFilter.
///
enum class TranslationModes
{
relative, ///< In this mode, the translation relative to the opposite element is considered.
absolute ///< In this mode, only the absolute translation of source and receiver is considered.
};
///
/// \brief Configuration class for the translation filter.
///
......@@ -33,6 +42,8 @@ namespace ITA
double dMinimumTranslation = 5.0;
TranslationModes eMode = TranslationModes::absolute;
VistaPropertyList store ( ) const override;
void load ( const VistaPropertyList& oProperties ) override;
......@@ -52,7 +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 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 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.
/// \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.
......@@ -76,6 +88,11 @@ namespace ITA
/// \brief The minimum translation, above which the filter deems the update audible.
///
double m_dMinimumTranslation = 1.0;
///
/// \brief Mode in which the translation should be evaluated.
///
TranslationModes m_eTranslationMode = TranslationModes::absolute;
};
} // namespace audibility_filter
} // namespace simulation_scheduler
......
......@@ -4,6 +4,7 @@
#include <ITA/simulation_scheduler/update_scene.h>
#include <ITA/simulation_scheduler/profiler/profiler.h>
#include "../configuration_keys.h"
#include "../utils.h"
#include "ITAException.h"
......@@ -21,6 +22,7 @@ namespace ITA
auto oProperties = AudibilityFilterConfig::store ( );
oProperties.SetValue ( translationFilterMinimumTranslationKey, dMinimumTranslation );
oProperties.SetValue ( rotationFilterRotationModeKey, as_integer ( eMode ) );
return oProperties;
}
......@@ -30,11 +32,13 @@ namespace ITA
AudibilityFilterConfig::load ( oProperties );
oProperties.GetValue ( translationFilterMinimumTranslationKey, dMinimumTranslation );
eMode = static_cast< TranslationModes >( oProperties.GetValue <int> ( rotationFilterRotationModeKey ) );
}
CTranslationFilter::CTranslationFilter ( const TranslationFilterConfig& oConfig )
{
m_dMinimumTranslation = oConfig.dMinimumTranslation;
m_eTranslationMode = oConfig.eMode;
}
bool CTranslationFilter::changeIsAudible ( const CUpdateScene& previousState, const CUpdateScene& newUpdate ) const
......@@ -45,10 +49,21 @@ namespace ITA
const auto previousSourceReceiverPair = previousState.getSourceReceiverPair ( );
const auto newSourceReceiverPair = newUpdate.getSourceReceiverPair ( );
const auto receiverTranslationLength = ( previousSourceReceiverPair.receiver->getPosition ( ) - newSourceReceiverPair.receiver->getPosition ( ) ).GetLength ( );
const auto sourceTranslationLength = ( previousSourceReceiverPair.source->getPosition ( ) - newSourceReceiverPair.source->getPosition ( ) ).GetLength ( );
if ( m_eTranslationMode == TranslationModes::absolute )
{
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_dMinimumTranslation || sourceTranslationLength >= m_dMinimumTranslation;
}
if ( m_eTranslationMode == TranslationModes::relative )
{
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;
}
}
std::string CTranslationFilter::getType ( )
......
......@@ -38,6 +38,7 @@ namespace ITA
namespace audibility_filter
{
const std::string translationFilterTranslationModeKey = "@TranslationMode";
const std::string translationFilterMinimumTranslationKey = "@MinimumTranslation";
const std::string rotationFilterSourceThresholdKey = "@SourceThreshold";
......
......@@ -89,7 +89,7 @@ TEST ( ZoneFilter, correctResult )
EXPECT_FALSE ( filter.changeIsAudible ( update, update ) );
}
TEST ( TranslationFilter, correctResult )
TEST ( TranslationFilter, correctResultAbsolut )
{
auto conf = CTranslationFilter::TranslationFilterConfig ( ); // min trans = 1m
conf.dMinimumTranslation = 1;
......@@ -381,3 +381,54 @@ INSTANTIATE_TEST_CASE_P ( PerceptiveRotationFilterTest, PerceptiveRotationFilter
PerceptiveRotationFilterTestParam { true, {0,-1,1}, {1,0,0}, 0, {0,-1,1}, {1,0,0}, 5, 0.5 } //17
) );
TEST ( TranslationFilter, correctResultRelative )
{
auto conf = CTranslationFilter::TranslationFilterConfig ( ); // min trans = 1m
conf.dMinimumTranslation = 1;
conf.eMode = CTranslationFilter::TranslationModes::relative;
CTranslationFilter filter ( conf );
CUpdateScene prevUpdate ( 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, 0 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::receiver,
0 ) );
CUpdateScene newUpdate ( 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 ),
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 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
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 ),
VistaQuaternion ( 0, 0, 0, 1 ),
C3DObject::Type::source,
0 ),
std::make_unique<C3DObject> ( VistaVector3D ( 0, 0, 0 ),
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