Commit 531decec authored by Robert Maynard's avatar Robert Maynard

Multiple changes to VertexClustering to make it more suitable for filter.

The original implementation wasn't flexible enough to handle the requirements
that filter requires ( mainly policy support ).
parent aaa10f0c
......@@ -313,14 +313,16 @@ public:
///////////////////////////////////////////////////
/// \brief VertexClustering: Mesh simplification
///
template<typename DeviceAdapter>
vtkm::cont::DataSet Run(const vtkm::cont::DynamicCellSet &cellSet,
const vtkm::cont::CoordinateSystem &coordinates,
vtkm::Id nDivisions,
template<typename DynamicCellSetType,
typename DynamicCoordinateHandleType,
typename DeviceAdapter>
vtkm::cont::DataSet Run(const DynamicCellSetType &cellSet,
const DynamicCoordinateHandleType &coordinates,
vtkm::Float64 *bounds,
const vtkm::Id3& nDivisions,
DeviceAdapter)
{
vtkm::Float64 bounds[6];
coordinates.GetBounds(bounds, DeviceAdapter());
/// determine grid resolution for clustering
GridInfo gridInfo;
......@@ -328,16 +330,16 @@ public:
vtkm::Float64 res[3];
for (vtkm::IdComponent i=0; i<3; i++)
{
res[i] = (bounds[i*2+1]-bounds[i*2])/nDivisions;
res[i] = (bounds[i*2+1]-bounds[i*2])/nDivisions[i];
}
gridInfo.grid_width = vtkm::Max(res[0], vtkm::Max(res[1], res[2]));
vtkm::Float64 inv_grid_width = gridInfo.inv_grid_width = vtkm::Float64(1) / gridInfo.grid_width;
//printf("Bounds: %lf, %lf, %lf, %lf, %lf, %lf\n", bounds[0], bounds[1], bounds[2], bounds[3], bounds[4], bounds[5]);
gridInfo.dim[0] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[1]-bounds[0])*inv_grid_width), nDivisions);
gridInfo.dim[1] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[3]-bounds[2])*inv_grid_width), nDivisions);
gridInfo.dim[2] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[5]-bounds[4])*inv_grid_width), nDivisions);
gridInfo.dim[0] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[1]-bounds[0])*inv_grid_width), nDivisions[0]);
gridInfo.dim[1] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[3]-bounds[2])*inv_grid_width), nDivisions[1]);
gridInfo.dim[2] = vtkm::Min((vtkm::Id)vtkm::Ceil((bounds[5]-bounds[4])*inv_grid_width), nDivisions[2]);
// center the mesh in the grids
gridInfo.origin[0] = (bounds[1]+bounds[0])*0.5 - gridInfo.grid_width*(gridInfo.dim[0])*.5;
......@@ -359,7 +361,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Id> pointCidArray;
vtkm::worklet::DispatcherMapField<MapPointsWorklet, DeviceAdapter>(
MapPointsWorklet(gridInfo)).Invoke(coordinates.GetData(), pointCidArray);
MapPointsWorklet(gridInfo)).Invoke(coordinates, pointCidArray);
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
std::cout << "Time map points (s): " << timer.GetElapsedTime() << std::endl;
......@@ -376,7 +378,7 @@ public:
vtkm::cont::ArrayHandle<vtkm::Id>,
DeviceAdapter>
averageByKey(pointCidArray, pointCidArrayReduced, repPointArray);
coordinates.GetData().CastAndCall(averageByKey);
coordinates.CastAndCall(averageByKey);
#ifdef __VTKM_VERTEX_CLUSTERING_BENCHMARK
std::cout << "Time after averaging (s): " << timer.GetElapsedTime() << std::endl;
......
......@@ -31,15 +31,19 @@
void TestVertexClustering()
{
vtkm::Float64 bounds[6];
const vtkm::Id divisions = 3;
const vtkm::Id3 divisions(3, 3, 3);
vtkm::cont::testing::MakeTestDataSet maker;
vtkm::cont::DataSet dataSet = maker.Make3DExplicitDataSetCowNose(bounds);
vtkm::cont::DataSet dataSet = maker.Make3DExplicitDataSetCowNose();
//compute the bounds before calling the algorithm
vtkm::Float64 bounds[6];
dataSet.GetCoordinateSystem().GetBounds(bounds, VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
// run
vtkm::worklet::VertexClustering clustering;
vtkm::cont::DataSet outDataSet = clustering.Run(dataSet.GetCellSet(),
dataSet.GetCoordinateSystem(),
dataSet.GetCoordinateSystem().GetData(),
bounds,
divisions,
VTKM_DEFAULT_DEVICE_ADAPTER_TAG());
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment