iCub-main
SkinMeshThreadPort.h
Go to the documentation of this file.
1 // -*- mode:C++; tab-width:4; c-basic-offset:4; indent-tabs-mode:nil -*-
2 
3 /*
4  * Copyright (C) 2009 RobotCub Consortium
5  * Author: Marco Maggiali, Alessandro Scalzo
6  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
7  *
8  */
9 
10 #ifndef __SKIN_MESH_THREAD_PORT_H__
11 #define __SKIN_MESH_THREAD_PORT_H__
12 
13 #include <mutex>
14 #include <string>
15 #include <vector>
16 
17 #include <yarp/os/PeriodicThread.h>
18 #include <yarp/os/Log.h>
19 #include <yarp/dev/ControlBoardInterfaces.h>
20 #include <yarp/dev/PolyDriver.h>
21 #include <yarp/dev/CanBusInterface.h>
22 #include <yarp/sig/Vector.h>
23 
24 #include "include/Quad16.h"
25 #include "include/PalmRight.h"
26 #include "include/PalmLeft.h"
27 #include "include/fakePalm.h"
28 #include "include/Triangle.h"
29 #include "include/Fingertip.h"
30 #include "include/Fingertip2Left.h"
32 #include "include/Fingertip3Left.h"
34 #include "include/Fingertip4Left.h"
36 #include "include/FingertipMID.h"
37 #include "include/Triangle_10pad.h"
38 #include "include/CER_SH_PDL.h"
39 
40 using namespace yarp::os;
41 using namespace yarp::dev;
42 
43 class SkinMeshThreadPort : public PeriodicThread
44 {
45 protected:
46  static const int MAX_SENSOR_NUM = 128;
47 
48  BufferedPort<Bottle> skin_port;
49  BufferedPort<Bottle> skin_port_virtual;
50  TouchSensor *sensor[MAX_SENSOR_NUM];
51 
52  std::mutex mtx;
53 
56 
57  std::vector<unsigned char> defaultColor;
58 
59  double skinThreshold;
60 
61 public:
62  SkinMeshThreadPort(Searchable& config,int period);
63 
65  {
66  for (int t=0; t<MAX_SENSOR_NUM; ++t)
67  {
68  if (sensor[t]) delete sensor[t];
69  }
70  }
71 
72  virtual bool threadInit();
73  virtual void threadRelease();
74  virtual void run();
75 
76  void resize(int width,int height)
77  {
78  std::lock_guard<std::mutex> lck(mtx);
79  for (int t=0; t<MAX_SENSOR_NUM; ++t)
80  {
81  if (sensor[t]) sensor[t]->resize(width,height,40);
82  }
83  }
84 
85  void eval(unsigned char *image)
86  {
87  std::lock_guard<std::mutex> lck(mtx);
88  for (int t=0; t<MAX_SENSOR_NUM; ++t)
89  {
90  if (sensor[t])
91  {
92  if (mbSimpleDraw)
93  {
94  sensor[t]->eval_light(image);
95  }
96  else
97  {
98  sensor[t]->eval(image);
99  }
100  }
101  }
102  }
103 
104  void draw(unsigned char *image)
105  {
106  for (int t=0; t<MAX_SENSOR_NUM; ++t)
107  {
108  if (sensor[t]) sensor[t]->draw(image);
109  }
110  }
111 };
112 
113 #endif
BufferedPort< Bottle > skin_port_virtual
std::vector< unsigned char > defaultColor
void eval(unsigned char *image)
void resize(int width, int height)
BufferedPort< Bottle > skin_port
void draw(unsigned char *image)
void eval(unsigned char *image)
Definition: TouchSensor.h:177
void resize(int width, int height, int margin)
Definition: TouchSensor.h:48
virtual void draw(unsigned char *image)
Definition: TouchSensor.h:275
void eval_light(unsigned char *image)
Definition: TouchSensor.h:128