Go to the documentation of this file.
10 #ifndef vtk_m_worklet_VertexClustering_h
11 #define vtk_m_worklet_VertexClustering_h
39 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
55 using ControlSignature = void(KeysIn clusterIds, ValuesIn points, ReducedValuesOut repPoints);
56 using ExecutionSignature = _3(_2);
57 using InputDomain = _1;
59 template <
typename Po
intsInVecType>
60 VTKM_EXEC typename PointsInVecType::ComponentType operator()(
61 const PointsInVecType& pointsIn)
const
69 return pointsIn[pointsIn.GetNumberOfComponents() / 2];
74 template <
typename InputPo
intsArrayType,
typename KeyType>
75 VTKM_CONT void operator()(
const InputPointsArrayType& points,
82 dispatcher.Invoke(keys, points, out);
88 template <
typename KeyType,
typename InputDynamicPo
intsArrayType>
91 const InputDynamicPointsArrayType& inputPoints)
94 RunTrampoline trampoline;
100 template <
typename ValueType,
typename StorageType,
typename IndexArrayType>
102 const IndexArrayType& indices,
111 template <
typename T, vtkm::IdComponent N>
114 const T* vmem =
reinterpret_cast<const T*
>(&*other.ReadPortal().GetIteratorBegin());
149 template <
typename Po
intType>
152 using ComponentType =
typename PointType::ComponentType;
153 PointType gridOrigin(
static_cast<ComponentType
>(this->Grid.
origin[0]),
154 static_cast<ComponentType
>(this->Grid.origin[1]),
155 static_cast<ComponentType
>(this->Grid.origin[2]));
157 PointType p_rel = (p - gridOrigin) * this->Grid.
inv_bin_size;
163 return x + this->Grid.
dim[0] * (y + this->Grid.
dim[1] * z);
166 template <
typename Po
intType>
186 template <
typename ClusterIdsVecType>
190 cellClusterId[0] = pointClusterIds[0];
191 cellClusterId[1] = pointClusterIds[1];
192 cellClusterId[2] = pointClusterIds[2];
203 template <
typename OutPortalType>
206 const OutPortalType& outPortal)
const
208 outPortal.Set(cid, counter);
235 template <
typename InPortalType>
238 const InPortalType& inPortal)
const
240 if (cid3[0] == cid3[1] || cid3[0] == cid3[2] || cid3[1] == cid3[2])
242 pointId3[0] = pointId3[1] = pointId3[2] = this->
NPoints;
246 pointId3[0] = inPortal.Get(cid3[0]);
247 pointId3[1] = inPortal.Get(cid3[1]);
248 pointId3[2] = inPortal.Get(cid3[2]);
252 if (pointId3[0] > pointId3[1] || pointId3[0] > pointId3[2])
255 if (pointId3[0] > pointId3[1] || pointId3[0] > pointId3[2])
285 cid[0] + this->NPoints * (cid[1] + this->NPoints * cid[2]);
308 vtkm::Int64 t = cidHash / this->
NPoints;
318 template <
typename UnknownCellSetType,
typename DynamicCoordinateHandleType>
319 void Run(
const UnknownCellSetType& cellSet,
320 const DynamicCoordinateHandleType& coordinates,
334 gridInfo.
dim[0] = nDivisions[0];
335 gridInfo.
dim[1] = nDivisions[1];
336 gridInfo.
dim[2] = nDivisions[2];
345 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
362 mapPointsDispatcher.Invoke(coordinates, pointCidArray);
364 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
366 std::cout <<
"Time map points (s): " << timer.
GetElapsedTime() << std::endl;
379 keys.GetOffsets(), 0, keys.GetOffsets().GetNumberOfValues() - 1);
383 this->
PointIdMap = internal::ConcretePermutationArray(keysView, keys.GetSortedValuesMap());
387 repPointArray = internal::SelectRepresentativePoint::Run(keys, coordinates);
390 auto repPointCidArray =
393 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
394 std::cout <<
"Time after reducing points (s): " << timer.
GetElapsedTime() << std::endl;
407 mapCellsDispatcher.Invoke(cellSet, pointCidArray, cid3Array);
409 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
410 std::cout <<
"Time after clustering cells (s): " << timer.
GetElapsedTime() << std::endl;
419 indexingDispatcher.Invoke(repPointCidArray, cidIndexArray);
422 repPointCidArray.ReleaseResources();
435 cid2PointIdDispatcher.Invoke(cid3Array, pointId3Array, cidIndexArray);
440 bool doHashing = (nPoints < (1 << 21));
449 cid3HashDispatcher.Invoke(pointId3Array, pointId3HashArray);
453 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
454 std::cout <<
"Time before sort and unique with hashing (s): " << timer.
GetElapsedTime()
462 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
463 std::cout <<
"Time after sort and unique with hashing (s): " << timer.
GetElapsedTime()
474 cid3UnhashDispatcher.Invoke(tmpPerm, pointId3Array);
478 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
479 std::cout <<
"Time before sort and unique [no hashing] (s): " << timer.
GetElapsedTime()
487 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
488 std::cout <<
"Time after sort and unique [no hashing] (s): " << timer.
GetElapsedTime()
497 tmp = internal::ConcretePermutationArray(this->
CellIdMap, pointId3Array);
504 if (cells > 0 && pointId3Array.
ReadPortal().Get(cells - 1)[2] >= nPoints)
512 outCoords = repPointArray;
518 internal::copyFromVec(pointId3Array));
519 outCellSet = triangles;
521 #ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
522 std::cout <<
"Wrap-up (s): " << timer.
GetElapsedTime() << std::endl;
524 std::cout <<
"Time (s): " << t << std::endl;
525 std::cout <<
"number of output points: " << repPointArray.
GetNumberOfValues() << std::endl;
526 std::cout <<
"number of output cells: " << pointId3Array.
GetNumberOfValues() << std::endl;
540 #endif // vtk_m_worklet_VertexClustering_h
#define VTKM_LOG_SCOPE(level,...)
Definition: Logging.h:265
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
VTKM_CONT vtkm::cont::ArrayHandleBasic< T > make_ArrayHandle(const T *array, vtkm::Id numberOfValues, vtkm::CopyFlag copy)
A convenience function for creating an ArrayHandle from a standard C array.
Definition: ArrayHandleBasic.h:217
Manages an array-worth of data.
Definition: ArrayHandle.h:283
VTKM_CONT Cid3UnhashWorklet(vtkm::Id nPoints)
Definition: worklet/VertexClustering.h:299
Definition: worklet/VertexClustering.h:174
#define VTKM_EXEC
Definition: ExportMacros.h:51
Groups connected points that have the same field value.
Definition: Atomic.h:19
ArrayHandleView< ArrayHandleType > make_ArrayHandleView(const ArrayHandleType &array, vtkm::Id startIndex, vtkm::Id numValues)
Definition: ArrayHandleView.h:222
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
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
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::cont::ArrayHandle< vtkm::Id > PointIdMap
Definition: worklet/VertexClustering.h:534
vtkm::Vec3f_64 inv_bin_size
Definition: worklet/VertexClustering.h:129
void(_1, _2) ExecutionSignature
Definition: worklet/VertexClustering.h:296
vtkm::cont::ArrayHandle< vtkm::Id > GetPointIdMap() const
Definition: worklet/VertexClustering.h:530
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
void(WorkIndex, _1, _2) ExecutionSignature
Definition: worklet/VertexClustering.h:201
VTKM_CONT MapPointsWorklet(const GridInfo &grid)
Definition: worklet/VertexClustering.h:143
Definition: CastAndCall.h:34
void(_1, _2) ExecutionSignature
Definition: worklet/VertexClustering.h:273
vtkm::Id3 dim
Definition: worklet/VertexClustering.h:126
VTKM_CONT Cid3HashWorklet(vtkm::Id nPoints)
Definition: worklet/VertexClustering.h:276
Definition: worklet/VertexClustering.h:266
VTKM_CONT MapCellsWorklet()
Definition: worklet/VertexClustering.h:183
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
static VTKM_CONT void Unique(vtkm::cont::DeviceAdapterId device, const vtkm::cont::ArrayHandle< KeyType, Storage > &keys, IndexArrayType &indices)
Reduces the array returned by Sort so that the mapped keys are unique.
Definition: StableSortIndices.h:204
pass 3
Definition: worklet/VertexClustering.h:197
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
void(FieldIn, WholeArrayOut) ControlSignature
Definition: worklet/VertexClustering.h:200
VTKM_CONT Cid2PointIdWorklet(vtkm::Id nPoints)
Definition: worklet/VertexClustering.h:230
vtkm::Int64 NPoints
Definition: worklet/VertexClustering.h:269
VTKM_EXEC void operator()(const vtkm::Int64 &cidHash, vtkm::Id3 &cid) const
Definition: worklet/VertexClustering.h:305
Definition: worklet/VertexClustering.h:124
VTKM_EXEC_CONT vtkm::Float64 Length() const
Returns the length of the range.
Definition: Range.h:87
vtkm::Id NPoints
Definition: worklet/VertexClustering.h:214
VTKM_EXEC void operator()(const ClusterIdsVecType &pointClusterIds, vtkm::Id3 &cellClusterId) const
Definition: worklet/VertexClustering.h:187
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
VTKM_EXEC void operator()(const vtkm::Id &counter, const vtkm::Id &cid, const OutPortalType &outPortal) const
Definition: worklet/VertexClustering.h:204
Dispatcher for worklets that inherit from WorkletMapTopology.
Definition: DispatcherMapTopology.h:31
A control signature tag for input fields.
Definition: WorkletMapField.h:49
Definition: WorkletReduceByKey.h:42
void(FieldIn, FieldOut) ControlSignature
Definition: worklet/VertexClustering.h:295
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::Vec3f_64 bin_size
Definition: worklet/VertexClustering.h:128
Definition: worklet/VertexClustering.h:212
Definition: worklet/VertexClustering.h:289
vtkm::Range Z
Definition: Bounds.h:33
FieldInIncident FieldInPoint
Definition: WorkletMapTopology.h:259
#define VTKM_CONT
Definition: ExportMacros.h:57
VTKM_CONT void BuildArrays(const KeyArrayType &keys, KeysSortType sort, vtkm::cont::DeviceAdapterId device=vtkm::cont::DeviceAdapterTagAny())
Build the internal arrays without modifying the input.
Definition: worklet/VertexClustering.h:133
void(_2, _3) ExecutionSignature
Definition: worklet/VertexClustering.h:180
void(FieldIn, FieldOut) ControlSignature
Definition: worklet/VertexClustering.h:272
A class that can be used to time operations in VTK-m that might be occuring in parallel.
Definition: Timer.h:43
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
void(_1, _2, _3) ExecutionSignature
Definition: worklet/VertexClustering.h:227
static VTKM_CONT void Sort(vtkm::cont::DeviceAdapterId device, const vtkm::cont::ArrayHandle< KeyType, Storage > &keys, IndexArrayType &indices)
Permutes the indices array so that it will map keys into a stable sorted order.
Definition: StableSortIndices.h:140
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_EXEC void rotate(vtkm::Id3 &ids) const
Definition: worklet/VertexClustering.h:217
vtkm::Vec3f_64 origin
Definition: worklet/VertexClustering.h:127
void(FieldIn, FieldOut, WholeArrayIn) ControlSignature
Definition: worklet/VertexClustering.h:226
vtkm::Float64 Min
Definition: Range.h:33
Dispatcher for worklets that inherit from WorkletReduceByKey.
Definition: DispatcherReduceByKey.h:27
VTKM_CONT ReadPortalType ReadPortal() const
Get an array portal that can be used in the control environment.
Definition: ArrayHandle.h:414
Manage keys for a WorkletReduceByKey.
Definition: Keys.h:131
vtkm::cont::ArrayHandle< vtkm::Id > GetCellIdMap() const
Definition: worklet/VertexClustering.h:531
double Float64
Definition: Types.h:155
void(_1, _2) ExecutionSignature
Definition: worklet/VertexClustering.h:140
vtkm::Range X
Definition: Bounds.h:31
vtkm::Range Y
Definition: Bounds.h:32
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of values in the array.
VTKM_EXEC void operator()(const vtkm::Id3 &cid, vtkm::Int64 &cidHash) const
Definition: worklet/VertexClustering.h:282
void(FieldIn, FieldOut) ControlSignature
Definition: worklet/VertexClustering.h:139
vtkm::cont::ArrayHandle< vtkm::Id > CellIdMap
Definition: worklet/VertexClustering.h:535
Definition: worklet/VertexClustering.h:122
vtkm::Int64 NPoints
Definition: worklet/VertexClustering.h:292
VTKM_CONT void Fill(vtkm::Id numPoints, vtkm::UInt8 shapeId, vtkm::IdComponent numberOfPointsPerCell, const vtkm::cont::ArrayHandle< vtkm::Id, ConnectivityStorageTag > &connectivity)
Definition: CellSetSingleType.h:186
GridInfo Grid
Definition: worklet/VertexClustering.h:136
void Run(const UnknownCellSetType &cellSet, const DynamicCoordinateHandleType &coordinates, const vtkm::Bounds &bounds, const vtkm::Id3 &nDivisions, vtkm::cont::UnknownCellSet &outCellSet, vtkm::cont::UnknownArrayHandle &outCoords)
VertexClustering: Mesh simplification.
Definition: worklet/VertexClustering.h:319
VTKM_EXEC vtkm::Id GetClusterId(const PointType &p) const
determine grid resolution for clustering
Definition: worklet/VertexClustering.h:150
VTKM_CONT void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:559
VTKM_CONT vtkm::Float64 GetElapsedTime() const
Get the elapsed time measured by the given device adapter.
@ Perf
General timing data and algorithm flow information, such as filter execution, worklet dispatches,...
VTKM_EXEC void operator()(const PointType &point, vtkm::Id &cid) const
Definition: worklet/VertexClustering.h:167
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263
The ExecutionSignature tag to use to get the work index.
Definition: WorkIndex.h:39
VTKM_EXEC void operator()(const vtkm::Id3 &cid3, vtkm::Id3 &pointId3, const InPortalType &inPortal) const
Definition: worklet/VertexClustering.h:236
void(CellSetIn cellset, FieldInPoint pointClusterIds, FieldOutCell cellClusterIds) ControlSignature
Definition: worklet/VertexClustering.h:179