2016-11-05 00:29:54 +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.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Copyright 2016 National Technology & Engineering Solutions of Sandia, LLC (NTESS).
|
2016-11-05 00:29:54 +00:00
|
|
|
// Copyright 2016 UT-Battelle, LLC.
|
|
|
|
// Copyright 2016 Los Alamos National Security.
|
|
|
|
//
|
2017-09-20 21:33:44 +00:00
|
|
|
// Under the terms of Contract DE-NA0003525 with NTESS,
|
2016-11-05 00:29:54 +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 vtk_m_worklet_RemoveUnusedPoints_h
|
|
|
|
#define vtk_m_worklet_RemoveUnusedPoints_h
|
|
|
|
|
|
|
|
#include <vtkm/cont/ArrayHandle.h>
|
|
|
|
#include <vtkm/cont/ArrayHandleConstant.h>
|
|
|
|
#include <vtkm/cont/ArrayHandlePermutation.h>
|
|
|
|
#include <vtkm/cont/CellSetExplicit.h>
|
|
|
|
|
|
|
|
#include <vtkm/worklet/DispatcherMapField.h>
|
|
|
|
#include <vtkm/worklet/ScatterCounting.h>
|
|
|
|
#include <vtkm/worklet/WorkletMapField.h>
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
namespace vtkm
|
|
|
|
{
|
|
|
|
namespace worklet
|
|
|
|
{
|
2016-11-05 00:29:54 +00:00
|
|
|
|
|
|
|
/// A collection of worklets used to identify which points are used by at least
|
|
|
|
/// one cell and then remove the points that are not used by any cells. The
|
|
|
|
/// class containing these worklets can be used to manage running these
|
|
|
|
/// worklets, building new cell sets, and redefine field arrays.
|
|
|
|
///
|
|
|
|
class RemoveUnusedPoints
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
/// A worklet that creates a mask of used points (the first step in removing
|
|
|
|
/// unused points). Given an array of point indices (taken from the
|
|
|
|
/// connectivity of a CellSetExplicit) and an array mask initialized to 0,
|
|
|
|
/// writes a 1 at the index of every point referenced by a cell.
|
|
|
|
///
|
|
|
|
struct GeneratePointMask : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
typedef void ControlSignature(FieldIn<> pointIndices, WholeArrayInOut<> pointMask);
|
2016-11-05 00:29:54 +00:00
|
|
|
typedef void ExecutionSignature(_1, _2);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename PointMaskPortalType>
|
|
|
|
VTKM_EXEC void operator()(vtkm::Id pointIndex, const PointMaskPortalType& pointMask) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
pointMask.Set(pointIndex, 1);
|
2016-11-05 00:29:54 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/// A worklet that takes an array of point indices (taken from the
|
|
|
|
/// connectivity of a CellSetExplicit) and an array that functions as a map
|
|
|
|
/// from the original indices to new indices, creates a new array with the
|
|
|
|
/// new mapped indices.
|
|
|
|
///
|
|
|
|
struct TransformPointIndices : public vtkm::worklet::WorkletMapField
|
|
|
|
{
|
2017-05-26 17:53:28 +00:00
|
|
|
typedef void ControlSignature(FieldIn<IdType> pointIndex,
|
|
|
|
WholeArrayIn<IdType> indexMap,
|
2016-11-05 03:23:07 +00:00
|
|
|
FieldOut<IdType> mappedPoints);
|
2016-11-05 00:29:54 +00:00
|
|
|
typedef _3 ExecutionSignature(_1, _2);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename IndexMapPortalType>
|
|
|
|
VTKM_EXEC vtkm::Id operator()(vtkm::Id pointIndex, const IndexMapPortalType& indexPortal) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
|
|
|
return indexPortal.Get(pointIndex);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
public:
|
2016-11-06 22:15:22 +00:00
|
|
|
VTKM_CONT
|
2017-05-18 14:29:41 +00:00
|
|
|
RemoveUnusedPoints() {}
|
|
|
|
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ShapeStorage,
|
|
|
|
typename NumIndicesStorage,
|
|
|
|
typename ConnectivityStorage,
|
|
|
|
typename OffsetsStorage,
|
|
|
|
typename Device>
|
|
|
|
VTKM_CONT RemoveUnusedPoints(const vtkm::cont::CellSetExplicit<ShapeStorage,
|
|
|
|
NumIndicesStorage,
|
|
|
|
ConnectivityStorage,
|
|
|
|
OffsetsStorage>& inCellSet,
|
|
|
|
Device)
|
2016-11-06 22:15:22 +00:00
|
|
|
{
|
|
|
|
this->FindPointsStart(Device());
|
|
|
|
this->FindPoints(inCellSet, Device());
|
|
|
|
this->FindPointsEnd(Device());
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Get this class ready for identifying the points used by cell sets.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
|
|
|
VTKM_CONT void FindPointsStart(Device)
|
2016-11-06 22:15:22 +00:00
|
|
|
{
|
|
|
|
this->MaskArray.ReleaseResources();
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Analyze the given cell set to find all points that are used. Unused
|
|
|
|
/// points are those that are not found in any cell sets passed to this
|
|
|
|
/// method.
|
|
|
|
///
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ShapeStorage,
|
|
|
|
typename NumIndicesStorage,
|
|
|
|
typename ConnectivityStorage,
|
|
|
|
typename OffsetsStorage,
|
|
|
|
typename Device>
|
|
|
|
VTKM_CONT void FindPoints(const vtkm::cont::CellSetExplicit<ShapeStorage,
|
|
|
|
NumIndicesStorage,
|
|
|
|
ConnectivityStorage,
|
|
|
|
OffsetsStorage>& inCellSet,
|
|
|
|
Device)
|
2016-11-06 22:15:22 +00:00
|
|
|
{
|
|
|
|
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<Device>;
|
|
|
|
|
|
|
|
if (this->MaskArray.GetNumberOfValues() < 1)
|
|
|
|
{
|
|
|
|
// Initialize mask array to 0.
|
|
|
|
Algorithm::Copy(
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandleConstant<vtkm::IdComponent>(0, inCellSet.GetNumberOfPoints()),
|
|
|
|
this->MaskArray);
|
2016-11-06 22:15:22 +00:00
|
|
|
}
|
2017-05-18 14:29:41 +00:00
|
|
|
VTKM_ASSERT(this->MaskArray.GetNumberOfValues() == inCellSet.GetNumberOfPoints());
|
|
|
|
|
|
|
|
vtkm::worklet::DispatcherMapField<GeneratePointMask, Device> dispatcher;
|
|
|
|
dispatcher.Invoke(inCellSet.GetConnectivityArray(vtkm::TopologyElementTagPoint(),
|
|
|
|
vtkm::TopologyElementTagCell()),
|
|
|
|
this->MaskArray);
|
2016-11-06 22:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// Compile the information collected from calls to \c FindPointsInCellSet to
|
|
|
|
/// ready this class for mapping cell sets and fields.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename Device>
|
|
|
|
VTKM_CONT void FindPointsEnd(Device)
|
2016-11-06 22:15:22 +00:00
|
|
|
{
|
2017-05-18 14:29:41 +00:00
|
|
|
this->PointScatter.reset(new vtkm::worklet::ScatterCounting(this->MaskArray, Device(), true));
|
2016-11-06 22:15:22 +00:00
|
|
|
|
|
|
|
this->MaskArray.ReleaseResources();
|
|
|
|
}
|
2016-11-05 00:29:54 +00:00
|
|
|
|
|
|
|
/// \brief Map cell indices
|
|
|
|
///
|
|
|
|
/// Given a cell set (typically the same one passed to the constructor) and
|
|
|
|
/// returns a new cell set with cell points transformed to use the indices of
|
|
|
|
/// the new reduced point arrays.
|
|
|
|
///
|
2017-05-26 17:53:28 +00:00
|
|
|
template <typename ShapeStorage,
|
|
|
|
typename NumIndicesStorage,
|
|
|
|
typename ConnectivityStorage,
|
|
|
|
typename OffsetsStorage,
|
|
|
|
typename Device>
|
|
|
|
VTKM_CONT vtkm::cont::CellSetExplicit<ShapeStorage,
|
|
|
|
NumIndicesStorage,
|
|
|
|
VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG,
|
|
|
|
OffsetsStorage>
|
|
|
|
MapCellSet(const vtkm::cont::CellSetExplicit<ShapeStorage,
|
|
|
|
NumIndicesStorage,
|
|
|
|
ConnectivityStorage,
|
2017-05-18 14:29:41 +00:00
|
|
|
OffsetsStorage>& inCellSet,
|
2016-11-06 22:15:22 +00:00
|
|
|
Device) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
|
|
|
using FromTopology = vtkm::TopologyElementTagPoint;
|
|
|
|
using ToTopology = vtkm::TopologyElementTagCell;
|
|
|
|
|
|
|
|
using NewConnectivityStorage = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG;
|
|
|
|
|
2016-11-06 22:15:22 +00:00
|
|
|
VTKM_ASSERT(this->PointScatter);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::Id, NewConnectivityStorage> newConnectivityArray;
|
|
|
|
|
|
|
|
vtkm::worklet::DispatcherMapField<TransformPointIndices, Device> dispatcher;
|
|
|
|
dispatcher.Invoke(inCellSet.GetConnectivityArray(FromTopology(), ToTopology()),
|
2017-05-26 17:53:28 +00:00
|
|
|
this->PointScatter->GetInputToOutputMap(),
|
|
|
|
newConnectivityArray);
|
2017-05-18 14:29:41 +00:00
|
|
|
|
|
|
|
vtkm::Id numberOfPoints = this->PointScatter->GetOutputToInputMap().GetNumberOfValues();
|
2017-05-26 17:53:28 +00:00
|
|
|
vtkm::cont::
|
|
|
|
CellSetExplicit<ShapeStorage, NumIndicesStorage, NewConnectivityStorage, OffsetsStorage>
|
|
|
|
outCellSet(inCellSet.GetName());
|
|
|
|
outCellSet.Fill(numberOfPoints,
|
|
|
|
inCellSet.GetShapesArray(FromTopology(), ToTopology()),
|
2017-05-18 14:29:41 +00:00
|
|
|
inCellSet.GetNumIndicesArray(FromTopology(), ToTopology()),
|
2016-11-05 00:29:54 +00:00
|
|
|
newConnectivityArray,
|
2017-05-18 14:29:41 +00:00
|
|
|
inCellSet.GetIndexOffsetArray(FromTopology(), ToTopology()));
|
2016-11-05 00:29:54 +00:00
|
|
|
|
|
|
|
return outCellSet;
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Maps a point field from the original points to the new reduced points
|
|
|
|
///
|
|
|
|
/// Given an array handle that holds the values for a point field of the
|
2018-01-30 00:24:31 +00:00
|
|
|
/// original data set, returns a new array handle containing field values
|
2016-11-05 00:29:54 +00:00
|
|
|
/// rearranged to the new indices of the reduced point set.
|
|
|
|
///
|
|
|
|
/// This version of point mapping performs a shallow copy by using a
|
|
|
|
/// permutation array.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename InArrayHandle>
|
|
|
|
VTKM_CONT vtkm::cont::ArrayHandlePermutation<vtkm::cont::ArrayHandle<vtkm::Id>, InArrayHandle>
|
|
|
|
MapPointFieldShallow(const InArrayHandle& inArray) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
2016-11-06 22:15:22 +00:00
|
|
|
VTKM_ASSERT(this->PointScatter);
|
|
|
|
|
2017-05-18 14:29:41 +00:00
|
|
|
return vtkm::cont::make_ArrayHandlePermutation(this->PointScatter->GetOutputToInputMap(),
|
|
|
|
inArray);
|
2016-11-05 00:29:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Maps a point field from the original points to the new reduced points
|
|
|
|
///
|
|
|
|
/// Given an array handle that holds the values for a point field of the
|
2018-01-30 00:24:31 +00:00
|
|
|
/// original data set, returns a new array handle containing field values
|
2016-11-05 00:29:54 +00:00
|
|
|
/// rearranged to the new indices of the reduced point set.
|
|
|
|
///
|
|
|
|
/// This version of point mapping performs a deep copy into the destination
|
|
|
|
/// array provided.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename InArrayHandle, typename OutArrayHandle, typename Device>
|
2017-05-26 17:53:28 +00:00
|
|
|
VTKM_CONT void MapPointFieldDeep(const InArrayHandle& inArray,
|
|
|
|
OutArrayHandle& outArray,
|
2017-05-18 14:29:41 +00:00
|
|
|
Device) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(InArrayHandle);
|
|
|
|
VTKM_IS_ARRAY_HANDLE(OutArrayHandle);
|
|
|
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
|
|
|
|
|
|
|
using Algorithm = vtkm::cont::DeviceAdapterAlgorithm<Device>;
|
|
|
|
|
|
|
|
Algorithm::Copy(this->MapPointFieldShallow(inArray), outArray);
|
|
|
|
}
|
|
|
|
|
|
|
|
/// \brief Maps a point field from the original points to the new reduced points
|
|
|
|
///
|
|
|
|
/// Given an array handle that holds the values for a point field of the
|
2018-01-30 00:24:31 +00:00
|
|
|
/// original data set, returns a new array handle containing field values
|
2016-11-05 00:29:54 +00:00
|
|
|
/// rearranged to the new indices of the reduced point set.
|
|
|
|
///
|
|
|
|
/// This version of point mapping performs a deep copy into an array that is
|
|
|
|
/// returned.
|
|
|
|
///
|
2017-05-18 14:29:41 +00:00
|
|
|
template <typename InArrayHandle, typename Device>
|
|
|
|
vtkm::cont::ArrayHandle<typename InArrayHandle::ValueType> MapPointFieldDeep(
|
2017-05-26 17:53:28 +00:00
|
|
|
const InArrayHandle& inArray,
|
|
|
|
Device) const
|
2016-11-05 00:29:54 +00:00
|
|
|
{
|
|
|
|
VTKM_IS_ARRAY_HANDLE(InArrayHandle);
|
|
|
|
VTKM_IS_DEVICE_ADAPTER_TAG(Device);
|
|
|
|
|
|
|
|
vtkm::cont::ArrayHandle<typename InArrayHandle::ValueType> outArray;
|
|
|
|
this->MapPointFieldDeep(inArray, outArray, Device());
|
|
|
|
|
|
|
|
return outArray;
|
|
|
|
}
|
|
|
|
|
|
|
|
private:
|
2016-11-06 22:15:22 +00:00
|
|
|
vtkm::cont::ArrayHandle<vtkm::IdComponent> MaskArray;
|
|
|
|
|
2016-11-05 00:29:54 +00:00
|
|
|
/// Manages how the original point indices map to the new point indices.
|
|
|
|
///
|
2016-11-06 22:15:22 +00:00
|
|
|
std::shared_ptr<vtkm::worklet::ScatterCounting> PointScatter;
|
2016-11-05 00:29:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
} // namespace vtkm::worklet
|
|
|
|
|
|
|
|
#endif //vtk_m_worklet_RemoveUnusedPoints_h
|