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

Move serialization classes

parent 7cf35b5c
/*
* RAVEN Interface
*
* (c) Copyright Institut fr Technische Akustik (ITA)
* RWTH Aachen (http://www.akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*
* Datei: R_RavenUtils.h
*
* Zweck: Helper classes and functions
*
* Autor(en): Jonas Stienen (stienen@akustik.rwth-aachen.de)
* Frank Wefers (fwe@akustik.rwth-aachen.de)
* Snke Pelzer (spe@akustik.rwth-aachen.de)
*
* ---------------------------------------------------------------------------------
*/
// $Id: R_RavenConfig.h 2732 2012-06-26 13:38:17Z stienen $
#ifndef __R_RAVEN_SERIALIZATION_H__
#define __R_RAVEN_SERIALIZATION_H__
// API includes
#include <ITASimulationScheduler/Interfaces.h>
// ITA includes
#include <ITAStringUtils.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
#include <VistaBase/VistaVersion.h>
#include <VistaBase/VistaBaseTypes.h>
// STL
#include <iomanip>
#include <iosfwd>
#include <string>
namespace ITASimulationScheduler
{
namespace RAVEN
{
#if (VISTA_MAJOR >= 1) && (VISTA_MINOR >= 13)
namespace RavenUtilsCompat
{
typedef VistaType::byte byte;
typedef VistaType::sint32 sint32;
typedef VistaType::uint64 uint64;
typedef VistaType::byte BBSetBuffer;
typedef VistaType::byte BBGetBuffer;
}
#else
namespace RavenUtilsCompat
{
typedef ubyte8 byte;
typedef sint32 sint32;
typedef uint64 uint64;
typedef char BBSetBuffer;
typedef unsigned char BBGetBuffer;
}
#endif
class ITA_SIMULATION_SCHEDULER_API CDeserializer : public VistaByteBufferDeSerializer
{
public:
CDeserializer();
virtual ~CDeserializer();
bool ReadBool();
using VistaByteBufferDeSerializer::ReadBool;
int ReadInt();
float ReadFloat();
double ReadDouble();
CStatistics ReadRavenStatistics();
void ReadRavenSimulationConfig(CConfig*);
void ReadRavenSimulationConfigGeometry(CConfig::Geometry*);
void ReadRavenSimulationConfigRoom(CConfig::Room*);
void ReadRavenSimulationConfigImageSource(CConfig::ImageSources*);
void ReadRavenSimulationConfigRayTracer(CConfig::RayTracer*);
void ReadRavenSimulationConfigFilterEngine(CConfig::FilterEngine*);
void ReadRavenSimulationConfigSimSettings(CConfig::SimulationSettings*);
void ReadRavenSimulationTask(CSimulationTask*);
void ReadRavenSimulationScene(CScene*);
void ReadRavenReceiverState(CReceiverState*);
void ReadRavenSourceState(CSourceState*);
void ReadRavenPortalState(CPortalState*);
void ReadRavenSimulationTaskProfiler(CSimulationTask::CProfiler*);
void ReadRavenSimulationProfilerState(ISimulationInterface::CProfiler*);
void ReadRavenSimulationProfilerState(ISimulationSchedulerInterface::CProfiler*);
void ReadRavenSimulationProfilerStateSimType(ISimulationSchedulerInterface::CProfiler::CProfilerSimType*);
RG_Vector ReadRavenRGVector();
//! Sample buffer has to be initialized!
void ReadITASampleBuffer(ITASampleBuffer&);
//! Sample frame has to be initialized!
void ReadITASampleFrame(ITASampleFrame&);
void ReadRavenSimulationComplexSoundPath(CSimulationResult::ComplexSimulationSoundPath&);
void ReadRavenSimulationResult(CSimulationResult*);
};
class ITA_SIMULATION_SCHEDULER_API CSerializer : public VistaByteBufferSerializer
{
public:
CSerializer();
virtual ~CSerializer();
void WriteInt(const int iValue);
void WriteFloat(const float fValue);
void WriteIntVector(const std::vector<int> viData);
void WriteRavenStatistics(const CStatistics&);
void WriteRavenSimulationTask(const CSimulationTask*);
void WriteRavenSimulationConfig(const CConfig*);
void WriteRavenSimulationConfigGeometry(const CConfig::Geometry*);
void WriteRavenSimulationConfigRoom(const CConfig::Room*);
void WriteRavenSimulationConfigImageSource(const CConfig::ImageSources*);
void WriteRavenSimulationConfigRayTracer(const CConfig::RayTracer*);
void WriteRavenSimulationConfigFilterEngine(const CConfig::FilterEngine*);
void WriteRavenSimulationConfigSimSettings(const CConfig::SimulationSettings*);
void WriteRavenSimulationScene(const CScene* pScene);
void WriteRavenReceiverState(const CReceiverState*);
void WriteRavenSourceState(const CSourceState*);
void WriteRavenPortalState(const CPortalState*);
void WriteRavenSimulationTaskProfiler(const CSimulationTask::CProfiler*);
void WriteRavenSimulationProfilerState(ISimulationInterface::CProfiler*);
void WriteRavenSimulationProfilerState(ISimulationSchedulerInterface::CProfiler*);
void WriteRavenSimulationProfilerStateSimType(ISimulationSchedulerInterface::CProfiler::CProfilerSimType*);
void WriteRavenRGVector(const RG_Vector&);
void WriteRavenSimulationComplexSoundPath(const CSimulationResult::ComplexSimulationSoundPath*);
//! Write a sample frame to serializer
/*
* \param pSampleFrame Pointer to sample frame that should be serialized into buffer
* \param iLength Size of samples to be written (smaller or equal to the actual size of the sample frame)
* \param iOffset Offset where to begin to copy samples from SampleFrame (smaller or equal to the actual size of given length)
*/
void WriteITASampleFrame(const ITASampleFrame* pSampleFrame, const int iLength, const int iOffset);
//! Write a sample buffer to serializer
/*
* \param pSampleBuffer Pointer to sample buffer that should be serialized into buffer
* \param iLength Size of samples to be written (smaller or equal to the actual size of the sample frame)
* \param iOffset Offset where to begin to copy samples from SampleBuffer (smaller or equal to the actual size of given length)
*/
void WriteITASampleBuffer(const ITASampleBuffer*, const int iLength, const int iOffset);
void WriteRavenSimulationResult(const CSimulationResult*);
};
}
}
#endif // __R_RAVEN_SERIALIZATION_H__
......@@ -8,6 +8,7 @@ set( DirFiles
RavenNetClient.h
RavenNetDefinitions.h
RavenNetServer.h
Serialization.h
#_SourceFiles.cmake
)
set( DirFiles_SourceGroup "${RelativeSourceGroup}" )
......
......@@ -41,27 +41,6 @@
namespace ITASimulationScheduler
{
#if (VISTA_MAJOR >= 1) && (VISTA_MINOR >= 13)
namespace RavenUtilsCompat
{
typedef VistaType::byte byte;
typedef VistaType::sint32 sint32;
typedef VistaType::uint64 uint64;
typedef VistaType::byte BBSetBuffer;
typedef VistaType::byte BBGetBuffer;
}
#else
namespace RavenUtilsCompat
{
typedef ubyte8 byte;
typedef sint32 sint32;
typedef uint64 uint64;
typedef char BBSetBuffer;
typedef unsigned char BBGetBuffer;
}
#endif
//! Compares input and returns simulation type as integer identifier
/**
* \param sShortSimType simulation type string in short form
......@@ -105,104 +84,6 @@ namespace ITASimulationScheduler
*/
int ITA_SIMULATION_SCHEDULER_API ParseSimulationType(const std::string& sShortSimType);
namespace RAVEN
{
class ITA_SIMULATION_SCHEDULER_API CDeserializer : public VistaByteBufferDeSerializer
{
public:
CDeserializer();
virtual ~CDeserializer();
bool ReadBool();
using VistaByteBufferDeSerializer::ReadBool;
int ReadInt();
float ReadFloat();
double ReadDouble();
CStatistics ReadRavenStatistics();
void ReadRavenSimulationConfig(CConfig*);
void ReadRavenSimulationConfigGeometry(CConfig::Geometry*);
void ReadRavenSimulationConfigRoom(CConfig::Room*);
void ReadRavenSimulationConfigImageSource(CConfig::ImageSources*);
void ReadRavenSimulationConfigRayTracer(CConfig::RayTracer*);
void ReadRavenSimulationConfigFilterEngine(CConfig::FilterEngine*);
void ReadRavenSimulationConfigSimSettings(CConfig::SimulationSettings*);
void ReadRavenSimulationTask(CSimulationTask*);
void ReadRavenSimulationScene(CScene*);
void ReadRavenReceiverState(CReceiverState*);
void ReadRavenSourceState(CSourceState*);
void ReadRavenPortalState(CPortalState*);
void ReadRavenSimulationTaskProfiler(CSimulationTask::CProfiler*);
void ReadRavenSimulationProfilerState(ISimulationInterface::CProfiler*);
void ReadRavenSimulationProfilerState(ISimulationSchedulerInterface::CProfiler*);
void ReadRavenSimulationProfilerStateSimType(ISimulationSchedulerInterface::CProfiler::CProfilerSimType*);
RG_Vector ReadRavenRGVector();
//! Sample buffer has to be initialized!
void ReadITASampleBuffer(ITASampleBuffer&);
//! Sample frame has to be initialized!
void ReadITASampleFrame(ITASampleFrame&);
void ReadRavenSimulationComplexSoundPath(CSimulationResult::ComplexSimulationSoundPath&);
void ReadRavenSimulationResult(CSimulationResult*);
};
class ITA_SIMULATION_SCHEDULER_API CSerializer : public VistaByteBufferSerializer
{
public:
CSerializer();
virtual ~CSerializer();
void WriteInt(const int iValue);
void WriteFloat(const float fValue);
void WriteIntVector(const std::vector<int> viData);
void WriteRavenStatistics(const CStatistics&);
void WriteRavenSimulationTask(const CSimulationTask*);
void WriteRavenSimulationConfig(const CConfig*);
void WriteRavenSimulationConfigGeometry(const CConfig::Geometry*);
void WriteRavenSimulationConfigRoom(const CConfig::Room*);
void WriteRavenSimulationConfigImageSource(const CConfig::ImageSources*);
void WriteRavenSimulationConfigRayTracer(const CConfig::RayTracer*);
void WriteRavenSimulationConfigFilterEngine(const CConfig::FilterEngine*);
void WriteRavenSimulationConfigSimSettings(const CConfig::SimulationSettings*);
void WriteRavenSimulationScene(const CScene* pScene);
void WriteRavenReceiverState(const CReceiverState*);
void WriteRavenSourceState(const CSourceState*);
void WriteRavenPortalState(const CPortalState*);
void WriteRavenSimulationTaskProfiler(const CSimulationTask::CProfiler*);
void WriteRavenSimulationProfilerState(ISimulationInterface::CProfiler*);
void WriteRavenSimulationProfilerState(ISimulationSchedulerInterface::CProfiler*);
void WriteRavenSimulationProfilerStateSimType(ISimulationSchedulerInterface::CProfiler::CProfilerSimType*);
void WriteRavenRGVector(const RG_Vector&);
void WriteRavenSimulationComplexSoundPath(const CSimulationResult::ComplexSimulationSoundPath*);
//! Write a sample frame to serializer
/*
* \param pSampleFrame Pointer to sample frame that should be serialized into buffer
* \param iLength Size of samples to be written (smaller or equal to the actual size of the sample frame)
* \param iOffset Offset where to begin to copy samples from SampleFrame (smaller or equal to the actual size of given length)
*/
void WriteITASampleFrame(const ITASampleFrame* pSampleFrame, const int iLength, const int iOffset);
//! Write a sample buffer to serializer
/*
* \param pSampleBuffer Pointer to sample buffer that should be serialized into buffer
* \param iLength Size of samples to be written (smaller or equal to the actual size of the sample frame)
* \param iOffset Offset where to begin to copy samples from SampleBuffer (smaller or equal to the actual size of given length)
*/
void WriteITASampleBuffer(const ITASampleBuffer*, const int iLength, const int iOffset);
void WriteRavenSimulationResult(const CSimulationResult*);
};
}
}
#endif // __R_RAVEN_UTILS_H__
......@@ -16,7 +16,7 @@
// Raven includes
#include <RG_Vector.h>
#include <ITASimulationScheduler/Interfaces.h>
#include <ITASimulationScheduler/Utils.h>
#include <ITASimulationScheduler/Raven/Serialization.h>
#include <string>
......
#include <ITASimulationScheduler/Raven/Serialization.h>
#include <ITAASCIITable.h>
#include <ITAConfigUtils.h>
#include <ITAStringUtils.h>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <sstream>
#define MAX_STRING_SIZE 4096
#ifndef RAVEN_SERIALIZER_RESULT_PRESERVE_ZEROS
#define RAVEN_SERIALIZER_RESULT_PRESERVE_ZEROS 0
#endif // RAVEN_SERIALIZER_RESULT_PRESERVE_ZEROS
namespace ITASimulationScheduler
{
namespace RAVEN
{
CDeserializer::CDeserializer() {};
CDeserializer::~CDeserializer() {};
bool CDeserializer::ReadBool()
{
bool val;
VistaByteBufferDeSerializer::ReadBool(val);
return val;
};
int CDeserializer::ReadInt()
{
VistaType::sint32 val;
ReadInt32(val);
return val;
};
float CDeserializer::ReadFloat()
{
float fValue;
ReadFloat32(fValue);
return fValue;
};
double CDeserializer::ReadDouble()
{
double dValue;
ReadFloat64(dValue);
return dValue;
};
void CDeserializer::ReadRavenSimulationConfig(CConfig* pConfig)
{
ReadRavenSimulationConfigGeometry(&(pConfig->oGeometry));
ReadRavenSimulationConfigRoom(&(pConfig->oRoom));
ReadRavenSimulationConfigImageSource(&(pConfig->oImageSource));
ReadRavenSimulationConfigRayTracer(&(pConfig->oRayTracer));
ReadRavenSimulationConfigSimSettings(&(pConfig->oSimulationSettings));
ReadRavenSimulationConfigFilterEngine(&(pConfig->oFilterEngine));
};
void CDeserializer::ReadRavenSimulationConfigGeometry(CConfig::Geometry* pGeo)
{
//int iSize = ReadInt();
//ReadString( pGeo->sSceneFileName, iSize );
ReadEncodedString(pGeo->sSceneFileName);
};
void CDeserializer::ReadRavenSimulationConfigRoom(CConfig::Room* pRoom)
{
pRoom->fHumidity = ReadFloat();
pRoom->fReverberationTime = ReadFloat();
pRoom->fStaticPressure = ReadFloat();
pRoom->fTemperature = ReadFloat();
};
void CDeserializer::ReadRavenSimulationConfigImageSource(CConfig::ImageSources* pIS)
{
pIS->iOrderPrimarySource = ReadInt();
pIS->iOrderSecondarySource = ReadInt();
};
void CDeserializer::ReadRavenSimulationConfigRayTracer(CConfig::RayTracer* pRT)
{
int l = sizeof(CConfig::RayTracer);
VistaType::uint64 val;
pRT->oSphereDetector.fEnergyLossThreshold = ReadFloat();
pRT->oSphereDetector.fFilterLength = ReadFloat();
ReadUInt64(val);
pRT->oSphereDetector.uliNumParticles = (unsigned long int) val;
pRT->oSphereDetector.fRadius = ReadFloat();
pRT->oSphereDetector.fResolutionAzimuth = ReadFloat();
pRT->oSphereDetector.fResolutionElevation = ReadFloat();
pRT->oSphereDetector.fResolutionTimeSlots = ReadFloat();
// Portal detector
pRT->oPortalDetector.fEnergyLossThreshold = ReadFloat();
pRT->oPortalDetector.fFilterLength = ReadFloat();
ReadUInt64(val);
pRT->oPortalDetector.uliNumParticles = (unsigned long int) val;
pRT->oPortalDetector.fResolutionTimeSlots = ReadFloat();
};
void CDeserializer::ReadRavenSimulationConfigFilterEngine(CConfig::FilterEngine* pFR)
{
pFR->iMagnitudesResolution = ReadInt();
}
void CDeserializer::ReadRavenSimulationConfigSimSettings(CConfig::SimulationSettings* pSimSettings)
{
pSimSettings->iAccelerationType = ReadInt();
pSimSettings->dSampleRate = ReadDouble();
}
void CDeserializer::ReadRavenSimulationTask(CSimulationTask* pTask)
{
VistaType::uint64 val;
ReadUInt64(val);
pTask->uiID = (unsigned long int) val;
ReadUInt64(val);
pTask->uiReferenceID = (unsigned long int) val;
pTask->iSimulationType = ReadInt();
ReadRavenSimulationConfig(&pTask->oConfig);
ReadRavenSimulationScene(&pTask->oScene);
ReadRavenSimulationTaskProfiler(&pTask->oProfiler);
}
void CDeserializer::ReadRavenSimulationTaskProfiler(CSimulationTask::CProfiler* pStatus)
{
ReadFloat64(pStatus->dCreationTime);
ReadFloat64(pStatus->dSchedulerEnqueTime);
ReadFloat64(pStatus->dSchedulerTurnaroundTime);
ReadFloat64(pStatus->dComputeTime);
pStatus->iDiscardReason = ReadInt();
}
void CDeserializer::ReadRavenSimulationScene(CScene* pScene)
{
pScene->Reset();
int iNumSources = ReadInt();
int iNumReceivers = ReadInt();
int iNumPortals = ReadInt();
for (int i = 0; i < iNumSources; i++)
{
int iID = ReadInt();
CSourceState oState;
ReadRavenSourceState(&oState);
pScene->AddSource(iID);
pScene->SetSourceState(iID, oState);
}
for (int i = 0; i < iNumReceivers; i++)
{
int iID = ReadInt();
CReceiverState oState;
ReadRavenReceiverState(&oState);
pScene->AddReceiver(iID);
pScene->SetReceiverState(iID, oState);
}
for (int i = 0; i < iNumPortals; i++)
{
int iID = ReadInt();
CPortalState oState;
ReadRavenPortalState(&oState);
pScene->AddPortal(iID);
pScene->SetPortalState(iID, oState);
}
};
void CDeserializer::ReadRavenReceiverState(CReceiverState* pState)
{
pState->vPos = ReadRavenRGVector();
pState->vView = ReadRavenRGVector();
pState->vUp = ReadRavenRGVector();
ReadEncodedString(pState->sHRIRFilename);
pState->bInsideRoom = ReadBool();
};
void CDeserializer::ReadRavenSourceState(CSourceState* pState)
{
pState->vPos = ReadRavenRGVector();
pState->vView = ReadRavenRGVector();
pState->vUp = ReadRavenRGVector();
ReadEncodedString(pState->sDirectivityFilename);
pState->bInsideRoom = ReadBool();
};
void CDeserializer::ReadRavenPortalState(CPortalState* pState)
{
pState->vPos = ReadRavenRGVector();
pState->dState = ReadDouble();
};
RG_Vector CDeserializer::ReadRavenRGVector()
{
RG_Vector v;
v.x = ReadFloat();
v.y = ReadFloat();
v.z = ReadFloat();
return v;
};
void CDeserializer::ReadITASampleBuffer(ITASampleBuffer& oSampleBuffer)
{
int iLength = ReadInt();
assert(iLength >= 0);
for (int i = 0; i < iLength; i++)
oSampleBuffer[i] = ReadFloat();
};
void CDeserializer::ReadITASampleFrame(ITASampleFrame& oSampleFrame)
{
int iNumChannels = ReadInt();
int iLength = ReadInt();
assert(iNumChannels >= 0);
assert(iLength >= 0);
oSampleFrame.init(iNumChannels, iLength, false);
for (int i = 0; i < iNumChannels; i++)
ReadITASampleBuffer(oSampleFrame[i]);
};
void CDeserializer::ReadRavenSimulationComplexSoundPath(CSimulationResult::ComplexSimulationSoundPath& oPath)
{
oPath.bDirectSoundAudible = ReadBool();
oPath.bEmpty = ReadBool();
oPath.bEntitiesInSameRoom = ReadBool();
oPath.iLeadingZeros = ReadInt();
oPath.iTailingZeros = ReadInt();
oPath.bZerosStripped = ReadBool();
oPath.iNumChannels = ReadInt();
oPath.iReceiverID = ReadInt();
oPath.iSenderID = ReadInt();
oPath.iType = ReadInt();
ReadITASampleFrame(*(oPath.psfResult));
};
void CDeserializer::ReadRavenSimulationResult(CSimulationResult* pResult)
{
int iNumResults = ReadInt();
for (int i = 0; i < iNumResults; i++)
{
CSimulationResult::ComplexSimulationSoundPath* pPath = new CSimulationResult::ComplexSimulationSoundPath();
pPath->psfResult = new ITASampleFrame;
ReadRavenSimulationComplexSoundPath(*pPath);
pResult->vcspResult.push_back(pPath);
}
}
CStatistics CDeserializer::ReadRavenStatistics()
{
CStatistics oStats;
oStats.dMean = ReadDouble();
oStats.dStdDev = ReadDouble();
oStats.dMin = ReadDouble();
oStats.dMax = ReadDouble();
VistaType::uint64 val;
ReadUInt64(val);
oStats.uiCycles = (unsigned long int) val;
ReadEncodedString(oStats.sName);
return oStats;
}
void CDeserializer::ReadRavenSimulationProfilerState(ISimulationInterface::CProfiler* pState)
{
VistaType::uint32 val;
ReadInt32(val);
pState->uiNumLoadScenes = (unsigned int)val;
ReadInt32(val);
pState->uiNumResets = (unsigned int)val;
pState->oCompute = ReadRavenStatistics();
pState->oSimulateDS = ReadRavenStatistics();
pState->oSimulateIS = ReadRavenStatistics();