H3D API  2.4.1
HapticsRenderers.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 __HAPTICSRENDERERS_H__
30 #define __HAPTICSRENDERERS_H__
31 
32 // H3DApi includes
34 #include <H3D/SFDouble.h>
35 #include <H3D/SFFloat.h>
36 #include <H3D/SFString.h>
37 #include <H3D/SFBool.h>
38 #include <H3D/FieldTemplates.h>
39 #include <H3D/MFNode.h>
40 
41 // HAPI includes
42 #include <HAPI/RuspiniRenderer.h>
43 #include <HAPI/GodObjectRenderer.h>
44 
45 namespace H3D {
46 
52  class H3DAPI_API OpenHapticsRenderer: public H3DHapticsRendererNode {
53  public:
56  class H3DAPI_API ShapeType: public OnValueChangeSField< SFString > {
57  protected:
58  virtual void onValueChange( const string &v );
59  };
60 
63  class H3DAPI_API AdaptiveViewport: public OnValueChangeSField< SFBool > {
64  protected:
65  virtual void onValueChange( const bool &v );
66  };
67 
68 
71  class H3DAPI_API CameraView: public OnValueChangeSField< SFBool > {
72  protected:
73  virtual void onValueChange( const bool &v );
74  };
75 
77  OpenHapticsRenderer( Inst< ShapeType > _defaultShapeType = 0,
78  Inst< AdaptiveViewport > _defaultAdaptiveViewport = 0,
79  Inst< CameraView > _defaultHapticCameraView = 0 ) :
80  defaultShapeType( _defaultShapeType ),
81  defaultAdaptiveViewport( _defaultAdaptiveViewport ),
82  defaultHapticCameraView( _defaultHapticCameraView ) {
83  type_name = "OpenHapticsRenderer";
84  database.initFields( this );
85 
86 #ifndef HAVE_OPENHAPTICS
87  Console(LogLevel::Error) << "Cannot use OpenHapticsRenderer. HAPI compiled without"
88  << " OpenHaptics support. Recompile HAPI with "
89  << "HAVE_OPENHAPTICS defined"
90  << " in order to use it." << endl;
91 #endif
92 
93  defaultShapeType->addValidValue( "FEEDBACK_BUFFER" );
94  defaultShapeType->addValidValue( "DEPTH_BUFFER" );
95  defaultShapeType->setValue( "FEEDBACK_BUFFER" );
96  defaultAdaptiveViewport->setValue( true );
97  defaultHapticCameraView->setValue( true );
98  }
99 
106  H3DUniquePtr< SFString > defaultShapeType;
107 
113  H3DUniquePtr< SFBool > defaultAdaptiveViewport;
114 
120  H3DUniquePtr< SFBool > defaultHapticCameraView;
121 
124  protected:
126  virtual HAPI::HAPIHapticsRenderer *getNewHapticsRenderer();
127  };
128 
136  class H3DAPI_API GodObjectRenderer: public H3DHapticsRendererNode {
137  public:
138 
141  class H3DAPI_API MinDistance : public OnValueChangeSField< SFDouble > {
142  virtual void onValueChange(const H3DDouble &v);
143  };
144 
147  class H3DAPI_API EnableSecondaryCollisions : public OnValueChangeSField< SFBool > {
148  virtual void onValueChange(const bool &v);
149  };
150 
152  GodObjectRenderer( Inst< MinDistance > _minDistance = 0,
153  Inst< EnableSecondaryCollisions > _enableSecondaryCollisions = 0);
154 
161  H3DUniquePtr< SFDouble > minDistance;
162 
171  H3DUniquePtr< SFBool > enableSecondaryCollisions;
172 
175  protected:
177  virtual HAPI::HAPIHapticsRenderer *getNewHapticsRenderer() {
178  return new HAPI::GodObjectRenderer( minDistance->getValue(), enableSecondaryCollisions->getValue());
179  }
180  };
181 
189  class H3DAPI_API RuspiniRenderer: public H3DHapticsRendererNode {
190  public:
193  class H3DAPI_API ProxyRadius: public OnValueChangeSField< SFFloat > {
194  virtual void onValueChange( const H3DFloat &v );
195  };
196 
197  class H3DAPI_API AlwaysFollowSurface: public OnValueChangeSField< SFBool > {
198  virtual void onValueChange( const bool &b );
199  };
200 
202  RuspiniRenderer( Inst< ProxyRadius > _proxyRadius = 0,
203  Inst< AlwaysFollowSurface > _alwaysFollowSurface = 0 );
204 
209  H3DUniquePtr< SFFloat > proxyRadius;
210 
234  H3DUniquePtr< SFBool > alwaysFollowSurface;
235 
238  protected:
240  virtual HAPI::HAPIHapticsRenderer *getNewHapticsRenderer() {
241  return new HAPI::RuspiniRenderer( proxyRadius->getValue(), alwaysFollowSurface->getValue() );
242  }
243  };
244 
245 #ifdef HAVE_CHAI3D
252  class H3DAPI_API Chai3DRenderer: public H3DHapticsRendererNode {
253  public:
254 
257  type_name = "Chai3DRenderer";
258  database.initFields( this );
259  }
260 
263 
264  protected:
266  virtual HAPI::HAPIHapticsRenderer *getNewHapticsRenderer();
267  };
268 #endif
269 
280  class H3DAPI_API LayeredRenderer: public H3DHapticsRendererNode {
281  public:
282 
286  class H3DAPI_API MFHapticsRendererNode:
287  public TypedMFNode< H3DHapticsRendererNode > {
288  protected:
289 
290  virtual void onAdd( Node *n );
291 
292  virtual void onRemove( Node *n );
293  };
294 
296  LayeredRenderer( Inst< MFHapticsRendererNode > _hapticsRenderer = 0 );
297 
299  virtual HAPI::HAPIHapticsRenderer *
300  getHapticsRenderer( unsigned int layer );
301 
308  virtual void hapticsRendererRemoved( unsigned int layer ) {
309  hapticsRendererRemovedInternal( layer );
310  if( layer < hapticsRenderer->size() )
311  hapticsRenderer->getValueByIndex( layer )->
312  hapticsRendererRemoved( 0 );
313  }
314 
321  H3DUniquePtr< MFHapticsRendererNode > hapticsRenderer;
322 
325  protected:
327  virtual HAPI::HAPIHapticsRenderer *getNewHapticsRenderer() {
328  return new HAPI::GodObjectRenderer;
329  }
330 
331  void hapticsRendererRemovedInternal( unsigned int layer, bool erase = false ) {
332  if( erase ) {
333  if( layer < renderers.size() ) {
334  vector< HAPI::HAPIHapticsRenderer * >::iterator i = renderers.begin();
335  i += layer;
336  renderers.erase( i );
337  }
338  } else
340  }
341  };
342 }
343 
344 #endif
Contains different templates to modify field behaviour.
Header file for H3DHapticsRendererNode.
Contains the MFNode class.
Contains the SFBool field class.
Contains the SFDouble field class.
Contains the SFFloat field class.
Contains the SFString field class.
Haptics renderer using Chai3D(www.chai3d.org) Uses the HAPI::Chai3DRenderer class.
Definition: HapticsRenderers.h:252
Chai3DRenderer()
Constructor.
Definition: HapticsRenderers.h:256
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HapticsRenderers.h:262
EnableSecondaryCollisions specializes SFBool to set the value determining whether to enable secondary...
Definition: HapticsRenderers.h:147
minDistance specializes SFDouble to set the minimum distance between the surface and the proxy in God...
Definition: HapticsRenderers.h:141
Haptics renderer using the god object algorithm to render objects.
Definition: HapticsRenderers.h:136
H3DUniquePtr< SFBool > enableSecondaryCollisions
Performs additional collision detection when calculating a new proxy position Attempts to avoid placi...
Definition: HapticsRenderers.h:171
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HapticsRenderers.h:174
virtual HAPI::HAPIHapticsRenderer * getNewHapticsRenderer()
Returns a new instance of HAPI::GodObjectRenderer.
Definition: HapticsRenderers.h:177
H3DUniquePtr< SFDouble > minDistance
The minimum distance the proxy will be from the surface.
Definition: HapticsRenderers.h:161
Base class for all haptic renderers, i.e.
Definition: H3DHapticsRendererNode.h:44
virtual void hapticsRendererRemoved(unsigned int layer)
This function should only be called if the HAPI::HAPIHapticsRenderer obtained for the given layer is ...
Definition: H3DHapticsRendererNode.h:69
MFHapticsRendererNode extends TypedMFNode< H3DHapticsRendererNode > in order to change the haptics re...
Definition: HapticsRenderers.h:287
Haptics renderer which may contain other haptics renderer nodes.
Definition: HapticsRenderers.h:280
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HapticsRenderers.h:324
virtual void hapticsRendererRemoved(unsigned int layer)
This function should only be called if the HAPI::HAPIHapticsRenderer obtained for the given layer is ...
Definition: HapticsRenderers.h:308
H3DUniquePtr< MFHapticsRendererNode > hapticsRenderer
The hapticsRenderer field contains a HapticsRendererNode for each layer.
Definition: HapticsRenderers.h:321
virtual HAPI::HAPIHapticsRenderer * getNewHapticsRenderer()
Returns a new instance of HAPI::RuspiniRenderer.
Definition: HapticsRenderers.h:327
Node is the base class for all classes that can be part of the H3D scene-graph.
Definition: Node.h:46
Template for adding the virtual function onValueChange that can be overridden in subclasses in order ...
Definition: FieldTemplates.h:49
AdaptiveViewport specializes SFBool to set the appropriate default values in the HAPI::OpenHapticsRen...
Definition: HapticsRenderers.h:63
CameraView specializes SFBool to set the appropriate default values in the HAPI::OpenHapticsRenderer ...
Definition: HapticsRenderers.h:71
ShapeType specializes SFString to set the appropriate default OpenHaptics shape in the HAPI::OpenHapt...
Definition: HapticsRenderers.h:56
Haptics renderer using OpenHaptics to render objects.
Definition: HapticsRenderers.h:52
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HapticsRenderers.h:123
H3DUniquePtr< SFBool > defaultAdaptiveViewport
The default value for use of adaptive viewport to use if it has not been specified with the OpenHapti...
Definition: HapticsRenderers.h:113
H3DUniquePtr< SFString > defaultShapeType
The default shape type to use if it has not been specified with the OpenHapticsOptions node.
Definition: HapticsRenderers.h:106
OpenHapticsRenderer(Inst< ShapeType > _defaultShapeType=0, Inst< AdaptiveViewport > _defaultAdaptiveViewport=0, Inst< CameraView > _defaultHapticCameraView=0)
Constructor.
Definition: HapticsRenderers.h:77
H3DUniquePtr< SFBool > defaultHapticCameraView
The default value for use of haptic camera view to use if it has not been specified with the OpenHapt...
Definition: HapticsRenderers.h:120
ProxyRadius specializes SFFloat to set the proxy radius in the HAPI::RuspiniRenderer used.
Definition: HapticsRenderers.h:193
Haptics renderer using a variant of the Ruspini algorithm allowing you to specify a radius on the pro...
Definition: HapticsRenderers.h:189
static H3DNodeDatabase database
The H3DNodeDatabase for this node.
Definition: HapticsRenderers.h:237
H3DUniquePtr< SFFloat > proxyRadius
The radius of the proxy in metres.
Definition: HapticsRenderers.h:209
virtual HAPI::HAPIHapticsRenderer * getNewHapticsRenderer()
Returns a new instance of HAPI::RuspiniRenderer.
Definition: HapticsRenderers.h:240
H3DUniquePtr< SFBool > alwaysFollowSurface
Always move the proxy when the object that it is in contact with moves.
Definition: HapticsRenderers.h:234
Template to make sure that the Nodes that are added to a MFNode are of a specified Node type.
Definition: MFNode.h:221
double H3DDouble
float H3DFloat
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