3Gear Systems SDK  v0.9.34
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator
HandTrackingMessage.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <string>
4 #include <vector>
5 #include <array>
6 #include <iosfwd>
7 #include <cmath>
8 #include "HandTrackingClient/VecMath.h"
9 #include "HandTrackingClient/OpenCVCamera.h"
10 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 namespace HandTrackingClient
28 {
29 
31 const static int N_JOINTS = 17;
32 
34 const static int N_FINGERS = 5;
35 
37 const static int N_HANDS = 2;
38 
42 const static int N_POSES = 7;
43 
45 const static int N_FINGER_DOFS_PER_HAND = 16;
46 
61 {
62  ROOT_JOINT = 0,
75  RING_DISTAL = 13,
78  PINKY_DISTAL = 16,
79 };
80 
83 
101 {
104  THUMB_MCP = 2,
105  THUMB_IP = 3,
108  INDEX_PIP = 6,
112  RING_MCP_AA = 10,
113  RING_MCP_FE = 11,
114  RING_PIP = 12,
117  PINKY_PIP = 15
118 };
119 
128 {
129 public:
131  HandState(const Vector3f& position,
132  const Quaternionf& rotation,
133  const int clickCount)
134  : _position(position),
135  _rotation(rotation),
136  _clickCount(clickCount) { }
137 
139  HandState() { }
140 
146  const Vector3f& getPosition() const { return _position; }
147 
153  const Quaternionf& getRotation() const { return _rotation; }
154 
157  const int getClickCount() const { return _clickCount; }
158 
159 private:
160  Vector3f _position;
161  Quaternionf _rotation;
162  int _clickCount;
163 };
164 
168 enum Hand
169 {
170  LEFT_HAND = 0,
173  INVALID_HAND = 10000
174 };
175 
179 const char* handToString(Hand hand);
180 
185 Hand stringToHand(const std::string& str);
186 
187 
190  : public std::exception
191 {
192 public:
193  ParseException (const char* message)
194  : _msg (message) {}
195  virtual ~ParseException() throw() {}
196 
197  virtual const char* what() const throw() { return _msg; }
198 
199 private:
200  const char* _msg;
201 };
202 
207 {
208 public:
213  {
214  WELCOME = 0,
215  USER = 100,
216  CALIBRATION = 101,
217  POSE = 200,
218  PRESSED = 300,
219  DRAGGED = 301,
220  RELEASED = 302,
221  MOVED = 303,
227  POINT = 500,
228  INVALID_DATA = 10000
229  };
230 
232  static const char* messageTypeToString(MessageType m);
233 
235  static MessageType stringToMessageType(const std::string& str);
236 
241  static HandTrackingMessage* deserialize(const std::string& data);
242 
246  virtual MessageType getType() const = 0 ;
247 
252  virtual std::string serialize() const = 0;
253 
254  virtual ~HandTrackingMessage();
255 protected:
259 };
260 
264 {
265 public:
266  MessageType getType() const { return _type; }
267 
273  const HandState& getHandState(int hand) const { return _hands[hand]; }
274 
276  BasicMessage(const MessageType type,
277  const Vector3f& positionLeft,
278  const Quaternionf& rotationLeft,
279  const int clickCountLeft,
280  const Vector3f& positionRight,
281  const Quaternionf& rotationRight,
282  const int clickCountRight);
283  virtual ~BasicMessage();
284 
287  std::string serialize() const;
288 
289 private:
290  MessageType _type;
291  std::array<HandState, N_HANDS> _hands;
292 };
293 
309 {
310 public:
312  PinchMessage(const MessageType type,
313  const Hand hand,
314  const Vector3f& positionLeft,
315  const Quaternionf& rotationLeft,
316  const int clickCountLeft,
317  const Vector3f& positionRight,
318  const Quaternionf& rotationRight,
319  const int clickCountRight);
320 
322  const Hand getHand() const { return _hand; }
323 
324  std::string serialize() const;
325 
326 private:
327  Hand _hand;
328 };
329 
373 {
374 public:
376  BimanualPinchMessage(const MessageType type,
377  const Hand hand,
378  const Vector3f& positionLeft,
379  const Quaternionf& rotationLeft,
380  const int clickCountLeft,
381  const Vector3f& positionRight,
382  const Quaternionf& rotationRight,
383  const int clickCountRight);
384 
386  const Hand getHand() const { return _hand; }
387 
388  std::string serialize() const;
389 
390 private:
391  Hand _hand;
392 };
393 
398 {
399 public:
401  PointMessage(const Hand hand,
402  const Vector3f& pointStart,
403  const Vector3f& pointEnd,
404  const float confidence);
405 
407  const Hand getHand() const { return _hand; }
408 
409  std::string serialize() const;
410 
411  virtual MessageType getType() const { return HandTrackingMessage::POINT; }
412 
414  Vector3f getPointStart() const { return _pointStart; }
415 
417  Vector3f getPointEnd() const { return _pointEnd; }
418 
420  Vector3f getPointDir() const { return (_pointEnd - _pointStart).normalized(); }
421 
423  float getConfidence() const { return _confidence; }
424 
425 private:
426  Hand _hand;
427  Vector3f _pointStart;
428  Vector3f _pointEnd;
429  float _confidence;
430 };
431 
435 class PoseMessage : public BasicMessage
436 {
437 
438 public:
441  enum HandPose
442  {
444  HAND_ELL = 1,
445  HAND_OKAY = 2,
450  };
451 
453  PoseMessage(const Vector3f& positionLeft,
454  const Quaternionf& rotationLeft,
455  const int clickCountLeft,
456  const Vector3f& positionRight,
457  const Quaternionf& rotationRight,
458  const int clickCountRight,
459  const std::array<float, N_HANDS>& confidenceEstimates,
460  const std::array<std::array<Quaternionf, N_JOINTS>, N_HANDS>& jointRotations,
461  const std::array<std::array<Vector3f, N_JOINTS>, N_HANDS>& jointTranslations,
462  const std::array<std::array<float, N_FINGER_DOFS_PER_HAND>, N_HANDS>& fingerDOFs,
463  const std::array<std::array<Vector3f, N_FINGERS>, N_HANDS>& fingerTips,
464  const std::array<std::array<float, N_POSES>, N_HANDS>& handPoseConfidences);
465 
466  std::string serialize() const;
467 
473  float getConfidenceEstimate(size_t hand) const { return _confidenceEstimates[hand]; }
474 
481  std::array<Matrix4f, N_JOINTS> getJointFrames(size_t hand) const;
482 
489  std::array<Transformf, N_JOINTS> getJointTransforms(size_t hand) const;
490 
499  const std::array<float, N_FINGER_DOFS_PER_HAND>& getFingerDOFs(size_t hand) const { return _fingerDOFs[hand]; }
500 
502  const std::array<Vector3f, N_FINGERS>& getFingerTips(size_t hand) const { return _fingerTips[hand]; }
503 
509  const std::array<float, N_POSES>& getHandPoseConfidences(size_t hand) const { return _handPoseConfidences[hand]; }
510 
511 private:
512  std::array<float, N_HANDS> _confidenceEstimates;
513  std::array<std::array<Quaternionf, N_JOINTS>, N_HANDS> _jointRotations;
514  std::array<std::array<Vector3f, N_JOINTS>, N_HANDS> _jointTranslations;
515  std::array<std::array<float, N_FINGER_DOFS_PER_HAND>, N_HANDS> _fingerDOFs;
516  std::array<std::array<Vector3f, N_FINGERS>, N_HANDS> _fingerTips;
517  std::array<std::array<float, N_POSES>, N_HANDS> _handPoseConfidences;
518 };
519 
520 
526 {
527 public:
529  WelcomeMessage (const std::string& serverVersion,
530  const std::string& protocolVersion,
531  const std::vector<OpenCVCamera>& cameras);
532 
534 
536  const std::string getServerVersion() const { return _serverVersion; }
537 
540  const std::string getProtocolVersion() const { return _protocolVersion; }
541 
542  std::string serialize() const;
543 
547  const std::vector<OpenCVCamera>& getCameras() const { return _cameras; }
548 
549 private:
550  std::string _serverVersion;
551  std::string _protocolVersion;
552 
553  std::vector<OpenCVCamera> _cameras;
554 };
555 
574 {
575 public:
577  typedef std::array<int,3> Triangle;
578 
579  // A list of bone influence indices (for a single vertex).
580  typedef std::vector<int> IndicesVector;
581 
582  // A list of bone influence weights (for a single vertex).
583  typedef std::vector<float> WeightsVector;
584 
591  const std::string& getUserProfileName() const { return _userProfileName; };
592 
595  const std::vector<Vector3f>& getRestPositions(int hand) const { return _restPositions[hand]; }
596 
598  const std::vector<Triangle>& getTriangles(int hand) const { return _triangles[hand]; }
599 
601  const std::vector<IndicesVector>& getSkinningIndices(int hand) const { return _skinningIndices[hand]; }
602 
651  const std::vector<WeightsVector>& getSkinningWeights(int hand) const { return _skinningWeights[hand]; }
652 
654  std::array<Matrix4f, N_JOINTS> getRestJointFrames(int hand) const;
655 
657  std::array<Transformf, N_JOINTS> getRestJointTransforms(int hand) const;
658 
660  UserMessage(const std::string& userProfileName,
661  const std::array<std::vector<Vector3f>, N_HANDS>& restPositions,
662  const std::array<std::vector<Triangle>, N_HANDS>& triangles,
663  const std::array<std::vector<IndicesVector>, N_HANDS>& skinningIndices,
664  const std::array<std::vector<WeightsVector>, N_HANDS>& skinningWeights,
665  const std::array<std::array<Quaternionf, N_JOINTS>, N_HANDS>& restJointRotations,
666  const std::array<std::array<Vector3f, N_JOINTS>, N_HANDS>& restJointTranslations);
667 
669 
670  std::string serialize() const;
671 
672 private:
673  std::string _userProfileName;
674  std::array<std::vector<Vector3f>, N_HANDS> _restPositions;
675  std::array<std::vector<Triangle>, N_HANDS> _triangles;
676  std::array<std::vector<IndicesVector>, N_HANDS> _skinningIndices;
677  std::array<std::vector<WeightsVector>, N_HANDS> _skinningWeights;
678  std::array<std::array<Quaternionf, N_JOINTS>, N_HANDS> _restJointRotations;
679  std::array<std::array<Vector3f, N_JOINTS>, N_HANDS> _restJointTranslations;
680 };
681 
692 {
693 public:
695  CalibrationMessage(const float percentComplete,
696  const float currentScale) : _percentComplete(percentComplete),
697  _currentScale(currentScale) {}
698 
701  float getPercentComplete() const { return _percentComplete; }
702 
704  float getCurrentScale() const { return _currentScale; }
705 
707 
708  std::string serialize() const;
709 
710 private:
711  float _percentComplete;
712  float _currentScale;
713 };
714 
715 } // namespace HandTrackingClient
716