iCub-main
bvh.h
Go to the documentation of this file.
1 /*
2  * bvh.h
3  */
4 
5 /*
6  * Copyright (C) 2009 RobotCub Consortium
7  * Author: Alessandro Scalzo alessandro.scalzo@iit.it
8  * CopyPolicy: Released under the terms of the GNU GPL v2.0.
9  *
10  * Based on:
11  *
12  * Qavimator
13  * Copyright (C) 2006 by Zi Ree *
14  * Zi Ree @ SecondLife *
15  * Released under the terms of the GNU GPL v2.0.
16  */
17 
18 #ifndef BVH_H
19 #define BVH_H
20 
22 
23 // YARP
24 
25 #include <yarp/os/Network.h>
26 #include <yarp/os/Port.h>
27 #include <yarp/os/Bottle.h>
28 #include <yarp/os/Time.h>
29 
30 #include <yarp/sig/Vector.h>
31 
32 //#include <yarp/dev/IGenericSensor.h>
33 //#include <yarp/dev/ControlBoardInterfaces.h>
34 //#include <yarp/dev/PolyDriver.h>
35 
36 //using namespace yarp::dev;
37 using namespace yarp::os;
38 
40 
41 //#include <QtCore>
42 
43 #include <yarp/os/ResourceFinder.h>
44 
45 #include "bvhnode.h"
46 #include "bvhnoderpy_xyz.h"
47 #include "bvhnodedh.h"
48 #include "bvhnodeend.h"
49 #include "bvhnodeinertial.h"
50 #include "bvhnodeforcetorque.h"
51 #include "bvhnodelefthand.h"
52 #include "bvhnoderighthand.h"
53 #include "bvhnodeeye.h"
54 #include "bvhnoderoot.h"
55 
56 #include "objectsthread.h"
57 
58 class BVH
59 {
60 public:
61  BVH(ObjectsManager* objManager=NULL);
62  bool Create(yarp::os::ResourceFinder& config);
63  ~BVH();
64 
65  QStringList partNames,bvhChannelName;
66 
67  void draw()
68  {
69  yarp::sig::Vector *enc =NULL;
70  yarp::sig::Vector *encV=NULL;
71 
72  if (portEncBase.getInputCount()>0)
73  {
74  encV=NULL;
75 
76  while (enc=portEncBase.read(false)) encV=enc;
77 
78  if (encV) for (int i=0; i<6; ++i) dEncBase[i]=(*encV)[i];
79 
80  //mObjectsManager->readEncoders(dEncBase);
81  }
82 
83  if (portEncTorso.getInputCount()>0)
84  {
85  encV=NULL;
86 
87  while (enc=portEncTorso.read(false)) encV=enc;
88 
89  if (encV) for (int i=0; i<nJTorso; ++i) dEncTorso[i]=(*encV)[i];
90  }
91 
92  if (portEncHead.getInputCount()>0)
93  {
94  encV=NULL;
95 
96  while (enc=portEncHead.read(false)) encV=enc;
97 
98  if (encV)
99  {
100  for (int i=0; i<nJHead; ++i) dEncHead[i]=(*encV)[i];
101 
102  double dLeftEye =dEncHead[4]-0.5*dEncHead[5];
103  double dRightEye=dEncHead[4]+0.5*dEncHead[5];
104 
105  dEncHead[4]=dLeftEye;
106  dEncHead[5]=dRightEye;
107  }
108  }
109 
110  if (portEncLeftArm.getInputCount()>0)
111  {
112  encV=NULL;
113 
114  while (enc=portEncLeftArm.read(false)) encV=enc;
115 
116  if (encV) for (int i=0; i<nJLeftArm; ++i) dEncLeftArm[i]=(*encV)[i];
117  }
118 
119  if (portEncRightArm.getInputCount()>0)
120  {
121  encV=NULL;
122 
123  while (enc=portEncRightArm.read(false)) encV=enc;
124 
125  if (encV) for (int i=0; i<nJRightArm; ++i) dEncRightArm[i]=(*encV)[i];
126  }
127 
128  if (portEncLeftLeg.getInputCount()>0)
129  {
130  encV=NULL;
131 
132  while (enc=portEncLeftLeg.read(false)) encV=enc;
133 
134  if (encV) for (int i=0; i<nJLeftLeg; ++i) dEncLeftLeg[i]=(*encV)[i];
135  }
136 
137  if (portEncRightLeg.getInputCount()>0)
138  {
139  encV=NULL;
140 
141  while (enc=portEncRightLeg.read(false)) encV=enc;
142 
143  if (encV) for (int i=0; i<nJRightLeg; ++i) dEncRightLeg[i]=(*encV)[i];
144  }
145 
146  glShadeModel(GL_SMOOTH);
147  GLfloat ambientA[]={0.9,0.667,0.561,1};
148  GLfloat diffuseA[]={0.9,0.667,0.561,0};
149  GLfloat specularA[]={0.6,0.6,0.6,0.0};
150  GLfloat shininessA=100.0;
151  glMaterialfv(GL_FRONT,GL_AMBIENT,ambientA);
152  glMaterialfv(GL_FRONT,GL_DIFFUSE,diffuseA);
153  glMaterialfv(GL_FRONT,GL_SPECULAR,specularA);
154  glMaterialf(GL_FRONT,GL_SHININESS,shininessA);
155  glEnable(GL_LIGHTING);
156  glEnable(GL_LIGHT0);
157  glEnable(GL_LIGHT1);
158  //glPolygonMode(GL_FRONT_AND_BACK,GL_FILL);
159  glEnable(GL_COLOR_MATERIAL);
160  glEnable(GL_LINE_SMOOTH);
161 
162  // save current drawing matrix
163  glPushMatrix();
164 
165  //static const double mm2inches=1.0/25.4;
166  double dScale=0.075*dAvatarScale;
167  glScaled(dScale,dScale,dScale);
168 
169  // visual compensation
170  glTranslated(0.0,3.5,0.0);
171 
172  pRoot->draw(dEncBuffer,NULL);
173 
174  glPopMatrix();
175  }
176 
177  protected:
178  QString inputFile;
179  QStringList tokens;
180  int tokenPos;
181  QString token();
182  bool expect_token(const QString& expect);
183 
184  double dAvatarScale;
185  BVHNode* bvhRead(yarp::os::ResourceFinder& config);
186  BVHNode* bvhReadNode(yarp::os::ResourceFinder& config);
188 
190 
192 
193  // YARP
194 
195  QString robot;
196 
197  //PolyDriver* OpenDriver(QString part);
198  //void CloseDriver(PolyDriver* &pDriver);
199 
200  //PolyDriver *pTorsoDriver,*pHeadDriver,*pLeftArmDriver,*pRightArmDriver,*pLeftLegDriver,*pRightLegDriver;
201  //IEncoders *pEncTorso,*pEncHead,*pEncLeftArm,*pEncRightArm,*pEncLeftLeg,*pEncRightLeg;
202  int nJTorso,nJHead,nJLeftArm,nJRightArm,nJLeftLeg,nJRightLeg,nJBase;
203 
204  yarp::os::BufferedPort<yarp::sig::Vector> portEncBase;
205  yarp::os::BufferedPort<yarp::sig::Vector> portEncTorso;
206  yarp::os::BufferedPort<yarp::sig::Vector> portEncHead;
207  yarp::os::BufferedPort<yarp::sig::Vector> portEncLeftArm;
208  yarp::os::BufferedPort<yarp::sig::Vector> portEncRightArm;
209  yarp::os::BufferedPort<yarp::sig::Vector> portEncLeftLeg;
210  yarp::os::BufferedPort<yarp::sig::Vector> portEncRightLeg;
211 
212  double dEncBuffer[59];
213  double *dEncTorso,*dEncHead,*dEncLeftArm,*dEncRightArm,*dEncLeftLeg,*dEncRightLeg,*dEncBase;
214 };
215 
216 #endif
Definition: bvh.h:59
QStringList tokens
Definition: bvh.h:179
ObjectsManager * mObjectsManager
Definition: bvh.h:189
yarp::os::BufferedPort< yarp::sig::Vector > portEncRightLeg
Definition: bvh.h:210
BVHNode *** mAB
Definition: bvh.h:191
yarp::os::BufferedPort< yarp::sig::Vector > portEncTorso
Definition: bvh.h:205
int tokenPos
Definition: bvh.h:180
yarp::os::BufferedPort< yarp::sig::Vector > portEncHead
Definition: bvh.h:206
QString inputFile
Definition: bvh.h:178
double * dEncBase
Definition: bvh.h:213
yarp::os::BufferedPort< yarp::sig::Vector > portEncRightArm
Definition: bvh.h:208
yarp::os::BufferedPort< yarp::sig::Vector > portEncBase
Definition: bvh.h:204
yarp::os::BufferedPort< yarp::sig::Vector > portEncLeftLeg
Definition: bvh.h:209
yarp::os::BufferedPort< yarp::sig::Vector > portEncLeftArm
Definition: bvh.h:207
QStringList bvhChannelName
Definition: bvh.h:65
BVHNode * pRoot
Definition: bvh.h:187
QString robot
Definition: bvh.h:195
void draw()
Definition: bvh.h:67
int nJBase
Definition: bvh.h:202
double dAvatarScale
Definition: bvh.h:184