VTK-m  2.0
ContourTreeMesh.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 // This software is distributed WITHOUT ANY WARRANTY; without even
6 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
7 // PURPOSE. See the above copyright notice for more information.
8 //
9 // Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
10 // Copyright 2014 UT-Battelle, LLC.
11 // Copyright 2014 Los Alamos National Security.
12 //
13 // Under the terms of Contract DE-NA0003525 with NTESS,
14 // the U.S. Government retains certain rights in this software.
15 //
16 // Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
17 // Laboratory (LANL), the U.S. Government retains certain rights in
18 // this software.
19 //============================================================================
20 // Copyright (c) 2018, The Regents of the University of California, through
21 // Lawrence Berkeley National Laboratory (subject to receipt of any required approvals
22 // from the U.S. Dept. of Energy). All rights reserved.
23 //
24 // Redistribution and use in source and binary forms, with or without modification,
25 // are permitted provided that the following conditions are met:
26 //
27 // (1) Redistributions of source code must retain the above copyright notice, this
28 // list of conditions and the following disclaimer.
29 //
30 // (2) Redistributions in binary form must reproduce the above copyright notice,
31 // this list of conditions and the following disclaimer in the documentation
32 // and/or other materials provided with the distribution.
33 //
34 // (3) Neither the name of the University of California, Lawrence Berkeley National
35 // Laboratory, U.S. Dept. of Energy nor the names of its contributors may be
36 // used to endorse or promote products derived from this software without
37 // specific prior written permission.
38 //
39 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
40 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
41 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42 // IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
43 // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
44 // BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
46 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
47 // OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
48 // OF THE POSSIBILITY OF SUCH DAMAGE.
49 //
50 //=============================================================================
51 //
52 // This code is an extension of the algorithm presented in the paper:
53 // Parallel Peak Pruning for Scalable SMP Contour Tree Computation.
54 // Hamish Carr, Gunther Weber, Christopher Sewell, and James Ahrens.
55 // Proceedings of the IEEE Symposium on Large Data Analysis and Visualization
56 // (LDAV), October 2016, Baltimore, Maryland.
57 //
58 // The PPP2 algorithm and software were jointly developed by
59 // Hamish Carr (University of Leeds), Gunther H. Weber (LBNL), and
60 // Oliver Ruebel (LBNL)
61 //==============================================================================
62 
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
65 
66 #include <cstdlib>
67 #include <fstream>
68 #include <iostream>
69 #include <vtkm/Types.h>
70 #include <vtkm/cont/Algorithm.h>
80 #include <vtkm/cont/Timer.h>
82 #include <vtkm/filter/scalar_topology/worklet/contourtree_augmented/data_set_mesh/IdRelabeler.h> // This is needed only as an unused default argument.
100 #include <vtkm/io/ErrorIO.h>
102 
103 #include <vtkm/filter/scalar_topology/worklet/contourtree_augmented/PrintVectors.h> // TODO remove should not be needed
104 
106 
107 #include <vtkm/cont/Invoker.h>
108 
109 #include <algorithm>
110 
111 VTKM_THIRDPARTY_PRE_INCLUDE
112 #include <vtkm/thirdparty/diy/Configure.h>
113 #include <vtkm/thirdparty/diy/diy.h>
114 VTKM_THIRDPARTY_POST_INCLUDE
115 // clang-format on
116 
117 namespace contourtree_mesh_inc_ns =
119 
120 // #define DEBUG_PRINT
121 
122 namespace vtkm
123 {
124 namespace worklet
125 {
126 namespace contourtree_augmented
127 {
128 template <typename FieldType>
130 { // class ContourTreeMesh
131 public:
132  //Mesh dependent helper functions
133  void SetPrepareForExecutionBehavior(bool getMax);
134 
137  vtkm::cont::Token& token) const;
138 
140 
141  // Constructor
142  ContourTreeMesh(const IdArrayType& arcs,
143  const IdArrayType& inSortOrder,
145  const IdArrayType& inGlobalMeshIndex);
146 
147  // Constructor
148  ContourTreeMesh(const IdArrayType& nodes,
149  const IdArrayType& arcs,
150  const IdArrayType& inSortOrder,
152  const IdArrayType& inGlobalMeshIndex);
153 
154  // Construct a ContourTreeMesh from nodes/arcs and another ContourTreeMesh (instead of a DataSetMesh)
155  // nodes/arcs: From the contour tree
156  // ContourTreeMesh: the contour tree mesh used to compute the contour tree described by nodes/arcs
157  ContourTreeMesh(const IdArrayType& nodes,
158  const IdArrayType& arcs,
159  const ContourTreeMesh<FieldType>& mesh);
160 
161  // Initalize contour tree mesh from mesh and arcs. For fully augmented contour tree with all
162  // mesh vertices as nodes. Same as using { 0, 1, ..., nodes.size()-1 } as nodes for the
163  // ContourTreeMeshh(nodes, arcsm mesh) constructor above
164  ContourTreeMesh(const IdArrayType& arcs, const ContourTreeMesh<FieldType>& mesh);
165 
166  // Load contour tree mesh from file
167  ContourTreeMesh(const char* filename)
168  {
169  Load(filename);
171  }
172 
173  vtkm::Id GetNumberOfVertices() const { return this->NumVertices; }
174 
175  // Combine two ContourTreeMeshes
178  std::string timingsMessage = "");
179 
180  // Save/Load the mesh helpers
181  void Save(const char* filename) const;
182  void Load(const char* filename);
183 
184  // Empty placeholder function to ensure compliance of this class with the interface
185  // the other mesh classes. This is a no-op here since this class is initalized
186  // from a known contour tree so sort is already done
187  template <typename T, typename StorageType>
189  {
190  (void)values; // Do nothink but avoid unsused param warning
191  }
192 
193  // Public fields
194  static const int MAX_OUTDEGREE = 20;
195 
201  // NeighborConnectivity stores for each vertex the indices of its neighbors. For each vertex
202  // the indices are sorted by value, i.e, the first neighbour has the lowest and
203  // the last neighbour the highest value for the vertex. In the array we just
204  // concatinate the list of neighbors from all vertices, i.e., we first
205  // have the list of neighbors of the first vertex, then the second vertex and so on, i.e.:
206  // [ n_1_1, n_1_2, n_2_1, n_2_2, n_2_3, etc.]
208  // NeighborOffsets gives us for each vertex an index into the neighours array indicating
209  // the index where the list of neighbors for the vertex begins
211  // the maximum number of neighbors of a vertex
213 
214  // Print Contents
215  void PrintContent(std::ostream& outStream = std::cout) const;
216 
217  // Debug print routine
218  void DebugPrint(const char* message, const char* fileName, long lineNum) const;
219 
220  // Get boundary execution object
222  vtkm::Id3 minIdx,
223  vtkm::Id3 maxIdx) const;
224 
225  void GetBoundaryVertices(IdArrayType& boundaryVertexArray, // output
226  IdArrayType& boundarySortIndexArray, // output
227  MeshBoundaryContourTreeMeshExec* meshBoundaryExecObj //input
228  ) const;
229 
240  const IdArrayType& sortIds,
241  const vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler* localToGlobalIdRelabeler =
242  nullptr) const
243  { // GetGlobalIDsFromSortIndices()
244  (void)localToGlobalIdRelabeler; // avoid compiler warning
245  return vtkm::cont::make_ArrayHandlePermutation(sortIds, this->GlobalMeshIndex);
246  } // GetGlobalIDsFromSortIndices()
247 
259  template <typename MeshIdArrayType>
261  GetGlobalIdsFromMeshIndices(const MeshIdArrayType& meshIds,
263  localToGlobalIdRelabeler = nullptr) const
264  { // GetGlobalIDsFromMeshIndices()
265  (void)localToGlobalIdRelabeler; // avoid compiler warning
266  return vtkm::cont::make_ArrayHandlePermutation(meshIds, this->GlobalMeshIndex);
267  } // GetGlobalIDsFromMeshIndices()
268 
269 private:
271 
272  bool mGetMax; // Define the behavior for the PrepareForExecution function
273 
274  // Private init and helper functions
276  void ComputeMaxNeighbors();
277 
278  // Private helper functions for saving data vectors
279  // Internal helper function to save 1D index array to file
280  template <typename ValueType>
281  void SaveVector(std::ostream& os, const vtkm::cont::ArrayHandle<ValueType>& vec) const;
282 
283  // Internal helper function to Load 1D index array from file
284  template <typename ValueType>
285  void LoadVector(std::istream& is, vtkm::cont::ArrayHandle<ValueType>& vec);
286 
287 }; // ContourTreeMesh
288 
289 // print content
290 template <typename FieldType>
291 inline void ContourTreeMesh<FieldType>::PrintContent(std::ostream& outStream /*= std::cout*/) const
292 { // PrintContent()
293  PrintHeader(this->NumVertices, outStream);
294  //PrintIndices("SortOrder", SortOrder, outStream);
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;
301 } // PrintContent()
302 
303 // debug routine
304 template <typename FieldType>
305 inline void ContourTreeMesh<FieldType>::DebugPrint(const char* message,
306  const char* fileName,
307  long lineNum) const
308 { // DebugPrint()
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;
316 
317  PrintContent(std::cout);
318 } // DebugPrint()
319 
320 // create the contour tree mesh from contour tree data
321 template <typename FieldType>
323  const IdArrayType& inSortOrder,
325  const IdArrayType& inGlobalMeshIndex)
326  : SortOrder()
327  , SortedValues()
328  , GlobalMeshIndex(inGlobalMeshIndex)
329  , NeighborConnectivity()
330  , NeighborOffsets()
331 {
332  this->NumVertices = inSortOrder.GetNumberOfValues();
333  // Initalize the SortedIndices as a smart array handle
336  // values permuted by SortOrder to sort the values
337  auto permutedValues = vtkm::cont::make_ArrayHandlePermutation(inSortOrder, values);
338  // TODO check if we actually need to make this copy here. we could just store the permutedValues array to save memory
339  vtkm::cont::Algorithm::Copy(permutedValues, this->SortedValues);
341 #ifdef DEBUG_PRINT
342  // Print the contents fo this for debugging
343  DebugPrint("ContourTreeMesh Initialized", __FILE__, __LINE__);
344 #endif
345 }
346 
347 
348 template <typename FieldType>
350  const IdArrayType& arcs,
351  const IdArrayType& inSortOrder,
353  const IdArrayType& inGlobalMeshIndex)
354  : GlobalMeshIndex(inGlobalMeshIndex)
355  , NeighborConnectivity()
356  , NeighborOffsets()
357 {
358  // Initialize the SortedValues array with values permuted by the SortOrder permuted by the nodes, i.e.,
359  // this->SortedValues[v] = values[inSortOrder[nodes[v]]];
361  inSortOrder);
362  auto permutedValues = vtkm::cont::make_ArrayHandlePermutation(permutedSortOrder, values);
363  vtkm::cont::Algorithm::Copy(permutedValues, this->SortedValues);
364  // Initalize the SortedIndices as a smart array handle
369 #ifdef DEBUG_PRINT
370  // Print the contents fo this for debugging
371  DebugPrint("ContourTreeMesh Initialized", __FILE__, __LINE__);
372 #endif
373 }
374 
375 template <typename FieldType>
377  const ContourTreeMesh<FieldType>& mesh)
378  : SortedValues(mesh.SortedValues)
379  , GlobalMeshIndex(mesh.GlobalMeshIndex)
380  , NeighborConnectivity()
381  , NeighborOffsets()
382 {
383  // Initalize the SortedIndices as a smart array handle
388 #ifdef DEBUG_PRINT
389  // Print the contents fo this for debugging
390  DebugPrint("ContourTreeMesh Initialized", __FILE__, __LINE__);
391 #endif
392 }
393 
394 
395 template <typename FieldType>
397  const IdArrayType& arcs,
398  const ContourTreeMesh<FieldType>& mesh)
399  : NeighborConnectivity()
400  , NeighborOffsets()
401 {
402  // Initatlize the global mesh index with the GlobalMeshIndex permutted by the nodes
404  nodes, mesh.GlobalMeshIndex);
405  vtkm::cont::Algorithm::Copy(permutedGlobalMeshIndex, this->GlobalMeshIndex);
406  // Initialize the SortedValues array with the SortedValues permutted by the nodes
407  auto permutedSortedValues = vtkm::cont::make_ArrayHandlePermutation(nodes, mesh.SortedValues);
408  vtkm::cont::Algorithm::Copy(permutedSortedValues, this->SortedValues);
409  // Initialize the neighbors from the arcs
414 #ifdef DEBUG_PRINT
415  // Print the contents fo this for debugging
416  DebugPrint("ContourTreeMesh Initialized", __FILE__, __LINE__);
417 #endif
418 }
419 
420 // Helper function to copy select set of indices of source array into
421 // select set of inidces of destination array. Important: srcIndices
422 // and dstIndices must contain the same number of values.
423 template <typename PT1, typename PT2, typename PT3, typename PT4>
424 inline void CopyArrayByIndices(const PT1& srcArray,
425  const PT2& srcIndices,
426  PT3& dstArray,
427  const PT4& dstIndices)
428 {
429  VTKM_ASSERT(srcIndices.GetNumberOfValues() == dstIndices.GetNumberOfValues());
430  auto srcPermutation = make_ArrayHandlePermutation(srcIndices, srcArray);
431  auto dstPermuation = make_ArrayHandlePermutation(dstIndices, dstArray);
432  vtkm::cont::Algorithm::Copy(srcPermutation, dstPermuation);
433 }
434 
435 // Helper function doing the same as previous function, but for
436 // arrays of vector. This is necessary since we use an array
437 // created with ArrayHandleGroupVecVariable as destination,
438 // which breaks some conventions of ArrayHandle and does not work
439 // with vtkm::cont::Algorithm::Copy.
440 template <typename PT1, typename PT2, typename PT3, typename PT4>
441 inline void CopyVecArrayByIndices(const PT1& srcArray,
442  const PT2& srcIndices,
443  PT3& dstArray,
444  const PT4& dstIndices)
445 {
446  VTKM_ASSERT(srcIndices.GetNumberOfValues() == dstIndices.GetNumberOfValues());
447  auto srcPermutation = make_ArrayHandlePermutation(srcIndices, srcArray);
448  auto dstPermuation = make_ArrayHandlePermutation(dstIndices, dstArray);
449  // Use a worklet for copying data since ArrayHandleGroupVecVariable does
450  // not work as destination for vtkm::cont::Algorithm::Copy.
451  vtkm::cont::Invoker invoke;
452  invoke(
453  contourtree_mesh_inc_ns::CopyIntoCombinedNeighborsWorklet{}, srcPermutation, dstPermuation);
454 }
455 
456 // Initalize the contour tree from the arcs array
457 template <typename FieldType>
459  const IdArrayType& arcs)
460 {
461  // This function computes the neighbor connecitvity (NeighborConnectivity, NeighborOffsets) from
462  // an arc array. An arc array consists of undirected arcs. arc[i] connects contour tree nodes
463  // i and arc[i]. For the neighbor connectiviy in the contour tree mesh, we first convert these
464  // into two directed arcs that are then used to compute a list of neighbors in the mesh for
465  // each node.
466  //
467  // Take this simple graph for example:
468  //
469  /* 4
470  \
471  > 3 -> 1 <- 0
472  /
473  /
474  2
475  (Use this comment style to avoid warnings about multi-line comments triggered by '\' at
476  the end of the line).
477  */
478  // (This is a graph with nodes 0 through 4 and edges 0 -> 1, 2 -> 3, 3 -> 1, 4 -> 3).
479  // The way the graph is structured, each nodes has at most one outgoing edge.
480  // The contour tree algorithm stores this in an arcs array:
481  //
482  // idx: 0 1 2 3 4
483  // arcs: 1 - 3 1 3 (- = NO_SUCH_ELEMENT, meaning no arc originating from this node)
484  //
485  // This function translates this into the internal contour tree mesh represnetation,
486  // which is "regular" vtk-m connectivity format, i.e., the connectity array is a
487  // flat list of neighbor vertices and offsets give the start index of the
488  // neighbor list for each vertex:
489  //
490  // connectivity: 1 0 3 3 1 2 4 3
491  // counts: 1 2 1 3 1
492  // offset: 0 1 3 4 7 8
493 
494  // Step 1: Implictely view arc array as directed arcs and add arcs in the opposite
495  // direction. In the resulting arc list, arc 2*idx is the arc idx->arcs[idx] and arc
496  // 2*idx+1 is the arc arcs[idx]->idx, i.e., in our example,
497  // idx: 0 1 2 3 4 5 6 7 8 9
498  // from: 0 1 1 - 2 3 3 1 4 3
499  // to: 1 0 - 1 3 2 1 3 3 4
500  vtkm::Id nArcsTotal = 2 * arcs.GetNumberOfValues();
501  vtkm::cont::ArrayHandleIndex indexArray(nArcsTotal);
502  auto arcIsValidArray = make_ArrayHandleDecorator(
504  // We first generate a list of "valid" arcs in this->NeighborConnectivity, in our
505  // example:
506  // connectivity: 0 1 4 5 6 7 8 9
507  vtkm::cont::Algorithm::CopyIf(indexArray, arcIsValidArray, this->NeighborConnectivity);
508  vtkm::Id nValidArcs = this->NeighborConnectivity.GetNumberOfValues();
509 
510  // Step 2: Sort arcs---by permuting their indices in the connectiviy array---so
511  // that all arcs originating at the same vertex (same `from`) are adjacent.
512  // All arcs are in neighbors array based on sort index of their 'from' vertex
513  // (and then within a run sorted by sort index of their 'to' vertex).
514  // In our example this results in:
515  // connectivity: 0 1 7 4 6 5 9 8
516  // corresponding to an arc order of
517  // from: 0 1 1 2 3 3 3 4
518  // to: 1 0 3 3 1 2 4 3
519  vtkm::cont::Algorithm::Sort(this->NeighborConnectivity,
521 
522  // We can now obtain counts of the connectivity array by counting the number
523  // of consecutive `from` entries with the same value. In our example:
524  // counts: 1 2 1 3 1
525  auto arcFrom = make_ArrayHandleDecorator(nValidArcs,
527  this->NeighborConnectivity,
528  arcs);
529  auto constOne = vtkm::cont::make_ArrayHandleConstant(vtkm::Id{ 1 }, nValidArcs);
532  vtkm::cont::Algorithm::ReduceByKey(arcFrom, constOne, uniqueKeys, counts, vtkm::Add());
533  VTKM_ASSERT(uniqueKeys.GetNumberOfValues() == this->NumVertices);
534 
535  // Convert counts into offsts for the connectivity array
536  vtkm::Id neighborOffsetsSize;
537  vtkm::cont::ConvertNumComponentsToOffsets(counts, this->NeighborOffsets, neighborOffsetsSize);
538 
539  // Finally, the correct connectivity array correspons to the `to` array,
540  // so replace arc indices with its `to`vertex. In our example, this results in:
541  // connectivity: 1 0 3 3 1 2 4 3
542  // which is exactly the array we needed to compute
543  contourtree_mesh_inc_ns::ReplaceArcNumWithToVertexWorklet replaceArcNumWithToVertexWorklet;
544  this->Invoke(replaceArcNumWithToVertexWorklet,
545  this->NeighborConnectivity, // input/output
546  arcs // input
547  );
548 
549  // Compute maximum number of neighbors
550  this->ComputeMaxNeighbors();
551 
552 #ifdef DEBUG_PRINT
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)
558  {
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();
564 
565  for (vtkm::Id ni = neighboursBeginIndex; ni < neighboursEndIndex; ++ni)
566  {
567  std::cout << neighborConnectivityPortal.Get(ni) << " ";
568  }
569  std::cout << std::endl;
570  }
571  std::cout << "Max neighbours: " << this->MaxNeighbors << std::endl;
572 #endif
573 }
574 
575 template <typename FieldType>
577 {
578  auto neighborCounts = make_ArrayHandleOffsetsToNumComponents(this->NeighborOffsets);
580  this->MaxNeighbors = static_cast<vtkm::Id>(rangeArray.ReadPortal().Get(0).Max);
581 }
582 
583 // Define the behavior for the execution object generate by the PrepareForExecution function
584 template <typename FieldType>
586 {
587  this->mGetMax = getMax;
588 }
589 
590 // Get VTKM execution object that represents the structure of the mesh and provides the mesh helper functions on the device
591 template <typename FieldType>
593  FieldType>::PrepareForExecution(vtkm::cont::DeviceAdapterId device,
594  vtkm::cont::Token& token) const
595 {
596  return contourtree_mesh_inc_ns::MeshStructureContourTreeMesh(this->NeighborConnectivity,
597  this->NeighborOffsets,
598  this->MaxNeighbors,
599  this->mGetMax,
600  device,
601  token);
602 }
603 
604 // Helper functor, basically negates criterion for CopyIf
605 struct IsUnique
606 {
607  VTKM_EXEC_CONT bool operator()(vtkm::IdComponent isInOther) const { return isInOther == 0; }
608 };
609 
610 // Combine two ContourTreeMeshes
611 template <typename FieldType>
613  vtkm::cont::LogLevel timingsLogLevel,
614  std::string timingsMessage)
615 { // Merge With
616 #ifdef DEBUG_PRINT
617  this->DebugPrint("THIS ContourTreeMesh", __FILE__, __LINE__);
618  other.DebugPrint("OTHER ContourTreeMesh", __FILE__, __LINE__);
619 #endif
620  // Track timing of main steps
621  vtkm::cont::Timer totalTimer; // Total time for each call
622  totalTimer.Start();
623  vtkm::cont::Timer timer; // Time individual steps
624  timer.Start();
625  std::stringstream timingsStream;
626 
627  // Create combined sort order
628  // TODO This vector could potentially be implemented purely as a smart array handle to reduce memory usage
629  IdArrayType overallSortOrder;
630  overallSortOrder.Allocate(this->NumVertices + other.NumVertices);
631 
632  { // Create a new scope so that the following two vectors get deleted when leaving the scope
633  auto thisIndices = vtkm::cont::ArrayHandleIndex(this->NumVertices); // A regular index array
634  MarkOther markOtherFunctor;
635  auto otherIndices = vtkm::cont::make_ArrayHandleTransform(
636  vtkm::cont::ArrayHandleIndex(other.NumVertices), markOtherFunctor);
638  cssicFunctorExecObj(
639  this->GlobalMeshIndex, other.GlobalMeshIndex, this->SortedValues, other.SortedValues);
641  copyIntoCombinedArrayWorkletLowerBound;
642  this->Invoke(copyIntoCombinedArrayWorkletLowerBound,
643  thisIndices,
644  otherIndices,
645  cssicFunctorExecObj,
646  overallSortOrder);
648  copyIntoCombinedArrayWorkletUpperBound;
649  this->Invoke(copyIntoCombinedArrayWorkletUpperBound,
650  otherIndices,
651  thisIndices,
652  cssicFunctorExecObj,
653  overallSortOrder);
654  }
655  timingsStream << " " << std::setw(38) << std::left << "Create OverallSortOrder"
656  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
657  timer.Start();
658 
659 #ifdef DEBUG_PRINT
660  std::cout << "OverallSortOrder.size " << overallSortOrder.GetNumberOfValues() << std::endl;
661  PrintIndices("overallSortOrder", overallSortOrder);
662  std::cout << std::endl;
663 #endif
664 
665  IdArrayType overallSortIndex;
666  overallSortIndex.Allocate(overallSortOrder.GetNumberOfValues());
667  {
668  // Array decorator with functor returning 0, 1 for each element depending
669  // on whethern the current value is different from the next.
670  auto differentFromNextArr = vtkm::cont::make_ArrayHandleDecorator(
671  overallSortOrder.GetNumberOfValues() - 1,
673  overallSortOrder,
674  this->GlobalMeshIndex,
675  other.GlobalMeshIndex);
676 
677  // Compute the extended scan of our transformed combined vector
678  vtkm::cont::Algorithm::ScanExtended(differentFromNextArr, overallSortIndex);
679  }
680  vtkm::Id numVerticesCombined =
681  ArrayGetValue(overallSortIndex.GetNumberOfValues() - 1, overallSortIndex) + 1;
682 
683 #ifdef DEBUG_PRINT
684  std::cout << "OverallSortIndex.size " << overallSortIndex.GetNumberOfValues() << std::endl;
685  PrintIndices("overallSortIndex", overallSortIndex);
686  std::cout << "numVerticesCombined: " << numVerticesCombined << std::endl;
687  std::cout << std::endl;
688 #endif
689  timingsStream << " " << std::setw(38) << std::left << "Create OverallSortIndex"
690  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
691  timer.Start();
692 
693  // thisToCombinedSortOrder and otherToCombinedSortOrder
694  IdArrayType thisToCombinedSortOrder;
695  thisToCombinedSortOrder.Allocate(this->NumVertices);
696  IdArrayType otherToCombinedSortOrder;
697  otherToCombinedSortOrder.Allocate(other.NumVertices);
699  initToCombinedSortOrderArraysWorklet;
700  this->Invoke(initToCombinedSortOrderArraysWorklet,
701  overallSortIndex,
702  overallSortOrder,
703  thisToCombinedSortOrder,
704  otherToCombinedSortOrder);
705 
706 #ifdef DEBUG_PRINT
707  PrintIndices("thisToCombinedSortOrder", thisToCombinedSortOrder);
708  PrintIndices("otherToCombinedSortOrder", otherToCombinedSortOrder);
709 #endif
710  timingsStream << " " << std::setw(38) << std::left << "Create This/OtherCombinedSortOrder"
711  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
712  timer.Start();
713 
714  // Map neighbor IDs to global ID (ID in the combined) and group them
715  auto neighborConnectivityGlobalThis =
716  make_ArrayHandleDecorator(this->NeighborConnectivity.GetNumberOfValues(),
718  this->NeighborConnectivity,
719  thisToCombinedSortOrder);
720  auto neighborConnectivityGlobalGroupsThis = vtkm::cont::make_ArrayHandleGroupVecVariable(
721  neighborConnectivityGlobalThis, this->NeighborOffsets);
722 
723  auto neighborConnectivityGlobalOther =
726  other.NeighborConnectivity,
727  otherToCombinedSortOrder);
728  auto neighborConnectivityGlobalGroupsOther = vtkm::cont::make_ArrayHandleGroupVecVariable(
729  neighborConnectivityGlobalOther, other.NeighborOffsets);
730 
731  // Merge the two neighborhood connecitivy lists. First, we split neighbor connectivity
732  // into three groups (i) vertices only in this, (ii) vertices only in other, (iii)
733  // vertices in both meshes. We then compute cobmined neighbor connectivity for vertices
734  // in both meshes. Finally, we copy them into the combined array.
735 
736  // Split vertices into groups (i) uniuqe this, (ii) unique other, (iii) in both
737  // ... compute arrays containing 1 if the element is in the other respective array
738  vtkm::cont::ArrayHandle<vtkm::IdComponent> thisToCombinedSortOrderIsDuplicate;
739  thisToCombinedSortOrderIsDuplicate.Allocate(thisToCombinedSortOrder.GetNumberOfValues());
740  vtkm::cont::ArrayHandle<vtkm::IdComponent> otherToCombinedSortOrderIsDuplicate;
741  otherToCombinedSortOrderIsDuplicate.AllocateAndFill(otherToCombinedSortOrder.GetNumberOfValues(),
742  vtkm::IdComponent{ 0 });
744  thisToCombinedSortOrder,
745  otherToCombinedSortOrder,
746  thisToCombinedSortOrderIsDuplicate,
747  otherToCombinedSortOrderIsDuplicate);
748 
749 #ifdef DEBUG_PRINT
750  PrintIndices("thisToCombinedSortOrderIsDuplicate", thisToCombinedSortOrderIsDuplicate);
751  PrintIndices("otherToCombinedSortOrderIsDuplicate", otherToCombinedSortOrderIsDuplicate);
752 #endif
753  // ... create lists for all groups to be used to restrict operations to them
754  vtkm::cont::ArrayHandleIndex indicesThis(thisToCombinedSortOrder.GetNumberOfValues());
755  vtkm::cont::ArrayHandleIndex indicesOther(otherToCombinedSortOrder.GetNumberOfValues());
756 
757  IdArrayType indicesThisUnique, indicesThisDuplicate;
759  indicesThis, thisToCombinedSortOrderIsDuplicate, indicesThisUnique, IsUnique{});
761  indicesThis, thisToCombinedSortOrderIsDuplicate, indicesThisDuplicate);
762 
763 #ifdef DEBUG_PRINT
764  PrintIndices("indicesThisUnique", indicesThisUnique);
765  PrintIndices("indicesThisDuplicate", indicesThisDuplicate);
766 #endif
767 
768  IdArrayType indicesOtherUnique, indicesOtherDuplicate;
770  indicesOther, otherToCombinedSortOrderIsDuplicate, indicesOtherUnique, IsUnique{});
772  indicesOther, otherToCombinedSortOrderIsDuplicate, indicesOtherDuplicate);
773 
774 #ifdef DEBUG_PRINT
775  PrintIndices("indicesOtherUnique", indicesOtherUnique);
776  PrintIndices("indicesOtherDuplicate", indicesOtherDuplicate);
777 #endif
778 
779  VTKM_ASSERT(indicesThisDuplicate.GetNumberOfValues() ==
780  indicesOtherDuplicate.GetNumberOfValues());
781 
782  // Merge the neighbor groups for vertices that occur in both meshes
783  // ... compute combined counts (with duplicates)
784  auto neighborCountsThis = make_ArrayHandleOffsetsToNumComponents(this->NeighborOffsets);
785  auto permutedNeighborCountsThis =
786  vtkm::cont::make_ArrayHandlePermutation(indicesThisDuplicate, neighborCountsThis);
787  auto neighborCountsOther = make_ArrayHandleOffsetsToNumComponents(other.NeighborOffsets);
788  auto permutedNeighborCountsOther =
789  vtkm::cont::make_ArrayHandlePermutation(indicesOtherDuplicate, neighborCountsOther);
790  vtkm::cont::ArrayHandle<vtkm::IdComponent> combinedCommonNeighborCountSums;
791  vtkm::cont::Algorithm::Transform(permutedNeighborCountsThis,
792  permutedNeighborCountsOther,
793  combinedCommonNeighborCountSums,
794  vtkm::Sum());
795 
796  // ... merge sorted lists
797  // ...... create output arrays/groups
798  vtkm::Id unpackedCombinedCommonNeighborConnectivitySize;
799  IdArrayType unpackedCombinedCommonNeighborOffsets;
800  vtkm::cont::ConvertNumComponentsToOffsets(combinedCommonNeighborCountSums,
801  unpackedCombinedCommonNeighborOffsets,
802  unpackedCombinedCommonNeighborConnectivitySize);
803  IdArrayType unpackedCombinedCommonNeighborConnectivity;
804  unpackedCombinedCommonNeighborConnectivity.Allocate(
805  unpackedCombinedCommonNeighborConnectivitySize);
806  auto unpackedCombinedCommonNeighborConnectivityGroups = make_ArrayHandleGroupVecVariable(
807  unpackedCombinedCommonNeighborConnectivity, unpackedCombinedCommonNeighborOffsets);
808 
809  // ....... create permuted input arrays/groups
810  auto permutedNeighborConnectivityGlobalGroupsThis =
811  make_ArrayHandlePermutation(indicesThisDuplicate, neighborConnectivityGlobalGroupsThis);
812  auto permutedNeighborConnectivityGlobalGroupsOther =
813  make_ArrayHandlePermutation(indicesOtherDuplicate, neighborConnectivityGlobalGroupsOther);
814 
815  // ........ create array for actual counts of unique neighbors
816  vtkm::cont::ArrayHandle<vtkm::IdComponent> packedCombinedCommonNeighborCounts;
817  packedCombinedCommonNeighborCounts.Allocate(combinedCommonNeighborCountSums.GetNumberOfValues());
818 
819  // ........ perform merge
821  permutedNeighborConnectivityGlobalGroupsThis,
822  permutedNeighborConnectivityGlobalGroupsOther,
823  unpackedCombinedCommonNeighborConnectivityGroups,
824  packedCombinedCommonNeighborCounts);
825 
826  // ... pack sorted lists
827  // ...... create the new offsets array for the merged groups (without duplicates).
828  vtkm::Id packedCombinedCommonNeighborConnectivitySize;
829  vtkm::cont::ArrayHandle<vtkm::Id> packedCombinedCommonNeighborOffsets;
830  vtkm::cont::ConvertNumComponentsToOffsets(packedCombinedCommonNeighborCounts,
831  packedCombinedCommonNeighborOffsets,
832  packedCombinedCommonNeighborConnectivitySize);
833 
834  // ...... create a new grouped array for the packed connectivity
835  vtkm::cont::ArrayHandle<vtkm::Id> packedCombinedCommonNeighborConnectivity;
836  packedCombinedCommonNeighborConnectivity.Allocate(packedCombinedCommonNeighborConnectivitySize);
837  auto packedCommonNeighborConnectivityGroups = vtkm::cont::make_ArrayHandleGroupVecVariable(
838  packedCombinedCommonNeighborConnectivity, packedCombinedCommonNeighborOffsets);
839 
840  // ...... copy data to the packed array.
842  unpackedCombinedCommonNeighborConnectivityGroups,
843  packedCommonNeighborConnectivityGroups);
844 
845  // Create array for all three groups
846  // ... create combined counts array
847  IdArrayType combinedNeighborCounts;
848  combinedNeighborCounts.Allocate(numVerticesCombined);
849 
850  auto thisOnlyToCombinedSortOrder =
851  make_ArrayHandlePermutation(indicesThisUnique, thisToCombinedSortOrder);
852  auto otherOnlyToCombinedSortOrder =
853  make_ArrayHandlePermutation(indicesOtherUnique, otherToCombinedSortOrder);
854  auto commonToCombinedSortOrder =
855  make_ArrayHandlePermutation(indicesThisDuplicate, thisToCombinedSortOrder);
856 
858  neighborCountsThis, indicesThisUnique, combinedNeighborCounts, thisOnlyToCombinedSortOrder);
860  neighborCountsOther, indicesOtherUnique, combinedNeighborCounts, otherOnlyToCombinedSortOrder);
861  auto commonCombinedNeighborCounts =
862  make_ArrayHandlePermutation(commonToCombinedSortOrder, combinedNeighborCounts);
863  vtkm::cont::Algorithm::Copy(packedCombinedCommonNeighborCounts, commonCombinedNeighborCounts);
864 
865  // ... create offsets and allocate combinedNeighborConnectivity array
866  vtkm::Id combinedNeighborConnectivitySize;
867  vtkm::cont::ArrayHandle<vtkm::Id> combinedNeighborOffsets;
869  combinedNeighborCounts, combinedNeighborOffsets, combinedNeighborConnectivitySize);
870  IdArrayType combinedNeighborConnectivity;
871  combinedNeighborConnectivity.Allocate(combinedNeighborConnectivitySize);
872  auto combinedNeighborConnectivityGroups =
873  make_ArrayHandleGroupVecVariable(combinedNeighborConnectivity, combinedNeighborOffsets);
874 
875  // ... copy the connectivity data including previously merged lists
876  CopyVecArrayByIndices(neighborConnectivityGlobalGroupsThis,
877  indicesThisUnique,
878  combinedNeighborConnectivityGroups,
879  thisOnlyToCombinedSortOrder);
880  CopyVecArrayByIndices(neighborConnectivityGlobalGroupsOther,
881  indicesOtherUnique,
882  combinedNeighborConnectivityGroups,
883  otherOnlyToCombinedSortOrder);
884  auto commonCombinedNeighborConnectivityGroups =
885  make_ArrayHandlePermutation(commonToCombinedSortOrder, combinedNeighborConnectivityGroups);
887  packedCommonNeighborConnectivityGroups,
888  commonCombinedNeighborConnectivityGroups);
889  // Why doesn't the following copy work instead?
890  // vtkm::cont::Algorithm::Copy(packedCommonNeighborConnectivityGroups, commonCombinedNeighborConnectivityGroups);
891 
892  timingsStream << " " << std::setw(38) << std::left << "Compute CombinedNeighborConnectivity"
893  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
894  timer.Start();
895 
896  // Compute combined global mesh index arrays
897  IdArrayType combinedGlobalMeshIndex;
898  combinedGlobalMeshIndex.Allocate(numVerticesCombined);
899  { // make sure arrays used for copy go out of scope
900  auto permutedCombinedGlobalMeshIndex =
901  vtkm::cont::make_ArrayHandlePermutation(thisToCombinedSortOrder, combinedGlobalMeshIndex);
902  vtkm::cont::Algorithm::Copy(GlobalMeshIndex, permutedCombinedGlobalMeshIndex);
903  }
904  { // make sure arrays used for copy go out of scope
905  auto permutedCombinedGlobalMeshIndex =
906  vtkm::cont::make_ArrayHandlePermutation(otherToCombinedSortOrder, combinedGlobalMeshIndex);
907  vtkm::cont::Algorithm::Copy(other.GlobalMeshIndex, permutedCombinedGlobalMeshIndex);
908  }
909 
910  timingsStream << " " << std::setw(38) << std::left << "Create CombinedGlobalMeshIndex"
911  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
912  timer.Start();
913 
914  // Compute combined sorted values
915  vtkm::cont::ArrayHandle<FieldType> combinedSortedValues;
916  combinedSortedValues.Allocate(numVerticesCombined);
917  { // make sure arrays used for copy go out of scope
918  auto permutedCombinedSortedValues =
919  vtkm::cont::make_ArrayHandlePermutation(thisToCombinedSortOrder, combinedSortedValues);
920  vtkm::cont::Algorithm::Copy(SortedValues, permutedCombinedSortedValues);
921  }
922  { // make sure arrays used for copy go out of scope
923  auto permutedCombinedSortedValues =
924  vtkm::cont::make_ArrayHandlePermutation(otherToCombinedSortOrder, combinedSortedValues);
925  vtkm::cont::Algorithm::Copy(other.SortedValues, permutedCombinedSortedValues);
926  }
927 
928  timingsStream << " " << std::setw(38) << std::left << "Create CombinedSortedValues"
929  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
930  timer.Start();
931 
932  // Swap in combined version. VTKM ArrayHandles are smart so we can just swap in the new for the old
933  this->SortedValues = combinedSortedValues;
934  this->GlobalMeshIndex = combinedGlobalMeshIndex;
935  this->NeighborConnectivity = combinedNeighborConnectivity;
936  this->NeighborOffsets = combinedNeighborOffsets;
937  this->NumVertices = SortedValues.GetNumberOfValues();
938  this->SortIndices = vtkm::cont::ArrayHandleIndex(this->NumVertices);
939  this->SortOrder = vtkm::cont::ArrayHandleIndex(this->NumVertices);
940 
941  timingsStream << " " << std::setw(38) << std::left << "Swap in new arrays"
942  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
943  timer.Start();
944 
945  // Re-compute maximum number of neigbours
946  ComputeMaxNeighbors();
947 
948  timingsStream << " " << std::setw(38) << std::left << "Compute MaxNeighbors"
949  << ": " << timer.GetElapsedTime() << " seconds" << std::endl;
950  timer.Start();
951  timingsStream << " " << std::setw(38) << std::left << "Total time MergeWith"
952  << ": " << totalTimer.GetElapsedTime() << " seconds" << std::endl;
953  timer.Start();
954  // Record the times we logged
955  VTKM_LOG_S(timingsLogLevel,
956  std::endl
957  << " ---------------- ContourTreeMesh MergeWith ---------------------"
958  << std::endl
959  << timingsMessage << timingsStream.str());
960  // Prevent unused parameter warning when compiled without logging
961  (void)timingsLogLevel;
962  (void)timingsMessage;
963 
964 #ifdef DEBUG_PRINT
965  // Print the contents fo this for debugging
966  DebugPrint("ContourTreeMeshes merged", __FILE__, __LINE__);
967 #endif
968 } // Merge With
969 
970 
971 template <typename FieldType>
972 inline void ContourTreeMesh<FieldType>::Save(const char* filename) const
973 {
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);
979 }
980 
981 template <typename FieldType>
982 inline void ContourTreeMesh<FieldType>::Load(const char* filename)
983 {
984  std::ifstream is(filename);
985  if (!is.is_open())
986  {
987  throw vtkm::io::ErrorIO(std::string("Unable to open file: ") + std::string(filename));
988  }
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();
995  this->SortOrder = vtkm::cont::ArrayHandleIndex(this->NumVertices);
996  this->SortIndices = vtkm::cont::ArrayHandleIndex(this->NumVertices);
997 }
998 
999 template <typename FieldType>
1000 template <typename ValueType>
1002  std::ostream& os,
1003  const vtkm::cont::ArrayHandle<ValueType>& vec) const
1004 {
1005  vtkm::Id numVals = vec.GetNumberOfValues();
1006  //os.write(rXeinterpret_cast<const char*>(&numVals), sizeof(ValueType));
1007  os << numVals << ": ";
1008  auto vecPortal = vec.ReadPortal();
1009  for (vtkm::Id i = 0; i < numVals; ++i)
1010  os << vecPortal.Get(i) << " ";
1011  //os.write(reinterpret_cast<const char*>(vecPortal.Get(i)), sizeof(ValueType));
1012  os << std::endl;
1013 }
1014 
1015 template <typename FieldType>
1016 template <typename ValueType>
1017 inline void ContourTreeMesh<FieldType>::LoadVector(std::istream& is,
1019 {
1020  vtkm::Id numVals;
1021  is >> numVals;
1022  char colon = is.get();
1023  if (colon != ':')
1024  {
1025  throw vtkm::io::ErrorIO("Error parsing file");
1026  }
1027 
1028  vec.Allocate(numVals);
1029  auto vecPortal = vec.WritePortal();
1030  ValueType val;
1031  for (vtkm::Id i = 0; i < numVals; ++i)
1032  {
1033  is >> val;
1034  vecPortal.Set(i, val);
1035  }
1036 }
1037 
1038 template <typename FieldType>
1040  vtkm::Id3 globalSize,
1041  vtkm::Id3 minIdx,
1042  vtkm::Id3 maxIdx) const
1043 {
1044  return MeshBoundaryContourTreeMeshExec(this->GlobalMeshIndex, globalSize, minIdx, maxIdx);
1045 }
1046 
1047 template <typename FieldType>
1049  IdArrayType& boundaryVertexArray, // output
1050  IdArrayType& boundarySortIndexArray, // output
1051  MeshBoundaryContourTreeMeshExec* meshBoundaryExecObj //input
1052 ) const
1053 {
1054  // start by generating a temporary array of indices
1055  auto indexArray = vtkm::cont::ArrayHandleIndex(this->GlobalMeshIndex.GetNumberOfValues());
1056  // compute the boolean array indicating which values lie on the boundary
1057  vtkm::cont::ArrayHandle<bool> isOnBoundary;
1058  ComputeMeshBoundaryContourTreeMesh computeMeshBoundaryContourTreeMeshWorklet;
1059  this->Invoke(computeMeshBoundaryContourTreeMeshWorklet,
1060  indexArray, // input
1061  *meshBoundaryExecObj, // input
1062  isOnBoundary // outut
1063  );
1064 
1065  // we will conditionally copy the boundary vertices' indices, capturing the end iterator to compute the # of boundary vertices
1066  vtkm::cont::Algorithm::CopyIf(indexArray, isOnBoundary, boundaryVertexArray);
1067  // duplicate these into the index array, since the BRACT uses indices into the underlying mesh anyway
1068  vtkm::cont::Algorithm::Copy(boundaryVertexArray, boundarySortIndexArray);
1069 }
1070 
1071 } // namespace contourtree_augmented
1072 } // worklet
1073 } // vtkm
1074 
1075 //#undef DEBUG_PRINT
1076 
1077 #endif
vtkm::worklet::contourtree_augmented::ContourTreeMesh::mGetMax
bool mGetMax
Definition: ContourTreeMesh.h:272
CombinedSimulatedSimplicityIndexComparator.h
vtkm::cont::make_ArrayHandleOffsetsToNumComponents
VTKM_CONT vtkm::cont::ArrayHandleOffsetsToNumComponents< vtkm::cont::ArrayHandle< vtkm::Id, OffsetsStorageTag > > make_ArrayHandleOffsetsToNumComponents(const vtkm::cont::ArrayHandle< vtkm::Id, OffsetsStorageTag > &array)
Definition: ArrayHandleOffsetsToNumComponents.h:155
MergeSortedListsWithoutDuplicatesWorklet.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GlobalMeshIndex
IdArrayType GlobalMeshIndex
Definition: ContourTreeMesh.h:200
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle< vtkm::Id >
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::ArcComparator
Definition: ArcComparator.h:118
vtkm::worklet::contourtree_augmented::ContourTreeMesh::Save
void Save(const char *filename) const
Definition: ContourTreeMesh.h:972
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GetGlobalIdsFromMeshIndices
vtkm::cont::ArrayHandlePermutation< MeshIdArrayType, IdArrayType > GetGlobalIdsFromMeshIndices(const MeshIdArrayType &meshIds, const vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler *localToGlobalIdRelabeler=nullptr) const
copies the global IDs for a set of mesh IDs notice that the sort ID is the same as the mesh ID for th...
Definition: ContourTreeMesh.h:261
FindDuplicateInOtherWorklet.h
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SortData
void SortData(const vtkm::cont::ArrayHandle< T, StorageType > &values) const
Definition: ContourTreeMesh.h:188
ArrayRangeCompute.h
Types.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
VTKM_EXEC_CONT
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
vtkm::cont::Timer::Start
VTKM_CONT void Start()
vtkm::cont::ArrayHandle::AllocateAndFill
VTKM_CONT void AllocateAndFill(vtkm::Id numberOfValues, const ValueType &fillValue, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array and fills it with an initial value.
Definition: ArrayHandle.h:495
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::worklet::contourtree_augmented::ContourTreeMesh::MergeWith
void MergeWith(ContourTreeMesh< FieldType > &other, vtkm::cont::LogLevel TreeLogLevel=vtkm::cont::LogLevel::Perf, std::string timingsMessage="")
Definition: ContourTreeMesh.h:612
ArrayPortalToIterators.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::GetArcFromDecoratorImpl
Definition: GetArcFromDecorator.h:75
GetArcFromDecorator.h
vtkm::cont::LogLevel
LogLevel
Log levels for use with the logging macros.
Definition: Logging.h:298
vtkm::worklet::contourtree_augmented::MarkOther
Definition: ArrayTransforms.h:114
vtkm::worklet::contourtree_augmented::ContourTreeMesh::ContourTreeMesh
ContourTreeMesh()
Definition: ContourTreeMesh.h:139
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::ArcValidDecoratorImpl
Definition: ArcValidDecorator.h:74
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SaveVector
void SaveVector(std::ostream &os, const vtkm::cont::ArrayHandle< ValueType > &vec) const
Definition: ContourTreeMesh.h:1001
vtkm::worklet::contourtree_augmented::CopyArrayByIndices
void CopyArrayByIndices(const PT1 &srcArray, const PT2 &srcIndices, PT3 &dstArray, const PT4 &dstIndices)
Definition: ContourTreeMesh.h:424
ArrayRangeComputeTemplate.h
vtkm::cont::Algorithm::Sort
static VTKM_CONT void Sort(vtkm::cont::DeviceAdapterId devId, vtkm::cont::ArrayHandle< T, Storage > &values)
Definition: Algorithm.h:965
vtkm::cont::make_ArrayHandleConstant
vtkm::cont::ArrayHandleConstant< T > make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
make_ArrayHandleConstant is convenience function to generate an ArrayHandleImplicit.
Definition: ArrayHandleConstant.h:89
ArrayHandleConstant.h
vtkm::cont::ArrayGetValue
VTKM_CONT T ArrayGetValue(vtkm::Id id, const vtkm::cont::ArrayHandle< T, S > &data)
Obtain a small set of values from an ArrayHandle with minimal device transfers.
Definition: ArrayGetValues.h:264
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::CopyNeighborsToPackedArray
Definition: CopyNeighborsToPackedArray.h:81
vtkm::cont::Algorithm::Copy
static VTKM_CONT bool Copy(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< U, COut > &output)
Definition: Algorithm.h:410
PrintVectors.h
Invoker.h
ArrayTransforms.h
ApplyLookupTableDecorator.h
EnvironmentTracker.h
MeshStructureContourTreeMesh.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh
Definition: ContourTreeMesh.h:129
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SortIndices
vtkm::cont::ArrayHandleIndex SortIndices
Definition: ContourTreeMesh.h:198
vtkm::cont::make_ArrayHandleDecorator
VTKM_CONT ArrayHandleDecorator< typename std::decay< DecoratorImplT >::type, typename std::decay< ArrayTs >::type... > make_ArrayHandleDecorator(vtkm::Id numValues, DecoratorImplT &&f, ArrayTs &&... arrays)
Create an ArrayHandleDecorator with the specified number of values that uses the provided DecoratorIm...
Definition: ArrayHandleDecorator.h:677
vtkm::worklet::contourtree_augmented::ContourTreeMesh::MaxNeighbors
vtkm::Id MaxNeighbors
Definition: ContourTreeMesh.h:212
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::contourtree_augmented::ContourTreeMesh::NeighborConnectivity
IdArrayType NeighborConnectivity
Definition: ContourTreeMesh.h:207
DispatcherMapField.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::Invoke
vtkm::cont::Invoker Invoke
Definition: ContourTreeMesh.h:270
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::CopyIntoCombinedArrayWorklet
Definition: CopyIntoCombinedArrayWorklet.h:81
vtkm::worklet::contourtree_augmented::ContourTreeMesh::NumVertices
vtkm::Id NumVertices
Definition: ContourTreeMesh.h:196
vtkm::Add
Definition: Types.h:222
vtkm::cont::Token
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::Sum
Binary Predicate that takes two arguments argument x, and y and returns sum (addition) of the two val...
Definition: BinaryOperators.h:33
vtkm::worklet::contourtree_augmented::IsUnique
Definition: ContourTreeMesh.h:605
vtkm::worklet::contourtree_augmented::ContourTreeMesh::Load
void Load(const char *filename)
Definition: ContourTreeMesh.h:982
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::CombinedSimulatedSimplicityIndexComparator
Execution object for the comparator used initial sort of data values in ContourTreeMesh<FieldType>::M...
Definition: CombinedSimulatedSimplicityIndexComparator.h:192
IdRelabeler.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::LoadVector
void LoadVector(std::istream &is, vtkm::cont::ArrayHandle< ValueType > &vec)
Definition: ContourTreeMesh.h:1017
vtkm::cont::make_ArrayHandleTransform
VTKM_CONT vtkm::cont::ArrayHandleTransform< HandleType, FunctorType > make_ArrayHandleTransform(HandleType handle, FunctorType functor)
make_ArrayHandleTransform is convenience function to generate an ArrayHandleTransform.
Definition: ArrayHandleTransform.h:474
vtkm::worklet::contourtree_augmented::ContourTreeMesh::ContourTreeMesh
ContourTreeMesh(const char *filename)
Definition: ContourTreeMesh.h:167
ArrayHandlePermutation.h
Timer.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GetNumberOfVertices
vtkm::Id GetNumberOfVertices() const
Definition: ContourTreeMesh.h:173
Algorithm.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc
Definition: AddToArrayElementsWorklet.h:75
ArrayHandleIndex.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::CopyIntoCombinedNeighborsWorklet
Definition: CopyIntoCombinedNeighborsWorklet.h:78
vtkm::cont::ArrayHandlePermutation
Implicitly permutes the values in an array.
Definition: ArrayHandlePermutation.h:227
vtkm::io::ErrorIO
Definition: ErrorIO.h:22
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::cont::make_ArrayHandleGroupVecVariable
VTKM_CONT vtkm::cont::ArrayHandleGroupVecVariable< ComponentsArrayHandleType, OffsetsArrayHandleType > make_ArrayHandleGroupVecVariable(const ComponentsArrayHandleType &componentsArray, const OffsetsArrayHandleType &offsetsArray)
make_ArrayHandleGroupVecVariable is convenience function to generate an ArrayHandleGroupVecVariable.
Definition: ArrayHandleGroupVecVariable.h:308
vtkm::cont::Algorithm::CopyIf
static VTKM_CONT void CopyIf(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, const vtkm::cont::ArrayHandle< U, CStencil > &stencil, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:435
ErrorIO.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SortedValues
vtkm::cont::ArrayHandle< FieldType > SortedValues
Definition: ContourTreeMesh.h:199
vtkm::worklet::contourtree_augmented::ContourTreeMesh::ComputeMaxNeighbors
void ComputeMaxNeighbors()
Definition: ContourTreeMesh.h:576
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GetMeshBoundaryExecutionObject
MeshBoundaryContourTreeMeshExec GetMeshBoundaryExecutionObject(vtkm::Id3 globalSize, vtkm::Id3 minIdx, vtkm::Id3 maxIdx) const
Definition: ContourTreeMesh.h:1039
MeshBoundaryContourTreeMesh.h
vtkm::worklet::contourtree_augmented::CopyVecArrayByIndices
void CopyVecArrayByIndices(const PT1 &srcArray, const PT2 &srcIndices, PT3 &dstArray, const PT4 &dstIndices)
Definition: ContourTreeMesh.h:441
vtkm::cont::ArrayHandle::WritePortal
VTKM_CONT WritePortalType WritePortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:435
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MeshStructureContourTreeMesh
Definition: MeshStructureContourTreeMesh.h:86
vtkm::worklet::contourtree_augmented::ContourTreeMesh::InitializeNeighborConnectivityFromArcs
void InitializeNeighborConnectivityFromArcs(const IdArrayType &arcs)
Definition: ContourTreeMesh.h:458
CopyIntoCombinedArrayWorklet.h
ReplaceArcNumWithToVertexWorklet.h
vtkm::cont::Timer
A class that can be used to time operations in VTK-m that might be occuring in parallel.
Definition: Timer.h:43
vtkm::worklet::contourtree_augmented::PrintValues
void PrintValues(std::string label, const vtkm::cont::ArrayHandle< T, StorageType > &dVec, vtkm::Id nValues=-1, std::ostream &outStream=std::cout)
Definition: augmented/PrintVectors.h:197
vtkm::worklet::contourtree_augmented::ContourTreeMesh::PrintContent
void PrintContent(std::ostream &outStream=std::cout) const
Definition: ContourTreeMesh.h:291
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::InitToCombinedSortOrderArraysWorklet
Definition: InitToCombinedSortOrderArraysWorklet.h:79
vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler
A utility class that converts Ids from local to global given a mesh.
Definition: IdRelabeler.h:79
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SetPrepareForExecutionBehavior
void SetPrepareForExecutionBehavior(bool getMax)
Definition: ContourTreeMesh.h:585
VTKM_LOG_S
#define VTKM_LOG_S(level,...)
Writes a message using stream syntax to the indicated log level.
Definition: Logging.h:261
vtkm::cont::make_ArrayHandlePermutation
VTKM_CONT vtkm::cont::ArrayHandlePermutation< IndexArrayHandleType, ValueArrayHandleType > make_ArrayHandlePermutation(IndexArrayHandleType indexArray, ValueArrayHandleType valueArray)
make_ArrayHandleTransform is convenience function to generate an ArrayHandleTransform.
Definition: ArrayHandlePermutation.h:279
vtkm::cont::ExecutionObjectBase
Base ExecutionObjectBase for execution objects to inherit from so that you can use an arbitrary objec...
Definition: ExecutionObjectBase.h:31
vtkm::cont::DeviceAdapterId
Definition: DeviceAdapterTag.h:52
vtkm::Vec< vtkm::Id, 3 >
vtkm::cont::ConvertNumComponentsToOffsets
VTKM_CONT_EXPORT void ConvertNumComponentsToOffsets(const vtkm::cont::UnknownArrayHandle &numComponentsArray, vtkm::cont::ArrayHandle< vtkm::Id > &offsetsArray, vtkm::Id &componentsArraySize, vtkm::cont::DeviceAdapterId device=vtkm::cont::DeviceAdapterTagAny{})
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GetGlobalIdsFromSortIndices
vtkm::cont::ArrayHandlePermutation< IdArrayType, IdArrayType > GetGlobalIdsFromSortIndices(const IdArrayType &sortIds, const vtkm::worklet::contourtree_augmented::mesh_dem::IdRelabeler *localToGlobalIdRelabeler=nullptr) const
copies the global IDs for a set of sort IDs notice that the sort ID is the same as the mesh ID for th...
Definition: ContourTreeMesh.h:239
vtkm::cont::Algorithm::Transform
static VTKM_CONT void Transform(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, StorageT > &input1, const vtkm::cont::ArrayHandle< U, StorageU > &input2, vtkm::cont::ArrayHandle< V, StorageV > &output, BinaryFunctor binaryFunctor)
Definition: Algorithm.h:1037
vtkm::worklet::contourtree_augmented::IsUnique::operator()
VTKM_EXEC_CONT bool operator()(vtkm::IdComponent isInOther) const
Definition: ContourTreeMesh.h:607
vtkm::cont::Algorithm::ReduceByKey
static VTKM_CONT void ReduceByKey(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CKeyIn > &keys, const vtkm::cont::ArrayHandle< U, CValIn > &values, vtkm::cont::ArrayHandle< T, CKeyOut > &keys_output, vtkm::cont::ArrayHandle< U, CValOut > &values_output, BinaryFunctor binary_functor)
Definition: Algorithm.h:697
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::CombinedVectorDifferentFromNextDecoratorImpl
Decorator to compute if element i is different from element i+1 in an arrays.
Definition: CombinedVectorDifferentFromNext.h:81
ConvertNumComponentsToOffsets.h
ArcValidDecorator.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::GetBoundaryVertices
void GetBoundaryVertices(IdArrayType &boundaryVertexArray, IdArrayType &boundarySortIndexArray, MeshBoundaryContourTreeMeshExec *meshBoundaryExecObj) const
Definition: ContourTreeMesh.h:1048
vtkm::worklet::contourtree_augmented::ComputeMeshBoundaryContourTreeMesh
Definition: ComputeMeshBoundaryContourTreeMesh.h:69
vtkm::cont::ArrayHandle::ReadPortal
VTKM_CONT ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:414
vtkm::cont::Algorithm::ScanExtended
static VTKM_CONT void ScanExtended(vtkm::cont::DeviceAdapterId devId, const vtkm::cont::ArrayHandle< T, CIn > &input, vtkm::cont::ArrayHandle< T, COut > &output)
Definition: Algorithm.h:901
ComputeMeshBoundaryContourTreeMesh.h
vtkm::worklet::contourtree_augmented::ContourTreeMesh::SortOrder
vtkm::cont::ArrayHandleIndex SortOrder
Definition: ContourTreeMesh.h:197
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::FindDuplicateInOtherWorklet
Definition: FindDuplicateInOtherWorklet.h:79
CopyNeighborsToPackedArray.h
CopyIntoCombinedNeighborsWorklet.h
ArrayHandleGroupVecVariable.h
vtkm::worklet::contourtree_augmented::PrintIndices
void PrintIndices(std::string label, const vtkm::cont::ArrayHandle< T > &iVec, vtkm::Id nIndices=-1, std::ostream &outStream=std::cout)
Definition: augmented/PrintVectors.h:253
vtkm::worklet::contourtree_augmented::PrintHeader
void PrintHeader(vtkm::Id howMany, std::ostream &outStream=std::cout)
Definition: augmented/PrintVectors.h:151
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::ApplyLookupTableDecoratorImpl
Definition: ApplyLookupTableDecorator.h:75
vtkm::worklet::contourtree_augmented::ContourTreeMesh::MAX_OUTDEGREE
static const int MAX_OUTDEGREE
Definition: ContourTreeMesh.h:194
vtkm::cont::ArrayRangeCompute
VTKM_CONT_EXPORT vtkm::cont::ArrayHandle< vtkm::Range > ArrayRangeCompute(const vtkm::cont::UnknownArrayHandle &array, vtkm::cont::DeviceAdapterId device=vtkm::cont::DeviceAdapterTagAny{})
Compute the range of the data in an array handle.
AddToArrayElementsWorklet.h
InitToCombinedSortOrderArraysWorklet.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::MergeSortedListsWithoutDuplicatesWorklet
Definition: MergeSortedListsWithoutDuplicatesWorklet.h:78
ArcComparator.h
vtkm::worklet::contourtree_augmented::MeshBoundaryContourTreeMeshExec
Definition: MeshBoundaryContourTreeMesh.h:133
ExecutionObjectBase.h
vtkm::worklet::contourtree_augmented::mesh_dem_contourtree_mesh_inc::ReplaceArcNumWithToVertexWorklet
Definition: ReplaceArcNumWithToVertexWorklet.h:79
vtkm::worklet::contourtree_augmented::ContourTreeMesh::NeighborOffsets
IdArrayType NeighborOffsets
Definition: ContourTreeMesh.h:210
CombinedVectorDifferentFromNext.h
vtkm::cont::Timer::GetElapsedTime
VTKM_CONT vtkm::Float64 GetElapsedTime() const
Get the elapsed time measured by the given device adapter.
vtkm::cont::LogLevel::Perf
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
vtkm::cont::ArrayHandleIndex
An implicit array handle containing the its own indices.
Definition: ArrayHandleIndex.h:54
vtkm::worklet::contourtree_augmented::ContourTreeMesh::PrepareForExecution
contourtree_mesh_inc_ns::MeshStructureContourTreeMesh PrepareForExecution(vtkm::cont::DeviceAdapterId, vtkm::cont::Token &token) const
Definition: ContourTreeMesh.h:593
vtkm::worklet::contourtree_augmented::ContourTreeMesh::DebugPrint
void DebugPrint(const char *message, const char *fileName, long lineNum) const
Definition: ContourTreeMesh.h:305