VTK-m  2.0
worklet/PointElevation.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 
11 #ifndef vtk_m_worklet_PointElevation_h
12 #define vtk_m_worklet_PointElevation_h
13 
15 
16 #include <vtkm/Math.h>
17 
18 namespace vtkm
19 {
20 namespace worklet
21 {
22 
23 namespace internal
24 {
25 
26 template <typename T>
27 VTKM_EXEC T clamp(const T& val, const T& min, const T& max)
28 {
29  return vtkm::Min(max, vtkm::Max(min, val));
30 }
31 }
32 
34 {
35 public:
37  using ExecutionSignature = _2(_1);
38 
39  VTKM_CONT
41  const vtkm::Vec3f_64& hp,
42  vtkm::Float64 low,
43  vtkm::Float64 hi)
44  : LowPoint(lp)
45  , HighPoint(hp)
46  , RangeLow(low)
47  , RangeHigh(hi)
48  {
49  }
50 
51  VTKM_EXEC
53  {
54  vtkm::Vec3f_64 direction = this->HighPoint - this->LowPoint;
55  vtkm::Float64 lengthSqr = vtkm::Dot(direction, direction);
56  vtkm::Float64 rangeLength = this->RangeHigh - this->RangeLow;
57  vtkm::Float64 s = vtkm::Dot(vec - this->LowPoint, direction) / lengthSqr;
58  s = internal::clamp(s, 0.0, 1.0);
59  return this->RangeLow + (s * rangeLength);
60  }
61 
62  template <typename T>
64  {
65  return (*this)(vtkm::make_Vec(static_cast<vtkm::Float64>(vec[0]),
66  static_cast<vtkm::Float64>(vec[1]),
67  static_cast<vtkm::Float64>(vec[2])));
68  }
69 
70 private:
73 };
74 }
75 } // namespace vtkm::worklet
76 
77 #endif // vtk_m_worklet_PointElevation_h
VTKM_EXEC
#define VTKM_EXEC
Definition: ExportMacros.h:51
vtkm
Groups connected points that have the same field value.
Definition: Atomic.h:19
WorkletMapField.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::PointElevation::RangeHigh
const vtkm::Float64 RangeHigh
Definition: worklet/PointElevation.h:72
vtkm::worklet::PointElevation::ControlSignature
void(FieldIn, FieldOut) ControlSignature
Definition: worklet/PointElevation.h:36
vtkm::worklet::PointElevation::RangeLow
const vtkm::Float64 RangeLow
Definition: worklet/PointElevation.h:72
vtkm::worklet::PointElevation::operator()
VTKM_EXEC vtkm::Float64 operator()(const vtkm::Vec< T, 3 > &vec) const
Definition: worklet/PointElevation.h:63
Math.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::PointElevation
Definition: worklet/PointElevation.h:33
VTKM_CONT
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::worklet::PointElevation::HighPoint
const vtkm::Vec3f_64 HighPoint
Definition: worklet/PointElevation.h:71
vtkm::worklet::PointElevation::PointElevation
VTKM_CONT PointElevation(const vtkm::Vec3f_64 &lp, const vtkm::Vec3f_64 &hp, vtkm::Float64 low, vtkm::Float64 hi)
Definition: worklet/PointElevation.h:40
vtkm::worklet::PointElevation::operator()
VTKM_EXEC vtkm::Float64 operator()(const vtkm::Vec3f_64 &vec) const
Definition: worklet/PointElevation.h:52
vtkm::make_Vec
constexpr VTKM_EXEC_CONT vtkm::Vec< T, vtkm::IdComponent(sizeof...(Ts)+1)> make_Vec(T value0, Ts &&... args)
Initializes and returns a Vec containing all the arguments.
Definition: Types.h:1212
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::Vec< vtkm::Float64, 3 >
vtkm::Float64
double Float64
Definition: Types.h:155
vtkm::worklet::PointElevation::ExecutionSignature
_2(_1) ExecutionSignature
Definition: worklet/PointElevation.h:37
vtkm::worklet::PointElevation::LowPoint
const vtkm::Vec3f_64 LowPoint
Definition: worklet/PointElevation.h:71
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38