------------------------------------------------------------------------------
| 330 | |
| 331 | //------------------------------------------------------------------------------ |
| 332 | double vtkRandomHyperTreeGridSource::GenerateMask(vtkHyperTreeGridNonOrientedCursor* cursor, |
| 333 | vtkIdType treeId, double unmaskedFraction, bool isParentMasked, double siblingsFractionMasked, |
| 334 | double errorMargin) |
| 335 | { |
| 336 | int numChildren = cursor->GetNumberOfChildren(); |
| 337 | vtkIdType level = cursor->GetLevel(); |
| 338 | bool isMasked = false; |
| 339 | double resultUnmaskedFraction = unmaskedFraction; |
| 340 | |
| 341 | // Initialize mask for new leaves |
| 342 | cursor->SetMask(false); |
| 343 | if (!isParentMasked) |
| 344 | { |
| 345 | double maskingCost = this->GetMaskingNodeCost(level); |
| 346 | if (this->ShouldMask(siblingsFractionMasked, level, errorMargin)) |
| 347 | { |
| 348 | /* Reduce the unmasked proportion only if we mask |
| 349 | * the root of a subtree. Since its proportion |
| 350 | * is equal to the sum of its children, we only need |
| 351 | * the reduction for the root. |
| 352 | * Also this line isn't thread safe |
| 353 | */ |
| 354 | resultUnmaskedFraction -= maskingCost; |
| 355 | isMasked = true; |
| 356 | } |
| 357 | } |
| 358 | isMasked = isMasked || isParentMasked; |
| 359 | if (!cursor->IsLeaf()) |
| 360 | { |
| 361 | // Need to shuffle children to avoid bias and get interesting results |
| 362 | int nbChildMasked = 0; |
| 363 | double childUnmaskedFraction = unmaskedFraction; |
| 364 | std::vector<int> children; |
| 365 | children.resize(numChildren); |
| 366 | std::iota(children.begin(), children.end(), 0); |
| 367 | ::ShuffleArray(children, this->MaskRNG); |
| 368 | |
| 369 | for (int childIdx : children) |
| 370 | { |
| 371 | double previousUnmaskedFraction = childUnmaskedFraction; |
| 372 | // Can't mask cursor before visiting child |
| 373 | cursor->ToChild(childIdx); |
| 374 | double maskedChildrenFraction = |
| 375 | static_cast<double>(nbChildMasked) / static_cast<double>(numChildren); |
| 376 | childUnmaskedFraction = this->GenerateMask(cursor, treeId, previousUnmaskedFraction, isMasked, |
| 377 | maskedChildrenFraction, 1.0 / numChildren); |
| 378 | if (childUnmaskedFraction < previousUnmaskedFraction) |
| 379 | { |
| 380 | nbChildMasked += 1; |
| 381 | } |
| 382 | cursor->ToParent(); |
| 383 | } |
| 384 | if (!isMasked) |
| 385 | { |
| 386 | resultUnmaskedFraction = childUnmaskedFraction; |
| 387 | } |
| 388 | if (nbChildMasked == numChildren) |
| 389 | { |
no test coverage detected