29 #ifndef __TRAVERSEINFO_H__
30 #define __TRAVERSEINFO_H__
33 #include <HAPI/HAPIForceEffect.h>
34 #include <HAPI/HAPIHapticShape.h>
44 class H3DHapticsDevice;
45 class X3DGeometryNode;
48 typedef AutoRefVector< HAPI::HAPIHapticShape > HapticShapeVector;
49 typedef AutoRefVector< HAPI::HAPIForceEffect > HapticEffectVector;
69 TraverseInfo(
const vector< H3DHapticsDevice * > &_haptics_devices );
74 if( haptic_shapes.size() > 0 ) {
75 return (
unsigned int) haptic_shapes[0].size();
84 for(
unsigned int i = 0; i < haptic_shapes.size(); ++i ) {
85 if( haptic_shapes[i].size() < nr_layers )
86 haptic_shapes[i].resize( nr_layers );
94 current_layer = layer;
106 for( vector< H3DHapticsDevice * >::iterator i = haptics_devices.begin();
107 i != haptics_devices.end();
109 if( (*i) == hd )
return index;
120 void addHapticShape(
int device_index,
121 HAPI::HAPIHapticShape *shape );
129 HAPI::HAPIHapticShape *shape ) {
130 int device_index = getHapticsDeviceIndex( hd );
131 addHapticShape( device_index, shape );
138 void addHapticShapeToAll( HAPI::HAPIHapticShape *shape );
144 if( device_index < 0 || device_index >= (
int)haptics_devices.size() ) {
146 s <<
"TraverseInfo only has " << (
unsigned int) haptics_devices.
size()
147 <<
" haptics device available. ";
152 return haptic_shapes[ device_index ][ current_layer ];
159 int device_index = getHapticsDeviceIndex( hd );
160 return getHapticShapes( device_index );
169 void addForceEffect(
int device_index, HAPI::HAPIForceEffect *effect );
177 HAPI::HAPIForceEffect *effect ) {
178 int device_index = getHapticsDeviceIndex( hd );
179 addForceEffect( device_index, effect );
186 void addForceEffectToAll( HAPI::HAPIForceEffect *effect );
193 if( device_index < 0 || device_index >= (
int)haptics_devices.size() ) {
195 s <<
"TraverseInfo only has " << (
unsigned int)haptics_devices.
size()
196 <<
" haptics device available. ";
201 return haptic_effects[ device_index ];
208 int device_index = getHapticsDeviceIndex( hd );
209 return getForceEffects( device_index );
219 return current_surface;
223 return haptics_devices[ device_index ];
228 return haptics_devices;
235 for(
unsigned int j = 0; j < haptics_enabled.size(); ++j ) {
236 haptics_enabled[j] =
false;
239 haptics_enabled[i] =
false;
247 for(
unsigned int j = 0; j < haptics_enabled.size(); ++j ) {
248 haptics_enabled[j] =
true;
251 haptics_enabled[i] =
true;
261 graphics_enabled =
false;
269 graphics_enabled =
true;
278 multi_pass_transparency = b;
283 return multi_pass_transparency;
294 if( i < haptics_enabled.size() ) {
295 return haptics_enabled[i];
303 for(
unsigned int i = 0; i < haptics_enabled.size(); ++i ) {
304 if( !haptics_enabled[i] )
return false;
311 for(
unsigned int i = 0; i < haptics_enabled.size(); ++i ) {
312 if( haptics_enabled[i] )
return false;
320 return haptics_enabled;
328 if( enabled.size() != haptics_enabled.size() )
return -1;
330 haptics_enabled = enabled;
337 return graphics_enabled;
348 const Matrix4f &inverse ) {
349 const TransformInfo &top = transform_stack.top();
350 transform_stack.push( TransformInfo( top.acc_frw * forward,
351 inverse * top.acc_inv ) );
357 transform_stack.pop();
364 return transform_stack.top().acc_frw;
371 return transform_stack.top().acc_inv;
377 return geometry_count[geom];
383 user_data[key] = data;
388 return user_data.find( key ) != user_data.end();
393 std::map<string, void *>::iterator i = user_data.find( key );
394 if( i != user_data.end() ) {
395 user_data.erase( i );
405 std::map<string, void *>::iterator i = user_data.find( key );
406 if( i != user_data.end() ) {
420 post_traverse_callbacks.push_back( make_pair( func, data ) );
424 void callPostTraverseCallbacks();
447 void addActiveLightNode(
X3DLightNode *light,
const Matrix4f &transform );
451 void removeActiveLightNode(
X3DLightNode *light,
const Matrix4f &transform );
459 class TransformInfo {
461 TransformInfo(
const Matrix4f &_acc_frw,
462 const Matrix4f &_acc_inv ):
464 acc_inv( _acc_inv ) {}
465 Matrix4f acc_frw, acc_inv;
467 stack< TransformInfo > transform_stack;
469 typedef std::list< std::pair< CallbackFunc, void * > > CallbackList;
471 CallbackList post_traverse_callbacks;
473 unsigned int current_layer;
474 H3DSurfaceNode *current_surface;
475 vector< H3DHapticsDevice * > haptics_devices;
476 vector< vector< HapticShapeVector > > haptic_shapes;
477 vector< HapticEffectVector > haptic_effects;
478 bool graphics_enabled;
479 bool multi_pass_transparency;
482 vector< bool > haptics_enabled;
484 typedef std::map< X3DGeometryNode *, int > GeometryCountMap;
485 GeometryCountMap geometry_count;
486 std::map< string, void * > user_data;
#define H3D_FULL_LOCATION
Include this file to include the H3D specific types.
Base class for all haptic devices.
Definition: H3DHapticsDevice.h:68
Base class for all surfaces.
Definition: H3DSurfaceNode.h:44
Thrown when trying to get hold of a H3DHapticsDevice using an invalid device index.
Definition: TraverseInfo.h:63
Class grouping X3DLightNode and its transformation matrix.
Definition: TraverseInfo.h:427
const Matrix4f & getLightTransform() const
Get the transformation matrix for the light.
Definition: TraverseInfo.h:434
TraverseInfo is a structure that is passed along when traversing the scene graph.
Definition: TraverseInfo.h:57
void enableGraphics()
Indicate that this node will be part of the graphics rendering traversal.
Definition: TraverseInfo.h:268
const vector< H3DHapticsDevice * > & getHapticsDevices()
Get the haptics devices that are available.
Definition: TraverseInfo.h:227
int getUserData(const string &key, void **data)
Get the user data value with the given key.
Definition: TraverseInfo.h:404
H3DSurfaceNode * getCurrentSurface()
Get the surface that is active in the current traversal.
Definition: TraverseInfo.h:218
const Matrix4f & getAccInverseMatrix()
Get the accumulated inverse transformation matrix, i.e.
Definition: TraverseInfo.h:370
bool hapticsEnabledForAll()
Returns true if haptics is enabled for all haptics devices.
Definition: TraverseInfo.h:302
void setCurrentSurface(H3DSurfaceNode *s)
Sets the surface that is active in the current traversal.
Definition: TraverseInfo.h:213
void setMultiPassTransparency(bool b)
If multi pass transparency is set to true the scene will be rendered three times graphically,...
Definition: TraverseInfo.h:277
vector< LightInfo > LightVector
Used to get all the X3DLightNodes that are global.
Definition: TraverseInfo.h:441
bool haveUserData(const string &key)
Returns true of user data with the given key exists.
Definition: TraverseInfo.h:387
const HapticShapeVector & getHapticShapes(H3DHapticsDevice *hd)
Get the HapticShapes that has been added for the given H3DHapticsDevice.
Definition: TraverseInfo.h:158
void enableHaptics(int i=-1)
When called, the addHapticShapes() and addForceEffects() functions calls will add HapticShapes to ren...
Definition: TraverseInfo.h:245
bool hapticsDisabledForAll()
Returns true if haptics is disabled for all haptics devices.
Definition: TraverseInfo.h:310
unsigned int nrLayers()
Returns the number of haptics layers that are available and initialized.
Definition: TraverseInfo.h:73
const HapticEffectVector & getForceEffects(H3DHapticsDevice *hd)
Get the HAPIForceEffects that has been added for the given H3DHapticsDevice.
Definition: TraverseInfo.h:207
void addHapticShape(H3DHapticsDevice *hd, HAPI::HAPIHapticShape *shape)
Adds a HapticShape to be rendered by a H3DHapticsDevice.
Definition: TraverseInfo.h:128
const vector< bool > & getHapticsEnabled()
Get a vector the same size as the haptics device vector indicating if haptics is disabled for that de...
Definition: TraverseInfo.h:319
int getHapticsDeviceIndex(H3DHapticsDevice *hd)
Returns the index of the given H3DHapticsDevice.
Definition: TraverseInfo.h:104
const HapticEffectVector & getForceEffects(int device_index)
Get the HAPIForceEffects that has been added for the H3DHapticsDevice with the given device_index.
Definition: TraverseInfo.h:192
bool getMultiPassTransparency()
See if multi pass transparency objects have been encountered.
Definition: TraverseInfo.h:282
int setHapticsEnabled(const vector< bool > &enabled)
Set a vector indicating for each haptics device if haptics is disabled or enabled.
Definition: TraverseInfo.h:327
bool graphicsEnabled()
Check whether graphics is enabled or not.
Definition: TraverseInfo.h:336
void setUserData(const string &key, void *data)
Set user data in the traversinfo object.
Definition: TraverseInfo.h:382
int deleteUserData(const string &key)
Delete user data with the given key. Returns 0 on success.
Definition: TraverseInfo.h:392
const Matrix4f & getAccForwardMatrix()
Get the accumulated forward transformation matrix, i.e.
Definition: TraverseInfo.h:363
void disableHaptics(int i=-1)
When called, future calls to addHapticShapes() and addForceEffects() functions will not add any shape...
Definition: TraverseInfo.h:233
const HapticShapeVector & getHapticShapes(int device_index)
Get the HapticShapes that has been added for the H3DHapticsDevice with the given device_index.
Definition: TraverseInfo.h:143
void addForceEffect(H3DHapticsDevice *hd, HAPI::HAPIForceEffect *effect)
Adds a HAPIForceEffect to be rendered by a H3DHapticsDevice.
Definition: TraverseInfo.h:176
void setCurrentLayer(unsigned int layer)
Set the currently active haptic layer.
Definition: TraverseInfo.h:93
void initializeLayers(unsigned int nr_layers)
Make sure that the TraverseInfo object have enough resources allocated for the given amount of haptic...
Definition: TraverseInfo.h:83
bool hapticsEnabled(unsigned int i=0)
Check whether haptics is enabled for a device index or not.
Definition: TraverseInfo.h:293
void pushMatrices(const Matrix4f &forward, const Matrix4f &inverse)
This function should be called when we move into a nested coordinate space with the transformation ma...
Definition: TraverseInfo.h:347
void disableGraphics()
Indicate that this node will not be part of the graphics rendering traversal.
Definition: TraverseInfo.h:260
void addPostTraverseCallback(CallbackFunc func, void *data)
Adds a callback function that will be called after the entire scene has been traversed
Definition: TraverseInfo.h:419
int getGeometryCount(X3DGeometryNode *geom)
Returns the number of times the given geometry has been added as the source of a haptic shape so far ...
Definition: TraverseInfo.h:376
unsigned int getCurrentLayer()
Get the currently active haptic layer.
Definition: TraverseInfo.h:98
void popMatrices()
This function should be called when we move out from a nested coordinate space.
Definition: TraverseInfo.h:356
This is the base node type for all geometry in X3D.
Definition: X3DGeometryNode.h:61
The X3DLightNode abstract node type is the base type from which all node types that serve as light so...
Definition: X3DLightNode.h:70
H3D_VALUE_EXCEPTION(string, InvalidType)
An exception thrown when a field is of the wrong type when it is checked.
H3D API namespace.
Definition: Anchor.h:38