68 #ifndef vtk_m_worklet_contourtree_distributed_hierarchical_contour_tree_h
69 #define vtk_m_worklet_contourtree_distributed_hierarchical_contour_tree_h
71 #define VOLUME_PRINT_WIDTH 8
89 namespace contourtree_distributed
99 template <
typename FieldType>
188 this->WhichIteration,
192 this->RegularNodeGlobalIds,
237 std::string
DebugPrint(std::string message,
const char* fileName,
long lineNum)
const;
256 const std::vector<vtkm::worklet::contourtree_augmented::IdArrayType>& inputVec,
268 template <
typename FieldType>
272 NumRegularNodesInRound.ReleaseResources();
273 NumSupernodesInRound.ReleaseResources();
274 NumHypernodesInRound.ReleaseResources();
275 NumIterations.ReleaseResources();
280 template <
typename FieldType>
288 this->NumRounds = numRounds;
310 this->NumRounds, tree.
NumIterations + 1, this->NumIterations);
311 this->FirstSupernodePerIteration.resize(
static_cast<std::size_t
>(this->NumRounds + 1));
312 this->FirstSupernodePerIteration[
static_cast<std::size_t
>(this->NumRounds)].Allocate(
314 this->FirstHypernodePerIteration.resize(
static_cast<std::size_t
>(this->NumRounds + 1));
315 this->FirstHypernodePerIteration[
static_cast<std::size_t
>(this->NumRounds)].Allocate(
324 this->FirstSupernodePerIteration[
static_cast<std::size_t
>(this->NumRounds)]);
329 this->FirstHypernodePerIteration[
static_cast<std::size_t
>(this->NumRounds)]);
379 auto regular2SupernodePermuted =
382 regular2SupernodePermuted);
390 auto super2HypernodePermuted =
393 super2HypernodePermuted);
397 this->Invoke(initalizeSuperchildrenWorklet,
407 template <
typename FieldType>
410 std::stringstream resultStream;
412 if (regularId >= this->DataValues.GetNumberOfValues())
414 resultStream <<
"Regular ID: ";
416 resultStream <<
" Value: N/A Global ID: N/A Regular ID: ";
418 resultStream <<
" SNode ID: N/A Superparent: N/A";
422 resultStream <<
"Regular ID: ";
425 resultStream <<
" Global ID: ";
428 resultStream <<
" Regular ID: ";
430 resultStream <<
" SNode ID: ";
433 resultStream <<
"Superparents: ";
437 return resultStream.str();
442 template <
typename FieldType>
445 std::stringstream resultStream;
448 resultStream <<
"Super ID: ";
455 resultStream <<
"Super ID: ";
457 resultStream <<
" Value: "
459 resultStream <<
" Global ID: ";
462 resultStream <<
" Regular Id: ";
464 resultStream <<
" Superarc: ";
467 resultStream <<
" HNode ID: ";
470 resultStream <<
" Hyperparent: ";
473 resultStream <<
" Round: ";
476 resultStream <<
" Iteration: ";
480 return resultStream.str();
485 template <
typename FieldType>
488 std::stringstream resultStream;
491 resultStream <<
"Hyper ID: ";
499 resultStream <<
"Hyper Id: ";
502 resultStream <<
" Global ID: ";
505 resultStream <<
" Regular ID: ";
507 resultStream <<
" Super ID: ";
509 resultStream <<
" Hyperarc: ";
512 resultStream <<
" Superchildren: "
515 return resultStream.str();
519 template <
typename FieldType>
523 std::stringstream resultStream;
524 resultStream <<
"Probing HyperPath\n";
525 resultStream <<
"Node: " << this->RegularString(regularId) << std::endl;
529 resultStream <<
"Superparent: " << SuperString(superparent) << std::endl;
539 if (length > maxLength && maxLength > 0)
543 resultStream <<
"Hyperparent: " << this->HyperString(hyperparent) << std::endl;
548 resultStream <<
"Hypertarget: "
570 resultStream <<
"Probe Complete" << std::endl << std::endl;
571 return resultStream.str();
576 template <
typename FieldType>
580 std::stringstream resultStream;
588 if (length > maxLength && maxLength > 0)
595 resultStream <<
"Superparent: " << this->SuperString(superparent) << std::endl;
596 resultStream <<
"Supertarget: "
597 << this->SuperString(
607 resultStream <<
"Next target: " << this->SuperString(nextSupertarget) << std::endl;
617 superparent = maskedNextSupertarget;
621 superparent = maskedSupertarget;
625 resultStream <<
"Probe Complete" << std::endl << std::endl;
626 return resultStream.str();
630 template <
typename FieldType>
634 std::string filename(
"temp/");
638 for (
unsigned int strChar = 0; strChar < filename.length(); strChar++)
639 if (filename[strChar] ==
' ')
640 filename[strChar] =
'_';
646 std::ofstream outstream(filename);
649 outstream <<
"digraph RegularTree\n\t{\n";
650 outstream <<
"\tsize=\"6.5, 9\"\n\tratio=\"fill\"\n";
651 outstream <<
"\tlabel=\"" << label <<
"\"\n\tlabelloc=t\n\tfontsize=30\n";
654 outstream <<
"\t// NULL node to use as a root for the tree\n";
655 outstream <<
"\tNULL [style=filled,fillcolor=white,shape=point,label=\"NULL\"];\n";
657 outstream <<
"\t// Supernodes\n";
660 auto supernodesPortal = this->Supernodes.ReadPortal();
661 auto hypernodesPortal = this->Hypernodes.ReadPortal();
662 auto hyperparentsPortal = this->Hyperparents.ReadPortal();
663 auto hyperarcsPortal = this->Hyperarcs.ReadPortal();
664 auto regularNodeGlobalIdsPortal = this->RegularNodeGlobalIds.ReadPortal();
665 auto whichIterationPortal = this->WhichIteration.ReadPortal();
666 auto whichRoundPortal = this->whichRound.ReadPortal();
667 auto superarcsPortal = this->Superarcs.ReadPortal();
668 auto superparentsPortal = this->Superparents.ReadPortal();
669 for (
vtkm::Id supernode = 0; supernode < this->Supernodes.GetNumberOfValues(); supernode++)
671 vtkm::Id regularID = supernodesPortal.Get(supernode);
674 <<
" SN" << std::setw(1) << supernode
675 <<
" [style=filled,fillcolor=white,shape=" << std::setw(1)
676 << ((hypernodesPortal.Get(hyperparentsPortal.Get(supernode)) == supernode)
679 <<
",label=\"sn" << std::setw(4) << supernode <<
" h" << std::setw(1)
680 << ((hypernodesPortal.Get(hyperparentsPortal.Get(supernode)) == supernode)
683 << std::setw(4) << hyperparentsPortal.Get(supernode) <<
"\\nm" << std::setw(1) << regularID
684 <<
" g" << std::setw(4) << regularNodeGlobalIdsPortal.Get(regularID) <<
"\\nrd"
685 << std::setw(1) << whichIterationPortal.Get(supernode) <<
" it" << std::setw(4)
689 outstream <<
"\t// Superarc nodes\n";
691 for (
vtkm::Id superarc = 0; superarc < this->Superarcs.GetNumberOfValues(); superarc++)
695 <<
"\tSA" << std::setw(1) << superarc
696 <<
" [shape=circle,fillcolor=white,fixedsize=true,height=0.5,width=0.5,label=\"\"];\n";
699 outstream <<
"\t// Superarc edges\n";
701 for (
vtkm::Id superarc = 0; superarc < this->Superarcs.GetNumberOfValues(); superarc++)
705 vtkm::Id superarcTo = superarcsPortal.Get(superarcFrom);
711 if (whichRoundPortal.Get(superarcFrom) == this->NRounds)
713 outstream <<
"\tSN" << std::setw(1) << superarcFrom <<
" -> SA" << std::setw(1) << superarc
714 <<
" [label=\"S" << std::setw(1) << superarc <<
"\",style=dotted]\n";
715 outstream <<
"\tSN" << std::setw(1) << superarc <<
" -> NULL[label=\"S" << std::setw(1)
716 << superarc <<
"\",style=dotted]\n";
722 vtkm::Id regularFrom = supernodesPortal.Get(superarcFrom);
723 superarcTo = superparentsPortal.Get(regularFrom);
726 outstream <<
"\tSN" << std::setw(1) << superarcFrom <<
" -> SA" << std::setw(1)
727 << superarcTo <<
"[label=\"S" << std::setw(1) << superarc <<
"\",style=dotted]\n";
740 outstream <<
"\tSN" << std::setw(1) << (ascendingSuperarc ? superarcTo : superarcFrom)
741 <<
" -> SA" << std::setw(1) << superarc <<
" [label=\"S" << std::setw(1) << superarc
742 <<
"\"" << (ascendingSuperarc ?
",dir=\"back\"" :
"") <<
",arrowhead=\"none\"]\n";
743 outstream <<
"\tSA" << std::setw(1) << superarc <<
" -> SN" << std::setw(1)
744 << (ascendingSuperarc ? superarcFrom : superarcTo) <<
" [label=\"S" << std::setw(1)
745 << superarc <<
"\"" << (ascendingSuperarc ?
",dir=\"back\"" :
"")
746 <<
",arrowhead=\"none\"]\n";
750 outstream <<
"\t// Hyperarcs\n";
752 for (
vtkm::Id hyperarc = 0; hyperarc < this->Hyperarcs.GetNumberOfValues(); hyperarc++)
755 vtkm::Id hyperarcFrom = hypernodesPortal.Get(hyperarc);
756 vtkm::Id hyperarcTo = hyperarcsPortal.Get(hyperarc);
760 outstream <<
"\tSN" << std::setw(1) << hyperarcFrom <<
" -> NULL[label=\"H" << std::setw(1)
761 << hyperarc <<
"\",penwidth=5.0,style=dotted]\n";
771 outstream <<
"\tSN" << std::setw(1) << (ascendingHyperarc ? hyperarcTo : hyperarcFrom)
772 <<
" -> SN" << std::setw(1) << (ascendingHyperarc ? hyperarcFrom : hyperarcTo)
773 <<
"[label=\"H" << std::setw(1) << hyperarc <<
"\",penwidth=5.0,dir=\"back\"]\n";
778 outstream <<
"\t}\n";
780 return std::string(
"HierarchicalContourTree<FieldType>::PrintDotSuperStructure() Complete");
784 template <
typename FieldType>
786 const char* fileName,
789 std::stringstream resultStream;
790 resultStream << std::endl;
791 resultStream <<
"[CUTHERE]-------------------------------" << std::endl;
792 resultStream << std::setw(30) << std::left << fileName <<
":" << std::right << std::setw(4)
793 << lineNum << std::endl;
794 resultStream << std::left << std::string(message) << std::endl;
795 resultStream <<
"Hierarchical Contour Tree Contains: " << std::endl;
796 resultStream <<
"----------------------------------------" << std::endl;
797 resultStream << std::endl;
802 "Regular Nodes (global ID)", this->RegularNodeGlobalIds, -1, resultStream);
804 "Data Values", this->DataValues, -1, resultStream);
806 "Regular Node Sort Order", this->RegularNodeSortOrder, -1, resultStream);
808 "Superparents (unsorted)", this->Superparents, -1, resultStream);
810 "Supernode ID (if any)", this->Regular2Supernode, -1, resultStream);
811 resultStream << std::endl;
815 "Supernodes (regular index)", this->Supernodes, -1, resultStream);
817 "Superarcs (supernode index)", this->Superarcs, -1, resultStream);
819 "Hyperparents (hypernode index)", this->Hyperparents, -1, resultStream);
821 "Hypernode ID (if any)", this->Super2Hypernode, -1, resultStream);
823 "Which Round", this->WhichRound, -1, resultStream);
825 "Which Iteration", this->WhichIteration, -1, resultStream);
826 resultStream << std::endl;
830 "Hypernodes (supernode index)", this->Hypernodes, -1, resultStream);
832 "Hyperarcs (supernode index)", this->Hyperarcs, -1, resultStream);
834 "Superchildren", this->Superchildren, -1, resultStream);
835 resultStream << std::endl;
836 resultStream <<
"nRounds: " << this->NumRounds << std::endl;
838 this->NumRegularNodesInRound.GetNumberOfValues(), resultStream);
840 "nRegular Nodes In Round", this->NumRegularNodesInRound, -1, resultStream);
842 "nSupernodes In Round", this->NumSupernodesInRound, -1, resultStream);
844 "nHypernodes In Round", this->NumHypernodesInRound, -1, resultStream);
849 "nIterations", this->NumIterations, -1, resultStream);
850 for (
vtkm::Id whichRound = 0; whichRound < this->NumIterations.GetNumberOfValues(); whichRound++)
852 resultStream <<
"Round " << whichRound << std::endl;
854 this->FirstSupernodePerIteration[
static_cast<std::size_t
>(whichRound)].GetNumberOfValues(),
857 "First Supernode Per Iteration",
858 this->FirstSupernodePerIteration[
static_cast<std::size_t
>(whichRound)],
862 "First Hypernode Per Iteration",
863 this->FirstHypernodePerIteration[
static_cast<std::size_t
>(whichRound)],
866 resultStream << std::endl;
868 return resultStream.str();
871 template <
typename FieldType>
874 std::stringstream resultStream;
875 resultStream << std::setw(42) << std::left <<
" NumRounds"
876 <<
": " << this->NumRounds << std::endl;
878 " NumIterations", this->NumIterations, -1, resultStream);
880 " NumRegularNodesInRound", this->NumRegularNodesInRound, -1, resultStream);
882 " NumSupernodesInRound", this->NumSupernodesInRound, -1, resultStream);
884 " NumHypernodesInRound", this->NumHypernodesInRound, -1, resultStream);
886 return resultStream.str();
891 template <
typename FieldType>
901 std::stringstream outStream;
904 outStream <<
"============" << std::endl;
905 outStream <<
"Contour Tree" << std::endl;
909 auto supernodesPortal = supernodes.
ReadPortal();
910 auto regularNodeGlobalIdsPortal = regularNodeGlobalIds.
ReadPortal();
911 auto superarcsPortal = superarcs.
ReadPortal();
912 auto intrinsicVolumePortal = intrinsicVolume.
ReadPortal();
913 auto dependentVolumePortal = dependentVolume.
ReadPortal();
917 vtkm::Id fromRegular = supernodesPortal.Get(supernode);
918 vtkm::Id fromGlobal = regularNodeGlobalIdsPortal.Get(fromRegular);
921 vtkm::Id toSuper = superarcsPortal.Get(supernode);
933 vtkm::Id toRegular = supernodesPortal.Get(toSuper);
934 vtkm::Id toGlobal = regularNodeGlobalIdsPortal.Get(toRegular);
937 vtkm::Id weight = dependentVolumePortal.Get(supernode);
939 vtkm::Id arcWeight = intrinsicVolumePortal.Get(supernode) - 1;
940 vtkm::Id counterWeight = totalVolume - weight + arcWeight;
950 outStream << std::endl;
959 outStream << std::endl;
964 return outStream.str();
967 template <
typename FieldType>
969 const std::vector<vtkm::worklet::contourtree_augmented::IdArrayType>& inputVec,
975 numComponents.
Allocate(inputVec.size());
976 auto numComponentsWritePortal = numComponents.
WritePortal();
978 for (
vtkm::Id i = 0; i < static_cast<vtkm::Id>(inputVec.size()); ++i)
980 numComponentsWritePortal.Set(i,
989 auto outputOffsetsReadPortal = outputOffsets.
ReadPortal();
990 outputComponents.
Allocate(componentsArraySize);
991 auto numComponentsReadPortal = numComponents.
ReadPortal();
992 for (
vtkm::Id i = 0; i < static_cast<vtkm::Id>(inputVec.size()); ++i)
995 outputComponents, outputOffsetsReadPortal.Get(i), numComponentsReadPortal.Get(i));
1000 template <
typename FieldType>
1006 this->RegularNodeGlobalIds);
1007 ds.
AddField(regularNodeGlobalIdsField);
1013 this->RegularNodeSortOrder);
1014 ds.
AddField(regularNodeSortOrderField);
1017 ds.
AddField(regular2SupernodeField);
1042 ConvertSTLVecOfHandlesToVTKMComponentsAndOffsetsArray(FirstSupernodePerIteration,
1043 firstSupernodePerIterationComponents,
1044 firstSupernodePerIterationOffsets);
1046 "FirstSupernodePerIterationComponents",
1048 firstSupernodePerIterationComponents);
1049 ds.
AddField(firstSupernodePerIterationComponentsField);
1051 "FirstSupernodePerIterationOffsets",
1053 firstSupernodePerIterationOffsets);
1054 ds.
AddField(firstSupernodePerIterationOffsetsField);