VTK-m  2.0
RemoveUnusedPoints.h
Go to the documentation of this file.
1 //============================================================================
2 // Copyright (c) Kitware, Inc.
3 // All rights reserved.
4 // See LICENSE.txt for details.
5 //
6 // This software is distributed WITHOUT ANY WARRANTY; without even
7 // the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
8 // PURPOSE. See the above copyright notice for more information.
9 //============================================================================
10 #ifndef vtk_m_worklet_RemoveUnusedPoints_h
11 #define vtk_m_worklet_RemoveUnusedPoints_h
12 
14 #include <vtkm/cont/ArrayHandle.h>
19 
23 
24 namespace vtkm
25 {
26 namespace worklet
27 {
28 
35 {
36 public:
43  {
44  using ControlSignature = void(FieldIn pointIndices, WholeArrayInOut pointMask);
45  using ExecutionSignature = void(_1, _2);
46 
47  template <typename PointMaskPortalType>
48  VTKM_EXEC void operator()(vtkm::Id pointIndex, const PointMaskPortalType& pointMask) const
49  {
50  pointMask.Set(pointIndex, 1);
51  }
52  };
53 
60  {
61  using ControlSignature = void(FieldIn pointIndex, WholeArrayIn indexMap, FieldOut mappedPoints);
62  using ExecutionSignature = _3(_1, _2);
63 
64  template <typename IndexMapPortalType>
65  VTKM_EXEC vtkm::Id operator()(vtkm::Id pointIndex, const IndexMapPortalType& indexPortal) const
66  {
67  return indexPortal.Get(pointIndex);
68  }
69  };
70 
71 public:
72  VTKM_CONT
73  RemoveUnusedPoints() = default;
74 
75  template <typename ShapeStorage, typename ConnectivityStorage, typename OffsetsStorage>
78  {
79  this->FindPointsStart();
80  this->FindPoints(inCellSet);
81  this->FindPointsEnd();
82  }
83 
87 
92  template <typename ShapeStorage, typename ConnectivityStorage, typename OffsetsStorage>
95  {
96  if (this->MaskArray.GetNumberOfValues() < 1)
97  {
98  // Initialize mask array to 0.
99  this->MaskArray.AllocateAndFill(inCellSet.GetNumberOfPoints(), 0);
100  }
102 
104  dispatcher.Invoke(inCellSet.GetConnectivityArray(vtkm::TopologyElementTagCell(),
106  this->MaskArray);
107  }
108 
113  {
114  this->PointScatter.reset(new vtkm::worklet::ScatterCounting(this->MaskArray, true));
115 
116  this->MaskArray.ReleaseResources();
117  }
118 
125  template <typename ShapeStorage, typename ConnectivityStorage, typename OffsetsStorage>
126  VTKM_CONT
129  inCellSet) const
130  {
131  VTKM_ASSERT(this->PointScatter);
132 
133  return MapCellSet(inCellSet,
134  this->PointScatter->GetInputToOutputMap(),
135  this->PointScatter->GetOutputToInputMap().GetNumberOfValues());
136  }
137 
150  template <typename ShapeStorage,
151  typename ConnectivityStorage,
152  typename OffsetsStorage,
153  typename MapStorage>
154  VTKM_CONT static vtkm::cont::CellSetExplicit<ShapeStorage,
156  OffsetsStorage>
159  const vtkm::cont::ArrayHandle<vtkm::Id, MapStorage>& inputToOutputPointMap,
160  vtkm::Id numberOfPoints)
161  {
162  using VisitTopology = vtkm::TopologyElementTagCell;
163  using IncidentTopology = vtkm::TopologyElementTagPoint;
164 
165  using NewConnectivityStorage = VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG;
166 
168 
170  dispatcher.Invoke(inCellSet.GetConnectivityArray(VisitTopology(), IncidentTopology()),
171  inputToOutputPointMap,
172  newConnectivityArray);
173 
175  outCellSet.Fill(numberOfPoints,
176  inCellSet.GetShapesArray(VisitTopology(), IncidentTopology()),
177  newConnectivityArray,
178  inCellSet.GetOffsetsArray(VisitTopology(), IncidentTopology()));
179 
180  return outCellSet;
181  }
182 
192  template <typename InArrayHandle>
194  MapPointFieldShallow(const InArrayHandle& inArray) const
195  {
196  VTKM_IS_ARRAY_HANDLE(InArrayHandle);
197  VTKM_ASSERT(this->PointScatter);
198 
199  return vtkm::cont::make_ArrayHandlePermutation(this->PointScatter->GetOutputToInputMap(),
200  inArray);
201  }
202 
203 private:
205  {
206  template <typename InT, typename InS, typename OutT, typename OutS>
209  const RemoveUnusedPoints& self) const
210  {
211  self.MapPointFieldDeep(inArray, outArray);
212  }
213 
214  template <typename InT, typename InS>
217  const RemoveUnusedPoints& self) const
218  {
220  (*this)(inArray, outArray, self);
221  outHolder = vtkm::cont::UnknownArrayHandle{ outArray };
222  }
223  };
224 
225 public:
236  template <typename InT, typename InS, typename OutT, typename OutS>
238  vtkm::cont::ArrayHandle<OutT, OutS>& outArray) const
239  {
240  vtkm::cont::ArrayCopyDevice(this->MapPointFieldShallow(inArray), outArray);
241  }
242 
243  template <typename T, typename S>
245  const vtkm::cont::ArrayHandle<T, S>& inArray) const
246  {
248  this->MapPointFieldDeep(inArray, outArray);
249 
250  return outArray;
251  }
252 
253  template <typename InValueTypes, typename InStorageTypes, typename OutArrayHandle>
256  OutArrayHandle& outArray) const
257  {
258  vtkm::cont::CastAndCall(inArray, MapPointFieldDeepFunctor{}, outArray, *this);
259  }
260 
261  template <typename InValueTypes, typename InStorageTypes>
264  {
266  vtkm::cont::CastAndCall(inArray, MapPointFieldDeepFunctor{}, outArray, *this);
267  return outArray;
268  }
270 
272 
273 private:
275 
278  std::shared_ptr<vtkm::worklet::ScatterCounting> PointScatter;
279 };
280 }
281 } // namespace vtkm::worklet
282 
283 #endif //vtk_m_worklet_RemoveUnusedPoints_h
vtkm::TopologyElementTagPoint
A tag used to identify the point elements in a topology.
Definition: TopologyElementTag.h:34
vtkm::cont::ArrayCopyDevice
VTKM_CONT void ArrayCopyDevice(const vtkm::cont::ArrayHandle< InValueType, InStorage > &source, vtkm::cont::ArrayHandle< OutValueType, OutStorage > &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopyDevice.h:75
vtkm::cont::ArrayHandle::GetNumberOfValues
VTKM_CONT vtkm::Id GetNumberOfValues() const
Returns the number of entries in the array.
Definition: ArrayHandle.h:448
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm::worklet::RemoveUnusedPoints::TransformPointIndices::ControlSignature
void(FieldIn pointIndex, WholeArrayIn indexMap, FieldOut mappedPoints) ControlSignature
Definition: RemoveUnusedPoints.h:61
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeep
VTKM_CONT vtkm::cont::ArrayHandle< T > MapPointFieldDeep(const vtkm::cont::ArrayHandle< T, S > &inArray) const
Maps a point field from the original points to the new reduced points.
Definition: RemoveUnusedPoints.h:244
WorkletMapField.h
VTKM_ASSERT
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
CellSetExplicit.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::cont::ArrayHandle::AllocateAndFill
VTKM_CONT void AllocateAndFill(vtkm::Id numberOfValues, const ValueType &fillValue, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array and fills it with an initial value.
Definition: ArrayHandle.h:495
vtkm::worklet::RemoveUnusedPoints::GetPointScatter
const vtkm::worklet::ScatterCounting & GetPointScatter() const
Definition: RemoveUnusedPoints.h:271
vtkm::worklet::RemoveUnusedPoints::MapCellSet
VTKM_CONT vtkm::cont::CellSetExplicit< ShapeStorage, VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG, OffsetsStorage > MapCellSet(const vtkm::cont::CellSetExplicit< ShapeStorage, ConnectivityStorage, OffsetsStorage > &inCellSet) const
Map cell indices.
Definition: RemoveUnusedPoints.h:128
vtkm::cont::UnknownArrayHandle
An ArrayHandle of an unknown value type and storage.
Definition: UnknownArrayHandle.h:406
ArrayHandleConstant.h
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeep
VTKM_CONT void MapPointFieldDeep(const vtkm::cont::ArrayHandle< InT, InS > &inArray, vtkm::cont::ArrayHandle< OutT, OutS > &outArray) const
Maps a point field from the original points to the new reduced points.
Definition: RemoveUnusedPoints.h:237
vtkm::worklet::RemoveUnusedPoints::GeneratePointMask::ExecutionSignature
void(_1, _2) ExecutionSignature
Definition: RemoveUnusedPoints.h:45
vtkm::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::RemoveUnusedPoints::MaskArray
vtkm::cont::ArrayHandle< vtkm::IdComponent > MaskArray
Definition: RemoveUnusedPoints.h:274
DispatcherMapField.h
ScatterCounting.h
vtkm::worklet::RemoveUnusedPoints::MapCellSet
static VTKM_CONT vtkm::cont::CellSetExplicit< ShapeStorage, VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG, OffsetsStorage > MapCellSet(const vtkm::cont::CellSetExplicit< ShapeStorage, ConnectivityStorage, OffsetsStorage > &inCellSet, const vtkm::cont::ArrayHandle< vtkm::Id, MapStorage > &inputToOutputPointMap, vtkm::Id numberOfPoints)
Map cell indices.
Definition: RemoveUnusedPoints.h:157
vtkm::worklet::RemoveUnusedPoints::RemoveUnusedPoints
VTKM_CONT RemoveUnusedPoints(const vtkm::cont::CellSetExplicit< ShapeStorage, ConnectivityStorage, OffsetsStorage > &inCellSet)
Definition: RemoveUnusedPoints.h:76
vtkm::worklet::ScatterCounting
A scatter that maps input to some numbers of output.
Definition: ScatterCounting.h:44
vtkm::cont::CellSetExplicit::GetOffsetsArray
const VTKM_CONT ConnectivityChooser< VisitTopology, IncidentTopology >::OffsetsArrayType & GetOffsetsArray(VisitTopology, IncidentTopology) const
vtkm::worklet::RemoveUnusedPoints::GeneratePointMask::ControlSignature
void(FieldIn pointIndices, WholeArrayInOut pointMask) ControlSignature
Definition: RemoveUnusedPoints.h:44
UnknownArrayHandle.h
vtkm::worklet::DispatcherMapField
Dispatcher for worklets that inherit from WorkletMapField.
Definition: DispatcherMapField.h:25
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeepFunctor::operator()
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle< InT, InS > &inArray, vtkm::cont::ArrayHandle< OutT, OutS > &outArray, const RemoveUnusedPoints &self) const
Definition: RemoveUnusedPoints.h:207
vtkm::worklet::RemoveUnusedPoints::TransformPointIndices::operator()
VTKM_EXEC vtkm::Id operator()(vtkm::Id pointIndex, const IndexMapPortalType &indexPortal) const
Definition: RemoveUnusedPoints.h:65
ArrayCopyDevice.h
ArrayHandlePermutation.h
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeep
VTKM_CONT vtkm::cont::UncertainArrayHandle< InValueTypes, InStorageTypes > MapPointFieldDeep(const vtkm::cont::UncertainArrayHandle< InValueTypes, InStorageTypes > &inArray) const
Maps a point field from the original points to the new reduced points.
Definition: RemoveUnusedPoints.h:262
vtkm::worklet::RemoveUnusedPoints::FindPointsStart
VTKM_CONT void FindPointsStart()
Get this class ready for identifying the points used by cell sets.
Definition: RemoveUnusedPoints.h:86
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::RemoveUnusedPoints
A collection of worklets used to identify which points are used by at least one cell and then remove ...
Definition: RemoveUnusedPoints.h:34
VTKM_IS_ARRAY_HANDLE
#define VTKM_IS_ARRAY_HANDLE(T)
Definition: ArrayHandle.h:132
vtkm::cont::ArrayHandlePermutation
Implicitly permutes the values in an array.
Definition: ArrayHandlePermutation.h:227
vtkm::worklet::RemoveUnusedPoints::MapPointFieldShallow
VTKM_CONT vtkm::cont::ArrayHandlePermutation< vtkm::cont::ArrayHandle< vtkm::Id >, InArrayHandle > MapPointFieldShallow(const InArrayHandle &inArray) const
Maps a point field from the original points to the new reduced points.
Definition: RemoveUnusedPoints.h:194
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::RemoveUnusedPoints::GeneratePointMask::operator()
VTKM_EXEC void operator()(vtkm::Id pointIndex, const PointMaskPortalType &pointMask) const
Definition: RemoveUnusedPoints.h:48
vtkm::cont::CellSetExplicit::Fill
VTKM_CONT void Fill(vtkm::Id numPoints, const vtkm::cont::ArrayHandle< vtkm::UInt8, ShapesStorageTag > &cellTypes, const vtkm::cont::ArrayHandle< vtkm::Id, ConnectivityStorageTag > &connectivity, const vtkm::cont::ArrayHandle< vtkm::Id, OffsetsStorageTag > &offsets)
Second method to add cells – all at once.
VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
#define VTKM_DEFAULT_CONNECTIVITY_STORAGE_TAG
Definition: CellSetExplicit.h:62
vtkm::worklet::RemoveUnusedPoints::FindPoints
VTKM_CONT void FindPoints(const vtkm::cont::CellSetExplicit< ShapeStorage, ConnectivityStorage, OffsetsStorage > &inCellSet)
Analyze the given cell set to find all points that are used.
Definition: RemoveUnusedPoints.h:93
vtkm::cont::make_ArrayHandlePermutation
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::cont::CellSetExplicit::GetNumberOfPoints
VTKM_CONT vtkm::Id GetNumberOfPoints() const override
vtkm::worklet::RemoveUnusedPoints::GeneratePointMask
A worklet that creates a mask of used points (the first step in removing unused points).
Definition: RemoveUnusedPoints.h:42
vtkm::cont::UncertainArrayHandle
An ArrayHandle of an uncertain value type and storage.
Definition: UncertainArrayHandle.h:39
vtkm::worklet::RemoveUnusedPoints::FindPointsEnd
VTKM_CONT void FindPointsEnd()
Compile the information collected from calls to FindPointsInCellSet to ready this class for mapping c...
Definition: RemoveUnusedPoints.h:112
vtkm::cont::CellSetExplicit::GetShapesArray
const VTKM_CONT ConnectivityChooser< VisitTopology, IncidentTopology >::ShapesArrayType & GetShapesArray(VisitTopology, IncidentTopology) const
vtkm::worklet::RemoveUnusedPoints::PointScatter
std::shared_ptr< vtkm::worklet::ScatterCounting > PointScatter
Manages how the original point indices map to the new point indices.
Definition: RemoveUnusedPoints.h:278
vtkm::cont::CellSetExplicit
Definition: CastAndCall.h:36
vtkm::worklet::RemoveUnusedPoints::RemoveUnusedPoints
VTKM_CONT RemoveUnusedPoints()=default
vtkm::TopologyElementTagCell
A tag used to identify the cell elements in a topology.
Definition: TopologyElementTag.h:24
vtkm::worklet::RemoveUnusedPoints::TransformPointIndices
A worklet that takes an array of point indices (taken from the connectivity of a CellSetExplicit) and...
Definition: RemoveUnusedPoints.h:59
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeepFunctor
Definition: RemoveUnusedPoints.h:204
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeep
VTKM_CONT void MapPointFieldDeep(const vtkm::cont::UncertainArrayHandle< InValueTypes, InStorageTypes > &inArray, OutArrayHandle &outArray) const
Maps a point field from the original points to the new reduced points.
Definition: RemoveUnusedPoints.h:254
vtkm::cont::ArrayHandle::ReleaseResources
VTKM_CONT void ReleaseResources() const
Releases all resources in both the control and execution environments.
Definition: ArrayHandle.h:559
vtkm::cont::CellSetExplicit::GetConnectivityArray
const VTKM_CONT ConnectivityChooser< VisitTopology, IncidentTopology >::ConnectivityArrayType & GetConnectivityArray(VisitTopology, IncidentTopology) const
vtkm::worklet::RemoveUnusedPoints::TransformPointIndices::ExecutionSignature
_3(_1, _2) ExecutionSignature
Definition: RemoveUnusedPoints.h:62
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::RemoveUnusedPoints::MapPointFieldDeepFunctor::operator()
VTKM_CONT void operator()(const vtkm::cont::ArrayHandle< InT, InS > &inArray, vtkm::cont::UnknownArrayHandle &outHolder, const RemoveUnusedPoints &self) const
Definition: RemoveUnusedPoints.h:215