MCPcopy Create free account
hub / github.com/Kitware/VTK / GenerateMask

Method GenerateMask

Filters/Sources/vtkRandomHyperTreeGridSource.cxx:332–395  ·  view source on GitHub ↗

------------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

330
331//------------------------------------------------------------------------------
332double 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 {

Callers 1

RequestDataMethod · 0.95

Calls 12

GetMaskingNodeCostMethod · 0.95
ShouldMaskMethod · 0.95
ShuffleArrayFunction · 0.85
GetNumberOfChildrenMethod · 0.45
GetLevelMethod · 0.45
SetMaskMethod · 0.45
IsLeafMethod · 0.45
resizeMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
ToChildMethod · 0.45
ToParentMethod · 0.45

Tested by

no test coverage detected