YARP
Yet Another Robot Platform
Mesh.h
Go to the documentation of this file.
1 /*
2  * SPDX-FileCopyrightText: 2006-2021 Istituto Italiano di Tecnologia (IIT)
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 // This is an automatically generated file.
7 
8 // Generated from the following "shape_msgs/Mesh" msg definition:
9 // # Definition of a mesh
10 //
11 // # list of triangles; the index values refer to positions in vertices[]
12 // MeshTriangle[] triangles
13 //
14 // # the actual vertices that make up the mesh
15 // geometry_msgs/Point[] vertices
16 // Instances of this class can be read and written with YARP ports,
17 // using a ROS-compatible format.
18 
19 #ifndef YARP_ROSMSG_shape_msgs_Mesh_h
20 #define YARP_ROSMSG_shape_msgs_Mesh_h
21 
22 #include <yarp/os/Wire.h>
23 #include <yarp/os/Type.h>
24 #include <yarp/os/idl/WireTypes.h>
25 #include <string>
26 #include <vector>
29 
30 namespace yarp {
31 namespace rosmsg {
32 namespace shape_msgs {
33 
35 {
36 public:
37  std::vector<yarp::rosmsg::shape_msgs::MeshTriangle> triangles;
38  std::vector<yarp::rosmsg::geometry_msgs::Point> vertices;
39 
40  Mesh() :
41  triangles(),
42  vertices()
43  {
44  }
45 
46  void clear()
47  {
48  // *** triangles ***
49  triangles.clear();
50 
51  // *** vertices ***
52  vertices.clear();
53  }
54 
55  bool readBare(yarp::os::ConnectionReader& connection) override
56  {
57  // *** triangles ***
58  int len = connection.expectInt32();
59  triangles.resize(len);
60  for (int i=0; i<len; i++) {
61  if (!triangles[i].read(connection)) {
62  return false;
63  }
64  }
65 
66  // *** vertices ***
67  len = connection.expectInt32();
68  vertices.resize(len);
69  for (int i=0; i<len; i++) {
70  if (!vertices[i].read(connection)) {
71  return false;
72  }
73  }
74 
75  return !connection.isError();
76  }
77 
78  bool readBottle(yarp::os::ConnectionReader& connection) override
79  {
80  connection.convertTextMode();
81  yarp::os::idl::WireReader reader(connection);
82  if (!reader.readListHeader(2)) {
83  return false;
84  }
85 
86  // *** triangles ***
87  if (connection.expectInt32() != BOTTLE_TAG_LIST) {
88  return false;
89  }
90  int len = connection.expectInt32();
91  triangles.resize(len);
92  for (int i=0; i<len; i++) {
93  if (!triangles[i].read(connection)) {
94  return false;
95  }
96  }
97 
98  // *** vertices ***
99  if (connection.expectInt32() != BOTTLE_TAG_LIST) {
100  return false;
101  }
102  len = connection.expectInt32();
103  vertices.resize(len);
104  for (int i=0; i<len; i++) {
105  if (!vertices[i].read(connection)) {
106  return false;
107  }
108  }
109 
110  return !connection.isError();
111  }
112 
114  bool read(yarp::os::ConnectionReader& connection) override
115  {
116  return (connection.isBareMode() ? readBare(connection)
117  : readBottle(connection));
118  }
119 
120  bool writeBare(yarp::os::ConnectionWriter& connection) const override
121  {
122  // *** triangles ***
123  connection.appendInt32(triangles.size());
124  for (size_t i=0; i<triangles.size(); i++) {
125  if (!triangles[i].write(connection)) {
126  return false;
127  }
128  }
129 
130  // *** vertices ***
131  connection.appendInt32(vertices.size());
132  for (size_t i=0; i<vertices.size(); i++) {
133  if (!vertices[i].write(connection)) {
134  return false;
135  }
136  }
137 
138  return !connection.isError();
139  }
140 
141  bool writeBottle(yarp::os::ConnectionWriter& connection) const override
142  {
143  connection.appendInt32(BOTTLE_TAG_LIST);
144  connection.appendInt32(2);
145 
146  // *** triangles ***
147  connection.appendInt32(BOTTLE_TAG_LIST);
148  connection.appendInt32(triangles.size());
149  for (size_t i=0; i<triangles.size(); i++) {
150  if (!triangles[i].write(connection)) {
151  return false;
152  }
153  }
154 
155  // *** vertices ***
156  connection.appendInt32(BOTTLE_TAG_LIST);
157  connection.appendInt32(vertices.size());
158  for (size_t i=0; i<vertices.size(); i++) {
159  if (!vertices[i].write(connection)) {
160  return false;
161  }
162  }
163 
164  connection.convertTextMode();
165  return !connection.isError();
166  }
167 
169  bool write(yarp::os::ConnectionWriter& connection) const override
170  {
171  return (connection.isBareMode() ? writeBare(connection)
172  : writeBottle(connection));
173  }
174 
175  // This class will serialize ROS style or YARP style depending on protocol.
176  // If you need to force a serialization style, use one of these classes:
179 
180  // The name for this message, ROS will need this
181  static constexpr const char* typeName = "shape_msgs/Mesh";
182 
183  // The checksum for this message, ROS will need this
184  static constexpr const char* typeChecksum = "1ffdae9486cd3316a121c578b47a85cc";
185 
186  // The source text for this message, ROS will need this
187  static constexpr const char* typeText = "\
188 # Definition of a mesh\n\
189 \n\
190 # list of triangles; the index values refer to positions in vertices[]\n\
191 MeshTriangle[] triangles\n\
192 \n\
193 # the actual vertices that make up the mesh\n\
194 geometry_msgs/Point[] vertices\n\
195 \n\
196 ================================================================================\n\
197 MSG: shape_msgs/MeshTriangle\n\
198 # Definition of a triangle's vertices\n\
199 uint32[3] vertex_indices\n\
200 \n\
201 ================================================================================\n\
202 MSG: geometry_msgs/Point\n\
203 # This contains the position of a point in free space\n\
204 float64 x\n\
205 float64 y\n\
206 float64 z\n\
207 ";
208 
209  yarp::os::Type getType() const override
210  {
212  typ.addProperty("md5sum", yarp::os::Value(typeChecksum));
213  typ.addProperty("message_definition", yarp::os::Value(typeText));
214  return typ;
215  }
216 };
217 
218 } // namespace shape_msgs
219 } // namespace rosmsg
220 } // namespace yarp
221 
222 #endif // YARP_ROSMSG_shape_msgs_Mesh_h
#define BOTTLE_TAG_LIST
Definition: Bottle.h:28
An interface for reading from a network connection.
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual std::int32_t expectInt32()=0
Read a 32-bit integer from the network connection.
virtual bool convertTextMode()=0
Reads in a standard description in text mode, and converts it to a standard description in binary.
virtual bool isError() const =0
An interface for writing to a network connection.
virtual bool isError() const =0
virtual bool isBareMode() const =0
Check if the connection is bare mode.
virtual bool convertTextMode()=0
Converts a standard description in binary into a textual description, if the connection is in text-mo...
virtual void appendInt32(std::int32_t data)=0
Send a representation of a 32-bit integer to the network connection.
static Type byName(const char *name)
Definition: Type.cpp:171
Type & addProperty(const char *key, const Value &val)
Definition: Type.cpp:134
A single value (typically within a Bottle).
Definition: Value.h:45
A "tamed" Portable, that promises to serialize itself in an IDL-friendly way.
Definition: WirePortable.h:23
virtual bool read(yarp::os::idl::WireReader &reader)
virtual bool write(const yarp::os::idl::WireWriter &writer) const
IDL-friendly connection reader.
Definition: WireReader.h:30
yarp::os::idl::BareStyle< yarp::rosmsg::shape_msgs::Mesh > rosStyle
Definition: Mesh.h:177
yarp::os::idl::BottleStyle< yarp::rosmsg::shape_msgs::Mesh > bottleStyle
Definition: Mesh.h:178
bool write(yarp::os::ConnectionWriter &connection) const override
Write this object to a network connection.
Definition: Mesh.h:169
bool readBare(yarp::os::ConnectionReader &connection) override
Definition: Mesh.h:55
static constexpr const char * typeText
Definition: Mesh.h:187
bool read(yarp::os::ConnectionReader &connection) override
Read this object from a network connection.
Definition: Mesh.h:114
std::vector< yarp::rosmsg::geometry_msgs::Point > vertices
Definition: Mesh.h:38
yarp::os::Type getType() const override
Definition: Mesh.h:209
static constexpr const char * typeChecksum
Definition: Mesh.h:184
bool readBottle(yarp::os::ConnectionReader &connection) override
Definition: Mesh.h:78
static constexpr const char * typeName
Definition: Mesh.h:181
bool writeBottle(yarp::os::ConnectionWriter &connection) const override
Definition: Mesh.h:141
bool writeBare(yarp::os::ConnectionWriter &connection) const override
Definition: Mesh.h:120
std::vector< yarp::rosmsg::shape_msgs::MeshTriangle > triangles
Definition: Mesh.h:37
The main, catch-all namespace for YARP.
Definition: dirs.h:16