VTK-m  2.0
CoordinateSystemTransform.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_CoordinateSystemTransform_h
12 #define vtk_m_worklet_CoordinateSystemTransform_h
13 
14 #include <vtkm/Math.h>
16 
17 namespace vtkm
18 {
19 namespace worklet
20 {
22 {
24  using ExecutionSignature = _2(_1);
25 
26  //Functor
27  template <typename T>
29  {
30  vtkm::Vec<T, 3> res(vec[0] * static_cast<T>(vtkm::Cos(vec[1])),
31  vec[0] * static_cast<T>(vtkm::Sin(vec[1])),
32  vec[2]);
33  return res;
34  }
35 };
36 
38 {
40  using ExecutionSignature = _2(_1);
41 
42  //Functor
43  template <typename T>
45  {
46  T R = vtkm::Sqrt(vec[0] * vec[0] + vec[1] * vec[1]);
47  T Theta = 0;
48 
49  if (vec[0] == 0 && vec[1] == 0)
50  Theta = 0;
51  else if (vec[0] < 0)
52  Theta = -vtkm::ASin(vec[1] / R) + static_cast<T>(vtkm::Pi());
53  else
54  Theta = vtkm::ASin(vec[1] / R);
55 
56  vtkm::Vec<T, 3> res(R, Theta, vec[2]);
57  return res;
58  }
59 };
60 
62 {
64  using ExecutionSignature = _2(_1);
65 
66  //Functor
67  template <typename T>
69  {
70  T R = vec[0];
71  T Theta = vec[1];
72  T Phi = vec[2];
73 
74  T sinTheta = static_cast<T>(vtkm::Sin(Theta));
75  T cosTheta = static_cast<T>(vtkm::Cos(Theta));
76  T sinPhi = static_cast<T>(vtkm::Sin(Phi));
77  T cosPhi = static_cast<T>(vtkm::Cos(Phi));
78 
79  T x = R * sinTheta * cosPhi;
80  T y = R * sinTheta * sinPhi;
81  T z = R * cosTheta;
82 
83  vtkm::Vec<T, 3> r(x, y, z);
84  return r;
85  }
86 };
87 
89 {
91  using ExecutionSignature = _2(_1);
92 
93  //Functor
94  template <typename T>
96  {
97  T R = vtkm::Sqrt(vtkm::Dot(vec, vec));
98  T Theta = 0;
99  if (R > 0)
100  Theta = vtkm::ACos(vec[2] / R);
101  T Phi = vtkm::ATan2(vec[1], vec[0]);
102  if (Phi < 0)
103  Phi += static_cast<T>(vtkm::TwoPi());
104 
105  return vtkm::Vec<T, 3>(R, Theta, Phi);
106  }
107 };
108 }
109 } // namespace vtkm::worklet
110 
111 #endif // vtk_m_worklet_CoordinateSystemTransform_h
vtkm::Sqrt
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
vtkm::worklet::SphereToCar
Definition: CoordinateSystemTransform.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::Cos
VTKM_EXEC_CONT vtkm::Float32 Cos(vtkm::Float32 x)
Compute the cosine of x.
Definition: Math.h:269
vtkm::worklet::CarToSphere
Definition: CoordinateSystemTransform.h:88
WorkletMapField.h
vtkm::worklet::WorkletMapField::FieldOut
A control signature tag for output fields.
Definition: WorkletMapField.h:60
vtkm::worklet::CylToCar
Definition: CoordinateSystemTransform.h:21
vtkm::worklet::SphereToCar::operator()
VTKM_EXEC vtkm::Vec< T, 3 > operator()(const vtkm::Vec< T, 3 > &vec) const
Definition: CoordinateSystemTransform.h:68
vtkm::worklet::CarToCyl::operator()
VTKM_EXEC vtkm::Vec< T, 3 > operator()(const vtkm::Vec< T, 3 > &vec) const
Definition: CoordinateSystemTransform.h:44
vtkm::worklet::CarToSphere::ExecutionSignature
_2(_1) ExecutionSignature
Definition: CoordinateSystemTransform.h:91
vtkm::Sin
VTKM_EXEC_CONT vtkm::Float32 Sin(vtkm::Float32 x)
Compute the sine of x.
Definition: Math.h:210
vtkm::worklet::CarToSphere::ControlSignature
void(FieldIn, FieldOut) ControlSignature
Definition: CoordinateSystemTransform.h:90
vtkm::ASin
VTKM_EXEC_CONT vtkm::Float32 ASin(vtkm::Float32 x)
Compute the arc sine of x.
Definition: Math.h:387
vtkm::worklet::CylToCar::operator()
VTKM_EXEC vtkm::Vec< T, 3 > operator()(const vtkm::Vec< T, 3 > &vec) const
Definition: CoordinateSystemTransform.h:28
Math.h
vtkm::worklet::WorkletMapField::FieldIn
A control signature tag for input fields.
Definition: WorkletMapField.h:49
vtkm::worklet::CylToCar::ControlSignature
void(FieldIn, FieldOut) ControlSignature
Definition: CoordinateSystemTransform.h:23
vtkm::worklet::CarToCyl::ControlSignature
void(FieldIn, FieldOut) ControlSignature
Definition: CoordinateSystemTransform.h:39
vtkm::worklet::CylToCar::ExecutionSignature
_2(_1) ExecutionSignature
Definition: CoordinateSystemTransform.h:24
vtkm::worklet::CarToCyl
Definition: CoordinateSystemTransform.h:37
vtkm::worklet::CarToCyl::ExecutionSignature
_2(_1) ExecutionSignature
Definition: CoordinateSystemTransform.h:40
vtkm::Vec< T, 3 >
Definition: Types.h:975
vtkm::worklet::CarToSphere::operator()
VTKM_EXEC vtkm::Vec< T, 3 > operator()(const vtkm::Vec< T, 3 > &vec) const
Definition: CoordinateSystemTransform.h:95
vtkm::ACos
VTKM_EXEC_CONT vtkm::Float32 ACos(vtkm::Float32 x)
Compute the arc cosine of x.
Definition: Math.h:446
vtkm::worklet::SphereToCar::ExecutionSignature
_2(_1) ExecutionSignature
Definition: CoordinateSystemTransform.h:64
vtkm::worklet::SphereToCar::ControlSignature
void(FieldIn, FieldOut) ControlSignature
Definition: CoordinateSystemTransform.h:63
vtkm::worklet::WorkletMapField
Base class for worklets that do a simple mapping of field arrays.
Definition: WorkletMapField.h:38