Open Inventor Release 2023.2.3
 
Loading...
Searching...
No Matches
SoCollisionManager.h
Go to the documentation of this file.
1/*=======================================================================
2 *** THE CONTENT OF THIS WORK IS PROPRIETARY TO FEI S.A.S, (FEI S.A.S.), ***
3 *** AND IS DISTRIBUTED UNDER A LICENSE AGREEMENT. ***
4 *** ***
5 *** REPRODUCTION, DISCLOSURE, OR USE, IN WHOLE OR IN PART, OTHER THAN AS ***
6 *** SPECIFIED IN THE LICENSE ARE NOT TO BE UNDERTAKEN EXCEPT WITH PRIOR ***
7 *** WRITTEN AUTHORIZATION OF FEI S.A.S. ***
8 *** ***
9 *** RESTRICTED RIGHTS LEGEND ***
10 *** USE, DUPLICATION, OR DISCLOSURE BY THE GOVERNMENT OF THE CONTENT OF THIS ***
11 *** WORK OR RELATED DOCUMENTATION IS SUBJECT TO RESTRICTIONS AS SET FORTH IN ***
12 *** SUBPARAGRAPH (C)(1) OF THE COMMERCIAL COMPUTER SOFTWARE RESTRICTED RIGHT ***
13 *** CLAUSE AT FAR 52.227-19 OR SUBPARAGRAPH (C)(1)(II) OF THE RIGHTS IN ***
14 *** TECHNICAL DATA AND COMPUTER SOFTWARE CLAUSE AT DFARS 52.227-7013. ***
15 *** ***
16 *** COPYRIGHT (C) 1996-2014 BY FEI S.A.S, ***
17 *** BORDEAUX, FRANCE ***
18 *** ALL RIGHTS RESERVED ***
19**=======================================================================*/
20/*=======================================================================
21** Author : Fabien ARNAUD (Jul 1997)
22**=======================================================================*/
23
24
25#ifndef _SO_COLLISION_MANAGER_
26#define _SO_COLLISION_MANAGER_
27
28
29//------------------------------------------------------------------------------
30// Includes
31#include <Inventor/SbBasic.h>
32#include <Inventor/SbLinear.h>
33
34
35//------------------------------------------------------------------------------
36// Types declaration
37class SoNode;
38class SoGroup;
39class SoPath;
40class SoTransform;
42class SoSensor;
43class SoDragger;
44class SoNodeSensor;
45class SoFieldSensor;
47
48
49//------------------------------------------------------------------------------
50// Types definition
54typedef SbBool SoFilterCollisionCB (void* userData,
55 const SoPath* p1,
56 const SoPath* p2);
60typedef void SoBBoxCollisionCB (void* userData,
61 const SoPath* p1,
62 const SoPath* p2);
63
76 TRIANGLE = 3
77 };
90};
91
92
134{
135
136public :
137
138 // Types definitions ---------------------------------------------------------
148
153 typedef Resp SoCollisionCB (void* userData,
154 const SoCollidingPrimitive* object,
155 const SoCollidingPrimitive* scene);
156
163 SoGroup* scene,
164 SoTransform* transform);
169
173 void setObject (SoPath* object);
174
178 SoPath* getObject () const;
179
183 void setScene (SoGroup* scene);
184
188 SoGroup* getScene () const;
189
193 void setTransform (SoTransform* transform);
194
199
207 void setGluingLevel (unsigned int level);
208
212 unsigned int getGluingLevel() const;
213
219
225
232
238
246 void setGluing (SbBool flag = TRUE);
247
253 SbBool isGluing () const;
254
260 void activate (SbBool flag = TRUE);
261
266
273 void setFilterCallback (SoFilterCollisionCB* f, void* userData = NULL);
274
283 void addBBoxCollisionCallback (SoBBoxCollisionCB* f, void* userData = NULL);
284
290 void* userData = NULL);
304 void addCollisionCallback (SoCollisionCB* f, void* userData = NULL);
305
310 void removeCollisionCallback(SoCollisionCB* f, void* userData = NULL);
311
312 // Computing types -----------------------------------------------------------
328
330 enum Axis {
336 Z_AXIS = 4
337 };
338
340 enum Position {
344 END
345 };
346
347#ifndef HIDDEN_FROM_DOC
348
349 struct ShapeBBoxInformationItem {
350 SoPath* path;
351 float x_min, y_min, z_min;
352 float x_max, y_max, z_max;
353 };
354
355 struct PairTableItem {
356 int overlap_flags;
357 float x_min, y_min, z_min;
358 float x_max, y_max, z_max;
359 };
360
361 struct CompListItem
362 {
363 int shape_index;
364 Position position;
365 SbBool to_remove;
366 float x, y, z;
367 };
368
369 struct ManagerListItem {
370 SoCollisionManager* manager;
371 ManagerListItem* next;
372 };
373
374 class SceneInformationItem {
375 public:
376 ~SceneInformationItem();
377
378 SoGroup* root;
379 SoNodeSensor* sensor;
380 SbBool need_refresh;
381 SbBool one_object_has_changed;
382
383 int refs;
384 ManagerListItem* manager_list;
385 int active_manager_count;
386
387 int shape_count;
388 int shape_bbox_information_reserved_size;
389 ShapeBBoxInformationItem* shape_bbox_information;
390
391 int pair_table_reserved_size;
392 PairTableItem* pair_table;
393
394 int comp_list_size;
395 int comp_list_reserved_size;
396 CompListItem* comp_list;
397
398
399 SceneInformationItem* next;
400 };
401#endif // HIDDEN_FROM_DOC
402
403private :
404
405 // General data --------------------------------------------------------------
406 SoPath* m_object;
407 SoGroup* m_scene;
408 SoTransform* m_transform;
409 int m_gluing_level;
410
411 // Flags ---------------------------------------------------------------------
412 SbBool m_object_bbox_only;
413 SbBool m_scene_bbox_only;
414 SbBool m_gluing;
415 SbBool m_activated;
416
417 // Managing callbacks --------------------------------------------------------
418 SoFilterCollisionCB* m_filter_cb;
419 void* m_filter_cb_ud;
420 void* m_bbox_cb_list;
421 void* m_collision_cb_list;
422 void invokeBBoxCallbacks (const SoPath* p1, const SoPath* p2);
423 Resp invokeCollisionCallbacks (const SoCollidingPrimitive* object,
424 const SoCollidingPrimitive* scene);
425
426 // Computing variables -------------------------------------------------------
427 SbBool m_need_check;
428 SbBool m_object_geometry_has_changed;
429 int m_primitive_count;
430 int m_num_primitive_reserved;
431 SoCollidingPrimitive* m_primitives;
432 SoPath* m_current_shape_path;
433 Resp m_upper_response;
434 SbBool m_new_moving;
435 SbBool m_new_shapes_pair;
436 static SceneInformationItem* m_scene_information_list;
437 SceneInformationItem* m_scene_information;
438 SbBool m_is_a_good_transform;
439 SbBool m_there_is_a_good_transform;
440 SbBool m_need_gluing;
441 SoTransform* m_last_know_good_transform;
442 SoTransform* m_temporary_transform;
443 SoFieldSensor* m_translation_sensor;
444 SoFieldSensor* m_scale_sensor;
445 SoFieldSensor* m_rotation_sensor;
446 SoFieldSensor* m_orientation_sensor;
447 SoFieldSensor* m_center_sensor;
448
449 // Computing functions -------------------------------------------------------
450 PairTableItem* pairTableGetItem (int shape1, int shape2);
451 void pairTableCompute (int (*fct)(const void*, const void*), Axis axis);
452 static int compListXCompare(const void* v1, const void* v2);
453 static int compListYCompare(const void* v1, const void* v2);
454 static int compListZCompare(const void* v1, const void* v2);
455 void refresh ();
456 void addPrimitiveToTable (SoPath* p,
458 SbVec3f v1,
459 SbVec3f v2,
460 SbVec3f v3);
461 void addPrimitiveToTable (SoPath* p,
463 SbVec3f v1,
464 SbVec3f v2)
465 { addPrimitiveToTable (p, type, v1, v2, SbVec3f (0, 0, 0)); }
466 void addTriangleToTable (SoCallbackAction* action,
467 const SoPrimitiveVertex* v1,
468 const SoPrimitiveVertex* v2,
469 const SoPrimitiveVertex* v3);
470 void addSegmentToTable (SoCallbackAction* action,
471 const SoPrimitiveVertex* v1,
472 const SoPrimitiveVertex* v2);
473 void onObjectTriangle (SoCallbackAction* action,
474 const SoPrimitiveVertex* v1,
475 const SoPrimitiveVertex* v2,
476 const SoPrimitiveVertex* v3);
477 void onObjectTriangleReal (const SbVec3f v0,
478 const SbVec3f v1,
479 const SbVec3f v2);
480 void onObjectSegment (SoCallbackAction* action,
481 const SoPrimitiveVertex* v1,
482 const SoPrimitiveVertex* v2);
483 SbBool intersectionTwoTriangles (SoCollidingPrimitive* t1,
485 // int intersectionTriangleAndSegment (SoCollidingPrimitive* t,
486 // SbVec3f s0, SbVec3f s1);
487 SbBool onTransformChange(SoSensor *sensor, TransformChangeType type);
488 SbBool onTransformChange(SbBool sensorIsNotNULL, TransformChangeType type);
489 SbBool checkSensor (SoSensor* sensor);
490 static SceneInformationItem* getSceneInformation(SoCollisionManager* manager);
491 static void removeSceneInformation (SoCollisionManager* manager);
492 static void onSceneChange (void* ud, SoSensor* sensor);
493 static void refresh (SceneInformationItem* scene);
494 void lastKnowGoodTransformComputing ();
495
496 // Real callbacks ------------------------------------------------------------
497 static void addTriangleToTableCB (void* ud, SoCallbackAction* action,
498 const SoPrimitiveVertex* v1,
499 const SoPrimitiveVertex* v2,
500 const SoPrimitiveVertex* v3)
501 { ((SoCollisionManager*) ud)->addTriangleToTable (action, v1, v2, v3); }
502 static void addSegmentToTableCB (void* ud, SoCallbackAction* action,
503 const SoPrimitiveVertex* v1,
504 const SoPrimitiveVertex* v2)
505 { ((SoCollisionManager*) ud)->addSegmentToTable (action, v1, v2); }
506
507 static void onObjectTriangleCB (void* ud, SoCallbackAction* action,
508 const SoPrimitiveVertex* v1,
509 const SoPrimitiveVertex* v2,
510 const SoPrimitiveVertex* v3)
511 { ((SoCollisionManager*) ud)->onObjectTriangle (action, v1, v2, v3); }
512 static void onObjectSegmentCB (void* ud, SoCallbackAction* action,
513 const SoPrimitiveVertex* v1,
514 const SoPrimitiveVertex* v2)
515 { ((SoCollisionManager*) ud)->onObjectSegment (action, v1, v2); }
516 static void onTranslationChangeCB (void* ud, SoSensor* sensor)
517 { ((SoCollisionManager*) ud)->onTransformChange (sensor, TRANSLATION); }
518 static void onScaleChangeCB (void* ud, SoSensor* sensor)
519 { ((SoCollisionManager*) ud)->onTransformChange (sensor, SCALE); }
520 static void onRotationChangeCB (void* ud, SoSensor* sensor)
521 { ((SoCollisionManager*) ud)->onTransformChange (sensor, ROTATION); }
522 static void onOrientationChangeCB (void* ud, SoSensor* sensor)
523 { ((SoCollisionManager*) ud)->onTransformChange (sensor, ORIENTATION); }
524 static void onCenterChangeCB (void* ud, SoSensor* sensor)
525 { ((SoCollisionManager*) ud)->onTransformChange (sensor, CENTER); }
526 static void onDraggerMotionCB (void* ud, SoDragger *)
527 { ((SoCollisionManager*) ud)->onDraggerMotion (); }
528
529 // Manipulator features ------------------------------------------------------
530 SbVec3f m_dragger_translation;
531 SbRotation m_dragger_rotation;
532 SbVec3f m_dragger_scale_factor;
533 SbRotation m_dragger_scale_orientation;
534 SbVec3f m_dragger_center;
535 void onDraggerMotion ();
536
537 // Miscelaneous --------------------------------------------------------------
538 void quickSort(void *array, int nElm, int elmSize,
539 int (*compare)(const void*, const void*),
540 char *tmp);
541
542};
543
544#endif //_SO_COLLISION_MANAGER_
545
#define TRUE
Possible value of SbBool.
Definition SbBase.h:77
void SoBBoxCollisionCB(void *userData, const SoPath *p1, const SoPath *p2)
SbBool SoFilterCollisionCB(void *userData, const SoPath *p1, const SoPath *p2)
Class for representing a rotation.
Definition SbRotation.h:126
3D vector class.
Definition SbVec.h:932
Performs a generic traversal of a scene graph or path.
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class to manage ...
void removeBBoxCollisionCallback(SoBBoxCollisionCB *f, void *userData=NULL)
Removes bounding box collision callback.
Resp
Types definitions.
@ ABORT
Do not continue.
@ NEXT_SHAPE
Continue and call again for next colliding shape.
@ NEXT_PRIMITIVE
Continue and call again for next colliding primitive.
void addCollisionCallback(SoCollisionCB *f, void *userData=NULL)
Adds collision callback.
void setFilterCallback(SoFilterCollisionCB *f, void *userData=NULL)
Sets the callback function called when an object shape collides with a scene shape.
void setObject(SoPath *object)
Sets the object that will be transformed.
SoGroup * getScene() const
Returns the scene the object is interacting with.
SoPath * getObject() const
Returns the object that will be transformed.
Resp SoCollisionCB(void *userData, const SoCollidingPrimitive *object, const SoCollidingPrimitive *scene)
void setScene(SoGroup *scene)
Sets the scene the object is interacting with.
TransformChangeType
Transform change type.
void setObjectBBoxOnly(SbBool flag=TRUE)
Sets a flag indicating whether to use the object's bounding box instead of the actual primitives when...
void activate(SbBool flag=TRUE)
Sets a flag to activate the collision manager, for instance, to tell it to watch the transformation a...
void setGluingLevel(unsigned int level)
Sets the gluing level.
void removeCollisionCallback(SoCollisionCB *f, void *userData=NULL)
Removes collision callback.
~SoCollisionManager()
Destructor.
SoCollisionManager(SoPath *object, SoGroup *scene, SoTransform *transform)
Constructor.
SbBool isGluing() const
Returns a flag indicating whether the collision manager should place the object at the position just ...
void setSceneBBoxOnly(SbBool flag=TRUE)
Sets a flag indicating whether to use the bounding boxes of objects in the scene instead of the actua...
void setGluing(SbBool flag=TRUE)
Sets a flag indicating that the collision manager should place the object at the position just before...
SbBool isSceneBBoxOnly() const
Returns a flag indicating whether to use the bounding boxes of objects in the scene instead of the ac...
SbBool isObjectBBoxOnly() const
Returns a flag indicating whether to use the object's bounding box instead of the actual primitives w...
SoTransform * getTransform() const
Returns the transformation that will be watched.
unsigned int getGluingLevel() const
Returns the gluing level.
void addBBoxCollisionCallback(SoBBoxCollisionCB *f, void *userData=NULL)
Adds bounding box collision callback.
SbBool isActivated() const
Returns a flag indicating whether the collision manager is activated.
void setTransform(SoTransform *transform)
Sets the transformation that will be watched.
Base class for nodekits that move in response to click-drag-release mouse events.
Definition SoDragger.h:534
Sensor class that can be attached to Open Inventor fields.
Base class for all group nodes.
Definition SoGroup.h:122
Abstract base class for all database nodes.
Definition SoNode.h:145
Sensor class that can be attached to Open Inventor nodes.
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Represents a vertex of a generated primitive.
Abstract base class for Open Inventor sensors.
Definition SoSensor.h:97
General 3D geometric transformation node.
int SbBool
Boolean type.
Definition SbBase.h:87
PrimitiveType type
Type of primitive.
SbVec3f vertex[3]
Vertex of the primitive.
SoPath * path
Path of the shape.
PrimitiveType
Primitive type.
@ LINE_SEGMENT
Line segment.