-
Notifications
You must be signed in to change notification settings - Fork 3
/
ZMQCommunication.h
executable file
·127 lines (93 loc) · 3.25 KB
/
ZMQCommunication.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#ifndef SOFA_RGBDTRACKING_ZMQCOMMUNICATION_H
#define SOFA_RGBDTRACKING_ZMQCOMMUNICATION_H
#include <RGBDTracking/config.h>
#include <boost/thread.hpp>
#include <SofaBaseTopology/TopologyData.h>
#include <SofaUserInteraction/Controller.h>
#include "DataIO.h"
#include <sofa/core/core.h>
#include <sofa/core/objectmodel/BaseObject.h>
#include <sofa/core/objectmodel/Event.h>
#include <sofa/simulation/AnimateBeginEvent.h>
#include <sofa/simulation/AnimateEndEvent.h>
#include <sofa/core/behavior/MechanicalState.h>
#include <sofa/helper/accessor.h>
#include <sofa/defaulttype/VecTypes.h>
#include <sofa/helper/vector.h>
#include <sofa/defaulttype/Vec.h>
#include <SofaBaseTopology/TopologyData.h>
#include <sofa/gui/BaseGUI.h>
#include <sofa/gui/BaseViewer.h>
#include <sofa/gui/GUIManager.h>
#include <image/ImageTypes.h>
#include <zmq.hpp>
#include <string>
#include <sofa/helper/OptionsGroup.h>
#include <sofa/helper/vectorData.h>
#include <sofa/simulation/AnimateBeginEvent.h>
#include <sofa/simulation/AnimateEndEvent.h>
#include <opencv2/core.hpp>
#include <boost/archive/binary_oarchive.hpp>
#include <boost/archive/binary_iarchive.hpp>
#include <fstream>
#include "serialization.h"
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>
#include <sstream>
namespace sofa
{
namespace core
{
namespace objectmodel
{
using core::objectmodel::Event;
using core::objectmodel::BaseObjectDescription;
using std::map;
using std::string;
using sofa::helper::vectorData;
using helper::vector;
using namespace sofa::defaulttype;
template< class DataTypes >
class ZMQCommunication : public virtual sofa::core::objectmodel::BaseObject
{
typedef sofa::defaulttype::Vec3d Vec3d;
typedef sofa::defaulttype::Vec2d Vec2d;
typedef sofa::defaulttype::Vec3f Vec3f;
typedef defaulttype::ImageF DepthTypes;
public:
typedef BaseObject Inherited;
SOFA_CLASS(SOFA_TEMPLATE(ZMQCommunication,DataTypes), Inherited);
ZMQCommunication();
virtual ~ZMQCommunication();
sofa::Data<std::string> d_host;
sofa::Data<ushort> d_port;
sofa::Data<sofa::helper::vector<Vec3d> > d_positions;
sofa::Data<sofa::helper::vector<Vec3d> > d_normals;
Data<bool> useSensor;
cv::Mat color;
sofa::Data<bool> d_SubORPub;
Data<bool> displayBackgroundImage;
Data<int> niterations;
////////////////////////// Inherited from BaseObject ////////////////////
virtual void init() override;
//virtual void reinit() override;
//virtual void reset() override;
/// Parse the given description to assign values to this object's fields and potentially other parameters
//virtual void parse(BaseObjectDescription *arg) override;
/// Assign the field values stored in the given map of name -> value pairs
//virtual void parseFields(const map<string,string*>& str) override;
void handleEvent(sofa::core::objectmodel::Event *event);
/////////////////////////////////////////////////////////////////////////
void serialize(std::stringstream& s);
void desserialize(std::stringstream& s);
void cleanup();
void draw(const core::visual::VisualParams* vparams) ;
private:
zmq::context_t m_context{1};
zmq::socket_t* m_sockSub;
zmq::socket_t* m_sockPub;
};
} // namespace controller
} // namespace component
} // namespace sofa
#endif // SOFA_ZMQCOMMUNICATION_H