vtk-m/vtkm/worklet/VertexClustering.h

552 lines
18 KiB
C
Raw Normal View History

//============================================================================
// Copyright (c) Kitware, Inc.
// All rights reserved.
// See LICENSE.txt for details.
// This software is distributed WITHOUT ANY WARRANTY; without even
// the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the above copyright notice for more information.
//
// Copyright 2014 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
// Copyright 2014 UT-Battelle, LLC.
// Copyright 2014 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
// the U.S. Government retains certain rights in this software.
//
// Under the terms of Contract DE-AC52-06NA25396 with Los Alamos National
// Laboratory (LANL), the U.S. Government retains certain rights in
// this software.
//============================================================================
#ifndef vtk_m_worklet_VertexClustering_h
#define vtk_m_worklet_VertexClustering_h
2017-08-24 17:09:48 +00:00
#include <vtkm/BinaryOperators.h>
#include <vtkm/Types.h>
#include <vtkm/cont/ArrayCopy.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleConstant.h>
2017-08-24 17:09:48 +00:00
#include <vtkm/cont/ArrayHandleDiscard.h>
#include <vtkm/cont/ArrayHandleIndex.h>
#include <vtkm/cont/DataSet.h>
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
#include <vtkm/cont/DynamicArrayHandle.h>
#include <vtkm/worklet/AverageByKey.h>
#include <vtkm/worklet/DispatcherMapField.h>
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapField.h>
#include <vtkm/worklet/WorkletMapTopology.h>
2015-06-25 14:52:02 +00:00
//#define __VTKM_VERTEX_CLUSTERING_BENCHMARK
//#include <vtkm/cont/Timer.h>
2015-06-24 19:13:16 +00:00
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace worklet
{
2017-05-18 14:29:41 +00:00
namespace internal
{
2017-05-18 14:29:41 +00:00
template <typename T, vtkm::IdComponent N, typename DeviceAdapter>
vtkm::cont::ArrayHandle<T> copyFromVec(vtkm::cont::ArrayHandle<vtkm::Vec<T, N>> const& other,
DeviceAdapter)
2015-06-19 18:23:20 +00:00
{
2017-05-18 14:29:41 +00:00
const T* vmem = reinterpret_cast<const T*>(&*other.GetPortalConstControl().GetIteratorBegin());
vtkm::cont::ArrayHandle<T> mem =
vtkm::cont::make_ArrayHandle(vmem, other.GetNumberOfValues() * N);
vtkm::cont::ArrayHandle<T> result;
vtkm::cont::ArrayCopy(mem, result, DeviceAdapter());
2017-05-18 14:29:41 +00:00
return result;
}
template <typename KeyArrayIn, typename KeyArrayOut, typename DeviceAdapter>
class AverageByKeyDynamicValue
{
private:
typedef typename KeyArrayIn::ValueType KeyType;
public:
VTKM_CONT
AverageByKeyDynamicValue(const KeyArrayIn& inputKeys,
KeyArrayOut& outputKeys,
2017-05-18 14:29:41 +00:00
vtkm::cont::DynamicArrayHandle& outputValues)
: InputKeys(inputKeys)
, OutputKeys(&outputKeys)
, OutputValues(&outputValues)
{
}
template <typename ValueArrayIn>
2017-05-18 14:29:41 +00:00
VTKM_CONT void operator()(const ValueArrayIn& coordinates) const
{
typedef typename ValueArrayIn::ValueType ValueType;
vtkm::cont::ArrayHandle<ValueType> outArray;
vtkm::worklet::AverageByKey::Run(
InputKeys, coordinates, *(this->OutputKeys), outArray, DeviceAdapter());
*(this->OutputValues) = vtkm::cont::DynamicArrayHandle(outArray);
}
private:
KeyArrayIn InputKeys;
2017-05-18 14:29:41 +00:00
KeyArrayOut* OutputKeys;
vtkm::cont::DynamicArrayHandle* OutputValues;
};
} // namespace internal
struct VertexClustering
{
struct GridInfo
{
vtkm::Vec<vtkm::Id, 3> dim;
vtkm::Vec<vtkm::Float64, 3> origin;
vtkm::Vec<vtkm::Float64, 3> bin_size;
vtkm::Vec<vtkm::Float64, 3> inv_bin_size;
};
// input: points output: cid of the points
class MapPointsWorklet : public vtkm::worklet::WorkletMapField
{
private:
GridInfo Grid;
public:
2017-05-18 14:29:41 +00:00
typedef void ControlSignature(FieldIn<Vec3>, FieldOut<IdType>);
typedef void ExecutionSignature(_1, _2);
VTKM_CONT
2017-05-18 14:29:41 +00:00
MapPointsWorklet(const GridInfo& grid)
: Grid(grid)
2017-05-18 14:29:41 +00:00
{
}
/// determine grid resolution for clustering
2017-05-18 14:29:41 +00:00
template <typename PointType>
VTKM_EXEC vtkm::Id GetClusterId(const PointType& p) const
{
typedef typename PointType::ComponentType ComponentType;
2017-05-18 14:29:41 +00:00
PointType gridOrigin(static_cast<ComponentType>(this->Grid.origin[0]),
static_cast<ComponentType>(this->Grid.origin[1]),
static_cast<ComponentType>(this->Grid.origin[2]));
PointType p_rel = (p - gridOrigin) * this->Grid.inv_bin_size;
vtkm::Id x = vtkm::Min(static_cast<vtkm::Id>(p_rel[0]), this->Grid.dim[0] - 1);
vtkm::Id y = vtkm::Min(static_cast<vtkm::Id>(p_rel[1]), this->Grid.dim[1] - 1);
vtkm::Id z = vtkm::Min(static_cast<vtkm::Id>(p_rel[2]), this->Grid.dim[2] - 1);
2017-05-18 14:29:41 +00:00
return x + this->Grid.dim[0] * (y + this->Grid.dim[1] * z); // get a unique hash value
}
2017-05-18 14:29:41 +00:00
template <typename PointType>
VTKM_EXEC void operator()(const PointType& point, vtkm::Id& cid) const
{
cid = this->GetClusterId(point);
2017-05-18 14:29:41 +00:00
VTKM_ASSERT(cid >= 0); // the id could overflow if too many cells
}
};
2017-05-18 14:29:41 +00:00
class MapCellsWorklet : public vtkm::worklet::WorkletMapPointToCell
{
public:
typedef void ControlSignature(CellSetIn cellset,
FieldInPoint<IdType> pointClusterIds,
FieldOutCell<Id3Type> cellClusterIds);
typedef void ExecutionSignature(_2, _3);
VTKM_CONT
2017-05-18 14:29:41 +00:00
MapCellsWorklet() {}
// TODO: Currently only works with Triangle cell types
2017-05-18 14:29:41 +00:00
template <typename ClusterIdsVecType>
VTKM_EXEC void operator()(const ClusterIdsVecType& pointClusterIds,
vtkm::Id3& cellClusterId) const
{
cellClusterId[0] = pointClusterIds[0];
cellClusterId[1] = pointClusterIds[1];
cellClusterId[2] = pointClusterIds[2];
}
};
/// pass 3
class IndexingWorklet : public vtkm::worklet::WorkletMapField
{
public:
2017-05-18 14:29:41 +00:00
typedef void ControlSignature(FieldIn<IdType>, WholeArrayOut<IdType>);
typedef void ExecutionSignature(WorkIndex, _1, _2); // WorkIndex: use vtkm indexing
template <typename OutPortalType>
VTKM_EXEC void operator()(const vtkm::Id& counter,
const vtkm::Id& cid,
2017-05-18 14:29:41 +00:00
const OutPortalType& outPortal) const
{
outPortal.Set(cid, counter);
}
};
class Cid2PointIdWorklet : public vtkm::worklet::WorkletMapField
{
vtkm::Id NPoints;
VTKM_EXEC
2017-05-18 14:29:41 +00:00
void rotate(vtkm::Id3& ids) const
{
2017-05-18 14:29:41 +00:00
vtkm::Id temp = ids[0];
ids[0] = ids[1];
ids[1] = ids[2];
ids[2] = temp;
}
public:
2017-05-18 14:29:41 +00:00
typedef void ControlSignature(FieldIn<Id3Type>, FieldOut<Id3Type>, WholeArrayIn<IdType>);
typedef void ExecutionSignature(_1, _2, _3);
VTKM_CONT
2017-05-18 14:29:41 +00:00
Cid2PointIdWorklet(vtkm::Id nPoints)
: NPoints(nPoints)
{
}
2017-05-18 14:29:41 +00:00
template <typename InPortalType>
VTKM_EXEC void operator()(const vtkm::Id3& cid3,
vtkm::Id3& pointId3,
2017-05-18 14:29:41 +00:00
const InPortalType& inPortal) const
{
2017-05-18 14:29:41 +00:00
if (cid3[0] == cid3[1] || cid3[0] == cid3[2] || cid3[1] == cid3[2])
{
2017-05-18 14:29:41 +00:00
pointId3[0] = pointId3[1] = pointId3[2] = this->NPoints; // invalid cell to be removed
}
else
{
2017-05-18 14:29:41 +00:00
pointId3[0] = inPortal.Get(cid3[0]);
pointId3[1] = inPortal.Get(cid3[1]);
pointId3[2] = inPortal.Get(cid3[2]);
// Sort triangle point ids so that the same triangle will have the same signature
// Rotate these ids making the first one the smallest
2017-05-18 14:29:41 +00:00
if (pointId3[0] > pointId3[1] || pointId3[0] > pointId3[2])
{
rotate(pointId3);
2017-05-18 14:29:41 +00:00
if (pointId3[0] > pointId3[1] || pointId3[0] > pointId3[2])
{
rotate(pointId3);
}
}
}
}
};
2017-05-18 14:29:41 +00:00
struct TypeInt64 : vtkm::ListTagBase<vtkm::Int64>
{
};
class Cid3HashWorklet : public vtkm::worklet::WorkletMapField
{
2015-07-01 04:24:45 +00:00
private:
vtkm::Int64 NPoints;
2015-07-01 04:24:45 +00:00
public:
2017-05-18 14:29:41 +00:00
typedef void ControlSignature(FieldIn<Id3Type>, FieldOut<TypeInt64>);
2015-07-01 04:24:45 +00:00
typedef void ExecutionSignature(_1, _2);
2015-06-30 19:29:37 +00:00
VTKM_CONT
Cid3HashWorklet(vtkm::Id nPoints)
: NPoints(nPoints)
2017-05-18 14:29:41 +00:00
{
}
2015-07-01 04:24:45 +00:00
VTKM_EXEC
2017-05-18 14:29:41 +00:00
void operator()(const vtkm::Id3& cid, vtkm::Int64& cidHash) const
2015-07-01 04:24:45 +00:00
{
2017-05-18 14:29:41 +00:00
cidHash =
cid[0] + this->NPoints * (cid[1] + this->NPoints * cid[2]); // get a unique hash value
2015-07-01 04:24:45 +00:00
}
};
2015-06-30 19:29:37 +00:00
class Cid3UnhashWorklet : public vtkm::worklet::WorkletMapField
{
2015-07-01 04:24:45 +00:00
private:
vtkm::Int64 NPoints;
2015-07-01 04:24:45 +00:00
public:
2017-05-18 14:29:41 +00:00
typedef void ControlSignature(FieldIn<TypeInt64>, FieldOut<Id3Type>);
2015-07-01 04:24:45 +00:00
typedef void ExecutionSignature(_1, _2);
VTKM_CONT
Cid3UnhashWorklet(vtkm::Id nPoints)
: NPoints(nPoints)
2017-05-18 14:29:41 +00:00
{
}
2015-07-01 04:24:45 +00:00
VTKM_EXEC
2017-05-18 14:29:41 +00:00
void operator()(const vtkm::Int64& cidHash, vtkm::Id3& cid) const
2015-07-01 04:24:45 +00:00
{
2017-05-18 14:29:41 +00:00
cid[0] = static_cast<vtkm::Id>(cidHash % this->NPoints);
vtkm::Int64 t = cidHash / this->NPoints;
cid[1] = static_cast<vtkm::Id>(t % this->NPoints);
cid[2] = static_cast<vtkm::Id>(t / this->NPoints);
2015-07-01 04:24:45 +00:00
}
};
public:
///////////////////////////////////////////////////
/// \brief VertexClustering: Mesh simplification
///
template <typename DynamicCellSetType,
typename DynamicCoordinateHandleType,
2017-05-18 14:29:41 +00:00
typename DeviceAdapter>
vtkm::cont::DataSet Run(const DynamicCellSetType& cellSet,
const DynamicCoordinateHandleType& coordinates,
const vtkm::Bounds& bounds,
const vtkm::Id3& nDivisions,
DeviceAdapter)
{
2017-08-24 17:09:48 +00:00
using Algo = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
/// determine grid resolution for clustering
GridInfo gridInfo;
{
gridInfo.origin[0] = bounds.X.Min;
gridInfo.origin[1] = bounds.Y.Min;
gridInfo.origin[2] = bounds.Z.Min;
gridInfo.dim[0] = nDivisions[0];
gridInfo.dim[1] = nDivisions[1];
gridInfo.dim[2] = nDivisions[2];
gridInfo.bin_size[0] = bounds.X.Length() / static_cast<vtkm::Float64>(nDivisions[0]);
gridInfo.bin_size[1] = bounds.Y.Length() / static_cast<vtkm::Float64>(nDivisions[1]);
gridInfo.bin_size[2] = bounds.Z.Length() / static_cast<vtkm::Float64>(nDivisions[2]);
gridInfo.inv_bin_size[0] = 1. / gridInfo.bin_size[0];
gridInfo.inv_bin_size[1] = 1. / gridInfo.bin_size[1];
gridInfo.inv_bin_size[2] = 1. / gridInfo.bin_size[2];
}
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
vtkm::cont::Timer<> timer;
2015-06-25 14:52:02 +00:00
#endif
//////////////////////////////////////////////
/// start algorithm
/// pass 1 : assign points with (cluster) ids based on the grid it falls in
///
/// map points
vtkm::cont::ArrayHandle<vtkm::Id> pointCidArray;
2017-05-18 14:29:41 +00:00
vtkm::worklet::DispatcherMapField<MapPointsWorklet, DeviceAdapter>(MapPointsWorklet(gridInfo))
.Invoke(coordinates, pointCidArray);
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
std::cout << "Time map points (s): " << timer.GetElapsedTime() << std::endl;
2015-06-24 19:13:16 +00:00
#endif
/// pass 2 : compute average point position for each cluster,
/// using pointCidArray as the key
///
vtkm::cont::ArrayHandle<vtkm::Id> pointCidArrayReduced;
2017-05-18 14:29:41 +00:00
vtkm::cont::DynamicArrayHandle repPointArray; // representative point
internal::AverageByKeyDynamicValue<vtkm::cont::ArrayHandle<vtkm::Id>,
vtkm::cont::ArrayHandle<vtkm::Id>,
DeviceAdapter>
2017-05-18 14:29:41 +00:00
averageByKey(pointCidArray, pointCidArrayReduced, repPointArray);
CastAndCall(coordinates, averageByKey);
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
std::cout << "Time after averaging (s): " << timer.GetElapsedTime() << std::endl;
2015-06-24 19:13:16 +00:00
#endif
/// Pass 3 : Decimated mesh generation
/// For each original triangle, only output vertices from
/// three different clusters
/// map each triangle vertex to the cluster id's
/// of the cell vertices
vtkm::cont::ArrayHandle<vtkm::Id3> cid3Array;
2017-05-18 14:29:41 +00:00
vtkm::worklet::DispatcherMapTopology<MapCellsWorklet, DeviceAdapter>(MapCellsWorklet())
.Invoke(cellSet, pointCidArray, cid3Array);
2017-08-24 17:09:48 +00:00
// Generate the point map before releasing pointCidArray. Just grab any value
// from the cluster -- this matches vtkQuadricClustering's behavior.
{
vtkm::cont::ArrayHandleDiscard<vtkm::Id> discard;
vtkm::cont::ArrayHandleIndex indexSrc(pointCidArray.GetNumberOfValues());
vtkm::cont::ArrayHandle<vtkm::Id> index;
Algo::Copy(indexSrc, index); // Need a real array for SortByKey
// Mimics the behavior of AverageByKey to get the original cellIds in the
// same order as pointCidArrayReduced.
Algo::SortByKey(pointCidArray, index, vtkm::SortLess());
Algo::ReduceByKey(pointCidArray, index, discard, this->PointIdMap, vtkm::Minimum());
}
2015-06-29 14:56:45 +00:00
pointCidArray.ReleaseResources();
/// preparation: Get the indexes of the clustered points to prepare for new cell array
vtkm::cont::ArrayHandle<vtkm::Id> cidIndexArray;
2017-05-18 14:29:41 +00:00
cidIndexArray.PrepareForOutput(gridInfo.dim[0] * gridInfo.dim[1] * gridInfo.dim[2],
DeviceAdapter());
2017-05-18 14:29:41 +00:00
vtkm::worklet::DispatcherMapField<IndexingWorklet, DeviceAdapter>().Invoke(pointCidArrayReduced,
cidIndexArray);
2015-06-29 14:56:45 +00:00
pointCidArrayReduced.ReleaseResources();
///
/// map: convert each triangle vertices from original point id to the new cluster indexes
2017-08-24 17:09:48 +00:00
/// If the triangle is degenerated, set the ids to <nPoints, nPoints, nPoints>
/// This ensures it will be placed at the end of the array when sorted.
///
2015-07-01 04:24:45 +00:00
vtkm::Id nPoints = repPointArray.GetNumberOfValues();
vtkm::cont::ArrayHandle<vtkm::Id3> pointId3Array;
vtkm::worklet::DispatcherMapField<Cid2PointIdWorklet, DeviceAdapter>(
2017-05-18 14:29:41 +00:00
Cid2PointIdWorklet(nPoints))
.Invoke(cid3Array, pointId3Array, cidIndexArray);
2015-06-29 14:56:45 +00:00
cid3Array.ReleaseResources();
cidIndexArray.ReleaseResources();
2017-05-18 14:29:41 +00:00
bool doHashing = (nPoints < (1 << 21)); // Check whether we can hash Id3 into 64-bit integers
if (doHashing)
{
2015-07-01 04:24:45 +00:00
/// Create hashed array
vtkm::cont::ArrayHandle<vtkm::Int64> pointId3HashArray;
2017-05-18 14:29:41 +00:00
vtkm::worklet::DispatcherMapField<Cid3HashWorklet, DeviceAdapter>(Cid3HashWorklet(nPoints))
.Invoke(pointId3Array, pointId3HashArray);
2015-07-01 04:24:45 +00:00
pointId3Array.ReleaseResources();
2015-06-29 14:56:45 +00:00
2017-08-24 17:09:48 +00:00
// These are used to generate the CellIdMap:
vtkm::cont::ArrayHandleIndex indexSrc(pointId3HashArray.GetNumberOfValues());
vtkm::cont::ArrayHandle<vtkm::Id> index;
Algo::Copy(indexSrc, index);
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
2017-05-18 14:29:41 +00:00
std::cout << "Time before sort and unique with hashing (s): " << timer.GetElapsedTime()
<< std::endl;
2015-06-24 19:13:16 +00:00
#endif
2017-08-24 17:09:48 +00:00
Algo::SortByKey(pointId3HashArray, index);
{
vtkm::cont::ArrayHandle<vtkm::Int64> tmp;
Algo::ReduceByKey(pointId3HashArray, index, tmp, this->CellIdMap, vtkm::Minimum());
pointId3HashArray = tmp;
}
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
2017-05-18 14:29:41 +00:00
std::cout << "Time after sort and unique with hashing (s): " << timer.GetElapsedTime()
<< std::endl;
2015-06-24 19:13:16 +00:00
#endif
2015-07-01 04:24:45 +00:00
// decode
vtkm::worklet::DispatcherMapField<Cid3UnhashWorklet, DeviceAdapter>(
2017-05-18 14:29:41 +00:00
Cid3UnhashWorklet(nPoints))
.Invoke(pointId3HashArray, pointId3Array);
}
else
{
2017-08-24 17:09:48 +00:00
// These are used to generate the CellIdMap:
vtkm::cont::ArrayHandleIndex indexSrc(pointId3Array.GetNumberOfValues());
vtkm::cont::ArrayHandle<vtkm::Id> index;
Algo::Copy(indexSrc, index);
2015-07-01 04:24:45 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
2017-05-18 14:29:41 +00:00
std::cout << "Time before sort and unique [no hashing] (s): " << timer.GetElapsedTime()
<< std::endl;
2015-07-01 04:24:45 +00:00
#endif
2017-08-24 17:09:48 +00:00
Algo::SortByKey(pointId3Array, index);
{
vtkm::cont::ArrayHandle<vtkm::Id3> tmp;
Algo::ReduceByKey(pointId3Array, index, tmp, this->CellIdMap, vtkm::Minimum());
pointId3Array = tmp;
}
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
2017-05-18 14:29:41 +00:00
std::cout << "Time after sort and unique [no hashing] (s): " << timer.GetElapsedTime()
<< std::endl;
2015-06-24 19:13:16 +00:00
#endif
2015-07-01 04:24:45 +00:00
}
// remove the last element if invalid
vtkm::Id cells = pointId3Array.GetNumberOfValues();
2017-05-18 14:29:41 +00:00
if (cells > 0 && pointId3Array.GetPortalConstControl().Get(cells - 1)[2] >= nPoints)
{
cells--;
2015-07-01 04:24:45 +00:00
pointId3Array.Shrink(cells);
2017-08-24 17:09:48 +00:00
this->CellIdMap.Shrink(cells);
2015-07-01 04:24:45 +00:00
}
/// output
vtkm::cont::DataSet output;
output.AddCoordinateSystem(vtkm::cont::CoordinateSystem("coordinates", repPointArray));
2017-05-18 14:29:41 +00:00
vtkm::cont::CellSetSingleType<> triangles("cells");
triangles.Fill(repPointArray.GetNumberOfValues(),
vtkm::CellShapeTagTriangle::Id,
3,
2017-05-18 14:29:41 +00:00
internal::copyFromVec(pointId3Array, DeviceAdapter()));
output.AddCellSet(triangles);
2015-06-25 14:52:02 +00:00
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
2015-06-25 15:46:28 +00:00
vtkm::Float64 t = timer.GetElapsedTime();
std::cout << "Time (s): " << t << std::endl;
2015-07-01 04:24:45 +00:00
std::cout << "number of output points: " << repPointArray.GetNumberOfValues() << std::endl;
std::cout << "number of output cells: " << pointId3Array.GetNumberOfValues() << std::endl;
2015-06-24 19:13:16 +00:00
#endif
return output;
}
2017-08-24 17:09:48 +00:00
template <typename ValueType, typename StorageType, typename DeviceAdapter>
vtkm::cont::ArrayHandle<ValueType> ProcessPointField(
const vtkm::cont::ArrayHandle<ValueType, StorageType>& input,
const DeviceAdapter&) const
{
using Algo = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
// Use a temporary permutation array to simplify the mapping:
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->PointIdMap, input);
// Copy into an array with default storage:
vtkm::cont::ArrayHandle<ValueType> result;
Algo::Copy(tmp, result);
return result;
}
template <typename ValueType, typename StorageType, typename DeviceAdapter>
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
const vtkm::cont::ArrayHandle<ValueType, StorageType>& input,
const DeviceAdapter&) const
{
using Algo = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
// Use a temporary permutation array to simplify the mapping:
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->CellIdMap, input);
// Copy into an array with default storage:
vtkm::cont::ArrayHandle<ValueType> result;
Algo::Copy(tmp, result);
return result;
}
private:
vtkm::cont::ArrayHandle<vtkm::Id> PointIdMap;
vtkm::cont::ArrayHandle<vtkm::Id> CellIdMap;
}; // struct VertexClustering
}
} // namespace vtkm::worklet
#endif // vtk_m_worklet_VertexClustering_h