53 #ifndef vtk_m_worklet_contourtree_augmented_process_contourtree_inc_hypersweep_worklets_h
54 #define vtk_m_worklet_contourtree_augmented_process_contourtree_inc_hypersweep_worklets_h
67 namespace contourtree_augmented
69 namespace process_contourtree_inc
75 typedef void ControlSignature(WholeArrayIn, WholeArrayIn, WholeArrayIn, WholeArrayInOut);
86 template <
typename IdWholeArrayInPortalType,
typename EdgeWholeArrayInOutPortal>
88 const IdWholeArrayInPortalType& hypersweepSumValuesPortal,
89 const IdWholeArrayInPortalType& superarcIntrinsicWeightPortal,
90 const IdWholeArrayInPortalType& superarcsPortal,
91 const EdgeWholeArrayInOutPortal& arcsPortal)
const
98 VTKM_ASSERT(i != superarcsPortal.GetNumberOfValues() - 2);
106 edge.
SubtreeVolume = (this->TotalVolume - hypersweepSumValuesPortal.Get(i)) +
107 (superarcIntrinsicWeightPortal.Get(i) - 1);
110 oppositeEdge.
I = parent;
113 oppositeEdge.
SubtreeVolume = hypersweepSumValuesPortal.Get(i);
115 arcsPortal.Set(i * 2, edge);
116 arcsPortal.Set(i * 2 + 1, oppositeEdge);
130 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
133 const IdWholeArrayInPortalType& nodesPortal,
134 const IdWholeArrayInPortalType& superparentsPortal,
135 const IdWholeArrayInOutPortalType& firstVertexForSuperparentPortal)
const
137 vtkm::Id sortID = nodesPortal.Get(sortedNode);
138 vtkm::Id superparent = superparentsPortal.Get(sortID);
141 firstVertexForSuperparentPortal.Set(superparent, sortedNode);
143 else if (superparent != superparentsPortal.Get(nodesPortal.Get(sortedNode - 1)))
145 firstVertexForSuperparentPortal.Set(superparent, sortedNode);
159 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
161 const IdWholeArrayInPortalType& arcsPortal,
162 const IdWholeArrayInPortalType& superarcsPortal,
163 const IdWholeArrayInPortalType& firstVertexForSuperparentPortal,
164 const IdWholeArrayInOutPortalType& superarcIntrinsicWeightPortal)
const
166 if (superarc == superarcsPortal.GetNumberOfValues() - 1)
168 superarcIntrinsicWeightPortal.Set(
169 superarc, arcsPortal.GetNumberOfValues() - firstVertexForSuperparentPortal.Get(superarc));
173 superarcIntrinsicWeightPortal.Set(superarc,
174 firstVertexForSuperparentPortal.Get(superarc + 1) -
175 firstVertexForSuperparentPortal.Get(superarc));
190 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
193 const IdWholeArrayInPortalType& whenTransferredPortal,
194 const IdWholeArrayInOutPortalType& firstSupernodePerIterationPortal)
const
199 firstSupernodePerIterationPortal.Set(when, supernode);
201 else if (when !=
MaskedIndex(whenTransferredPortal.Get(supernode - 1)))
203 firstSupernodePerIterationPortal.Set(when, supernode);
211 template <
typename Operator>
216 WholeArrayIn hypernodes,
217 WholeArrayIn hyperarcs,
218 WholeArrayIn howManyUsed,
219 AtomicArrayInOut minMaxIndex);
232 template <
typename IdWholeArrayHandleCountingIn,
233 typename IdWholeArrayIn,
234 typename IdWholeArrayInOut>
236 const IdWholeArrayHandleCountingIn& iterationHypernodesPortal,
237 const IdWholeArrayIn& hypernodesPortal,
238 const IdWholeArrayIn& hyperarcsPortal,
239 const IdWholeArrayIn& howManyUsedPortal,
240 const IdWholeArrayInOut& minMaxIndexPortal)
const
242 Id i = iterationHypernodesPortal.Get(hyperarcId);
245 if (i >= hypernodesPortal.GetNumberOfValues() - 1)
253 vtkm::Id lastSupernode =
MaskedIndex(hypernodesPortal.Get(i + 1)) - howManyUsedPortal.Get(i);
258 Id vertex = lastSupernode - 1;
261 Id vertexValue = minMaxIndexPortal.Get(vertex);
266 auto cur = minMaxIndexPortal.Get(parent);
268 while (!minMaxIndexPortal.CompareExchange(parent, &cur, this->Op(cur, vertexValue)))
298 template <
typename IdWholeArrayInPortalType,
typename EdgeWholeArrayInOutPortal>
300 const IdWholeArrayInPortalType& minParentsPortal,
301 const IdWholeArrayInPortalType& maxParentsPortal,
302 const IdWholeArrayInPortalType& minValuesPortal,
303 const IdWholeArrayInPortalType& maxValuesPortal,
304 const IdWholeArrayInPortalType& superarcsPortal,
305 const EdgeWholeArrayInOutPortal& arcsPortal)
const
320 oppositeEdge.
I = parent;
333 oppositeEdge.
SubtreeMin = minValuesPortal.Get(oppositeEdge.
J);
345 oppositeEdge.
SubtreeMax = maxValuesPortal.Get(oppositeEdge.
J);
350 if (i > this->RootSupernodeId)
355 arcsPortal.Set(i * 2, edge);
356 arcsPortal.Set(i * 2 + 1, oppositeEdge);
370 template <
typename Float64WholeArrayInPortalType,
371 typename IdWholeArrayInPortalType,
372 typename EdgeWholeArrayInOutPortal>
374 const Float64WholeArrayInPortalType& fieldValuesPortal,
375 const IdWholeArrayInPortalType& ctSortOrderPortal,
376 const IdWholeArrayInPortalType& supernodesPortal,
377 const EdgeWholeArrayInOutPortal& arcsPortal)
const
382 Float64 minIsoval = fieldValuesPortal.Get(ctSortOrderPortal.Get(edge.
SubtreeMin));
383 Float64 maxIsoval = fieldValuesPortal.Get(ctSortOrderPortal.Get(edge.
SubtreeMax));
385 fieldValuesPortal.Get(ctSortOrderPortal.Get(supernodesPortal.Get(edge.
I)));
393 arcsPortal.Set(i, edge);
409 template <
typename IdWholeArrayInPortalType,
typename EdgeWholeArrayInOutPortal>
411 const IdWholeArrayInPortalType& bestUpwardPortal,
412 const IdWholeArrayInPortalType& bestDownwardPortal,
413 const EdgeWholeArrayInOutPortal& arcsPortal)
const
419 if (arcsPortal.Get(0).UpEdge == 0)
421 bestDownwardPortal.Set(arcsPortal.Get(0).I, arcsPortal.Get(0).J);
425 bestUpwardPortal.Set(arcsPortal.Get(0).I, arcsPortal.Get(0).J);
430 if (arcsPortal.Get(i).UpEdge == 0 && arcsPortal.Get(i).I != arcsPortal.Get(i - 1).I)
432 bestDownwardPortal.Set(arcsPortal.Get(i).I, arcsPortal.Get(i).J);
435 if (arcsPortal.Get(i).UpEdge == 1 &&
436 (arcsPortal.Get(i).I != arcsPortal.Get(i - 1).I || arcsPortal.Get(i - 1).UpEdge == 0))
438 bestUpwardPortal.Set(arcsPortal.Get(i).I, arcsPortal.Get(i).J);
457 template <
typename IdWholeArrayInPortalType>
459 const IdWholeArrayInPortalType& maskedArrayPortal)
const
461 const auto currentValue = maskedArrayPortal.Get(currentId);
462 maskedArrayPortal.Set(currentId,
MaskedIndex(currentValue));
478 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayOutPortalType>
480 const IdWholeArrayInPortalType& bestUpwardPortal,
481 const IdWholeArrayInPortalType& bestDownwardPortal,
482 const IdWholeArrayOutPortalType& whichBranchPortal)
const
484 vtkm::Id bestUp = bestUpwardPortal.Get(supernodeId);
490 else if (bestDownwardPortal.Get(bestUp) == supernodeId)
491 whichBranchPortal.Set(supernodeId, bestUp);
509 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
511 const IdWholeArrayInPortalType& chainToBranchPortal,
512 const IdWholeArrayInOutPortalType& whichBranchPortal)
const
514 const auto currentValue =
MaskedIndex(whichBranchPortal.Get(supernode));
515 whichBranchPortal.Set(supernode, chainToBranchPortal.Get(currentValue));
522 typedef void ControlSignature(WholeArrayIn, WholeArrayIn, WholeArrayInOut, WholeArrayInOut);
535 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
537 const IdWholeArrayInPortalType& supernodeSorterPortal,
538 const IdWholeArrayInPortalType& whichBranchPortal,
539 const IdWholeArrayInOutPortalType& branchMinimumPortal,
540 const IdWholeArrayInOutPortalType& branchMaximumPortal)
const
543 vtkm::Id supernodeID = supernodeSorterPortal.Get(supernode);
544 vtkm::Id branchID = whichBranchPortal.Get(supernodeID);
549 branchMinimumPortal.Set(branchID, supernodeID);
551 else if (branchID != whichBranchPortal.Get(supernodeSorterPortal.Get(supernode - 1)))
553 branchMinimumPortal.Set(branchID, supernodeID);
556 if (supernode == this->NumSupernodes - 1)
558 branchMaximumPortal.Set(branchID, supernodeID);
560 else if (branchID != whichBranchPortal.Get(supernodeSorterPortal.Get(supernode + 1)))
562 branchMaximumPortal.Set(branchID, supernodeID);
584 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
586 const IdWholeArrayInPortalType& whichBranchPortal,
587 const IdWholeArrayInPortalType& branchMinimumPortal,
588 const IdWholeArrayInPortalType& branchMaximumPortal,
589 const IdWholeArrayInPortalType& bestDownwardPortal,
590 const IdWholeArrayInPortalType& bestUpwardPortal,
591 const IdWholeArrayInOutPortalType& branchSaddlePortal,
592 const IdWholeArrayInOutPortalType& branchParentPortal)
const
594 vtkm::Id branchMax = branchMaximumPortal.Get(branchID);
598 branchSaddlePortal.Set(branchID,
MaskedIndex(bestUpwardPortal.Get(branchMax)));
600 branchParentPortal.Set(branchID, whichBranchPortal.Get(bestUpwardPortal.Get(branchMax)));
603 vtkm::Id branchMin = branchMinimumPortal.Get(branchID);
607 branchSaddlePortal.Set(branchID,
MaskedIndex(bestDownwardPortal.Get(branchMin)));
609 branchParentPortal.Set(branchID, whichBranchPortal.Get(bestDownwardPortal.Get(branchMin)));
628 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
630 const IdWholeArrayInPortalType& whichBranchPortal,
631 const IdWholeArrayInOutPortalType& chainToBranchPortal)
const
634 if (
MaskedIndex(whichBranchPortal.Get(supernode)) == supernode)
636 chainToBranchPortal.Set(supernode, 1);
652 template <
typename IdWholeArrayInPortalType,
typename IdWholeArrayInOutPortalType>
654 const IdWholeArrayInPortalType& whichBranchPortal,
655 const IdWholeArrayInOutPortalType& chainToBranchPortal)
const
658 if (
MaskedIndex(whichBranchPortal.Get(supernode)) == supernode)
660 const auto value = chainToBranchPortal.Get(supernode);
661 chainToBranchPortal.Set(supernode, value - 1);
671 template <
typename Operator>
688 template <
typename IdWholeArrayIn,
typename IdWholeArrayInOut>
690 const IdWholeArrayIn& parentsPortal,
691 const IdWholeArrayIn& supernodesPortal,
692 const IdWholeArrayInOut& hypersweepValuesPortal)
const
698 Id subtreeValue = hypersweepValuesPortal.Get(i);
701 hypersweepValuesPortal.Set(i, this->
Op(subtreeValue, parentValue));