Go to the documentation of this file.
10 #ifndef vtk_m_ImplicitFunction_h
11 #define vtk_m_ImplicitFunction_h
38 template <
typename Derived>
47 return reinterpret_cast<const Derived*
>(
this)->Value(Vector(x, y, z));
52 return reinterpret_cast<const Derived*
>(
this)->Gradient(Vector(x, y, z));
57 return *
reinterpret_cast<const Derived*
>(
this);
60 VTKM_CONT Derived PrepareForControl()
const {
return *
reinterpret_cast<const Derived*
>(
this); }
70 template <
typename FunctionType>
74 using Scalar =
typename FunctionType::Scalar;
75 using Vector =
typename FunctionType::Vector;
80 const vtkm::internal::ImplicitFunctionBase<FunctionType>&
function)
81 :
Function(reinterpret_cast<const FunctionType&>(function))
103 template <
typename FunctionType>
107 using Scalar =
typename FunctionType::Scalar;
108 using Vector =
typename FunctionType::Vector;
113 const vtkm::internal::ImplicitFunctionBase<FunctionType>&
function)
114 :
Function(reinterpret_cast<const FunctionType&>(function))
125 return this->
Function->Gradient(point);
145 : MinPoint(Vector(Scalar(-0.5)))
146 , MaxPoint(Vector(Scalar(0.5)))
158 VTKM_EXEC_CONT Box(Scalar xmin, Scalar xmax, Scalar ymin, Scalar ymax, Scalar zmin, Scalar zmax)
159 : MinPoint(xmin, ymin, zmin)
160 , MaxPoint(xmax, ymax, zmax)
182 this->SetMinPoint({ Scalar(bounds.
X.
Min), Scalar(bounds.
Y.
Min), Scalar(bounds.
Z.
Min) });
183 this->SetMaxPoint({ Scalar(bounds.
X.
Max), Scalar(bounds.
Y.
Max), Scalar(bounds.
Z.
Max) });
191 vtkm::Range(this->MinPoint[2], this->MaxPoint[2]));
205 Scalar minDistance = vtkm::NegativeInfinity32();
206 Scalar diff, t, dist;
207 Scalar distance = Scalar(0.0);
212 diff = this->MaxPoint[d] - this->MinPoint[d];
213 if (diff != Scalar(0.0))
215 t = (point[d] - this->MinPoint[d]) / diff;
220 dist = this->MinPoint[d] - point[d];
223 else if (t > Scalar(1.0))
226 dist = point[d] - this->MaxPoint[d];
231 if (t <= Scalar(0.5))
233 dist = MinPoint[d] - point[d];
238 dist = point[d] - MaxPoint[d];
240 if (dist > minDistance)
248 dist = vtkm::Abs(point[d] - MinPoint[d]);
249 if (dist > Scalar(0.0))
254 if (dist > Scalar(0.0))
256 distance += dist * dist;
282 Scalar minDist = vtkm::Infinity32();
284 Vector normal(Scalar(0));
285 Vector inside(Scalar(0));
286 Vector outside(Scalar(0));
287 Vector center((this->MaxPoint + this->MinPoint) * Scalar(0.5));
294 if (point[d] < this->MinPoint[d])
300 else if (point[d] > this->MaxPoint[d])
309 if (point[d] <= center[d])
312 dist = point[d] - this->MinPoint[d];
318 dist = this->MaxPoint[d] - point[d];
329 vtkm::Id indx = location[0] + 3 * location[1] + 9 * location[2];
343 normal[d] = point[d] - center[d];
363 if (outside[d] != 0.0)
365 normal[d] = point[d] - center[d];
384 normal[d] = outside[d];
390 normal[0] = normal[1] = normal[2] = 0.0;
391 normal[minAxis] = inside[minAxis];
423 , Axis(Scalar(0), Scalar(1), Scalar(0))
424 , Radius(Scalar(0.5))
467 Vector x2c = point - this->Center;
469 return vtkm::Dot(x2c, x2c) - (proj * proj) - (this->Radius * this->Radius);
481 Vector x2c = point - this->Center;
482 FloatDefault t = this->Axis[0] * x2c[0] + this->Axis[1] * x2c[1] + this->Axis[2] * x2c[2];
504 this->SetPlanes(points, normals);
515 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
517 this->Points[index] = points[index];
519 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
521 this->Normals[index] = normals[index];
529 this->Points[idx] = point;
530 this->Normals[idx] = normal;
536 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
538 points[index] = this->Points[index];
540 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
542 normals[index] = this->Normals[index];
558 { 3, 2, 0 }, { 4, 5, 7 }, { 0, 1, 4 }, { 1, 2, 5 }, { 2, 3, 6 }, { 3, 0, 7 }
562 for (
int i = 0; i < 6; ++i)
564 const Vector& v0 = points[planes[i][0]];
565 const Vector& v1 = points[planes[i][1]];
566 const Vector& v2 = points[planes[i][2]];
568 this->Points[i] = v0;
584 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
585 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
587 const Vector& p = this->Points[index];
588 const Vector& n = this->Normals[index];
589 const Scalar val = vtkm::Dot(point - p, n);
590 maxVal = vtkm::Max(maxVal, val);
604 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
606 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
608 const Vector& p = this->Points[index];
609 const Vector& n = this->Normals[index];
610 Scalar val = vtkm::Dot(point - p, n);
617 return this->Normals[maxValIdx];
621 Vector Points[6] = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, { 0.0f, -0.5f, 0.0f },
622 { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, 0.5f } };
623 Vector Normals[6] = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f },
624 { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } };
680 return vtkm::Dot(point - this->Origin, this->
Normal);
757 return Scalar(2) * (point - this->Center);
771 template <vtkm::IdComponent MaxNumPlanes>
773 :
public vtkm::internal::ImplicitFunctionBase<MultiPlane<MaxNumPlanes>>
779 template <vtkm::IdComponent SrcMaxPlanes>
781 : Planes(src.GetPlanes())
784 template <vtkm::IdComponent SrcMaxPlanes>
791 VTKM_ASSERT(this->Planes.GetNumberOfComponents() < MaxNumPlanes);
792 this->Planes.Append(
Plane(origin, normal));
797 return this->Planes[idx];
812 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
816 const Vector& p = this->Planes[index].GetOrigin();
817 const Vector& n = this->Planes[index].GetNormal();
818 const Scalar val = vtkm::Dot(point - p, n);
819 maxVal = vtkm::Max(maxVal, val);
833 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
838 const Vector& p = this->Planes[index].GetOrigin();
839 const Vector& n = this->Planes[index].GetNormal();
840 Scalar val = vtkm::Dot(point - p, n);
847 return this->Planes[maxValIdx].GetNormal();
859 template <
typename ImplicitFunctionType>
861 const ImplicitFunctionType&
function,
862 const typename ImplicitFunctionType::Vector& point)
const
864 return function.Value(point);
868 struct ImplicitFunctionGradientFunctor
870 template <
typename ImplicitFunctionType>
872 const ImplicitFunctionType&
function,
873 const typename ImplicitFunctionType::Vector& point)
const
875 return function.Gradient(point);
898 template <
typename... ImplicitFunctionTypes>
900 :
public vtkm::internal::ImplicitFunctionBase<
901 ImplicitFunctionMultiplexer<ImplicitFunctionTypes...>>
903 vtkm::exec::Variant<ImplicitFunctionTypes...>
Variant;
909 using Scalar =
typename Superclass::Scalar;
910 using Vector =
typename Superclass::Vector;
914 template <
typename FunctionType>
916 const vtkm::internal::ImplicitFunctionBase<FunctionType>&
function)
917 :
Variant(reinterpret_cast<const FunctionType&>(function))
932 return this->
Variant.CastAndCall(detail::ImplicitFunctionValueFunctor{}, point);
944 return this->
Variant.CastAndCall(detail::ImplicitFunctionGradientFunctor{}, point);
986 #endif //vtk_m_ImplicitFunction_h
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:203
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:930
Vector Gradient(const Vector &) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:690
Implicit function for a MultiPlane.
Definition: ImplicitFunction.h:772
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:582
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:75
ImplicitFunctionGradientFunctor()=default
void GetPlanes(Vector points[6], Vector normals[6]) const
Specifies the 6 planes of the frustum.
Definition: ImplicitFunction.h:534
Implicit function for a frustum.
Definition: ImplicitFunction.h:495
Implicit function that can switch among known implicit function types.
Definition: ImplicitFunction.h:965
#define VTKM_EXEC
Definition: ExportMacros.h:51
void SetOrigin(const Vector &origin)
Specify the origin of the plane.
Definition: ImplicitFunction.h:654
Groups connected points that have the same field value.
Definition: Atomic.h:19
vtkm::Float32 Sqrt(vtkm::Float32 x)
Definition: Math.h:943
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
Vector Center
Definition: ImplicitFunction.h:488
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ImplicitFunctionValueFunctor()=default
vtkm::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:194
Implicit function that can switch among different types.
Definition: ImplicitFunction.h:899
void SetRadius(Scalar radius)
Specify the radius of the cylinder.
Definition: ImplicitFunction.h:454
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:107
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:678
Scalar Radius
Definition: ImplicitFunction.h:761
const Vector & GetOrigin() const
Specify the origin of the plane.
Definition: ImplicitFunction.h:665
Vector Axis
Definition: ImplicitFunction.h:489
Sphere(Scalar radius=0.5)
Construct a sphere with center at (0,0,0) and the given radius.
Definition: ImplicitFunction.h:709
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:465
ImplicitFunctionMultiplexer(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:915
vtkm::Vec< typename detail::FloatingPointReturnType< T >::Type, 3 > TriangleNormal(const vtkm::Vec< T, 3 > &a, const vtkm::Vec< T, 3 > &b, const vtkm::Vec< T, 3 > &c)
Find the normal of a triangle.
Definition: VectorAnalysis.h:203
Cylinder(const Vector ¢er, const Vector &axis, Scalar radius)
Construct a cylinder at the given center, axis, and radius.
Definition: ImplicitFunction.h:438
vtkm::VecVariable< vtkm::Plane, MaxNumPlanes > GetPlanes() const
Definition: ImplicitFunction.h:799
const Vector & GetNormal() const
Specify the normal vector to the plane.
Definition: ImplicitFunction.h:667
Box(const vtkm::Bounds &bounds)
Construct a box that encompasses the given bounds.
Definition: ImplicitFunction.h:165
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:810
ImplicitFunctionGradientFunctor(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:112
void SetNormal(const Vector &normal)
Specify the normal vector to the plane.
Definition: ImplicitFunction.h:662
vtkm::exec::Variant< ImplicitFunctionTypes... > Variant
Definition: ImplicitFunction.h:903
T Normal(const T &x)
Returns a normalized version of the given vector.
Definition: VectorAnalysis.h:158
A helpful functor that calls the gradient method of a given ImplicitFunction.
Definition: ImplicitFunction.h:104
const Vector & GetCenter() const
Specify the center of the sphere.
Definition: ImplicitFunction.h:732
const Vector & GetMaxPoint() const
Specify the maximum coordinate of the box.
Definition: ImplicitFunction.h:177
Base ExecutionAndControlObjectBase class.
Definition: ExecutionAndControlObjectBase.h:28
const Vector & GetMinPoint() const
Specify the minimum coordinate of the box.
Definition: ImplicitFunction.h:174
Cylinder()
Construct cylinder radius of 0.5; centered at origin with axis along y coordinate axis.
Definition: ImplicitFunction.h:421
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
vtkm::Plane GetPlane(int idx)
Definition: ImplicitFunction.h:794
const Vector * GetPoints() const
Definition: ImplicitFunction.h:546
detail::FloatingPointReturnType< T >::Type MagnitudeSquared(const T &x)
Returns the square of the magnitude of a vector.
Definition: VectorAnalysis.h:64
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:479
typename Superclass::Vector Vector
Definition: ImplicitFunction.h:910
vtkm::FloatDefault Scalar
Definition: ImplicitFunction.h:776
Box()
Construct box with center at (0,0,0) and each side of length 1.0.
Definition: ImplicitFunction.h:144
void SetMinPoint(const Vector &point)
Specify the minimum coordinate of the box.
Definition: ImplicitFunction.h:168
FunctionType Function
Definition: ImplicitFunction.h:129
void SetPlanes(const Vector points[6], const Vector normals[6])
Specifies the 6 planes of the frustum.
Definition: ImplicitFunction.h:513
MultiPlane & operator=(const MultiPlane< SrcMaxPlanes > &src)
Definition: ImplicitFunction.h:785
vtkm::VecVariable< vtkm::Plane, MaxNumPlanes > Planes
Definition: ImplicitFunction.h:851
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:942
void SetBounds(const vtkm::Bounds &bounds)
Specify the size and location of the box by the bounds it encompasses.
Definition: ImplicitFunction.h:180
Scalar GetRadius() const
Specify the radius of the sphere.
Definition: ImplicitFunction.h:729
void AddPlane(const Vector &origin, const Vector &normal)
Definition: ImplicitFunction.h:789
const Vector * GetNormals() const
Definition: ImplicitFunction.h:548
Scalar Radius
Definition: ImplicitFunction.h:490
vtkm::Bounds GetBounds() const
Specify the size and location of the box by the bounds it encompasses.
Definition: ImplicitFunction.h:187
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:755
void CreateFromPoints(const Vector points[8])
Specifies the frustum as the 8 points of the bounding hexahedron.
Definition: ImplicitFunction.h:553
typename Superclass::Scalar Scalar
Definition: ImplicitFunction.h:909
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:743
Vector MinPoint
Definition: ImplicitFunction.h:401
Frustum(const Vector points[8])
Construct a frustum defined by the 8 points of the bounding hexahedron.
Definition: ImplicitFunction.h:510
void Normalize(T &x)
Changes a vector to be normal.
Definition: VectorAnalysis.h:169
vtkm::Range Z
The range of values in the Z direction.
Definition: Bounds.h:39
#define VTKM_CONT
Definition: ExportMacros.h:57
vtkm::Int64 Id
Base type to use to index arrays.
Definition: Types.h:227
vtkm::internal::ImplicitFunctionBase< ImplicitFunctionMultiplexer< ImplicitFunctionTypes... > > Superclass
Definition: ImplicitFunction.h:906
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
void SetCenter(const Vector ¢er)
Specify the center of the cylinder.
Definition: ImplicitFunction.h:448
void SetCenter(const Vector ¢er)
Specify the center of the sphere.
Definition: ImplicitFunction.h:726
Sphere(Vector center, Scalar radius)
Construct a sphere with the given center and radius.
Definition: ImplicitFunction.h:716
An object used to specify a device.
Definition: DeviceAdapterTag.h:58
Represent a sphere of the given Dimension.
Definition: Geometry.h:27
A short fixed-length array.
Definition: Types.h:357
Frustum(const Vector points[6], const Vector normals[6])
Construct a frustum defined with 6 planes of the given points and normals.
Definition: ImplicitFunction.h:502
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:236
MultiPlane(const MultiPlane< SrcMaxPlanes > &src)
Definition: ImplicitFunction.h:780
ImplicitFunctionValueFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:85
vtkm::Float64 Min
The minumum value of the range (inclusive).
Definition: Range.h:34
ImplicitFunctionValueFunctor(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:79
A helpful functor that calls the value method of a given ImplicitFunction.
Definition: ImplicitFunction.h:71
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:602
Implicit function for a box.
Definition: ImplicitFunction.h:140
Scalar operator()(const Vector &point) const
Definition: ImplicitFunction.h:90
ImplicitFunctionMultiplexer()=default
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:74
vtkm::Range X
The range of values in the X direction.
Definition: Bounds.h:33
vtkm::Range Y
The range of values in the Y direction.
Definition: Bounds.h:36
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:831
Plane(const Vector &normal={ 0, 0, 1 })
Construct a plane through the origin with the given normal.
Definition: ImplicitFunction.h:638
Box(const Vector &minPoint, const Vector &maxPoint)
Construct a box with the specified minimum and maximum point.
Definition: ImplicitFunction.h:151
vtkm::Float64 Max
Tha maximum value of the range (inclusive).
Definition: Range.h:36
Vector MaxPoint
Definition: ImplicitFunction.h:402
Box(Scalar xmin, Scalar xmax, Scalar ymin, Scalar ymax, Scalar zmin, Scalar zmax)
Construct a box with the specified minimum and maximum point.
Definition: ImplicitFunction.h:158
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:89
Cylinder(const Vector &axis, Scalar radius)
Construct a cylinder with the given axis and radius.
Definition: ImplicitFunction.h:430
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:108
Represent a plane with a base point (origin) and normal vector.
Definition: Geometry.h:25
void SetRadius(Scalar radius)
Specify the radius of the sphere.
Definition: ImplicitFunction.h:723
FunctionType Function
Definition: ImplicitFunction.h:96
void SetMaxPoint(const Vector &point)
Specify the maximum coordinate of the box.
Definition: ImplicitFunction.h:171
Plane(const Vector &origin, const Vector &normal)
Construct a plane through the given point with the given normal.
Definition: ImplicitFunction.h:645
void SetAxis(const Vector &axis)
Specify the direction of the axis of the cylinder.
Definition: ImplicitFunction.h:451
Implicit function for a cylinder.
Definition: ImplicitFunction.h:416
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:278
void SetPlane(int idx, const Vector &point, const Vector &normal)
Set one of the 6 planes of the frustum.
Definition: ImplicitFunction.h:526
Vector operator()(const Vector &point) const
Definition: ImplicitFunction.h:123
ImplicitFunctionGradientFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:118
Represent a continuous scalar range of values.
Definition: Range.h:31