Open Inventor Release 2024.1.0
 
Loading...
Searching...
No Matches
SoIntersectionDetectionAction.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 : 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
34#include <Inventor/SoType.h>
37
38//------------------------------------------------------------------------------
39// Types declaration
40
41
42//------------------------------------------------------------------------------
43// Types definition
47typedef SbBool SoIntersectionFilterCB(void *userData,
48 const SoPath *p1,
49 const SoPath *p2);
50
63 TRIANGLE = 3
64 };
81};
82
106{
108
109public:
110
111 // Types definitions ---------------------------------------------------------
121
126 typedef Resp SoIntersectionCB(void *userData,
129
138
139 // Applying the action -------------------------------------------------------
140 void apply(SoNode *node);
141 void apply(SoPath *path);
142 void apply(const SoPathList &pathList, SbBool obeysRules = FALSE);
143
149 void setFilterCallback(SoIntersectionFilterCB *newFilterCB, void *data=NULL);
150
155 void addIntersectionCallback (SoIntersectionCB* f, void* userData = NULL);
156
161 void removeIntersectionCallback(SoIntersectionCB* f, void* userData = NULL);
162
163 // Computing types -----------------------------------------------------------
165 enum Axis {
171 Z_AXIS = 4
172 };
173
175 enum Position {
179 END
180 };
181#ifndef HIDDEN_FROM_DOC
182 struct ShapeInformationItem {
183 SoPath *path;
184 float xMin, yMin, zMin;
185 float xMax, yMax, zMax;
186 };
187
188 struct CoupleTableItem {
189 int overlapFlags;
190 float xMin, yMin, zMin;
191 float xMax, yMax, zMax;
192 };
193
194 struct ActiveListItem {
195 int shapeIndex;
197 enum Position position;
198 SbBool toRemove;
199 float x, y, z;
200 };
201 static float m_fIntersectEpsilon;
202#endif // HIDDEN_FROM_DOC
203
209 static void setIntersectEpsilon(float epsilon);
210
214 static float getIntersectEpsilon();
215
216private:
217
218 static void initClass();
219 static void exitClass();
220
221private :
222 friend class SoCollisionManager;
223
224 // General data --------------------------------------------------------------
225
226 // Flags ---------------------------------------------------------------------
227 SbBool m_new_test;
228 SbBool m_new_shapes;
229
230 // Managing callbacks --------------------------------------------------------
231 SoIntersectionFilterCB* filterCB;
232 void* userDataFilterCB;
233 SoIntersectionCB* intersectionCB;
234 void* userDataIntersectionCB;
235 void* m_callback_list;
236 Resp response;
237 Resp invokeCallbacks (const SoIntersectingPrimitive* p1,
238 const SoIntersectingPrimitive* p2);
239
240 // Computing variables -------------------------------------------------------
241 int shapeCount;
242 SbViewportRegion viewportRegion;
243 int shapeInformationSize;
244 int shapeInformationReservedSize;
245 ShapeInformationItem* shapeInformation;
246 int coupleTableSize;
247 int coupleTableReservedSize;
248 CoupleTableItem* coupleTable;
249 int activeListSize;
250 int activeListReservedSize;
251 ActiveListItem* activeList;
252 int primitiveTableSize;
253 int primitiveTableReservedSize;
254 SoIntersectingPrimitive* primitiveTable;
255 int currentShapeIndex1;
256 int currentShapeIndex2;
257 CoupleTableItem* currentCouple;
258
259 // Computing functions -------------------------------------------------------
260 void seek (SoSearchAction* search);
261 //void shapeInformationBuild(SoNode *root);
262 void shapeInformationDestroy();
263 void shapeInformationClear();
264 void shapeInformationAddItem(SoPath *path);
265 //void coupleTableBuild();
266 void coupleTableDestroy();
267 void coupleTableClear();
268 CoupleTableItem * coupleTableGetItem(int shapeIndex1, int shapeIndex2);
269 void coupleTableSetOverlaping(int shapeIndex1, int shapeIndex2,
270 Axis axis);
271 void coupleTableUpdate(enum Axis axis);
272 //void activeListBuild();
273 void activeListDestroy();
274 void activeListClear();
275 void activeListAddItem(int shapeIndex);
276 void activeListSort(int (*compareFunction)(void const *, void const *));
277 static int activeListXCompare(void const *pointer1, void const *pointer2);
278 static int activeListYCompare(void const *pointer1, void const *pointer2);
279 static int activeListZCompare(void const *pointer1, void const *pointer2);
280 void activeListClean();
281 void primitiveTableBuild();
282 void primitiveTableDestroy();
283 void primitiveTableClear();
284 void primitiveTableReserveSpace();
285 void primitiveTableAddTriangle (SoCallbackAction *action,
286 const SoPrimitiveVertex *vertex1,
287 const SoPrimitiveVertex *vertex2,
288 const SoPrimitiveVertex *vertex3);
289 void primitiveTableAddLineSegment(SoCallbackAction *action,
290 const SoPrimitiveVertex *vertex1,
291 const SoPrimitiveVertex *vertex2);
292 void shapesCollisionTest(int shapeIndex1, int shapeIndex2);
293
294 void triangleCollisionTest(SoCallbackAction *action,
295 const SoPrimitiveVertex *vertex1,
296 const SoPrimitiveVertex *vertex2,
297 const SoPrimitiveVertex *vertex3);
298 void lineSegmentCollisionTest(SoCallbackAction *action,
299 const SoPrimitiveVertex *vertex1,
300 const SoPrimitiveVertex *vertex2);
301 static SbBool isTriangleIntersectSegment(const SbVec3f &A,
302 const SbVec3f &B,
303 const SbVec3f &C,
304 const SbVec3f &D,
305 const SbVec3f &E);
306 static SbBool isTriangleIntersectTriangle (const SoIntersectingPrimitive &triangle1,
307 const SoIntersectingPrimitive &triangle2);
308 static SbBool isSegmentIntersectSegment (const SbVec3f &A,
309 const SbVec3f &B,
310 const SbVec3f &C,
311 const SbVec3f &D);
312
313 // Real callbacks ------------------------------------------------------------
314 static void primitiveTableAddTriangleCB (void *userData,
315 SoCallbackAction *action,
316 const SoPrimitiveVertex *vertex1,
317 const SoPrimitiveVertex *vertex2,
318 const SoPrimitiveVertex *vertex3)
319 { ((SoIntersectionDetectionAction*) userData)->
320 primitiveTableAddTriangle (action, vertex1, vertex2, vertex3); }
321 static void primitiveTableAddLineSegmentCB (void *userData,
322 SoCallbackAction *action,
323 const SoPrimitiveVertex *vertex1,
324 const SoPrimitiveVertex *vertex2)
325 { ((SoIntersectionDetectionAction*) userData)->
326 primitiveTableAddLineSegment (action, vertex1, vertex2); }
327 static void triangleCollisionTestCB (void *userData,
328 SoCallbackAction *action,
329 const SoPrimitiveVertex *vertex1,
330 const SoPrimitiveVertex *vertex2,
331 const SoPrimitiveVertex *vertex3)
332 { ((SoIntersectionDetectionAction*) userData)->
333 triangleCollisionTest (action, vertex1, vertex2, vertex3); }
334 static void lineSegmentCollisionTestCB (void *userData,
335 SoCallbackAction *action,
336 const SoPrimitiveVertex *vertex1,
337 const SoPrimitiveVertex *vertex2)
338 { ((SoIntersectionDetectionAction*) userData)->
339 lineSegmentCollisionTest (action, vertex1, vertex2); }
340
341 // Miscelaneous --------------------------------------------------------------
342 void quickSort(void *array, int nElm, int elmSize,
343 int (*compare)(void const *, void const *),
344 char *tmp);
345 void sort(void *array, int nElm, int elmSize,
346 int (*compare)(void const *, void const *));
347
348 static SbThreadMutex classMutex;
349};
350
351
352#endif // _SO_INTERSECTION_DETECTION_ACTION_
353
354
355
356
357
358
359
360
361
#define FALSE
Possible value of SbBool.
Definition SbBase.h:75
SbBool SoIntersectionFilterCB(void *userData, const SoPath *p1, const SoPath *p2)
#define SO_ACTION_HEADER(className)
Definition SoSubAction.h:69
<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.
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.