@@ -22,13 +22,32 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
22
22
if ( aTree.nodes ().empty () || bTree.nodes ().empty () )
23
23
return res;
24
24
25
- Timer t ( " 1 init" );
25
+ // parallel prepare of int boxes that will be used for consistency with precise intersections
26
+ Timer t ( " 1 precise boxes" );
27
+ Vector<Box3i, NodeId> aPreciseBoxes;
28
+ aPreciseBoxes.resizeNoInit ( aTree.nodes ().size () );
29
+ ParallelFor ( aPreciseBoxes, [&]( NodeId i )
30
+ {
31
+ const auto & node = aTree.nodes ()[i];
32
+ aPreciseBoxes[i] = Box3i{ conv ( node.box .min ), conv ( node.box .max ) };
33
+ } );
34
+
35
+ Vector<Box3i, NodeId> bPreciseBoxes;
36
+ bPreciseBoxes.resizeNoInit ( bTree.nodes ().size () );
37
+ ParallelFor ( bPreciseBoxes, [&]( NodeId i )
38
+ {
39
+ const auto & node = bTree.nodes ()[i];
40
+ auto transformedBoxb = transformed ( node.box , rigidB2A );
41
+ bPreciseBoxes[i] = Box3i{ conv ( transformedBoxb.min ), conv ( transformedBoxb.max ) };
42
+ } );
26
43
27
44
// sequentially subdivide full task on smaller subtasks;
28
45
// they shall be not too many for this subdivision not to take too long;
29
46
// and they shall be not too few for enough parallelism later
47
+ t.restart ( " 2 top subtasks" );
48
+
30
49
std::vector<NodeNode> subtasks{ { NodeId{ 0 }, NodeId{ 0 } } }, nextSubtasks, leafTasks;
31
- // tested on two Spheres each with 3366 vertices:
50
+ // tested on two Spheres each with 3366 vertices (these numbers are outdated after preparation of precise boxes) :
32
51
// 16 -> init=0.886 (13%), main=5.948, total=6.834
33
52
// 14 -> init=0.429 ( 7%), main=5.990, total=6.419
34
53
// 12 -> init=0.226 ( 3%), main=6.445, total=6.671
@@ -39,16 +58,14 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
39
58
{
40
59
const auto s = subtasks.back ();
41
60
subtasks.pop_back ();
42
- const auto & aNode = aTree[s.aNode ];
43
- const auto & bNode = bTree[s.bNode ];
44
61
45
- // check intersection in int boxes for consistency with precise intersections
46
- auto transformedBoxb = transformed ( bNode.box , rigidB2A );
47
- Box3i aBox{ conv ( aNode.box .min ),conv ( aNode.box .max ) };
48
- Box3i bBox{ conv ( transformedBoxb.min ),conv ( transformedBoxb.max ) };
62
+ const Box3i& aBox = aPreciseBoxes[s.aNode ];
63
+ const Box3i& bBox = bPreciseBoxes[s.bNode ];
49
64
if ( !aBox.intersects ( bBox ) )
50
65
continue ;
51
66
67
+ const auto & aNode = aTree[s.aNode ];
68
+ const auto & bNode = bTree[s.bNode ];
52
69
if ( aNode.leaf () && bNode.leaf () )
53
70
{
54
71
leafTasks.push_back ( s );
@@ -162,7 +179,8 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
162
179
}
163
180
};
164
181
165
- t.restart ( " 2 process" );
182
+ // checks subtasks in parallel
183
+ t.restart ( " 3 process" );
166
184
167
185
struct ThreadData
168
186
{
@@ -182,7 +200,6 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
182
200
std::vector<SubtaskRes> subtaskRes ( subtasks.size () );
183
201
184
202
std::atomic<bool > anyIntersectionAtm{ false };
185
- // checks subtasks in parallel
186
203
ParallelFor ( subtasks, threadData, [&]( size_t is, ThreadData & tls )
187
204
{
188
205
std::vector<NodeNode>& mySubtasks = tls.subtasks ;
@@ -196,16 +213,14 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
196
213
break ;
197
214
const auto s = mySubtasks.back ();
198
215
mySubtasks.pop_back ();
199
- const auto & aNode = aTree[s.aNode ];
200
- const auto & bNode = bTree[s.bNode ];
201
216
202
- // check intersection in int boxes for consistency with precise intersections
203
- auto transformedBoxb = transformed ( bNode.box , rigidB2A );
204
- Box3i aBox{ conv ( aNode.box .min ),conv ( aNode.box .max ) };
205
- Box3i bBox{ conv ( transformedBoxb.min ),conv ( transformedBoxb.max ) };
217
+ const Box3i& aBox = aPreciseBoxes[s.aNode ];
218
+ const Box3i& bBox = bPreciseBoxes[s.bNode ];
206
219
if ( !aBox.intersects ( bBox ) )
207
220
continue ;
208
221
222
+ const auto & aNode = aTree[s.aNode ];
223
+ const auto & bNode = bTree[s.bNode ];
209
224
if ( aNode.leaf () && bNode.leaf () )
210
225
{
211
226
const auto aFace = aNode.leafId ();
@@ -242,8 +257,8 @@ PreciseCollisionResult findCollidingEdgeTrisPrecise( const MeshPart & a, const M
242
257
subtaskRes[is] = std::move ( myRes );
243
258
} );
244
259
245
- // unite results from sub-trees into final vectors
246
- t.restart ( " 3 unite" );
260
+ // unite results from sub-trees into final vector
261
+ t.restart ( " 4 unite" );
247
262
size_t cols = 0 ;
248
263
for ( const auto & s : subtaskRes )
249
264
cols += s.last - s.first ;
0 commit comments