Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoCollisionManager.h
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-2024 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
56typedef SbBool SoFilterCollisionCB (void* userData,
57 const SoPath* p1,
58 const SoPath* p2);
64typedef void SoBBoxCollisionCB (void* userData,
65 const SoPath* p1,
66 const SoPath* p2);
67
80 TRIANGLE = 3
81 };
94};
95
96
138{
139
140public :
141
142 // Types definitions ---------------------------------------------------------
152
157 typedef Resp SoCollisionCB (void* userData,
158 const SoCollidingPrimitive* object,
159 const SoCollidingPrimitive* scene);
160
167 SoGroup* scene,
168 SoTransform* transform);
173
177 void setObject (SoPath* object);
178
182 SoPath* getObject () const;
183
187 void setScene (SoGroup* scene);
188
192 SoGroup* getScene () const;
193
197 void setTransform (SoTransform* transform);
198
203
211 void setGluingLevel (unsigned int level);
212
216 unsigned int getGluingLevel() const;
217
222 void setObjectBBoxOnly (SbBool flag = TRUE);
223
229
235 void setSceneBBoxOnly (SbBool flag = TRUE);
236
242
250 void setGluing (SbBool flag = TRUE);
251
257 SbBool isGluing () const;
258
264 void activate (SbBool flag = TRUE);
265
270
277 void setFilterCallback (SoFilterCollisionCB* f, void* userData = NULL);
278
287 void addBBoxCollisionCallback (SoBBoxCollisionCB* f, void* userData = NULL);
288
294 void* userData = NULL);
308 void addCollisionCallback (SoCollisionCB* f, void* userData = NULL);
309
314 void removeCollisionCallback(SoCollisionCB* f, void* userData = NULL);
315
316 // Computing types -----------------------------------------------------------
332
334 enum Axis {
340 Z_AXIS = 4
341 };
342
344 enum Position {
348 END
349 };
350
351#ifndef HIDDEN_FROM_DOC
352
353 struct ShapeBBoxInformationItem {
354 SoPath* path;
355 float x_min, y_min, z_min;
356 float x_max, y_max, z_max;
357 };
358
359 struct PairTableItem {
360 int overlap_flags;
361 float x_min, y_min, z_min;
362 float x_max, y_max, z_max;
363 };
364
365 struct CompListItem
366 {
367 int shape_index;
368 Position position;
369 SbBool to_remove;
370 float x, y, z;
371 };
372
373 struct ManagerListItem {
374 SoCollisionManager* manager;
375 ManagerListItem* next;
376 };
377
378 class SceneInformationItem {
379 public:
380 ~SceneInformationItem();
381
382 SoGroup* root;
383 SoNodeSensor* sensor;
384 SbBool need_refresh;
385 SbBool one_object_has_changed;
386
387 int refs;
388 ManagerListItem* manager_list;
389 int active_manager_count;
390
391 int shape_count;
392 int shape_bbox_information_reserved_size;
393 ShapeBBoxInformationItem* shape_bbox_information;
394
395 int pair_table_reserved_size;
396 PairTableItem* pair_table;
397
398 int comp_list_size;
399 int comp_list_reserved_size;
400 CompListItem* comp_list;
401
402
403 SceneInformationItem* next;
404 };
405#endif // HIDDEN_FROM_DOC
406
407private :
408
409 // General data --------------------------------------------------------------
410 SoPath* m_object;
411 SoGroup* m_scene;
412 SoTransform* m_transform;
413 int m_gluing_level;
414
415 // Flags ---------------------------------------------------------------------
416 SbBool m_object_bbox_only;
417 SbBool m_scene_bbox_only;
418 SbBool m_gluing;
419 SbBool m_activated;
420
421 // Managing callbacks --------------------------------------------------------
422 SoFilterCollisionCB* m_filter_cb;
423 void* m_filter_cb_ud;
424 void* m_bbox_cb_list;
425 void* m_collision_cb_list;
426 void invokeBBoxCallbacks (const SoPath* p1, const SoPath* p2);
427 Resp invokeCollisionCallbacks (const SoCollidingPrimitive* object,
428 const SoCollidingPrimitive* scene);
429
430 // Computing variables -------------------------------------------------------
431 SbBool m_need_check;
432 SbBool m_object_geometry_has_changed;
433 int m_primitive_count;
434 int m_num_primitive_reserved;
435 SoCollidingPrimitive* m_primitives;
436 SoPath* m_current_shape_path;
437 Resp m_upper_response;
438 SbBool m_new_moving;
439 SbBool m_new_shapes_pair;
440 static SceneInformationItem* m_scene_information_list;
441 SceneInformationItem* m_scene_information;
442 SbBool m_is_a_good_transform;
443 SbBool m_there_is_a_good_transform;
444 SbBool m_need_gluing;
445 SoTransform* m_last_know_good_transform;
446 SoTransform* m_temporary_transform;
447 SoFieldSensor* m_translation_sensor;
448 SoFieldSensor* m_scale_sensor;
449 SoFieldSensor* m_rotation_sensor;
450 SoFieldSensor* m_orientation_sensor;
451 SoFieldSensor* m_center_sensor;
452
453 // Computing functions -------------------------------------------------------
454 PairTableItem* pairTableGetItem (int shape1, int shape2);
455 void pairTableCompute (int (*fct)(const void*, const void*), Axis axis);
456 static int compListXCompare(const void* v1, const void* v2);
457 static int compListYCompare(const void* v1, const void* v2);
458 static int compListZCompare(const void* v1, const void* v2);
459 void refresh ();
460 void addPrimitiveToTable (SoPath* p,
462 SbVec3f v1,
463 SbVec3f v2,
464 SbVec3f v3);
465 void addPrimitiveToTable (SoPath* p,
467 SbVec3f v1,
468 SbVec3f v2)
469 { addPrimitiveToTable (p, type, v1, v2, SbVec3f (0, 0, 0)); }
470 void addTriangleToTable (SoCallbackAction* action,
471 const SoPrimitiveVertex* v1,
472 const SoPrimitiveVertex* v2,
473 const SoPrimitiveVertex* v3);
474 void addSegmentToTable (SoCallbackAction* action,
475 const SoPrimitiveVertex* v1,
476 const SoPrimitiveVertex* v2);
477 void onObjectTriangle (SoCallbackAction* action,
478 const SoPrimitiveVertex* v1,
479 const SoPrimitiveVertex* v2,
480 const SoPrimitiveVertex* v3);
481 void onObjectTriangleReal (const SbVec3f v0,
482 const SbVec3f v1,
483 const SbVec3f v2);
484 void onObjectSegment (SoCallbackAction* action,
485 const SoPrimitiveVertex* v1,
486 const SoPrimitiveVertex* v2);
487 SbBool intersectionTwoTriangles (SoCollidingPrimitive* t1,
489 // int intersectionTriangleAndSegment (SoCollidingPrimitive* t,
490 // SbVec3f s0, SbVec3f s1);
491 SbBool onTransformChange(SoSensor *sensor, TransformChangeType type);
492 SbBool onTransformChange(SbBool sensorIsNotNULL, TransformChangeType type);
493 SbBool checkSensor (SoSensor* sensor);
494 static SceneInformationItem* getSceneInformation(SoCollisionManager* manager);
495 static void removeSceneInformation (SoCollisionManager* manager);
496 static void onSceneChange (void* ud, SoSensor* sensor);
497 static void refresh (SceneInformationItem* scene);
498 void lastKnowGoodTransformComputing ();
499
500 // Real callbacks ------------------------------------------------------------
501 static void addTriangleToTableCB (void* ud, SoCallbackAction* action,
502 const SoPrimitiveVertex* v1,
503 const SoPrimitiveVertex* v2,
504 const SoPrimitiveVertex* v3)
505 { ((SoCollisionManager*) ud)->addTriangleToTable (action, v1, v2, v3); }
506 static void addSegmentToTableCB (void* ud, SoCallbackAction* action,
507 const SoPrimitiveVertex* v1,
508 const SoPrimitiveVertex* v2)
509 { ((SoCollisionManager*) ud)->addSegmentToTable (action, v1, v2); }
510
511 static void onObjectTriangleCB (void* ud, SoCallbackAction* action,
512 const SoPrimitiveVertex* v1,
513 const SoPrimitiveVertex* v2,
514 const SoPrimitiveVertex* v3)
515 { ((SoCollisionManager*) ud)->onObjectTriangle (action, v1, v2, v3); }
516 static void onObjectSegmentCB (void* ud, SoCallbackAction* action,
517 const SoPrimitiveVertex* v1,
518 const SoPrimitiveVertex* v2)
519 { ((SoCollisionManager*) ud)->onObjectSegment (action, v1, v2); }
520 static void onTranslationChangeCB (void* ud, SoSensor* sensor)
521 { ((SoCollisionManager*) ud)->onTransformChange (sensor, TRANSLATION); }
522 static void onScaleChangeCB (void* ud, SoSensor* sensor)
523 { ((SoCollisionManager*) ud)->onTransformChange (sensor, SCALE); }
524 static void onRotationChangeCB (void* ud, SoSensor* sensor)
525 { ((SoCollisionManager*) ud)->onTransformChange (sensor, ROTATION); }
526 static void onOrientationChangeCB (void* ud, SoSensor* sensor)
527 { ((SoCollisionManager*) ud)->onTransformChange (sensor, ORIENTATION); }
528 static void onCenterChangeCB (void* ud, SoSensor* sensor)
529 { ((SoCollisionManager*) ud)->onTransformChange (sensor, CENTER); }
530 static void onDraggerMotionCB (void* ud, SoDragger *)
531 { ((SoCollisionManager*) ud)->onDraggerMotion (); }
532
533 // Manipulator features ------------------------------------------------------
534 SbVec3f m_dragger_translation;
535 SbRotation m_dragger_rotation;
536 SbVec3f m_dragger_scale_factor;
537 SbRotation m_dragger_scale_orientation;
538 SbVec3f m_dragger_center;
539 void onDraggerMotion ();
540
541 // Miscelaneous --------------------------------------------------------------
542 void quickSort(void *array, int nElm, int elmSize,
543 int (*compare)(const void*, const void*),
544 char *tmp);
545
546};
547
548#endif //_SO_COLLISION_MANAGER_
549
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.
void SoBBoxCollisionCB(void *userData, const SoPath *p1, const SoPath *p2)
TransformChangeType
Transform change type.
SbBool SoFilterCollisionCB(void *userData, const SoPath *p1, const SoPath *p2)
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:537
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:100
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.