VTK  9.7.1
vtkLocatorInterface.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) Ken Martin, Will Schroeder, Bill Lorensen
2 // SPDX-License-Identifier: BSD-3-Clause
17 #ifndef vtkLocatorInterface_h
18 #define vtkLocatorInterface_h
19 
20 #include "vtkABINamespace.h"
21 #include "vtkCommonDataModelModule.h" // For export macro
22 #include "vtkSystemIncludes.h"
23 
24 #include <vector>
25 
26 VTK_ABI_NAMESPACE_BEGIN
27 
36 {
38  double Dist2;
40  : Id(-1)
41  , Dist2(0)
42  {
43  }
44  vtkDist2Tuple(vtkIdType id, double d2)
45  : Id(id)
46  , Dist2(d2)
47  {
48  }
49 
50  // Support sort operation from smallest to largest.
51  bool operator<(const vtkDist2Tuple& tuple) const { return Dist2 < tuple.Dist2; }
52 };
53 
62 struct VTKCOMMONDATAMODEL_EXPORT vtkDist2TupleArray : public std::vector<vtkDist2Tuple>
63 {
64 };
65 typedef std::vector<vtkDist2Tuple> vtkDist2TupleType;
66 typedef std::vector<vtkDist2Tuple>::iterator vtkDist2TupleIterator;
67 
68 //------------------------------------------------------------------------------
69 // The following tuple is what is sorted in the locator maps (i.e., a map of
70 // bucket/bins to point ids). Note that it is templated because depending on
71 // the number of points / buckets to process we may want to use vtkIdType to
72 // represent the tuple. Otherwise for performance reasons it's best to use an
73 // int (or other integral type). Typically sort() is 25-30% faster on smaller
74 // integral types, plus it takes a heck less memory (when vtkIdType is 64-bit
75 // and int is 32-bit).
76 template <typename TTuple>
78 {
79  TTuple PtId; // originating point id
80  TTuple Bucket; // i-j-k index into bucket space
81 
82  // Operator< used to support the subsequent sort operation. There are two
83  // implementations, one gives a stable sort (points ordered by id within
84  // each bucket) and the other a little faster but less stable (in parallel
85  // sorting the order of sorted points in a bucket may vary).
86  bool operator<(const vtkLocatorTuple& tuple) const
87  {
88  if (Bucket < tuple.Bucket)
89  return true;
90  if (tuple.Bucket < Bucket)
91  return false;
92  if (PtId < tuple.PtId)
93  return true;
94  return false;
95  }
96 };
97 
98 VTK_ABI_NAMESPACE_END
99 #endif
100 // VTK-HeaderTest-Exclude: vtkLocatorInterface.h
int vtkIdType
Definition: vtkType.h:363
Represent a 2-tuple consisting of a VTK Id, and a distance**2 value.
std::vector< vtkDist2Tuple >::iterator vtkDist2TupleIterator
bool operator<(const vtkLocatorTuple &tuple) const
bool operator<(const vtkDist2Tuple &tuple) const
Represent an array of vtkDist2Tuples.
vtkDist2Tuple(vtkIdType id, double d2)
std::vector< vtkDist2Tuple > vtkDist2TupleType