Commit ab6fe38e authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add simulation result class - WIP

parent e430d8e5
#ifndef INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SIMULATION_RESULT
#define INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SIMULATION_RESULT
// API includes
#include <ITA/simulation_scheduler/definitions.h>
// simulation scheduler includes
#include <ITA/simulation_scheduler/types.h>
// VISTA includes
#include <VistaAspects/VistaSerializable.h>
// ITA includes
#include <ITASampleFrame.h>
namespace ITA
{
namespace simulation_scheduler
{
namespace room_acoustics
{
///
/// \brief Result of a simulation.
///
/// This class is primarily just a container for the data of an update.
///
struct ITA_SIMULATION_SCHEDULER_API CSimulationResult : public IVistaSerializable
{
///
/// \brief Type of result.
/// \sa #FieldOfDuty
///
FieldOfDuty eResultType = FieldOfDuty::directSound;
///
/// \brief
/// \todo We probably need a copy of the pair .. make it bullet proof.
///
SourceReceiverPair sourceReceiverPair = SourceReceiverPair();
///
/// \brief Sample Frame containing the actual result od the simulation.
///
ITASampleFrame sfResult = ITASampleFrame();
///
/// \brief Number of leading zeros.
///
int iLeadingZeros = 0;
///
/// \brief Number of trailing zeros.
///
int iTrailingZeros = 0;
///
/// \brief True if leading and trailing zeros were removed from #sfResult.
///
bool bZerosStripped = true;
///
/// \brief True if the Source and receiver are in the same room for this result.
///
bool bSameRoom = true;
///
/// \brief Serialize the object.
/// \param pSerializer the IVistaSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int Serialize ( IVistaSerializer& pSerializer ) const override;
///
/// \brief DeSerialize the object.
/// \param pDeserializer the IVistaDeSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int DeSerialize ( IVistaDeSerializer& pDeserializer ) override;
///
/// \brief Return a unique identifier for the object for serialization.
/// \return "CSimulationResult".
///
virtual std::string GetSignature ( ) const override;
};
} // namespace room_acoustics
} // namespace simulation_scheduler
} // namespace ITA
#endif // INCLUDE_WATCHER_ITA_SIMULATION_SCHEDULER_ROOM_ACOUSTICS_SIMULATION_RESULT
\ No newline at end of file
// Header include
#include <ITA/simulation_scheduler/room_acoustics/simulation_result.h>
// simulation scheduler include
#include "../src/ITA/simulation_scheduler/utils.h"
#include "../src/ITA/simulation_scheduler/room_acoustics/serialization_helper.h"
// Vista include
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>
namespace ITA
{
namespace simulation_scheduler
{
namespace room_acoustics
{
int CSimulationResult::Serialize ( IVistaSerializer& pSerializer ) const
{
int returnVal = 0;
returnVal += pSerializer.WriteInt32 ( as_integer ( eResultType ) );
returnVal += pSerializer.WriteSerializable ( *sourceReceiverPair.source );
returnVal += pSerializer.WriteSerializable ( *sourceReceiverPair.receiver );
returnVal += SerializationHelper::writeITASampleFrame ( pSerializer, &sfResult, sfResult.GetLength ( ), 0 );
returnVal += pSerializer.WriteInt32 ( iLeadingZeros );
returnVal += pSerializer.WriteInt32 ( iTrailingZeros );
returnVal += pSerializer.WriteBool ( bZerosStripped );
returnVal += pSerializer.WriteBool ( bSameRoom );
return returnVal;
}
int CSimulationResult::DeSerialize ( IVistaDeSerializer& pDeserializer )
{
int returnVal = 0;
int tmp;
returnVal += pDeserializer.ReadInt32 ( tmp );
eResultType = FieldOfDuty ( tmp );
auto source = new C3DObject();
auto receiver = new C3DObject ( );
returnVal += pDeserializer.ReadSerializable ( *source );
sourceReceiverPair.source = source;
returnVal += pDeserializer.ReadSerializable ( *receiver );
sourceReceiverPair.receiver = receiver;
returnVal += SerializationHelper::readITASampleFrame ( pDeserializer, sfResult );
returnVal += pDeserializer.ReadInt32 ( iLeadingZeros );
returnVal += pDeserializer.ReadInt32 ( iTrailingZeros );
returnVal += pDeserializer.ReadBool ( bZerosStripped );
returnVal += pDeserializer.ReadBool ( bSameRoom );
return returnVal;
}
std::string CSimulationResult::GetSignature ( ) const
{
return "CSimulationResult";
}
} // namespace room_acoustics
} // namespace simulation_scheduler
} // namespace ITA
\ No newline at end of file
......@@ -14,6 +14,7 @@ set( ProjectSources "all_tests.cpp"
"update_scene_test.cpp"
"enum_to_int.cpp"
"master_simulation_controller_test.cpp"
"simulation_result_test.cpp"
)
add_executable( all_tests ${ProjectSources} )
......
#include <iostream>
#include <string>
#include <memory>
// simulation scheduler includes
#include <ITA/simulation_scheduler/room_acoustics/simulation_result.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// GTest
#include "gtest/gtest.h"
using namespace ITA::simulation_scheduler;
using namespace ITA::simulation_scheduler::room_acoustics;
struct SimulationResultTest : testing::Test
{
std::unique_ptr<CSimulationResult> result;
C3DObject* source;
C3DObject* receiver;
SimulationResultTest ( )
{
result = std::make_unique<CSimulationResult> ( );
source = new C3DObject ( VistaVector3D ( 3, 2, 6 ),
VistaQuaternion ( 1, 0, 0, 0 ),
C3DObject::Type::source, 1 );
receiver = new C3DObject ( VistaVector3D ( 6, 1, 10 ),
VistaQuaternion ( 1, 0, 0, 0 ),
C3DObject::Type::receiver, 1 );
result->sourceReceiverPair.source = source;
result->sourceReceiverPair.receiver = receiver;
result->eResultType = FieldOfDuty::earlyReflections;
result->iLeadingZeros = 10;
result->iTrailingZeros = 30;
result->bZerosStripped = false;
result->bSameRoom = false;
auto frame = ITASampleFrame ( 2, 314, true );
for ( int i = 0; i < frame.GetLength ( ); i++ )
frame [1][i] = sin ( 2 * 3.14 * 50 * i );
result->sfResult = frame;
}
};
TEST_F ( SimulationResultTest, serialization )
{
auto serializer = VistaByteBufferSerializer ( );
auto deserializer = VistaByteBufferDeSerializer ( );
auto writeBytes = serializer.WriteSerializable ( *result);
deserializer.SetBuffer ( serializer.GetBuffer ( ), serializer.GetBufferSize ( ) );
CSimulationResult newResult;
auto readBytes = deserializer.ReadSerializable ( newResult );
EXPECT_EQ ( writeBytes, readBytes );
EXPECT_EQ ( result->bSameRoom, newResult.bSameRoom );
EXPECT_EQ ( result->bZerosStripped, newResult.bZerosStripped );
EXPECT_EQ ( result->iTrailingZeros, newResult.iTrailingZeros );
EXPECT_EQ ( result->iLeadingZeros, newResult.iLeadingZeros );
EXPECT_EQ ( result->eResultType, newResult.eResultType );
EXPECT_EQ ( *result->sourceReceiverPair.source, *newResult.sourceReceiverPair.source );
EXPECT_EQ ( *result->sourceReceiverPair.receiver, *newResult.sourceReceiverPair.receiver );
EXPECT_EQ ( result->sfResult.toString ( ), newResult.sfResult.toString ( ) );
for ( int i = 0; i < newResult.sfResult.GetNumChannels ( ); i++ )
EXPECT_EQ ( result->sfResult [i].ValuesToString ( ), newResult.sfResult [i].ValuesToString ( ) );
}
\ 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