vtk-m/vtkm/worklet/Mask.h

88 lines
3.0 KiB
C
Raw Normal View History

2017-03-28 20:42:22 +00:00
//============================================================================
// 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 2015 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
2017-03-28 20:42:22 +00:00
// Copyright 2015 UT-Battelle, LLC.
// Copyright 2015 Los Alamos National Security.
//
// Under the terms of Contract DE-NA0003525 with NTESS,
2017-03-28 20:42:22 +00:00
// 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 vtkm_m_worklet_Mask_h
#define vtkm_m_worklet_Mask_h
#include <vtkm/worklet/DispatcherMapTopology.h>
#include <vtkm/worklet/WorkletMapTopology.h>
#include <vtkm/cont/ArrayHandle.h>
#include <vtkm/cont/ArrayHandleCounting.h>
#include <vtkm/cont/ArrayHandlePermutation.h>
2017-05-18 14:51:24 +00:00
#include <vtkm/cont/CellSetPermutation.h>
#include <vtkm/cont/DataSet.h>
2017-03-28 20:42:22 +00:00
#include <vtkm/cont/DeviceAdapterAlgorithm.h>
2017-05-18 14:29:41 +00:00
namespace vtkm
{
namespace worklet
{
2017-03-28 20:42:22 +00:00
// Subselect points using stride for now, creating new cellset of vertices
class Mask
{
public:
2017-05-18 14:29:41 +00:00
struct BoolType : vtkm::ListTagBase<bool>
{
};
template <typename CellSetType, typename DeviceAdapter>
vtkm::cont::CellSetPermutation<CellSetType> Run(const CellSetType& cellSet,
const vtkm::Id stride,
2017-05-18 14:29:41 +00:00
DeviceAdapter)
2017-03-28 20:42:22 +00:00
{
typedef typename vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter> DeviceAlgorithm;
typedef vtkm::cont::CellSetPermutation<CellSetType> OutputType;
vtkm::Id numberOfInputCells = cellSet.GetNumberOfCells();
vtkm::Id numberOfSampledCells = numberOfInputCells / stride;
vtkm::cont::ArrayHandleCounting<vtkm::Id> strideArray(0, stride, numberOfSampledCells);
DeviceAlgorithm::Copy(strideArray, this->ValidCellIds);
return OutputType(this->ValidCellIds, cellSet, cellSet.GetName());
}
//----------------------------------------------------------------------------
template <typename ValueType, typename StorageType, typename DeviceAdapter>
vtkm::cont::ArrayHandle<ValueType> ProcessCellField(
const vtkm::cont::ArrayHandle<ValueType, StorageType>& in,
const DeviceAdapter&) const
2017-03-28 20:42:22 +00:00
{
using Algo = vtkm::cont::DeviceAdapterAlgorithm<DeviceAdapter>;
2017-03-28 20:42:22 +00:00
// Use a temporary permutation array to simplify the mapping:
auto tmp = vtkm::cont::make_ArrayHandlePermutation(this->ValidCellIds, in);
2017-03-28 20:42:22 +00:00
// Copy into an array with default storage:
vtkm::cont::ArrayHandle<ValueType> result;
Algo::Copy(tmp, result);
2017-03-28 20:42:22 +00:00
return result;
2017-03-28 20:42:22 +00:00
}
private:
vtkm::cont::ArrayHandle<vtkm::Id> ValidCellIds;
};
}
} // namespace vtkm::worklet
#endif // vtkm_m_worklet_Mask_h