VTK-m  2.0
worklet/Probe.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_Probe_h
11 #define vtk_m_worklet_Probe_h
12 
13 #include <vtkm/cont/ArrayCopy.h>
14 #include <vtkm/cont/ArrayHandle.h>
16 #include <vtkm/cont/Invoker.h>
17 #include <vtkm/exec/CellInside.h>
20 
23 
25 
26 namespace vtkm
27 {
28 namespace worklet
29 {
30 
31 class Probe
32 {
33  //============================================================================
34 public:
36  {
37  public:
38  using ControlSignature = void(FieldIn points,
39  ExecObject locator,
40  FieldOut cellIds,
41  FieldOut pcoords);
42  using ExecutionSignature = void(_1, _2, _3, _4);
43 
44  template <typename LocatorType>
45  VTKM_EXEC void operator()(const vtkm::Vec3f& point,
46  const LocatorType& locator,
47  vtkm::Id& cellId,
48  vtkm::Vec3f& pcoords) const
49  {
50  locator.FindCell(point, cellId, pcoords);
51  }
52  };
53 
54 private:
56  {
57  template <typename LocatorType, typename PointsType>
58  void operator()(const LocatorType& locator, Probe& worklet, const PointsType& points) const
59  {
60  worklet.Invoke(
61  FindCellWorklet{}, points, locator, worklet.CellIds, worklet.ParametricCoordinates);
62  }
63  };
64 
65  template <typename CellSetType, typename PointsType, typename PointsStorage>
66  void RunImpl(const CellSetType& cells,
67  const vtkm::cont::CoordinateSystem& coords,
69  {
71 
72  vtkm::cont::CastAndCallCellLocatorChooser(cells, coords, RunSelectLocator{}, *this, points);
73  }
74 
75  //============================================================================
76 public:
78  {
79  public:
80  using ControlSignature = void(CellSetIn cellset,
81  FieldInPoint coords,
82  WholeArrayIn points,
83  WholeArrayInOut cellIds,
84  WholeArrayOut parametricCoords);
85  using ExecutionSignature = void(InputIndex, CellShape, _2, _3, _4, _5);
86  using InputDomain = _1;
87 
88  template <typename CellShapeTag,
89  typename CoordsVecType,
90  typename UniformPoints,
91  typename CellIdsType,
92  typename ParametricCoordsType>
94  CellShapeTag cellShape,
95  const CoordsVecType& cellPoints,
96  const UniformPoints& points,
97  CellIdsType& cellIds,
98  ParametricCoordsType& pcoords) const
99  {
100  // Compute cell bounds
101  using CoordsType = typename vtkm::VecTraits<CoordsVecType>::ComponentType;
102  auto numPoints = vtkm::VecTraits<CoordsVecType>::GetNumberOfComponents(cellPoints);
103 
104  CoordsType cbmin = cellPoints[0], cbmax = cellPoints[0];
105  for (vtkm::IdComponent i = 1; i < numPoints; ++i)
106  {
107  cbmin = vtkm::Min(cbmin, cellPoints[i]);
108  cbmax = vtkm::Max(cbmax, cellPoints[i]);
109  }
110 
111  // Compute points inside cell bounds
112  auto minp =
113  static_cast<vtkm::Id3>(vtkm::Ceil((cbmin - points.GetOrigin()) / points.GetSpacing()));
114  auto maxp =
115  static_cast<vtkm::Id3>(vtkm::Floor((cbmax - points.GetOrigin()) / points.GetSpacing()));
116 
117  // clamp
118  minp = vtkm::Max(minp, vtkm::Id3(0));
119  maxp = vtkm::Min(maxp, points.GetDimensions() - vtkm::Id3(1));
120 
121  for (vtkm::Id k = minp[2]; k <= maxp[2]; ++k)
122  {
123  for (vtkm::Id j = minp[1]; j <= maxp[1]; ++j)
124  {
125  for (vtkm::Id i = minp[0]; i <= maxp[0]; ++i)
126  {
127  auto pt = points.Get(vtkm::Id3(i, j, k));
128  CoordsType pc;
129  vtkm::ErrorCode status =
130  vtkm::exec::WorldCoordinatesToParametricCoordinates(cellPoints, pt, cellShape, pc);
131  if ((status == vtkm::ErrorCode::Success) && vtkm::exec::CellInside(pc, cellShape))
132  {
133  auto pointId = i + points.GetDimensions()[0] * (j + points.GetDimensions()[1] * k);
134  cellIds.Set(pointId, cellId);
135  pcoords.Set(pointId, pc);
136  }
137  }
138  }
139  }
140  }
141  };
142 
143 private:
144  template <typename CellSetType>
145  void RunImpl(const CellSetType& cells,
146  const vtkm::cont::CoordinateSystem& coords,
147  const vtkm::cont::ArrayHandleUniformPointCoordinates::Superclass& points)
148  {
151  vtkm::cont::make_ArrayHandleConstant(vtkm::Id(-1), points.GetNumberOfValues()),
152  this->CellIds);
153  this->ParametricCoordinates.Allocate(points.GetNumberOfValues());
154 
155  this->Invoke(
156  ProbeUniformPoints{}, cells, coords, points, this->CellIds, this->ParametricCoordinates);
157  }
158 
159  //============================================================================
161  {
162  template <typename PointsArrayType, typename CellSetType>
163  void operator()(const PointsArrayType& points,
164  Probe& worklet,
165  const CellSetType& cells,
166  const vtkm::cont::CoordinateSystem& coords) const
167  {
168  worklet.RunImpl(cells, coords, points);
169  }
170  };
171 
172 public:
173  template <typename CellSetType, typename PointsArrayType>
174  void Run(const CellSetType& cells,
175  const vtkm::cont::CoordinateSystem& coords,
176  const PointsArrayType& points)
177  {
178  vtkm::cont::CastAndCall(points, RunImplCaller(), *this, cells, coords);
179  }
180 
181  //============================================================================
182  template <typename T>
184  {
185  public:
187  InterpolatePointField(const T& invalidValue)
188  : InvalidValue(invalidValue)
189  {
190  }
191 
192  using ControlSignature = void(FieldIn cellIds,
193  FieldIn parametricCoords,
194  WholeCellSetIn<> inputCells,
195  WholeArrayIn inputField,
196  FieldOut result);
197  using ExecutionSignature = void(_1, _2, _3, _4, _5);
198 
199  template <typename ParametricCoordType, typename CellSetType, typename InputFieldPortalType>
201  const ParametricCoordType& pc,
202  const CellSetType& cells,
203  const InputFieldPortalType& in,
204  typename InputFieldPortalType::ValueType& out) const
205  {
206  if (cellId != -1)
207  {
208  auto indices = cells.GetIndices(cellId);
209  auto pointVals = vtkm::make_VecFromPortalPermute(&indices, in);
210  vtkm::exec::CellInterpolate(pointVals, pc, cells.GetCellShape(cellId), out);
211  }
212  else
213  {
214  out = this->InvalidValue;
215  }
216  }
217  };
218 
220  template <typename T,
221  typename Storage,
222  typename InputCellSetTypeList = VTKM_DEFAULT_CELL_SET_LIST>
225  const T& invalidValue,
226  InputCellSetTypeList icsTypes = InputCellSetTypeList()) const
227  {
229  vtkm::cont::Invoker invoke;
230  invoke(InterpolatePointField<T>(invalidValue),
231  this->CellIds,
232  this->ParametricCoordinates,
233  this->InputCellSet.ResetCellSetList(icsTypes),
234  field,
235  result);
236 
237  return result;
238  }
239 
241 
242  //============================================================================
244  {
245  using ControlSignature = void(FieldIn cellids, FieldOut hfield);
246  using ExecutionSignature = _2(_1);
247 
248  VTKM_EXEC vtkm::UInt8 operator()(vtkm::Id cellId) const { return (cellId == -1) ? HIDDEN : 0; }
249  };
250 
255  {
257  this->Invoke(HiddenPointsWorklet{}, this->CellIds, field);
258  return field;
259  }
260 
261  //============================================================================
263  {
264  using ControlSignature = void(CellSetIn cellset, FieldInPoint cellids, FieldOutCell);
266 
267  template <typename CellIdsVecType>
268  VTKM_EXEC vtkm::UInt8 operator()(const CellIdsVecType& cellIds,
269  vtkm::IdComponent numPoints) const
270  {
271  for (vtkm::IdComponent i = 0; i < numPoints; ++i)
272  {
273  if (cellIds[i] == -1)
274  {
275  return HIDDEN;
276  }
277  }
278  return 0;
279  }
280  };
281 
285  template <typename CellSetType>
287  {
289  this->Invoke(HiddenCellsWorklet{}, cellset, this->CellIds, field);
290  return field;
291  }
292 
293  //============================================================================
294 private:
295  static constexpr vtkm::UInt8 HIDDEN = 2; // from vtk
296 
300 
302 };
303 }
304 } // vtkm::worklet
305 
306 #endif // vtk_m_worklet_Probe_h
vtkm::worklet::Probe::FindCellWorklet::ExecutionSignature
void(_1, _2, _3, _4) ExecutionSignature
Definition: worklet/Probe.h:42
vtkm::worklet::Probe::ProcessPointField
vtkm::cont::ArrayHandle< T > ProcessPointField(const vtkm::cont::ArrayHandle< T, Storage > &field, const T &invalidValue, InputCellSetTypeList icsTypes=InputCellSetTypeList()) const
Intepolate the input point field data at the points of the geometry.
Definition: worklet/Probe.h:223
vtkm::cont::ArrayHandle
Manages an array-worth of data.
Definition: ArrayHandle.h:283
ArrayHandle.h
vtkm::ErrorCode
ErrorCode
Definition: ErrorCode.h:19
vtkm::worklet::Probe::GetCellIds
vtkm::cont::ArrayHandle< vtkm::Id > GetCellIds() const
Definition: worklet/Probe.h:240
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::Probe::RunImplCaller
Definition: worklet/Probe.h:160
vtkm::make_VecFromPortalPermute
VTKM_EXEC VecFromPortalPermute< IndexVecType, PortalType > make_VecFromPortalPermute(const IndexVecType *index, const PortalType &portal)
Definition: VecFromPortalPermute.h:166
vtkm::Ceil
VTKM_EXEC_CONT vtkm::Float32 Ceil(vtkm::Float32 x)
Round x to the smallest integer value not less than x.
Definition: Math.h:2145
vtkm::worklet::Probe::InterpolatePointField::ControlSignature
void(FieldIn cellIds, FieldIn parametricCoords, WholeCellSetIn<> inputCells, WholeArrayIn inputField, FieldOut result) ControlSignature
Definition: worklet/Probe.h:196
vtkm::worklet::Probe::ProbeUniformPoints
Definition: worklet/Probe.h:77
vtkm::worklet::Probe::RunSelectLocator::operator()
void operator()(const LocatorType &locator, Probe &worklet, const PointsType &points) const
Definition: worklet/Probe.h:58
WorkletMapField.h
vtkm::cont::ArrayHandle::Allocate
VTKM_CONT void Allocate(vtkm::Id numberOfValues, vtkm::CopyFlag preserve, vtkm::cont::Token &token) const
Allocates an array large enough to hold the given number of values.
Definition: ArrayHandle.h:465
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::WorkletVisitCellsWithPoints::PointCount
IncidentElementCount PointCount
Definition: WorkletMapTopology.h:267
vtkm::worklet::Probe::InterpolatePointField::InvalidValue
T InvalidValue
Definition: worklet/Probe.h:186
vtkm::IdComponent
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
vtkm::ErrorCode::Success
@ Success
vtkm::cont::UnknownCellSet::ResetCellSetList
VTKM_CONT vtkm::cont::UncertainCellSet< CellSetList > ResetCellSetList(CellSetList) const
Assigns potential cell set types.
vtkm::worklet::Probe::HiddenCellsWorklet::ExecutionSignature
_3(_2, PointCount) ExecutionSignature
Definition: worklet/Probe.h:265
vtkm::worklet::Probe::FindCellWorklet
Definition: worklet/Probe.h:35
vtkm::cont::make_ArrayHandleConstant
vtkm::cont::ArrayHandleConstant< T > make_ArrayHandleConstant(T value, vtkm::Id numberOfValues)
make_ArrayHandleConstant is convenience function to generate an ArrayHandleImplicit.
Definition: ArrayHandleConstant.h:89
vtkm::worklet::Probe::InterpolatePointField::ExecutionSignature
void(_1, _2, _3, _4, _5) ExecutionSignature
Definition: worklet/Probe.h:197
CellInterpolate.h
vtkm::worklet::Probe::InterpolatePointField::operator()
VTKM_EXEC void operator()(vtkm::Id cellId, const ParametricCoordType &pc, const CellSetType &cells, const InputFieldPortalType &in, typename InputFieldPortalType::ValueType &out) const
Definition: worklet/Probe.h:200
Invoker.h
vtkm::worklet::Probe::CellIds
vtkm::cont::ArrayHandle< vtkm::Id > CellIds
Definition: worklet/Probe.h:297
vtkm::cont::UnknownCellSet
A CellSet of an unknown type.
Definition: UnknownCellSet.h:48
vtkm::worklet::Probe::Invoke
vtkm::cont::Invoker Invoke
Definition: worklet/Probe.h:301
vtkm::cont::CastAndCall
void CastAndCall(const DynamicObject &dynamicObject, Functor &&f, Args &&... args)
A Generic interface to CastAndCall.
Definition: CastAndCall.h:47
vtkm::worklet::Probe::HiddenPointsWorklet::operator()
VTKM_EXEC vtkm::UInt8 operator()(vtkm::Id cellId) const
Definition: worklet/Probe.h:248
vtkm::worklet::Probe::HIDDEN
static constexpr vtkm::UInt8 HIDDEN
Definition: worklet/Probe.h:295
vtkm::Id
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
vtkm::worklet::Probe::FindCellWorklet::operator()
VTKM_EXEC void operator()(const vtkm::Vec3f &point, const LocatorType &locator, vtkm::Id &cellId, vtkm::Vec3f &pcoords) const
Definition: worklet/Probe.h:45
VecFromPortalPermute.h
ArrayCopy.h
CellLocatorChooser.h
vtkm::worklet::Probe::InterpolatePointField
Definition: worklet/Probe.h:183
vtkm::cont::CoordinateSystem
Definition: CoordinateSystem.h:25
vtkm::worklet::Probe::ParametricCoordinates
vtkm::cont::ArrayHandle< vtkm::Vec3f > ParametricCoordinates
Definition: worklet/Probe.h:298
vtkm::Floor
VTKM_EXEC_CONT vtkm::Float32 Floor(vtkm::Float32 x)
Round x to the largest integer value not greater than x.
Definition: Math.h:2204
vtkm::worklet::Probe::HiddenPointsWorklet::ExecutionSignature
_2(_1) ExecutionSignature
Definition: worklet/Probe.h:246
vtkm::worklet::Probe::FindCellWorklet::ControlSignature
void(FieldIn points, ExecObject locator, FieldOut cellIds, FieldOut pcoords) ControlSignature
Definition: worklet/Probe.h:41
vtkm::worklet::Probe::HiddenCellsWorklet
Definition: worklet/Probe.h:262
vtkm::cont::CastAndCallCellLocatorChooser
VTKM_CONT void CastAndCallCellLocatorChooser(const CellSetType &cellSet, const vtkm::cont::CoordinateSystem &coordinateSystem, Functor &&functor, Args &&... args)
Calls a functor with the appropriate type of CellLocator.
Definition: CellLocatorChooser.h:130
CellInside.h
vtkm::worklet::Probe::Run
void Run(const CellSetType &cells, const vtkm::cont::CoordinateSystem &coords, const PointsArrayType &points)
Definition: worklet/Probe.h:174
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::Probe::HiddenPointsWorklet::ControlSignature
void(FieldIn cellids, FieldOut hfield) ControlSignature
Definition: worklet/Probe.h:245
vtkm::worklet::Probe::GetHiddenPointsField
vtkm::cont::ArrayHandle< vtkm::UInt8 > GetHiddenPointsField() const
Get an array of flags marking the invalid points (points that do not fall inside any of the cells of ...
Definition: worklet/Probe.h:254
vtkm::worklet::Probe::RunImpl
void RunImpl(const CellSetType &cells, const vtkm::cont::CoordinateSystem &coords, const vtkm::cont::ArrayHandle< PointsType, PointsStorage > &points)
Definition: worklet/Probe.h:66
vtkm::cont::Invoker
Allows launching any worklet without a dispatcher.
Definition: Invoker.h:41
vtkm::worklet::WorkletVisitCellsWithPoints
Base class for worklets that map from Points to Cells.
Definition: WorkletMapTopology.h:255
vtkm::cont::ArrayCopy
void ArrayCopy(const SourceArrayType &source, DestArrayType &destination)
Does a deep copy from one array to another array.
Definition: ArrayCopy.h:142
vtkm::worklet::Probe::GetHiddenCellsField
vtkm::cont::ArrayHandle< vtkm::UInt8 > GetHiddenCellsField(CellSetType cellset) const
Get an array of flags marking the invalid cells.
Definition: worklet/Probe.h:286
vtkm::worklet::Probe::ProbeUniformPoints::ControlSignature
void(CellSetIn cellset, FieldInPoint coords, WholeArrayIn points, WholeArrayInOut cellIds, WholeArrayOut parametricCoords) ControlSignature
Definition: worklet/Probe.h:84
vtkm::worklet::Probe::HiddenCellsWorklet::ControlSignature
void(CellSetIn cellset, FieldInPoint cellids, FieldOutCell) ControlSignature
Definition: worklet/Probe.h:264
vtkm::worklet::WorkletVisitCellsWithPoints::FieldInPoint
FieldInIncident FieldInPoint
Definition: WorkletMapTopology.h:259
vtkm::exec::CellInterpolate
VTKM_EXEC vtkm::ErrorCode CellInterpolate(const FieldVecType &pointFieldValues, const vtkm::Vec< ParametricCoordType, 3 > &pcoords, CellShapeTag tag, typename FieldVecType::ComponentType &result)
Definition: CellInterpolate.h:56
vtkm::worklet::Probe
Definition: worklet/Probe.h:31
vtkm::UInt8
uint8_t UInt8
Definition: Types.h:157
vtkm::worklet::Probe::HiddenCellsWorklet::operator()
VTKM_EXEC vtkm::UInt8 operator()(const CellIdsVecType &cellIds, vtkm::IdComponent numPoints) const
Definition: worklet/Probe.h:268
vtkm::worklet::Probe::HiddenPointsWorklet
Definition: worklet/Probe.h:243
vtkm::worklet::Probe::RunSelectLocator
Definition: worklet/Probe.h:55
vtkm::Vec< vtkm::FloatDefault, 3 >
vtkm::worklet::Probe::InterpolatePointField::InterpolatePointField
InterpolatePointField(const T &invalidValue)
Definition: worklet/Probe.h:187
vtkm::worklet::Probe::ProbeUniformPoints::operator()
VTKM_EXEC void operator()(vtkm::Id cellId, CellShapeTag cellShape, const CoordsVecType &cellPoints, const UniformPoints &points, CellIdsType &cellIds, ParametricCoordsType &pcoords) const
Definition: worklet/Probe.h:93
vtkm::worklet::Probe::ProbeUniformPoints::ExecutionSignature
void(InputIndex, CellShape, _2, _3, _4, _5) ExecutionSignature
Definition: worklet/Probe.h:85
vtkm::VecTraits::ComponentType
typename VecType::ComponentType ComponentType
Type of the components in the vector.
Definition: VecTraits.h:73
vtkm::worklet::Probe::RunImpl
void RunImpl(const CellSetType &cells, const vtkm::cont::CoordinateSystem &coords, const vtkm::cont::ArrayHandleUniformPointCoordinates::Superclass &points)
Definition: worklet/Probe.h:145
vtkm::worklet::Probe::InputCellSet
vtkm::cont::UnknownCellSet InputCellSet
Definition: worklet/Probe.h:299
vtkm::worklet::Probe::ProbeUniformPoints::InputDomain
_1 InputDomain
Definition: worklet/Probe.h:86
WorkletMapTopology.h
vtkm::exec::arg::InputIndex
The ExecutionSignature tag to use to get the input index.
Definition: InputIndex.h:42
ParametricCoordinates.h
vtkm::VecTraits::GetNumberOfComponents
static vtkm::IdComponent GetNumberOfComponents(const VecType &vec)
Number of components in the given vector.
vtkm::worklet::Probe::RunImplCaller::operator()
void operator()(const PointsArrayType &points, Probe &worklet, const CellSetType &cells, const vtkm::cont::CoordinateSystem &coords) const
Definition: worklet/Probe.h:163
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38
vtkm::worklet::WorkletVisitCellsWithPoints::FieldOutCell
FieldOut FieldOutCell
Definition: WorkletMapTopology.h:263