53 #ifndef vtk_m_worklet_contourtree_augmented_process_contourtree_inc_branch_h
54 #define vtk_m_worklet_contourtree_augmented_process_contourtree_inc_branch_h
67 namespace contourtree_augmented
69 namespace process_contourtree_inc
87 template <
typename StorageType>
98 bool dataFieldIsSorted);
135 template <
typename T>
142 template <
typename T>
149 template <
typename T>
150 template <
typename StorageType>
161 bool dataFieldIsSorted)
163 auto branchMinimumPortal = branchMinimum.
ReadPortal();
164 auto branchMaximumPortal = branchMaximum.
ReadPortal();
165 auto branchSaddlePortal = branchSaddle.
ReadPortal();
166 auto branchParentPortal = branchParent.
ReadPortal();
167 auto sortOrderPortal = sortOrder.
ReadPortal();
168 auto supernodesPortal = contourTreeSupernodes.
ReadPortal();
169 auto dataFieldPortal = dataField.
ReadPortal();
171 std::vector<Branch<T>*> branches;
173 branches.reserve(
static_cast<std::size_t
>(nBranches));
175 for (
int branchID = 0; branchID < nBranches; ++branchID)
179 for (std::size_t branchID = 0; branchID < static_cast<std::size_t>(nBranches); ++branchID)
185 supernodesPortal.Get(
MaskedIndex(branchSaddlePortal.Get(
static_cast<vtkm::Id>(branchID)))));
190 if (branchMin < branches[branchID]->Saddle)
191 branches[branchID]->Extremum = branchMin;
192 else if (branchMax > branches[branchID]->Saddle)
193 branches[branchID]->Extremum = branchMax;
196 std::cerr <<
"Internal error";
202 branches[branchID]->Saddle =
203 supernodesPortal.Get(
MaskedIndex(branchMinimumPortal.Get(
static_cast<vtkm::Id>(branchID))));
204 branches[branchID]->Extremum =
205 supernodesPortal.Get(
MaskedIndex(branchMaximumPortal.Get(
static_cast<vtkm::Id>(branchID))));
208 if (dataFieldIsSorted)
210 branches[branchID]->SaddleVal = dataFieldPortal.Get(branches[branchID]->Saddle);
211 branches[branchID]->ExtremumVal = dataFieldPortal.Get(branches[branchID]->Extremum);
215 branches[branchID]->SaddleVal =
216 dataFieldPortal.Get(sortOrderPortal.Get(branches[branchID]->Saddle));
217 branches[branchID]->ExtremumVal =
218 dataFieldPortal.Get(sortOrderPortal.Get(branches[branchID]->Extremum));
221 branches[branchID]->Saddle = sortOrderPortal.Get(branches[branchID]->Saddle);
222 branches[branchID]->Extremum = sortOrderPortal.Get(branches[branchID]->Extremum);
226 root = branches[branchID];
230 branches[branchID]->
Parent = branches[
static_cast<size_t>(
232 branches[branchID]->Parent->Children.push_back(branches[branchID]);
238 auto whichBranchPortal = whichBranch.
ReadPortal();
239 auto superparentsPortal = contourTreeSuperparents.
ReadPortal();
242 branches[
static_cast<size_t>(
255 template <
typename T>
262 std::vector<Branch<T>*> q;
265 std::vector<Branch<T>*> active;
266 while (active.size() <
static_cast<std::size_t
>(targetSize) && !q.empty())
268 if (usePersistenceSorter)
292 if (usePersistenceSorter)
308 b->Parent->Children.erase(
309 std::remove(b->Parent->Children.begin(), b->Parent->Children.end(), b));
316 template <
typename T>
319 os << std::string(indent,
' ') <<
"{" << std::endl;
320 os << std::string(indent,
' ') <<
" Saddle = " << SaddleVal <<
" (" << Saddle <<
")"
322 os << std::string(indent,
' ') <<
" Extremum = " << ExtremumVal <<
" (" << Extremum <<
")"
324 os << std::string(indent,
' ') <<
" Volume = " << Volume << std::endl;
325 if (!Children.empty())
327 os << std::string(indent,
' ') <<
" Children = [" << std::endl;
329 c->PrintBranchDecomposition(os, indent + 4);
330 os << std::string(indent,
' ') << std::string(indent,
' ') <<
" ]" << std::endl;
332 os << std::string(indent,
' ') <<
"}" << std::endl;
336 template <
typename T>
342 Parent->Volume += Volume;
347 template <
typename T>
353 if (ExtremumVal > SaddleVal)
360 val = SaddleVal + (isMax ? +eps : -eps);
363 val = T(0.5f) * (ExtremumVal + SaddleVal);
366 val = ExtremumVal + (isMax ? -eps : +eps);
370 values.push_back({ val });
371 for (
Branch* c : Children)
372 c->GetRelevantValues(type, eps, values);
376 template <
typename T>
379 bool isMax = (ExtremumVal > SaddleVal);
386 val = SaddleVal + (isMax ? +eps : -eps);
389 val = T(0.5f) * (ExtremumVal + SaddleVal);
392 val = ExtremumVal + (isMax ? -eps : +eps);
405 c->AccumulateIntervals(type, eps, plf);
409 template <
typename T>
412 std::vector<Branch<T>*> newChildren;
418 c->removeSymbolicPerturbation();
421 if (c->ExtremumVal == c->SaddleVal && c->Children.empty())
429 newChildren.push_back(c);
433 Children.swap(newChildren);
441 #endif // vtk_m_worklet_contourtree_augmented_process_contourtree_inc_branch_h