grasp
All Data Structures Namespaces Functions Modules
SurfaceMesh.h
1 // This is an automatically-generated file.
2 // It could get re-generated if the ALLOW_IDL_GENERATION flag is on.
3 
4 #ifndef YARP_THRIFT_GENERATOR_STRUCT_SurfaceMesh
5 #define YARP_THRIFT_GENERATOR_STRUCT_SurfaceMesh
6 
7 #include <yarp/os/Wire.h>
8 #include <yarp/os/idl/WireTypes.h>
9 #include <iCub/data3D/PointXYZ.h>
10 #include <iCub/data3D/Polygon.h>
11 #include <iCub/data3D/RGBA.h>
12 
13 namespace iCub {
14  namespace data3D {
15  class SurfaceMesh;
16  }
17 }
18 
19 
20 class iCub::data3D::SurfaceMesh : public yarp::os::idl::WirePortable {
21 public:
22  // Fields
23  std::string meshName;
24  std::vector<PointXYZ> points;
25  std::vector<RGBA> rgbColour;
26  std::vector<Polygon> polygons;
27 
28  // Default constructor
29  SurfaceMesh() : meshName("") {
30  }
31 
32  // Constructor with field values
33  SurfaceMesh(const std::string& meshName,const std::vector<PointXYZ> & points,const std::vector<RGBA> & rgbColour,const std::vector<Polygon> & polygons) : meshName(meshName), points(points), rgbColour(rgbColour), polygons(polygons) {
34  }
35 
36  // Copy constructor
37  SurfaceMesh(const SurfaceMesh& __alt) : WirePortable(__alt) {
38  this->meshName = __alt.meshName;
39  this->points = __alt.points;
40  this->rgbColour = __alt.rgbColour;
41  this->polygons = __alt.polygons;
42  }
43 
44  // Assignment operator
45  const SurfaceMesh& operator = (const SurfaceMesh& __alt) {
46  this->meshName = __alt.meshName;
47  this->points = __alt.points;
48  this->rgbColour = __alt.rgbColour;
49  this->polygons = __alt.polygons;
50  return *this;
51  }
52 
53  // read and write structure on a connection
54  bool read(yarp::os::idl::WireReader& reader);
55  bool read(yarp::os::ConnectionReader& connection);
56  bool write(yarp::os::idl::WireWriter& writer);
57  bool write(yarp::os::ConnectionWriter& connection);
58 
59 private:
60  bool write_meshName(yarp::os::idl::WireWriter& writer);
61  bool nested_write_meshName(yarp::os::idl::WireWriter& writer);
62  bool write_points(yarp::os::idl::WireWriter& writer);
63  bool nested_write_points(yarp::os::idl::WireWriter& writer);
64  bool write_rgbColour(yarp::os::idl::WireWriter& writer);
65  bool nested_write_rgbColour(yarp::os::idl::WireWriter& writer);
66  bool write_polygons(yarp::os::idl::WireWriter& writer);
67  bool nested_write_polygons(yarp::os::idl::WireWriter& writer);
68  bool read_meshName(yarp::os::idl::WireReader& reader);
69  bool nested_read_meshName(yarp::os::idl::WireReader& reader);
70  bool read_points(yarp::os::idl::WireReader& reader);
71  bool nested_read_points(yarp::os::idl::WireReader& reader);
72  bool read_rgbColour(yarp::os::idl::WireReader& reader);
73  bool nested_read_rgbColour(yarp::os::idl::WireReader& reader);
74  bool read_polygons(yarp::os::idl::WireReader& reader);
75  bool nested_read_polygons(yarp::os::idl::WireReader& reader);
76 
77 public:
78 
79  yarp::os::ConstString toString();
80 
81  // if you want to serialize this class without nesting, use this helper
82  typedef yarp::os::idl::Unwrapped<iCub::data3D::SurfaceMesh > unwrapped;
83 
84  class Editor : public yarp::os::Wire, public yarp::os::PortWriter {
85  public:
86 
87  Editor() {
88  group = 0;
89  obj_owned = true;
90  obj = new SurfaceMesh;
91  dirty_flags(false);
92  yarp().setOwner(*this);
93  }
94 
95  Editor(SurfaceMesh& obj) {
96  group = 0;
97  obj_owned = false;
98  edit(obj,false);
99  yarp().setOwner(*this);
100  }
101 
102  bool edit(SurfaceMesh& obj, bool dirty = true) {
103  if (obj_owned) delete this->obj;
104  this->obj = &obj;
105  obj_owned = false;
106  dirty_flags(dirty);
107  return true;
108  }
109 
110  virtual ~Editor() {
111  if (obj_owned) delete obj;
112  }
113 
114  bool isValid() const {
115  return obj!=0/*NULL*/;
116  }
117 
118  SurfaceMesh& state() { return *obj; }
119 
120  void begin() { group++; }
121 
122  void end() {
123  group--;
124  if (group==0&&is_dirty) communicate();
125  }
126  void set_meshName(const std::string& meshName) {
127  will_set_meshName();
128  obj->meshName = meshName;
129  mark_dirty_meshName();
130  communicate();
131  did_set_meshName();
132  }
133  void set_points(const std::vector<PointXYZ> & points) {
134  will_set_points();
135  obj->points = points;
136  mark_dirty_points();
137  communicate();
138  did_set_points();
139  }
140  void set_points(int index, const PointXYZ& elem) {
141  will_set_points();
142  obj->points[index] = elem;
143  mark_dirty_points();
144  communicate();
145  did_set_points();
146  }
147  void set_rgbColour(const std::vector<RGBA> & rgbColour) {
148  will_set_rgbColour();
149  obj->rgbColour = rgbColour;
150  mark_dirty_rgbColour();
151  communicate();
152  did_set_rgbColour();
153  }
154  void set_rgbColour(int index, const RGBA& elem) {
155  will_set_rgbColour();
156  obj->rgbColour[index] = elem;
157  mark_dirty_rgbColour();
158  communicate();
159  did_set_rgbColour();
160  }
161  void set_polygons(const std::vector<Polygon> & polygons) {
162  will_set_polygons();
163  obj->polygons = polygons;
164  mark_dirty_polygons();
165  communicate();
166  did_set_polygons();
167  }
168  void set_polygons(int index, const Polygon& elem) {
169  will_set_polygons();
170  obj->polygons[index] = elem;
171  mark_dirty_polygons();
172  communicate();
173  did_set_polygons();
174  }
175  const std::string& get_meshName() {
176  return obj->meshName;
177  }
178  const std::vector<PointXYZ> & get_points() {
179  return obj->points;
180  }
181  const std::vector<RGBA> & get_rgbColour() {
182  return obj->rgbColour;
183  }
184  const std::vector<Polygon> & get_polygons() {
185  return obj->polygons;
186  }
187  virtual bool will_set_meshName() { return true; }
188  virtual bool will_set_points() { return true; }
189  virtual bool will_set_rgbColour() { return true; }
190  virtual bool will_set_polygons() { return true; }
191  virtual bool did_set_meshName() { return true; }
192  virtual bool did_set_points() { return true; }
193  virtual bool did_set_rgbColour() { return true; }
194  virtual bool did_set_polygons() { return true; }
195  void clean() {
196  dirty_flags(false);
197  }
198  bool read(yarp::os::ConnectionReader& connection);
199  bool write(yarp::os::ConnectionWriter& connection);
200  private:
201 
202  SurfaceMesh *obj;
203 
204  bool obj_owned;
205  int group;
206 
207  void communicate() {
208  if (group!=0) return;
209  if (yarp().canWrite()) {
210  yarp().write(*this);
211  clean();
212  }
213  }
214  void mark_dirty() {
215  is_dirty = true;
216  }
217  void mark_dirty_meshName() {
218  if (is_dirty_meshName) return;
219  dirty_count++;
220  is_dirty_meshName = true;
221  mark_dirty();
222  }
223  void mark_dirty_points() {
224  if (is_dirty_points) return;
225  dirty_count++;
226  is_dirty_points = true;
227  mark_dirty();
228  }
229  void mark_dirty_rgbColour() {
230  if (is_dirty_rgbColour) return;
231  dirty_count++;
232  is_dirty_rgbColour = true;
233  mark_dirty();
234  }
235  void mark_dirty_polygons() {
236  if (is_dirty_polygons) return;
237  dirty_count++;
238  is_dirty_polygons = true;
239  mark_dirty();
240  }
241  void dirty_flags(bool flag) {
242  is_dirty = flag;
243  is_dirty_meshName = flag;
244  is_dirty_points = flag;
245  is_dirty_rgbColour = flag;
246  is_dirty_polygons = flag;
247  dirty_count = flag ? 4 : 0;
248  }
249  bool is_dirty;
250  int dirty_count;
251  bool is_dirty_meshName;
252  bool is_dirty_points;
253  bool is_dirty_rgbColour;
254  bool is_dirty_polygons;
255  };
256 };
257 
258 #endif
259