63 #ifndef vtk_m_worklet_contourtree_augmented_mesh_dem_contour_tree_mesh_h 
   64 #define vtk_m_worklet_contourtree_augmented_mesh_dem_contour_tree_mesh_h 
  111 VTKM_THIRDPARTY_PRE_INCLUDE
 
  112 #include <vtkm/thirdparty/diy/Configure.h> 
  113 #include <vtkm/thirdparty/diy/diy.h> 
  114 VTKM_THIRDPARTY_POST_INCLUDE
 
  126 namespace contourtree_augmented
 
  128 template <
typename FieldType>
 
  178                  std::string timingsMessage = 
"");
 
  181   void Save(
const char* filename) 
const;
 
  182   void Load(
const char* filename);
 
  187   template <
typename T, 
typename StorageType>
 
  215   void PrintContent(std::ostream& outStream = std::cout) 
const;
 
  218   void DebugPrint(
const char* message, 
const char* fileName, 
long lineNum) 
const;
 
  244     (void)localToGlobalIdRelabeler; 
 
  259   template <
typename MeshIdArrayType>
 
  263                                 localToGlobalIdRelabeler = 
nullptr)
 const 
  265     (void)localToGlobalIdRelabeler; 
 
  280   template <
typename ValueType>
 
  284   template <
typename ValueType>
 
  290 template <
typename FieldType>
 
  295   PrintValues(
"SortedValues", this->SortedValues, -1, outStream);
 
  296   PrintIndices(
"GlobalMeshIndex", this->GlobalMeshIndex, -1, outStream);
 
  297   PrintIndices(
"NeighborConnectivity", this->NeighborConnectivity, -1, outStream);
 
  298   PrintIndices(
"NeighborOffsets", this->NeighborOffsets, -1, outStream);
 
  299   outStream << 
"MaxNeighbors=" << this->MaxNeighbors << std::endl;
 
  300   outStream << 
"mGetMax=" << this->mGetMax << std::endl;
 
  304 template <
typename FieldType>
 
  306                                                    const char* fileName,
 
  309   std::cout << 
"---------------------------" << std::endl;
 
  310   std::cout << std::setw(30) << std::left << fileName << 
":" << std::right << std::setw(4)
 
  311             << lineNum << std::endl;
 
  312   std::cout << std::left << std::string(message) << std::endl;
 
  313   std::cout << 
"Contour Tree Mesh Contains:     " << std::endl;
 
  314   std::cout << 
"---------------------------" << std::endl;
 
  315   std::cout << std::endl;
 
  317   PrintContent(std::cout);
 
  321 template <
typename FieldType>
 
  328   , GlobalMeshIndex(inGlobalMeshIndex)
 
  329   , NeighborConnectivity()
 
  343   DebugPrint(
"ContourTreeMesh Initialized", __FILE__, __LINE__);
 
  348 template <
typename FieldType>
 
  354   : GlobalMeshIndex(inGlobalMeshIndex)
 
  355   , NeighborConnectivity()
 
  371   DebugPrint(
"ContourTreeMesh Initialized", __FILE__, __LINE__);
 
  375 template <
typename FieldType>
 
  378   : SortedValues(mesh.SortedValues)
 
  379   , GlobalMeshIndex(mesh.GlobalMeshIndex)
 
  380   , NeighborConnectivity()
 
  390   DebugPrint(
"ContourTreeMesh Initialized", __FILE__, __LINE__);
 
  395 template <
typename FieldType>
 
  399   : NeighborConnectivity()
 
  416   DebugPrint(
"ContourTreeMesh Initialized", __FILE__, __LINE__);
 
  423 template <
typename PT1, 
typename PT2, 
typename PT3, 
typename PT4>
 
  425                                const PT2& srcIndices,
 
  427                                const PT4& dstIndices)
 
  429   VTKM_ASSERT(srcIndices.GetNumberOfValues() == dstIndices.GetNumberOfValues());
 
  440 template <
typename PT1, 
typename PT2, 
typename PT3, 
typename PT4>
 
  442                                   const PT2& srcIndices,
 
  444                                   const PT4& dstIndices)
 
  446   VTKM_ASSERT(srcIndices.GetNumberOfValues() == dstIndices.GetNumberOfValues());
 
  457 template <
typename FieldType>
 
  508   vtkm::Id nValidArcs = this->NeighborConnectivity.GetNumberOfValues();
 
  527                                            this->NeighborConnectivity,
 
  533   VTKM_ASSERT(uniqueKeys.GetNumberOfValues() == this->NumVertices);
 
  544   this->Invoke(replaceArcNumWithToVertexWorklet,
 
  545                this->NeighborConnectivity, 
 
  550   this->ComputeMaxNeighbors();
 
  553   std::cout << std::setw(30) << std::left << __FILE__ << 
":" << std::right << std::setw(4)
 
  554             << __LINE__ << std::endl;
 
  555   auto neighborOffsetPortal = this->NeighborOffsets.ReadPortal();
 
  556   auto neighborConnectivityPortal = this->NeighborConnectivity.ReadPortal();
 
  557   for (
vtkm::Id vtx = 0; vtx < NeighborOffsets.GetNumberOfValues(); ++vtx)
 
  559     std::cout << vtx << 
": ";
 
  560     vtkm::Id neighboursBeginIndex = neighborOffsetPortal.Get(vtx);
 
  561     vtkm::Id neighboursEndIndex = (vtx < this->NumVertices - 1)
 
  562       ? neighborOffsetPortal.Get(vtx + 1)
 
  563       : NeighborConnectivity.GetNumberOfValues();
 
  565     for (
vtkm::Id ni = neighboursBeginIndex; ni < neighboursEndIndex; ++ni)
 
  567       std::cout << neighborConnectivityPortal.Get(ni) << 
" ";
 
  569     std::cout << std::endl;
 
  571   std::cout << 
"Max neighbours: " << this->MaxNeighbors << std::endl;
 
  575 template <
typename FieldType>
 
  584 template <
typename FieldType>
 
  587   this->mGetMax = getMax;
 
  591 template <
typename FieldType>
 
  597                                                                this->NeighborOffsets,
 
  611 template <
typename FieldType>
 
  614                                                   std::string timingsMessage)
 
  617   this->DebugPrint(
"THIS ContourTreeMesh", __FILE__, __LINE__);
 
  618   other.
DebugPrint(
"OTHER ContourTreeMesh", __FILE__, __LINE__);
 
  625   std::stringstream timingsStream;
 
  641       copyIntoCombinedArrayWorkletLowerBound;
 
  642     this->Invoke(copyIntoCombinedArrayWorkletLowerBound,
 
  648       copyIntoCombinedArrayWorkletUpperBound;
 
  649     this->Invoke(copyIntoCombinedArrayWorkletUpperBound,
 
  655   timingsStream << 
"    " << std::setw(38) << std::left << 
"Create OverallSortOrder" 
  660   std::cout << 
"OverallSortOrder.size  " << overallSortOrder.
GetNumberOfValues() << std::endl;
 
  662   std::cout << std::endl;
 
  674       this->GlobalMeshIndex,
 
  684   std::cout << 
"OverallSortIndex.size  " << overallSortIndex.
GetNumberOfValues() << std::endl;
 
  686   std::cout << 
"numVerticesCombined: " << numVerticesCombined << std::endl;
 
  687   std::cout << std::endl;
 
  689   timingsStream << 
"    " << std::setw(38) << std::left << 
"Create OverallSortIndex" 
  695   thisToCombinedSortOrder.
Allocate(this->NumVertices);
 
  699     initToCombinedSortOrderArraysWorklet;
 
  700   this->Invoke(initToCombinedSortOrderArraysWorklet,
 
  703                thisToCombinedSortOrder,
 
  704                otherToCombinedSortOrder);
 
  707   PrintIndices(
"thisToCombinedSortOrder", thisToCombinedSortOrder);
 
  708   PrintIndices(
"otherToCombinedSortOrder", otherToCombinedSortOrder);
 
  710   timingsStream << 
"    " << std::setw(38) << std::left << 
"Create This/OtherCombinedSortOrder" 
  715   auto neighborConnectivityGlobalThis =
 
  718                               this->NeighborConnectivity,
 
  719                               thisToCombinedSortOrder);
 
  721     neighborConnectivityGlobalThis, this->NeighborOffsets);
 
  723   auto neighborConnectivityGlobalOther =
 
  727                               otherToCombinedSortOrder);
 
  744                thisToCombinedSortOrder,
 
  745                otherToCombinedSortOrder,
 
  746                thisToCombinedSortOrderIsDuplicate,
 
  747                otherToCombinedSortOrderIsDuplicate);
 
  750   PrintIndices(
"thisToCombinedSortOrderIsDuplicate", thisToCombinedSortOrderIsDuplicate);
 
  751   PrintIndices(
"otherToCombinedSortOrderIsDuplicate", otherToCombinedSortOrderIsDuplicate);
 
  757   IdArrayType indicesThisUnique, indicesThisDuplicate;
 
  759     indicesThis, thisToCombinedSortOrderIsDuplicate, indicesThisUnique, 
IsUnique{});
 
  761     indicesThis, thisToCombinedSortOrderIsDuplicate, indicesThisDuplicate);
 
  765   PrintIndices(
"indicesThisDuplicate", indicesThisDuplicate);
 
  768   IdArrayType indicesOtherUnique, indicesOtherDuplicate;
 
  770     indicesOther, otherToCombinedSortOrderIsDuplicate, indicesOtherUnique, 
IsUnique{});
 
  772     indicesOther, otherToCombinedSortOrderIsDuplicate, indicesOtherDuplicate);
 
  776   PrintIndices(
"indicesOtherDuplicate", indicesOtherDuplicate);
 
  785   auto permutedNeighborCountsThis =
 
  788   auto permutedNeighborCountsOther =
 
  792                                    permutedNeighborCountsOther,
 
  793                                    combinedCommonNeighborCountSums,
 
  798   vtkm::Id unpackedCombinedCommonNeighborConnectivitySize;
 
  801                                             unpackedCombinedCommonNeighborOffsets,
 
  802                                             unpackedCombinedCommonNeighborConnectivitySize);
 
  803   IdArrayType unpackedCombinedCommonNeighborConnectivity;
 
  804   unpackedCombinedCommonNeighborConnectivity.
Allocate(
 
  805     unpackedCombinedCommonNeighborConnectivitySize);
 
  807     unpackedCombinedCommonNeighborConnectivity, unpackedCombinedCommonNeighborOffsets);
 
  810   auto permutedNeighborConnectivityGlobalGroupsThis =
 
  812   auto permutedNeighborConnectivityGlobalGroupsOther =
 
  821                permutedNeighborConnectivityGlobalGroupsThis,
 
  822                permutedNeighborConnectivityGlobalGroupsOther,
 
  823                unpackedCombinedCommonNeighborConnectivityGroups,
 
  824                packedCombinedCommonNeighborCounts);
 
  828   vtkm::Id packedCombinedCommonNeighborConnectivitySize;
 
  831                                             packedCombinedCommonNeighborOffsets,
 
  832                                             packedCombinedCommonNeighborConnectivitySize);
 
  836   packedCombinedCommonNeighborConnectivity.
Allocate(packedCombinedCommonNeighborConnectivitySize);
 
  838     packedCombinedCommonNeighborConnectivity, packedCombinedCommonNeighborOffsets);
 
  842                unpackedCombinedCommonNeighborConnectivityGroups,
 
  843                packedCommonNeighborConnectivityGroups);
 
  848   combinedNeighborCounts.
Allocate(numVerticesCombined);
 
  850   auto thisOnlyToCombinedSortOrder =
 
  852   auto otherOnlyToCombinedSortOrder =
 
  854   auto commonToCombinedSortOrder =
 
  858     neighborCountsThis, indicesThisUnique, combinedNeighborCounts, thisOnlyToCombinedSortOrder);
 
  860     neighborCountsOther, indicesOtherUnique, combinedNeighborCounts, otherOnlyToCombinedSortOrder);
 
  861   auto commonCombinedNeighborCounts =
 
  866   vtkm::Id combinedNeighborConnectivitySize;
 
  869     combinedNeighborCounts, combinedNeighborOffsets, combinedNeighborConnectivitySize);
 
  871   combinedNeighborConnectivity.
Allocate(combinedNeighborConnectivitySize);
 
  872   auto combinedNeighborConnectivityGroups =
 
  878                         combinedNeighborConnectivityGroups,
 
  879                         thisOnlyToCombinedSortOrder);
 
  882                         combinedNeighborConnectivityGroups,
 
  883                         otherOnlyToCombinedSortOrder);
 
  884   auto commonCombinedNeighborConnectivityGroups =
 
  887                packedCommonNeighborConnectivityGroups,
 
  888                commonCombinedNeighborConnectivityGroups);
 
  892   timingsStream << 
"    " << std::setw(38) << std::left << 
"Compute CombinedNeighborConnectivity" 
  898   combinedGlobalMeshIndex.
Allocate(numVerticesCombined);
 
  900     auto permutedCombinedGlobalMeshIndex =
 
  905     auto permutedCombinedGlobalMeshIndex =
 
  910   timingsStream << 
"    " << std::setw(38) << std::left << 
"Create CombinedGlobalMeshIndex" 
  916   combinedSortedValues.
Allocate(numVerticesCombined);
 
  918     auto permutedCombinedSortedValues =
 
  923     auto permutedCombinedSortedValues =
 
  928   timingsStream << 
"    " << std::setw(38) << std::left << 
"Create CombinedSortedValues" 
  933   this->SortedValues = combinedSortedValues;
 
  934   this->GlobalMeshIndex = combinedGlobalMeshIndex;
 
  935   this->NeighborConnectivity = combinedNeighborConnectivity;
 
  936   this->NeighborOffsets = combinedNeighborOffsets;
 
  941   timingsStream << 
"    " << std::setw(38) << std::left << 
"Swap in new arrays" 
  946   ComputeMaxNeighbors();
 
  948   timingsStream << 
"    " << std::setw(38) << std::left << 
"Compute MaxNeighbors" 
  951   timingsStream << 
"    " << std::setw(38) << std::left << 
"Total time MergeWith" 
  952                 << 
": " << totalTimer.
GetElapsedTime() << 
" seconds" << std::endl;
 
  957                << 
"    ---------------- ContourTreeMesh MergeWith ---------------------" 
  959                << timingsMessage << timingsStream.str());
 
  961   (void)timingsLogLevel;
 
  962   (void)timingsMessage;
 
  966   DebugPrint(
"ContourTreeMeshes merged", __FILE__, __LINE__);
 
  971 template <
typename FieldType>
 
  974   std::ofstream os(filename);
 
  975   SaveVector(os, this->SortedValues);
 
  976   SaveVector(os, this->GlobalMeshIndex);
 
  977   SaveVector(os, this->NeighborConnectivity);
 
  978   SaveVector(os, this->NeighborOffsets);
 
  981 template <
typename FieldType>
 
  984   std::ifstream is(filename);
 
  987     throw vtkm::io::ErrorIO(std::string(
"Unable to open file: ") + std::string(filename));
 
  989   LoadVector(is, this->SortedValues);
 
  990   LoadVector(is, this->GlobalMeshIndex);
 
  991   LoadVector(is, this->NeighborConnectivity);
 
  992   LoadVector(is, this->NeighborOffsets);
 
  993   this->ComputeMaxNeighbors();
 
  994   this->NumVertices = this->SortedValues.GetNumberOfValues();
 
  999 template <
typename FieldType>
 
 1000 template <
typename ValueType>
 
 1007   os << numVals << 
": ";
 
 1009   for (
vtkm::Id i = 0; i < numVals; ++i)
 
 1010     os << vecPortal.Get(i) << 
" ";
 
 1015 template <
typename FieldType>
 
 1016 template <
typename ValueType>
 
 1022   char colon = is.get();
 
 1031   for (
vtkm::Id i = 0; i < numVals; ++i)
 
 1034     vecPortal.Set(i, val);
 
 1038 template <
typename FieldType>
 
 1047 template <
typename FieldType>
 
 1059   this->Invoke(computeMeshBoundaryContourTreeMeshWorklet,
 
 1061                *meshBoundaryExecObj,