Commit 69517f86 authored by Pascal Palenda's avatar Pascal Palenda
Browse files

Add serialization to 3DObject - WIP

parent 6ce6f4cb
......@@ -7,6 +7,7 @@
// VISTA includes
#include <VistaBase/VistaVector3D.h>
#include <VistaBase/VistaQuaternion.h>
#include <VistaAspects/VistaSerializable.h>
namespace ITA
{
......@@ -15,7 +16,7 @@ namespace ITA
///
/// \brief Modells a source or reciever in 3D space.
///
class ITA_SIMULATION_SCHEDULER_API C3DObject
class ITA_SIMULATION_SCHEDULER_API C3DObject : public IVistaSerializable
{
public:
///
......@@ -27,7 +28,13 @@ namespace ITA
receiver
};
C3DObject ( ) = delete;
///
/// \brief Default constructor.
///
/// This constructor is primarily used for creating an object for deserialization.
/// It does not inizializes the object.
///
C3DObject ( ) = default;
///
/// \brief Constructor of a C3DObject.
......@@ -72,10 +79,30 @@ namespace ITA
/// However, this comparison allows for a tolerance for the comparison of #position and #orientation.
/// \param obj the object to check against.
/// \param dTolerance the allowed tolerance.
/// \return true if the given object is exactly the same as this.
/// \return true if the given object is the same as this with the given tolerance.
///
bool isEqualTolerance ( const C3DObject& obj, double dTolerance ) const;
///
/// \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;
///
/// \brief DeSerialize the object.
/// \param pSerializer the IVistaDeSerializer to use.
/// \return the number of bytes written or -1 on failure.
///
int DeSerialize ( IVistaDeSerializer& pDeserializer );
///
/// \brief Return a unique identifier for the object for serialization.
/// \return "CUpdateConfig".
///
virtual std::string GetSignature ( ) const;
private:
///
/// \brief Identification number of the C3DObject.
......
......@@ -4,6 +4,10 @@
// std includes
#include <cmath>
// Vista include
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>
namespace ITA
{
namespace simulation_scheduler
......@@ -49,6 +53,50 @@ namespace ITA
}
return false;
}
int C3DObject::Serialize ( IVistaSerializer& pSerializer ) const
{
int returnVal = 0;
returnVal += pSerializer.WriteFloat32 ( m_v3Position [0] );
returnVal += pSerializer.WriteFloat32 ( m_v3Position [1] );
returnVal += pSerializer.WriteFloat32 ( m_v3Position [2] );
returnVal += pSerializer.WriteFloat32 ( m_v3Position [3] );
returnVal += pSerializer.WriteFloat32 ( m_qOrientation [0] );
returnVal += pSerializer.WriteFloat32 ( m_qOrientation [1] );
returnVal += pSerializer.WriteFloat32 ( m_qOrientation [2] );
returnVal += pSerializer.WriteFloat32 ( m_qOrientation [3] );
returnVal += pSerializer.WriteInt32 ( m_uiID );
returnVal += pSerializer.WriteInt32 ( static_cast< std::underlying_type<Type>::type >( m_eType ) );
return returnVal;
}
int C3DObject::DeSerialize ( IVistaDeSerializer& pDeserializer )
{
int returnVal = 0;
int tmp;
returnVal += pDeserializer.ReadFloat32 ( m_v3Position [0] );
returnVal += pDeserializer.ReadFloat32 ( m_v3Position [1] );
returnVal += pDeserializer.ReadFloat32 ( m_v3Position [2] );
returnVal += pDeserializer.ReadFloat32 ( m_v3Position [3] );
returnVal += pDeserializer.ReadFloat32 ( m_qOrientation [0] );
returnVal += pDeserializer.ReadFloat32 ( m_qOrientation [1] );
returnVal += pDeserializer.ReadFloat32 ( m_qOrientation [2] );
returnVal += pDeserializer.ReadFloat32 ( m_qOrientation [3] );
returnVal += pDeserializer.ReadInt32 ( m_uiID );
returnVal += pDeserializer.ReadInt32 ( tmp );
m_eType = Type ( tmp );
return returnVal;
}
std::string C3DObject::GetSignature ( ) const
{
return "C3DObject";
}
} // namespace simulation_scheduler
} // namespace ITA
......@@ -5,6 +5,10 @@
// simulation scheduler includes
#include <ITA/simulation_scheduler/3d_object.h>
// Vista includes
#include <VistaInterProcComm/Connections/VistaByteBufferSerializer.h>
#include <VistaInterProcComm/Connections/VistaByteBufferDeSerializer.h>
// GTest
#include "gtest/gtest.h"
......@@ -133,4 +137,31 @@ INSTANTIATE_TEST_CASE_P ( C3DObject, ParamTestC3DObject,
1,
false,
false,
0.2 } ) );
\ No newline at end of file
0.2 } ) );
TEST ( C3DObject, serialization )
{
auto obj1 = simsched::C3DObject ( { 4,6,1 }, { 1,0,0,0 }, simsched::C3DObject::Type::receiver, 1 );
auto serializer = VistaByteBufferSerializer ( );
auto deserializer = VistaByteBufferDeSerializer ( );
serializer.WriteSerializable ( obj1 );
deserializer.SetBuffer ( serializer.GetBuffer ( ), serializer.GetBufferSize ( ) );
auto obj2 = simsched::C3DObject ( );
deserializer.ReadSerializable ( obj2 );
EXPECT_EQ ( true, obj1 == obj2 );
}
TEST ( C3DObject, uniqueptr )
{
auto ptr = std::make_unique<simsched::C3DObject> (
VistaVector3D ( 1, 2, 3 ), VistaQuaternion ( 1, 0, 0, 0 ), simsched::C3DObject::Type::receiver, 1 );
EXPECT_EQ ( VistaVector3D ( 1, 2, 3 ), ptr->getPosition ( ) );
EXPECT_EQ ( VistaQuaternion ( 1, 0, 0, 0 ), ptr->getOrientation ( ) );
EXPECT_EQ ( simsched::C3DObject::Type::receiver, ptr->getType ( ) );
EXPECT_EQ ( 1, ptr->getID ( ) );
}
\ 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