0

I am working with Simulation Open Framework Architecture SOFA (C++ language) and my goal is setup some communication type between some sofa origin native data to other external application. With this order I am using ZeroMQ to transport the sofa data to a python external application.

In SOFA (C++) I have the following instrumentData structure

#include <sofa/core/behavior/BaseController.h>
#include <sofa/defaulttype/VecTypes.h>

// To Quat datatype
#include <sofa/defaulttype/Quat.h>
using sofa::defaulttype::Quat;

using std::string;

namespace sofa
{

namespace component
{
namespace controller
{
struct instrumentData
{
  typedef sofa::defaulttype::Vec3d Vec3d;
  Vec3d pos;
  Quat quat;
  int btnState;
  float openInst;
  bool blnDataReady;
};
}
}
}

I am trying a data communication of these below data member instrumentData structure via zmq, and to serialize / unserialize these data I am using Google Protocol Buffer with the order of my python destiny data application understand and interpret it the content of the instrumentData data members structure. Currently this data members structure arrive to your destiny but in binary format/content.

Google Protocol Buffer require describe a protocol in a format build inside .proto file extension, in which is necessary

you'll need to start with a .proto file. The definitions in a .proto file are simple: you add a message for each data structure you want to serialize, then specify a name and a type for each field in the message.

How to can I represent in my instrumentdata.proto file, the following fields: pos, quat, bool ... ?

typedef sofa::defaulttype::Vec3d Vec3d;
Vec3d pos;

using sofa::defaulttype::Quat;
Quat quat;

bool blnDataReady;

Currently, in the documentation is not clear about of how to should I define the fields in relation to Vectors and other data types like Quat (quaternions) which are SOFA native.

Vec3d and Quat is composed of some elements such as follow:

void ZMQServerComponent::instrumentDataSend(instrumentData a)
{
    a.pos = sofa::defaulttype::Vec3d(1.0f, 1.0f, 1.0f);
    a.quat = defaulttype::Quat(1.0f, 1.0f, 4.0f, 1.0f);
}

Is possible define as enumerators?

UPDATE

For the moment my tentative instumentdata.proto file which I am building according to the documentation is:

sintax = "proto3";
message InstrumentData {
    // enum Pos {}
    // enum Quat {}
    int32 btnState;
    float openInst;
    bool blnDataReady
}

Although I have some doubts in relation to this single protocol definition

5
  • You probably need to have some additional .proto files (message descriptions) to describe Vec3D and Quat types. Can you show your attempts for the .proto files please? Anyways a mapping layer to your native structures will be necessary, you can't represent those native structures in a direct manner. And of course it's possible to define enumerations in the protocol buffer language. Did you even bother to read their documentation? Commented Jan 29, 2018 at 20:38
  • @TheDude In first instance thanks for the hints. It's not that I have not researched or read, is that I already have some proto file version, just that I don't think so that this was sufficiently well builded. Can you see my UPDATE please? Commented Jan 29, 2018 at 20:51
  • @TheDude sure, I've read the enums documentation and I have clear their application case, my question were oriented in relation to how to can I apply the enum concept in relation with my Vec3d and Quat data types struct. I really really sorry if my question degrade the stackoverflow philosophy and I take your comments and suggest of a better way :) And of course. I will have that really research a lot about of my question specifically. Best Regards Commented Jan 29, 2018 at 21:03
  • These aren't representable as arrays of enums. As mentioned you have to resemble those types as separate message definitions. Good you provided your .proto language attempts now though. Commented Jan 29, 2018 at 21:09
  • @TheDude Ok thanks!. I'll follow research and document me about of how to represent in my .proto file this SOFA data types struct which are not include inside C++ stack Commented Jan 29, 2018 at 21:13

2 Answers 2

3

From the description, Vec3d and Quat are not enumerations, but structures, which you would describe as separate message types, e.g.

message Vec3d {
  float x = 1;
  float y = 2;
  float z = 3;
}

and

message Quat {
  float a = 1;
  float b = 2;
  float c = 3;
  float d = 4;
}

These message types can then be used in the InstrumentData message type

message InstrumentData {
  Vec3d pos = 1;
  Quat quat = 2;
  int32 btnState = 3;
  float openInst = 4;
  bool blnDataReady = 5;
}
Sign up to request clarification or add additional context in comments.

8 Comments

As for my understanding from the Sofa docs Vec3D rather resembles to an array of points, looks like you're missing one more level of indirection there. Also Quat seems to be a typo, the original type is named Quad actually.
Also if you look closer at the Quad definition there aren't float values actually, but PointID values, which finally turn out to be unsigned int typedef's.
According to Vec.h, I would say it's just a vector of 3 doubles.
Ah, it means a geometrical vector. In that case you're right.
And looking at Quat.h, it's float or double.
|
1

As mentioned you have to resemble the types from your framework to reasonable message definitions and provide a mapping layer to translate the generated stuff to your frameworks native classes.

Vec3D and Quad aren't enums in your framework and shouldn't represented as such in the protocol buffer messages definitions accordingly.

Your .proto file should rather look like (not tested yet):

message Vec3D {
    required float x = 1;
    required float y = 2;
    required float z = 3;
}

message Quad {
    required float a = 1;
    required float b = 2;
    required float c = 3;
    required float d = 4;
}

message InstrumentData {
    optional Vec3D = 1;
    optional Quat = 2;
    optional int32 btnState = 3;
    optional float openInst = 4;
    optional bool blnDataReady = 5;
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.