Open Inventor Release 2024.2.1
 
Loading...
Searching...
No Matches
SoIntersectionDetectionAction.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 : Sebastien Dedieu (Jul 1997)
22**=======================================================================*/
23
24
25#ifndef _SO_INTERSECTION_DETECTION_ACTION_
26#define _SO_INTERSECTION_DETECTION_ACTION_
27
28
29//------------------------------------------------------------------------------
30// Includes
31
32#include <Inventor/actions/SoAction.h>
33#include <Inventor/actions/SoSubAction.h>
34#include <Inventor/SoType.h>
35#include <Inventor/SbViewportRegion.h>
36#include <Inventor/SoPrimitiveVertex.h>
37
38//------------------------------------------------------------------------------
39// Types declaration
40
41
42//------------------------------------------------------------------------------
43// Types definition
49typedef SbBool SoIntersectionFilterCB(void *userData,
50 const SoPath *p1,
51 const SoPath *p2);
52
65 TRIANGLE = 3
66 };
83};
84
108{
110
111public:
112
113 // Types definitions ---------------------------------------------------------
123
128 typedef Resp SoIntersectionCB(void *userData,
131
140
141 // Applying the action -------------------------------------------------------
142 void apply(SoNode *node);
143 void apply(SoPath *path);
144 void apply(const SoPathList &pathList, SbBool obeysRules = FALSE);
145
151 void setFilterCallback(SoIntersectionFilterCB *newFilterCB, void *data=NULL);
152
157 void addIntersectionCallback (SoIntersectionCB* f, void* userData = NULL);
158
163 void removeIntersectionCallback(SoIntersectionCB* f, void* userData = NULL);
164
165 // Computing types -----------------------------------------------------------
167 enum Axis {
173 Z_AXIS = 4
174 };
175
177 enum Position {
181 END
182 };
183#ifndef HIDDEN_FROM_DOC
184 struct ShapeInformationItem {
185 SoPath *path;
186 float xMin, yMin, zMin;
187 float xMax, yMax, zMax;
188 };
189
190 struct CoupleTableItem {
191 int overlapFlags;
192 float xMin, yMin, zMin;
193 float xMax, yMax, zMax;
194 };
195
196 struct ActiveListItem {
197 int shapeIndex;
199 enum Position position;
200 SbBool toRemove;
201 float x, y, z;
202 };
203 static float m_fIntersectEpsilon;
204#endif // HIDDEN_FROM_DOC
205
211 static void setIntersectEpsilon(float epsilon);
212
216 static float getIntersectEpsilon();
217
218private:
219
220 static void initClass();
221 static void exitClass();
222
223private :
224 friend class SoCollisionManager;
225
226 // General data --------------------------------------------------------------
227
228 // Flags ---------------------------------------------------------------------
229 SbBool m_new_test;
230 SbBool m_new_shapes;
231
232 // Managing callbacks --------------------------------------------------------
233 SoIntersectionFilterCB* filterCB;
234 void* userDataFilterCB;
235 SoIntersectionCB* intersectionCB;
236 void* userDataIntersectionCB;
237 void* m_callback_list;
238 Resp response;
239 Resp invokeCallbacks (const SoIntersectingPrimitive* p1,
240 const SoIntersectingPrimitive* p2);
241
242 // Computing variables -------------------------------------------------------
243 int shapeCount;
244 SbViewportRegion viewportRegion;
245 int shapeInformationSize;
246 int shapeInformationReservedSize;
247 ShapeInformationItem* shapeInformation;
248 int coupleTableSize;
249 int coupleTableReservedSize;
250 CoupleTableItem* coupleTable;
251 int activeListSize;
252 int activeListReservedSize;
253 ActiveListItem* activeList;
254 int primitiveTableSize;
255 int primitiveTableReservedSize;
256 SoIntersectingPrimitive* primitiveTable;
257 int currentShapeIndex1;
258 int currentShapeIndex2;
259 CoupleTableItem* currentCouple;
260
261 // Computing functions -------------------------------------------------------
262 void seek (SoSearchAction* search);
263 //void shapeInformationBuild(SoNode *root);
264 void shapeInformationDestroy();
265 void shapeInformationClear();
266 void shapeInformationAddItem(SoPath *path);
267 //void coupleTableBuild();
268 void coupleTableDestroy();
269 void coupleTableClear();
270 CoupleTableItem * coupleTableGetItem(int shapeIndex1, int shapeIndex2);
271 void coupleTableSetOverlaping(int shapeIndex1, int shapeIndex2,
272 Axis axis);
273 void coupleTableUpdate(enum Axis axis);
274 //void activeListBuild();
275 void activeListDestroy();
276 void activeListClear();
277 void activeListAddItem(int shapeIndex);
278 void activeListSort(int (*compareFunction)(void const *, void const *));
279 static int activeListXCompare(void const *pointer1, void const *pointer2);
280 static int activeListYCompare(void const *pointer1, void const *pointer2);
281 static int activeListZCompare(void const *pointer1, void const *pointer2);
282 void activeListClean();
283 void primitiveTableBuild();
284 void primitiveTableDestroy();
285 void primitiveTableClear();
286 void primitiveTableReserveSpace();
287 void primitiveTableAddTriangle (SoCallbackAction *action,
288 const SoPrimitiveVertex *vertex1,
289 const SoPrimitiveVertex *vertex2,
290 const SoPrimitiveVertex *vertex3);
291 void primitiveTableAddLineSegment(SoCallbackAction *action,
292 const SoPrimitiveVertex *vertex1,
293 const SoPrimitiveVertex *vertex2);
294 void shapesCollisionTest(int shapeIndex1, int shapeIndex2);
295
296 void triangleCollisionTest(SoCallbackAction *action,
297 const SoPrimitiveVertex *vertex1,
298 const SoPrimitiveVertex *vertex2,
299 const SoPrimitiveVertex *vertex3);
300 void lineSegmentCollisionTest(SoCallbackAction *action,
301 const SoPrimitiveVertex *vertex1,
302 const SoPrimitiveVertex *vertex2);
303 static SbBool isTriangleIntersectSegment(const SbVec3f &A,
304 const SbVec3f &B,
305 const SbVec3f &C,
306 const SbVec3f &D,
307 const SbVec3f &E);
308 static SbBool isTriangleIntersectTriangle (const SoIntersectingPrimitive &triangle1,
309 const SoIntersectingPrimitive &triangle2);
310 static SbBool isSegmentIntersectSegment (const SbVec3f &A,
311 const SbVec3f &B,
312 const SbVec3f &C,
313 const SbVec3f &D);
314
315 // Real callbacks ------------------------------------------------------------
316 static void primitiveTableAddTriangleCB (void *userData,
317 SoCallbackAction *action,
318 const SoPrimitiveVertex *vertex1,
319 const SoPrimitiveVertex *vertex2,
320 const SoPrimitiveVertex *vertex3)
321 { ((SoIntersectionDetectionAction*) userData)->
322 primitiveTableAddTriangle (action, vertex1, vertex2, vertex3); }
323 static void primitiveTableAddLineSegmentCB (void *userData,
324 SoCallbackAction *action,
325 const SoPrimitiveVertex *vertex1,
326 const SoPrimitiveVertex *vertex2)
327 { ((SoIntersectionDetectionAction*) userData)->
328 primitiveTableAddLineSegment (action, vertex1, vertex2); }
329 static void triangleCollisionTestCB (void *userData,
330 SoCallbackAction *action,
331 const SoPrimitiveVertex *vertex1,
332 const SoPrimitiveVertex *vertex2,
333 const SoPrimitiveVertex *vertex3)
334 { ((SoIntersectionDetectionAction*) userData)->
335 triangleCollisionTest (action, vertex1, vertex2, vertex3); }
336 static void lineSegmentCollisionTestCB (void *userData,
337 SoCallbackAction *action,
338 const SoPrimitiveVertex *vertex1,
339 const SoPrimitiveVertex *vertex2)
340 { ((SoIntersectionDetectionAction*) userData)->
341 lineSegmentCollisionTest (action, vertex1, vertex2); }
342
343 // Miscelaneous --------------------------------------------------------------
344 void quickSort(void *array, int nElm, int elmSize,
345 int (*compare)(void const *, void const *),
346 char *tmp);
347 void sort(void *array, int nElm, int elmSize,
348 int (*compare)(void const *, void const *));
349
350 static SbThreadMutex classMutex;
351};
352
353
354#endif // _SO_INTERSECTION_DETECTION_ACTION_
355
356
357
358
359
360
361
362
363
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Portable mutex c...
3D vector class.
Definition SbVec.h:932
Class for representing a viewport.
Abstract base class for all actions.
Definition SoAction.h:132
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 ...
<a href="IconLegend.html"><img src="extTGS.gif" alt="VSG extension" border="0"></a> Class to detect ...
void apply(const SoPathList &pathList, SbBool obeysRules=FALSE)
Initiates an action on the graph defined by a list of paths.
static float getIntersectEpsilon()
Queries epsilon (small value) to be used in the collision computation.
void removeIntersectionCallback(SoIntersectionCB *f, void *userData=NULL)
Removes a callback to be called when there is an intersection.
SbBool SoIntersectionFilterCB(void *userData, const SoPath *p1, const SoPath *p2)
SoIntersectionDetectionAction()
Constructor.
static void setIntersectEpsilon(float epsilon)
Sets epsilon (small value) to be used in the collision computation.
void apply(SoPath *path)
Initiates an action on the graph defined by a path.
void apply(SoNode *node)
Initiates an action on the graph defined by a node.
~SoIntersectionDetectionAction()
Destructor.
void setFilterCallback(SoIntersectionFilterCB *newFilterCB, void *data=NULL)
Sets a filter which allow the user to continue or not the intersection finding for a pair of shapes.
Resp SoIntersectionCB(void *userData, const SoIntersectingPrimitive *, const SoIntersectingPrimitive *)
void addIntersectionCallback(SoIntersectionCB *f, void *userData=NULL)
Adds a callback to be called when there is an intersection.
Abstract base class for all database nodes.
Definition SoNode.h:145
Path that points to a list of hierarchical nodes.
Definition SoPath.h:187
Maintains a list of pointers to paths.
Definition SoPathList.h:81
Represents a vertex of a generated primitive.
Searches for nodes in a scene graph.
int SbBool
Boolean type.
Definition SbBase.h:87
SbVec3f vertex[3]
Vertex of the primitive.
SbVec3f xf_vertex[3]
Transformed vertex of the primitive.
PrimitiveType type
Type of primitive.
SoPath * path
Path of the shape.