3d_object.cpp 2.7 KB
Newer Older
Pascal Palenda's avatar
Pascal Palenda committed
1
// Header include
Pascal Palenda's avatar
Pascal Palenda committed
2
#include <ITA/SimulationScheduler/3d_object.h>
Pascal Palenda's avatar
Pascal Palenda committed
3
4
5
6

// std includes
#include <cmath>

Pascal Palenda's avatar
Pascal Palenda committed
7
// simulation scheduler include
8
#include <ITA/SimulationScheduler/Utils/utils.h>
9
#include "../src/ITA/SimulationScheduler/serialization_helper.h"
Pascal Palenda's avatar
Pascal Palenda committed
10

11
12
13
14
// Vista include
#include <VistaAspects/VistaSerializer.h>
#include <VistaAspects/VistaDeSerializer.h>

Pascal Palenda's avatar
Pascal Palenda committed
15
16
namespace ITA
{
17
	namespace SimulationScheduler
Pascal Palenda's avatar
Pascal Palenda committed
18
	{
19
		C3DObject::C3DObject ( const VistaVector3D& position,
Pascal Palenda's avatar
Pascal Palenda committed
20
							   const VistaQuaternion& orientation,
21
22
23
							   const Type type,
							   const int id ) :
			m_iID ( id ),
Pascal Palenda's avatar
Pascal Palenda committed
24
			m_eType ( type ),
25
26
			m_v3Position ( position ),
			m_qOrientation ( orientation )
Pascal Palenda's avatar
Pascal Palenda committed
27
		{ }
28
		const VistaVector3D& C3DObject::GetPosition ( ) const
Pascal Palenda's avatar
Pascal Palenda committed
29
30
31
		{
			return m_v3Position;
		}
32
		const VistaQuaternion& C3DObject::GetOrientation ( ) const
Pascal Palenda's avatar
Pascal Palenda committed
33
34
35
		{
			return m_qOrientation;
		}
36
		unsigned int C3DObject::GetId ( ) const
Pascal Palenda's avatar
Pascal Palenda committed
37
		{
38
			return m_iID;
Pascal Palenda's avatar
Pascal Palenda committed
39
		}
40
		C3DObject::Type C3DObject::GetType ( ) const
Pascal Palenda's avatar
Pascal Palenda committed
41
42
43
		{
			return m_eType;
		}
44
		bool C3DObject::IsEqualTolerance ( const C3DObject& obj, const double dTolerance ) const
Pascal Palenda's avatar
Pascal Palenda committed
45
46
		{
			if ( obj.m_eType == m_eType &&
47
				 obj.m_iID == m_iID )
Pascal Palenda's avatar
Pascal Palenda committed
48
49
50
51
52
53
54
55
56
57
58
59
			{ 
				return ( abs ( m_v3Position [0] - obj.m_v3Position [0] ) <= dTolerance &&
						 abs ( m_v3Position [1] - obj.m_v3Position [1] ) <= dTolerance &&
						 abs ( m_v3Position [2] - obj.m_v3Position [2] ) <= dTolerance &&
						 abs ( m_v3Position [3] - obj.m_v3Position [3] ) <= dTolerance ) &&
					( abs ( m_qOrientation [0] - obj.m_qOrientation [0] ) <= dTolerance &&
					  abs ( m_qOrientation [1] - obj.m_qOrientation [1] ) <= dTolerance &&
					  abs ( m_qOrientation [2] - obj.m_qOrientation [2] ) <= dTolerance &&
					  abs ( m_qOrientation [3] - obj.m_qOrientation [3] ) <= dTolerance );
			}
			return false;
		}
60
61
62
		int C3DObject::Serialize ( IVistaSerializer& pSerializer ) const
		{
			int returnVal = 0;
63
			returnVal += SerializationHelper::WriteVistaVector3D ( pSerializer, m_v3Position );
64

65
			returnVal += SerializationHelper::WriteVistaQuaternion ( pSerializer, m_qOrientation );
66

67
			returnVal += pSerializer.WriteInt32 ( m_iID );
68

69
			returnVal += pSerializer.WriteInt32 ( AsInteger( m_eType ) );
70
71
72
73
74
75
76

			return returnVal;
		}
		int C3DObject::DeSerialize ( IVistaDeSerializer& pDeserializer )
		{
			int returnVal = 0;
			int tmp;
77
			returnVal += SerializationHelper::ReadVistaVector3D ( pDeserializer, m_v3Position );
78

79
			returnVal += SerializationHelper::ReadVistaQuaternion ( pDeserializer, m_qOrientation );
80

81
			returnVal += pDeserializer.ReadInt32 ( m_iID );
82
83
84
85
86
87
88
89
90
91

			returnVal += pDeserializer.ReadInt32 ( tmp );
			m_eType = Type ( tmp );

			return returnVal;
		}
		std::string C3DObject::GetSignature ( ) const
		{
			return "C3DObject";
		}
92
	} // namespace SimulationScheduler
Pascal Palenda's avatar
Pascal Palenda committed
93
94
} // namespace ITA