H3D API  2.4.1
HumanHand.h
Go to the documentation of this file.
1 // Copyright 2004-2019, SenseGraphics AB
3 //
4 // This file is part of H3D API.
5 //
6 // H3D API is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
10 //
11 // H3D API is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public License
17 // along with H3D API; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 //
20 // A commercial license is also available. Please contact us at
21 // www.sensegraphics.com for more information.
22 //
23 //
27 //
29 #ifndef __HUMANHANDH3D_H__
30 #define __HUMANHANDH3D_H__
31 
32 // H3D includes
33 #include <H3D/X3DGeometryNode.h>
34 #include <H3D/CyberGloveSensor.h>
36 
37 #ifdef HAVE_VIRTUAL_HAND_SDK
38 // Virtual Hand SDK includes
39 #include <vhandtk/vhtHumanHand.h>
40 #include <vhandtk/vhtOglDrawer.h>
41 #endif
42 
43 namespace H3D {
44 
66  class H3DAPI_API HumanHand : public X3DGeometryNode {
67  public:
68 
72  class SFCyberGloveSensor: public TypedSFNode< CyberGloveSensor > {
73  protected:
74  virtual void onAdd( Node *node ) {
76  if( node ) {
77  CyberGloveSensor * cgs = static_cast< CyberGloveSensor * >(node);
78  HumanHand *hh = static_cast< HumanHand * >(owner);
79  cgs->thumb->route( hh->displayList );
80  cgs->index->route( hh->displayList );
81  cgs->middle->route( hh->displayList );
82  cgs->ring->route( hh->displayList );
83  cgs->pinky->route( hh->displayList );
84  }
85  }
86 
87  virtual void onRemove( Node *node ) {
88  if( node ) {
89  CyberGloveSensor * cgs = static_cast< CyberGloveSensor * >(node);
90  HumanHand *hh = static_cast< HumanHand * >(owner);
91  cgs->thumb->unroute( hh->displayList );
92  cgs->index->unroute( hh->displayList );
93  cgs->middle->unroute( hh->displayList );
94  cgs->ring->unroute( hh->displayList );
95  cgs->pinky->unroute( hh->displayList );
96  }
98  }
99  };
100 
105  class SFBound: public TypedField< X3DGeometryNode::SFBound,
106  Types< SFCyberGloveSensor,
107  SFFloat, SFVec3f > > {
108  protected:
110  virtual void update() {
111  Vec3f b;
112  if( static_cast< SFCyberGloveSensor * >( routes_in[0] )->getValue() ) {
113  Vec3f scene_graph_scale =
114  static_cast< SFVec3f * >(routes_in[2])->getValue();
115  // The units of the virtual hand is centimeters, so a bounding box of
116  // about 30 centimeters in every direction should enclose the hand.
117  // The scale will scale down the hand to the correct size, by default
118  // the scale is 0.01 in order to translate into meters.
119  if( scene_graph_scale.length() > Constants::f_epsilon ) {
120  H3DFloat scale_field =
121  static_cast< SFFloat * >(routes_in[1])->getValue();
122  b = Vec3f( 35, 35, 35 ) * scale_field;
123  b.x *= 1/scene_graph_scale.x;
124  b.y *= 1/scene_graph_scale.y;
125  b.z *= 1/scene_graph_scale.z;
126  }
127  }
128  BoxBound *bb = new BoxBound;
129  bb->size->setValue( b );
130  value = bb;
131  }
132  };
133 
135  HumanHand( Inst< SFNode > _metadata = 0,
136  Inst< SFBound > _bound = 0,
137  Inst< DisplayList > _displayList = 0,
138  Inst< SFCyberGloveSensor > _cyberGlove = 0,
139  Inst< SFString > _gloveHandedness = 0,
140  Inst< SFFloat > _scale = 0 );
141 
144  CyberGloveSensor * cyber_glove = cyberGlove->getValue();
145  if( cyber_glove )
146  cyber_glove->resetGlove();
147 #ifdef HAVE_VIRTUAL_HAND_SDK
148  drawer.reset( 0 );
149  if( hand.get() )
150  hand->disconnect();
151  hand.reset( 0 );
152 #endif
153  }
154 
156  virtual void initialize();
157 
158  // render the hand.
159  virtual void render();
160 
161  // updates the hand data.
162  virtual void traverseSG( TraverseInfo &ti );
163 
167  virtual int nrTriangles() {
168  return 2000;
169  }
170 
178  virtual bool lineIntersect( const Vec3f &from,
179  const Vec3f &to,
180  LineIntersectResult &result ) { return false; }
181 
187  virtual void closestPoint( const Vec3f &p,
188  NodeIntersectResult &result ) {}
189 
198  virtual bool movingSphereIntersect( H3DFloat radius,
199  const Vec3f &from,
200  const Vec3f &to,
201  NodeIntersectResult &result )
202  { return false; }
203 
208  H3DUniquePtr< SFCyberGloveSensor> cyberGlove;
209 
215  H3DUniquePtr< SFString> gloveHandedness;
216 
224  H3DUniquePtr< SFFloat > scale;
225 
228 
229  protected:
230 #ifdef HAVE_VIRTUAL_HAND_SDK
231  // VHSDK classes
232  H3DUniquePtr< vhtHumanHand > hand;
233  H3DUniquePtr< vhtOglDrawer > drawer;
234  vhtTransform3D * cameraXForm;
235 #endif
236 
240  H3DUniquePtr< SFVec3f > sceneGraphScaling;
241  };
242 }
243 
244 #endif
Header file for CyberGloveSensor.
Contains the DependentSFNode and DependentMFNode template classes.
Header file for X3DGeometryNode, X3D scene-graph node.
The BoxBound is a Bound class that specifies the bound using an axis-aligned bounding box.
Definition: Bound.h:144
H3DUniquePtr< SFVec3f > size
The size of the bounding box.
Definition: Bound.h:287
Connects to a CyberGlove through the Virtual HandSDK.
Definition: CyberGloveSensor.h:51
H3DUniquePtr< MFDouble > ring
Outputs the angles for the joints on the ring finger.
Definition: CyberGloveSensor.h:112
H3DUniquePtr< MFDouble > index
Outputs the angles for the joints on the index finger.
Definition: CyberGloveSensor.h:98
H3DUniquePtr< MFDouble > pinky
Outputs the angles for the joints on the pinky.
Definition: CyberGloveSensor.h:119
H3DUniquePtr< MFDouble > middle
Outputs the angles for the joints on the middle finger.
Definition: CyberGloveSensor.h:105
H3DUniquePtr< MFDouble > thumb
Outputs the angles for the joints on the thumb.
Definition: CyberGloveSensor.h:91
H3DUniquePtr< DisplayList > displayList
The DisplayList instance handling the OpenGL caching of this object.
Definition: H3DDisplayListObject.h:256
Update geometric bounds of the HumanHand.
Definition: HumanHand.h:107
virtual void update()
Update the bound from the size field.
Definition: HumanHand.h:110
Field class used to check if a CyberGloveSensor is used and then set up routes from fields in the Cyb...
Definition: HumanHand.h:72
virtual void onRemove(Node *node)
This function will be called when the value of RefCountSField changes.
Definition: HumanHand.h:87
virtual void onAdd(Node *node)
We check that the type of the Node is of the correct type.
Definition: HumanHand.h:74
This is a X3DGeometryNode which renders a hand using the Virtual Hand SDK.
Definition: HumanHand.h:66
virtual int nrTriangles()
The number of triangles renderered in this geometry.
Definition: HumanHand.h:167
~HumanHand()
Destructor.
Definition: HumanHand.h:143
virtual bool lineIntersect(const Vec3f &from, const Vec3f &to, LineIntersectResult &result)
Detect intersection between a line segment and the HumanHands bounding box.
Definition: HumanHand.h:178
virtual void closestPoint(const Vec3f &p, NodeIntersectResult &result)
Find closest point on the HumanHands bounding box to point p.
Definition: HumanHand.h:187
H3DUniquePtr< SFVec3f > sceneGraphScaling
Internal C++ field used to modify the bound.
Definition: HumanHand.h:240
H3DUniquePtr< SFString > gloveHandedness
Decides whether the CyberGlove is a left or right hand.
Definition: HumanHand.h:215
H3DUniquePtr< SFCyberGloveSensor > cyberGlove
An instance of the cyberGlove.
Definition: HumanHand.h:208
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HumanHand.h:227
H3DUniquePtr< SFFloat > scale
The default hand geometrys units in the Virtual Hand SDK seems to be in centimeters.
Definition: HumanHand.h:224
virtual bool movingSphereIntersect(H3DFloat radius, const Vec3f &from, const Vec3f &to, NodeIntersectResult &result)
Detect collision between a moving sphere and the HumanHands bounding box.
Definition: HumanHand.h:198
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
virtual void onRemove(Node *n)
This function will be called when the value of RefCountSField changes.
Definition: RefCountSField.h:176
The SFFloat field contains one single-precision floating point number.
Definition: SFFloat.h:41
The SFVec3f field contains a Vec3f.
Definition: SFVec3f.h:41
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
A template modifier class for adding type checking on the routes to any Field class.
Definition: TypedField.h:84
Template to make sure that the Node that is set in a SFNode is of a specified Node type.
Definition: SFNode.h:97
virtual void onAdd(Node *n)
We check that the type of the Node is of the correct type.
Definition: SFNode.h:108
void resetGlove()
Reset glove to 0, needed in cleanup phase to not accidently try to delete instance of vhtGlove twice.
Definition: VirtualHandGloveSensor.h:101
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
float H3DFloat
Type getValue(const char *s, const char *&rest)
Function that reads characters from a char * and converts them to a given type.
Definition: X3DFieldConversion.h:134
H3D API namespace.
Definition: Anchor.h:38
The H3DNodeDatabase contains a mapping between a name of a Node and the constructor for the Node with...
Definition: H3DNodeDatabase.h:194
Used as input to lineIntersect functions.
Definition: Node.h:224
Used as input to intersection functions.
Definition: Node.h:114