-
Notifications
You must be signed in to change notification settings - Fork 155
/
EditKernels.cuh
689 lines (586 loc) · 25.6 KB
/
EditKernels.cuh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
#pragma once
#include "EngineInterface/Colors.h"
#include "EngineInterface/SimulationParameters.h"
#include "cuda_runtime_api.h"
#include "sm_60_atomic_functions.h"
#include "AccessTOs.cuh"
#include "Base.cuh"
#include "Map.cuh"
#include "EntityFactory.cuh"
#include "CleanupKernels.cuh"
#include "SelectionResult.cuh"
#include "CellConnectionProcessor.cuh"
#include "CellProcessor.cuh"
#include "SimulationData.cuh"
__global__ void applyForceToCells(ApplyForceData applyData, int2 universeSize, Array<Cell*> cells)
{
auto const cellBlock = calcAllThreadsPartition(cells.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = cells.at(index);
auto const& pos = cell->absPos;
auto distanceToSegment =
Math::calcDistanceToLineSegment(applyData.startPos, applyData.endPos, pos, applyData.radius);
if (distanceToSegment < applyData.radius) {
auto weightedForce = applyData.force;
//*(actionRadius - distanceToSegment) / actionRadius;
cell->vel = cell->vel + weightedForce;
}
}
}
__global__ void applyForceToParticles(ApplyForceData applyData, int2 universeSize, Array<Particle*> particles)
{
auto const particleBlock = calcAllThreadsPartition(particles.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = particles.at(index);
auto const& pos = particle->absPos;
auto distanceToSegment =
Math::calcDistanceToLineSegment(applyData.startPos, applyData.endPos, pos, applyData.radius);
if (distanceToSegment < applyData.radius) {
auto weightedForce = applyData.force;//*(actionRadius - distanceToSegment) / actionRadius;
particle->vel = particle->vel + weightedForce;
}
}
}
__global__ void existSelection(PointSelectionData pointData, SimulationData data, int* result)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (1 == cell->selected && data.cellMap.mapDistance(pointData.pos, cell->absPos) < pointData.radius) {
atomicExch(result, 1);
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (1 == particle->selected && data.cellMap.mapDistance(pointData.pos, particle->absPos) < pointData.radius) {
atomicExch(result, 1);
}
}
}
__global__ void setSelection(float2 pos, float radius, SimulationData data)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (data.cellMap.mapDistance(pos, cell->absPos) < radius) {
cell->selected = 1;
} else {
cell->selected = 0;
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (data.particleMap.mapDistance(pos, particle->absPos) < radius) {
particle->selected = 1;
} else {
particle->selected = 0;
}
}
}
__global__ void setSelection(AreaSelectionData selectionData, SimulationData data)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (isContainedInRect(selectionData.startPos, selectionData.endPos, cell->absPos)) {
cell->selected = 1;
} else {
cell->selected = 0;
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (isContainedInRect(selectionData.startPos, selectionData.endPos, particle->absPos)) {
particle->selected = 1;
} else {
particle->selected = 0;
}
}
}
__global__ void swapSelection(float2 pos, float radius, SimulationData data)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (data.cellMap.mapDistance(pos, cell->absPos) < radius) {
if (cell->selected == 0) {
cell->selected = 1;
}
else if (cell->selected == 1) {
cell->selected = 0;
}
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (data.particleMap.mapDistance(pos, particle->absPos) < radius) {
particle->selected = 1 - particle->selected;
}
}
}
__global__ void rolloutSelectionStep(SimulationData data, int* result)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (0 != cell->selected) {
auto currentCell = cell;
for (int i = 0; i < 10; ++i) {
bool found = false;
for (int j = 0; j < currentCell->numConnections; ++j) {
auto candidateCell = currentCell->connections[j].cell;
if (0 == candidateCell->selected) {
currentCell = candidateCell;
found = true;
break;
}
}
if (!found) {
break;
}
currentCell->selected = 2;
atomicExch(result, 1);
}
}
}
}
__global__ void rolloutSelection(SimulationData data)
{
int* result = new int;
do {
*result = 0;
KERNEL_CALL(rolloutSelectionStep, data, result);
} while (1 == *result);
delete result;
}
__global__ void updatePosAndVelForSelection(ShallowUpdateSelectionData updateData, SimulationData data)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if ((0 != cell->selected && updateData.considerClusters)
|| (1 == cell->selected && !updateData.considerClusters)) {
cell->absPos = cell->absPos + float2{updateData.posDeltaX, updateData.posDeltaY};
cell->vel = cell->vel + float2{updateData.velDeltaX, updateData.velDeltaY};
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (0 != particle->selected) {
particle->absPos = particle->absPos + float2{updateData.posDeltaX, updateData.posDeltaY};
particle->vel = particle->vel + float2{updateData.velDeltaX, updateData.velDeltaY};
}
}
}
__global__ void removeSelection(SimulationData data, bool onlyClusterSelection)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (!onlyClusterSelection || cell->selected == 2) {
cell->selected = 0;
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (!onlyClusterSelection || particle->selected == 2) {
particle->selected = 0;
}
}
}
__global__ void removeClusterSelection(SimulationData data)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (2 == cell->selected) {
cell->selected = 0;
}
}
}
__global__ void getSelectionShallowData(SimulationData data, SelectionResult result)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (0 != cell->selected) {
result.collectCell(cell);
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (0 != particle->selected) {
result.collectParticle(particle);
}
}
}
__global__ void disconnectSelection(SimulationData data, int* result)
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if (1 == cell->selected) {
for (int i = 0; i < cell->numConnections; ++i) {
auto const& connectedCell = cell->connections[i].cell;
if (1 != connectedCell->selected
&& data.cellMap.mapDistance(cell->absPos, connectedCell->absPos)
> cudaSimulationParameters.cellMaxBindingDistance) {
CellConnectionProcessor::scheduleDelConnection(data, cell, connectedCell);
atomicExch(result, 1);
}
}
}
}
}
__global__ void updateMapForConnection(SimulationData data)
{
CellProcessor cellProcessor;
cellProcessor.updateMap(data);
}
__global__ void connectSelection(SimulationData data, int* result)
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
Cell* otherCells[18];
int numOtherCells;
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& cell = data.entities.cellPointers.at(index);
if (1 != cell->selected) {
continue;
}
data.cellMap.get(
otherCells, 18, numOtherCells, cell->absPos, cudaSimulationParameters.cellMaxCollisionDistance);
for (int i = 0; i < numOtherCells; ++i) {
Cell* otherCell = otherCells[i];
if (!otherCell || otherCell == cell) {
continue;
}
if (1 == otherCell->selected) {
continue;
}
auto posDelta = cell->absPos - otherCell->absPos;
data.cellMap.mapDisplacementCorrection(posDelta);
bool alreadyConnected = false;
for (int i = 0; i < cell->numConnections; ++i) {
auto const& connectedCell = cell->connections[i].cell;
if (connectedCell == otherCell) {
alreadyConnected = true;
break;
}
}
if (alreadyConnected) {
continue;
}
if (cell->numConnections < cell->maxConnections && otherCell->numConnections < otherCell->maxConnections) {
CellConnectionProcessor::scheduleAddConnections(data, cell, otherCell, false);
atomicExch(result, 1);
}
}
}
}
__global__ void processConnectionChanges(SimulationData data)
{
CellConnectionProcessor::processConnectionsOperations(data);
}
__global__ void calcAccumulatedCenter(ShallowUpdateSelectionData updateData, SimulationData data, float2* center, int* numEntities)
{
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if ((updateData.considerClusters && cell->selected != 0)
|| (!updateData.considerClusters && cell->selected == 1)) {
atomicAdd(¢er->x, cell->absPos.x);
atomicAdd(¢er->y, cell->absPos.y);
atomicAdd(numEntities, 1);
}
}
}
{
auto const partition = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (particle->selected != 0) {
atomicAdd(¢er->x, particle->absPos.x);
atomicAdd(¢er->y, particle->absPos.y);
atomicAdd(numEntities, 1);
}
}
}
}
__global__ void
updateAngleAndAngularVelForSelection(ShallowUpdateSelectionData updateData, SimulationData data, float2 center)
{
__shared__ Math::Matrix rotationMatrix;
if (0 == threadIdx.x) {
Math::rotationMatrix(updateData.angleDelta, rotationMatrix);
}
__syncthreads();
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if ((updateData.considerClusters && cell->selected != 0)
|| (!updateData.considerClusters && cell->selected == 1)) {
auto relPos = cell->absPos - center;
data.cellMap.mapDisplacementCorrection(relPos);
if (updateData.angleDelta != 0) {
cell->absPos = Math::applyMatrix(relPos, rotationMatrix) + center;
data.cellMap.mapPosCorrection(cell->absPos);
}
if (updateData.angularVelDelta != 0) {
auto velDelta = relPos;
Math::rotateQuarterClockwise(velDelta);
velDelta = velDelta * updateData.angularVelDelta * DEG_TO_RAD;
cell->vel = cell->vel + velDelta;
}
}
}
}
{
auto const partition = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (particle->selected != 0) {
auto relPos = particle->absPos - center;
data.cellMap.mapDisplacementCorrection(relPos);
particle->absPos = Math::applyMatrix(relPos, rotationMatrix) + center;
data.cellMap.mapPosCorrection(particle->absPos);
}
}
}
}
__global__ void removeSelectedCellConnections(SimulationData data, bool includeClusters, int* retry)
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& cell = data.entities.cellPointers.at(index);
if ((includeClusters && cell->selected != 0) || (!includeClusters && cell->selected == 1)) {
for (int i = 0; i < cell->numConnections; ++i) {
auto connectedCell = cell->connections[i].cell;
if ((includeClusters && connectedCell->selected == 0)
|| (!includeClusters && connectedCell->selected != 1)) {
if (connectedCell->tryLock()) {
CellConnectionProcessor::delConnections(cell, connectedCell);
--i;
connectedCell->releaseLock();
} else {
atomicExch(retry, 1);
}
}
}
}
}
}
__global__ void removeSelectedCells(SimulationData data, bool includeClusters)
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& cell = data.entities.cellPointers.at(index);
if ((includeClusters && cell->selected != 0) || (!includeClusters && cell->selected == 1)) {
cell = nullptr;
}
}
}
__global__ void removeSelectedParticles(SimulationData data)
{
auto const partition = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& particle = data.entities.particlePointers.at(index);
if (particle->selected == 1) {
particle = nullptr;
}
}
}
__global__ void colorSelection(SimulationData data, unsigned char color, bool includeClusters)
{
auto const cellBlock = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = cellBlock.startIndex; index <= cellBlock.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
if ((0 != cell->selected && includeClusters) || (1 == cell->selected && !includeClusters)) {
cell->metadata.color = color;
}
}
auto const particleBlock = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = particleBlock.startIndex; index <= particleBlock.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
if (0 != particle->selected) {
particle->metadata.color = color;
}
}
}
//assumes that *changeDataTO.numCells == 1
__global__ void changeCell(SimulationData data, DataAccessTO changeDataTO, int numTokenPointers)
{
//delete tokens on cell to be changed
{
auto const partition = calcAllThreadsPartition(numTokenPointers);
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto& token = data.entities.tokenPointers.at(index);
if (token->cell->id == changeDataTO.cells[0].id) {
token = nullptr;
}
}
}
{
auto const partition = calcAllThreadsPartition(data.entities.cellPointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& cell = data.entities.cellPointers.at(index);
auto const& cellTO = changeDataTO.cells[0];
if (cell->id == cellTO.id) {
EntityFactory entityFactory;
entityFactory.init(&data);
entityFactory.changeCellFromTO(cellTO, changeDataTO, cell);
auto tokenSubarray = data.entities.tokens.getNewSubarray(*changeDataTO.numTokens);
for (int i = 0; i < *changeDataTO.numTokens; ++i) {
entityFactory.createTokenFromTO(i, changeDataTO.tokens[i], cell, tokenSubarray);
}
}
}
}
}
//assumes that *changeDataTO.numCells == 1
__global__ void changeParticle(SimulationData data, DataAccessTO changeDataTO)
{
auto const partition = calcAllThreadsPartition(data.entities.particlePointers.getNumEntries());
for (int index = partition.startIndex; index <= partition.endIndex; ++index) {
auto const& particle = data.entities.particlePointers.at(index);
auto const& particleTO = changeDataTO.particles[0];
if (particle->id == particleTO.id) {
EntityFactory entityFactory;
entityFactory.init(&data);
entityFactory.changeParticleFromTO(particleTO, particle);
}
}
}
/************************************************************************/
/* Main */
/************************************************************************/
__global__ void cudaApplyForce(ApplyForceData applyData, SimulationData data)
{
KERNEL_CALL(applyForceToCells, applyData, data.size, data.entities.cellPointers);
KERNEL_CALL(applyForceToParticles, applyData, data.size, data.entities.particlePointers);
}
__global__ void
cudaSwitchSelection(PointSelectionData switchData, SimulationData data)
{
int* result = new int;
*result = 0;
KERNEL_CALL(existSelection, switchData, data, result);
if (0 == *result) {
KERNEL_CALL(setSelection, switchData.pos, switchData.radius, data);
KERNEL_CALL_1_1(rolloutSelection, data);
}
delete result;
}
__global__ void cudaSwapSelection(PointSelectionData switchData, SimulationData data)
{
int* result = new int;
*result = 0;
KERNEL_CALL(removeSelection, data, true);
KERNEL_CALL(swapSelection, switchData.pos, switchData.radius, data);
KERNEL_CALL_1_1(rolloutSelection, data);
delete result;
}
__global__ void cudaSetSelection(AreaSelectionData setData, SimulationData data)
{
int* result = new int;
*result = 0;
KERNEL_CALL(setSelection, setData, data);
KERNEL_CALL_1_1(rolloutSelection, data);
delete result;
}
__global__ void cudaGetSelectionShallowData(SimulationData data, SelectionResult selectionResult)
{
selectionResult.reset();
KERNEL_CALL(getSelectionShallowData, data, selectionResult);
selectionResult.finalize();
}
__global__ void cudaUpdateSelection(SimulationData data)
{
KERNEL_CALL(removeSelection, data, true);
KERNEL_CALL_1_1(rolloutSelection, data);
}
__global__ void cudaShallowUpdateSelectedEntities(ShallowUpdateSelectionData updateData, SimulationData data)
{
int* result = new int;
bool reconnectionRequired =
!updateData.considerClusters && (updateData.posDeltaX != 0 || updateData.posDeltaY != 0 || updateData.angleDelta != 0);
//disconnect selection in case of reconnection
if (reconnectionRequired) {
int counter = 10;
do {
*result = 0;
data.prepareForSimulation();
KERNEL_CALL(disconnectSelection, data, result);
KERNEL_CALL(processConnectionChanges, data);
} while (1 == *result && --counter > 0); //due to locking not all affecting connections may be removed at first => repeat
}
if (updateData.posDeltaX != 0 || updateData.posDeltaY != 0 || updateData.velDeltaX != 0
|| updateData.velDeltaY != 0) {
KERNEL_CALL(updatePosAndVelForSelection, updateData, data);
}
if (updateData.angleDelta != 0 || updateData.angularVelDelta != 0) {
float2* center = new float2;
int* numEntities = new int;
*center = {0, 0};
*numEntities = 0;
KERNEL_CALL(calcAccumulatedCenter, updateData, data, center, numEntities);
if (*numEntities != 0) {
*center = *center / *numEntities;
}
KERNEL_CALL(updateAngleAndAngularVelForSelection, updateData, data, *center);
delete center;
delete numEntities;
}
//connect selection in case of reconnection
if (reconnectionRequired) {
int counter = 10;
do {
*result = 0;
data.prepareForSimulation();
KERNEL_CALL(updateMapForConnection, data);
KERNEL_CALL(connectSelection, data, result);
KERNEL_CALL(processConnectionChanges, data);
KERNEL_CALL(cleanupCellMap, data);
} while (1 == *result && --counter > 0); //due to locking not all necessary connections may be established at first => repeat
KERNEL_CALL_1_1(cudaUpdateSelection, data);
}
delete result;
}
__global__ void cudaRemoveSelection(SimulationData data)
{
KERNEL_CALL(removeSelection, data, false);
}
__global__ void cudaRemoveSelectedEntities(SimulationData data, bool includeClusters)
{
int* result = new int;
do {
*result = 0;
KERNEL_CALL(removeSelectedCellConnections, data, includeClusters, result);
} while (1 == *result);
KERNEL_CALL(removeSelectedCells, data, includeClusters);
KERNEL_CALL(removeSelectedParticles, data);
KERNEL_CALL_1_1(cleanupAfterDataManipulationKernel, data);
delete result;
}
__global__ void cudaColorSelectedEntities(SimulationData data, unsigned char color, bool includeClusters)
{
KERNEL_CALL(colorSelection, data, color, includeClusters);
}
__global__ void cudaChangeSimulationData(SimulationData data, DataAccessTO changeDataTO)
{
if (*changeDataTO.numCells == 1) {
KERNEL_CALL(changeCell, data, changeDataTO, data.entities.tokenPointers.getNumEntries());
}
if (*changeDataTO.numParticles == 1) {
KERNEL_CALL(changeParticle, data, changeDataTO);
}
KERNEL_CALL_1_1(cleanupAfterDataManipulationKernel, data);
}