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)))
156 VTKM_EXEC_CONT Box(Scalar xmin, Scalar xmax, Scalar ymin, Scalar ymax, Scalar zmin, Scalar zmax)
157 : MinPoint(xmin, ymin, zmin)
158 , MaxPoint(xmax, ymax, zmax)
174 this->SetMinPoint({ Scalar(bounds.
X.
Min), Scalar(bounds.
Y.
Min), Scalar(bounds.
Z.
Min) });
175 this->SetMaxPoint({ Scalar(bounds.
X.
Max), Scalar(bounds.
Y.
Max), Scalar(bounds.
Z.
Max) });
182 vtkm::Range(this->MinPoint[2], this->MaxPoint[2]));
187 Scalar minDistance = vtkm::NegativeInfinity32();
188 Scalar diff, t, dist;
189 Scalar distance = Scalar(0.0);
194 diff = this->MaxPoint[d] - this->MinPoint[d];
195 if (diff != Scalar(0.0))
197 t = (point[d] - this->MinPoint[d]) / diff;
202 dist = this->MinPoint[d] - point[d];
205 else if (t > Scalar(1.0))
208 dist = point[d] - this->MaxPoint[d];
213 if (t <= Scalar(0.5))
215 dist = MinPoint[d] - point[d];
220 dist = point[d] - MaxPoint[d];
222 if (dist > minDistance)
230 dist = vtkm::Abs(point[d] - MinPoint[d]);
231 if (dist > Scalar(0.0))
236 if (dist > Scalar(0.0))
238 distance += dist * dist;
257 Scalar minDist = vtkm::Infinity32();
259 Vector normal(Scalar(0));
260 Vector inside(Scalar(0));
261 Vector outside(Scalar(0));
262 Vector center((this->MaxPoint + this->MinPoint) * Scalar(0.5));
269 if (point[d] < this->MinPoint[d])
275 else if (point[d] > this->MaxPoint[d])
284 if (point[d] <= center[d])
287 dist = point[d] - this->MinPoint[d];
293 dist = this->MaxPoint[d] - point[d];
304 vtkm::Id indx = location[0] + 3 * location[1] + 9 * location[2];
318 normal[d] = point[d] - center[d];
338 if (outside[d] != 0.0)
340 normal[d] = point[d] - center[d];
359 normal[d] = outside[d];
365 normal[0] = normal[1] = normal[2] = 0.0;
366 normal[minAxis] = inside[minAxis];
398 , Axis(Scalar(0), Scalar(1), Scalar(0))
399 , Radius(Scalar(0.5))
425 Vector x2c = point - this->Center;
427 return vtkm::Dot(x2c, x2c) - (proj * proj) - (this->Radius * this->Radius);
432 Vector x2c = point - this->Center;
433 FloatDefault t = this->Axis[0] * x2c[0] + this->Axis[1] * x2c[1] + this->Axis[2] * x2c[2];
454 this->SetPlanes(points, normals);
461 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
463 this->Points[index] = points[index];
465 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
467 this->Normals[index] = normals[index];
474 this->Points[idx] = point;
475 this->Normals[idx] = normal;
480 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
482 points[index] = this->Points[index];
484 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
486 normals[index] = this->Normals[index];
500 { 3, 2, 0 }, { 4, 5, 7 }, { 0, 1, 4 }, { 1, 2, 5 }, { 2, 3, 6 }, { 3, 0, 7 }
504 for (
int i = 0; i < 6; ++i)
506 const Vector& v0 = points[planes[i][0]];
507 const Vector& v1 = points[planes[i][1]];
508 const Vector& v2 = points[planes[i][2]];
510 this->Points[i] = v0;
517 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
518 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
520 const Vector& p = this->Points[index];
521 const Vector& n = this->Normals[index];
522 const Scalar val = vtkm::Dot(point - p, n);
523 maxVal = vtkm::Max(maxVal, val);
530 Scalar maxVal = vtkm::NegativeInfinity<Scalar>();
532 for (
vtkm::Id index : { 0, 1, 2, 3, 4, 5 })
534 const Vector& p = this->Points[index];
535 const Vector& n = this->Normals[index];
536 Scalar val = vtkm::Dot(point - p, n);
543 return this->Normals[maxValIdx];
547 Vector Points[6] = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, { 0.0f, -0.5f, 0.0f },
548 { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, 0.5f } };
549 Vector Normals[6] = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f },
550 { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } };
566 ,
Normal(Scalar(0), Scalar(0), Scalar(1))
593 return vtkm::Dot(point - this->Origin, this->
Normal);
616 : Radius(Scalar(0.5))
649 return Scalar(2) * (point - this->Center);
662 template <
typename ImplicitFunctionType>
664 const ImplicitFunctionType&
function,
665 const typename ImplicitFunctionType::Vector& point)
const
667 return function.Value(point);
671 struct ImplicitFunctionGradientFunctor
673 template <
typename ImplicitFunctionType>
675 const ImplicitFunctionType&
function,
676 const typename ImplicitFunctionType::Vector& point)
const
678 return function.Gradient(point);
701 template <
typename... ImplicitFunctionTypes>
703 :
public vtkm::internal::ImplicitFunctionBase<
704 ImplicitFunctionMultiplexer<ImplicitFunctionTypes...>>
706 vtkm::exec::Variant<ImplicitFunctionTypes...>
Variant;
712 using Scalar =
typename Superclass::Scalar;
713 using Vector =
typename Superclass::Vector;
717 template <
typename FunctionType>
719 const vtkm::internal::ImplicitFunctionBase<FunctionType>&
function)
720 :
Variant(reinterpret_cast<const FunctionType&>(function))
726 return this->
Variant.CastAndCall(detail::ImplicitFunctionValueFunctor{}, point);
731 return this->
Variant.CastAndCall(detail::ImplicitFunctionGradientFunctor{}, point);
768 #endif //vtk_m_ImplicitFunction_h
const VTKM_EXEC_CONT Vector & GetCenter() const
Definition: ImplicitFunction.h:640
VTKM_CONT void SetAxis(const Vector &axis)
Definition: ImplicitFunction.h:419
VTKM_EXEC_CONT Sphere()
Construct sphere with center at (0,0,0) and radius = 0.5.
Definition: ImplicitFunction.h:615
VTKM_EXEC_CONT vtkm::Float32 Sqrt(vtkm::Float32 x)
Compute the square root of x.
Definition: Math.h:958
VTKM_EXEC_CONT Cylinder()
Construct cylinder radius of 0.5; centered at origin with axis along y coordinate axis.
Definition: ImplicitFunction.h:396
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:75
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:724
VTKM_EXEC_CONT Sphere(Scalar radius)
Construct a sphere with center at (0,0,0) and the given radius.
Definition: ImplicitFunction.h:622
ImplicitFunctionGradientFunctor()=default
VTKM_EXEC_CONT detail::FloatingPointReturnType< T >::Type MagnitudeSquared(const T &x)
Returns the square of the magnitude of a vector.
Definition: VectorAnalysis.h:64
Implicit function for a frustum.
Definition: ImplicitFunction.h:446
Implicit function that can switch among known implicit function types.
Definition: ImplicitFunction.h:749
#define VTKM_EXEC
Definition: ExportMacros.h:51
Groups connected points that have the same field value.
Definition: Atomic.h:19
#define VTKM_ASSERT(condition)
Definition: Assert.h:43
Vector Center
Definition: ImplicitFunction.h:439
#define VTKM_EXEC_CONT
Definition: ExportMacros.h:52
ImplicitFunctionValueFunctor()=default
VTKM_EXEC_CONT ImplicitFunctionGradientFunctor(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:112
VTKM_EXEC_CONT void Normalize(T &x)
Changes a vector to be normal.
Definition: VectorAnalysis.h:168
vtkm::Int32 IdComponent
Represents a component ID (index of component in a vector).
Definition: Types.h:168
Implicit function that can switch among different types.
Definition: ImplicitFunction.h:702
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:107
VTKM_EXEC_CONT Box(const Vector &minPoint, const Vector &maxPoint)
Definition: ImplicitFunction.h:150
Scalar Radius
Definition: ImplicitFunction.h:653
Vector Axis
Definition: ImplicitFunction.h:440
VTKM_EXEC_CONT ImplicitFunctionValueFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:85
const VTKM_EXEC_CONT Vector & GetMinPoint() const
Definition: ImplicitFunction.h:168
vtkm::exec::Variant< ImplicitFunctionTypes... > Variant
Definition: ImplicitFunction.h:706
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:515
A helpful functor that calls the gradient method of a given ImplicitFunction.
Definition: ImplicitFunction.h:104
vtkm::Int32 Id
Represents an ID (index into arrays).
Definition: Types.h:191
VTKM_CONT void SetMinPoint(const Vector &point)
Definition: ImplicitFunction.h:164
VTKM_EXEC_CONT Vector operator()(const Vector &point) const
Definition: ImplicitFunction.h:123
Base ExecutionAndControlObjectBase class.
Definition: ExecutionAndControlObjectBase.h:28
VTKM_EXEC_CONT T Normal(const T &x)
Returns a normalized version of the given vector.
Definition: VectorAnalysis.h:157
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:642
VTKM_CONT void SetCenter(const Vector ¢er)
Definition: ImplicitFunction.h:417
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:35
VTKM_EXEC_CONT void CreateFromPoints(const Vector points[8])
Definition: ImplicitFunction.h:495
VTKM_EXEC_CONT Scalar operator()(const Vector &point) const
Definition: ImplicitFunction.h:90
VTKM_EXEC void SetPlanes(const Vector points[6], const Vector normals[6])
Definition: ImplicitFunction.h:459
typename Superclass::Vector Vector
Definition: ImplicitFunction.h:713
VTKM_EXEC_CONT Plane(const Vector &normal)
Construct a plane through the origin with the given normal.
Definition: ImplicitFunction.h:571
FunctionType Function
Definition: ImplicitFunction.h:129
VTKM_EXEC_CONT Vector Gradient(const Vector &point) const
Definition: ImplicitFunction.h:647
const VTKM_EXEC_CONT Vector * GetNormals() const
Definition: ImplicitFunction.h:492
VTKM_EXEC_CONT Frustum(const Vector points[8])
Definition: ImplicitFunction.h:457
VTKM_EXEC_CONT Plane()
Construct plane passing through origin and normal to z-axis.
Definition: ImplicitFunction.h:564
VTKM_EXEC_CONT Vector Gradient(const Vector &point) const
Definition: ImplicitFunction.h:253
VTKM_EXEC_CONT Cylinder(const Vector &axis, Scalar radius)
Definition: ImplicitFunction.h:403
Scalar Radius
Definition: ImplicitFunction.h:441
VTKM_CONT void SetRadius(Scalar radius)
Definition: ImplicitFunction.h:421
typename Superclass::Scalar Scalar
Definition: ImplicitFunction.h:712
Vector MinPoint
Definition: ImplicitFunction.h:376
VTKM_EXEC_CONT Plane(const Vector &origin, const Vector &normal)
Construct a plane through the given point with the given normal.
Definition: ImplicitFunction.h:578
VTKM_EXEC_CONT Vector Gradient(const Vector &point) const
Definition: ImplicitFunction.h:430
vtkm::Range Z
Definition: Bounds.h:33
#define VTKM_CONT
Definition: ExportMacros.h:57
VTKM_EXEC_CONT Scalar GetRadius() const
Definition: ImplicitFunction.h:638
const VTKM_EXEC_CONT Vector & GetMaxPoint() const
Definition: ImplicitFunction.h:170
vtkm::internal::ImplicitFunctionBase< ImplicitFunctionMultiplexer< ImplicitFunctionTypes... > > Superclass
Definition: ImplicitFunction.h:709
VTKM_EXEC_CONT ImplicitFunctionValueFunctor(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:79
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:29
const VTKM_EXEC_CONT Vector * GetPoints() const
Definition: ImplicitFunction.h:490
VTKM_EXEC_CONT 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:200
VTKM_EXEC_CONT Frustum(const Vector points[6], const Vector normals[6])
Definition: ImplicitFunction.h:452
VTKM_EXEC_CONT Box(Scalar xmin, Scalar xmax, Scalar ymin, Scalar ymax, Scalar zmin, Scalar zmax)
Definition: ImplicitFunction.h:156
VTKM_EXEC_CONT Vector Gradient(const Vector &point) const
Definition: ImplicitFunction.h:528
Definition: DeviceAdapterTag.h:52
VTKM_EXEC_CONT vtkm::Bounds GetBounds() const
Definition: ImplicitFunction.h:178
Represent a sphere of the given Dimension.
Definition: Geometry.h:27
A short fixed-length array.
Definition: Types.h:767
vtkm::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:198
VTKM_EXEC void SetPlane(int idx, const Vector &point, const Vector &normal)
Definition: ImplicitFunction.h:471
VTKM_EXEC_CONT Vector Gradient(const Vector &point) const
Definition: ImplicitFunction.h:729
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:423
vtkm::Float64 Min
Definition: Range.h:33
VTKM_CONT void SetBounds(const vtkm::Bounds &bounds)
Definition: ImplicitFunction.h:172
VTKM_EXEC_CONT Cylinder(const Vector ¢er, const Vector &axis, Scalar radius)
Definition: ImplicitFunction.h:410
const VTKM_EXEC_CONT Vector & GetOrigin() const
Definition: ImplicitFunction.h:588
A helpful functor that calls the value method of a given ImplicitFunction.
Definition: ImplicitFunction.h:71
const VTKM_EXEC_CONT Vector & GetNormal() const
Definition: ImplicitFunction.h:589
Implicit function for a box.
Definition: ImplicitFunction.h:140
ImplicitFunctionMultiplexer()=default
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:74
vtkm::Range X
Definition: Bounds.h:31
VTKM_EXEC_CONT Box()
Construct box with center at (0,0,0) and each side of length 1.0.
Definition: ImplicitFunction.h:144
vtkm::Range Y
Definition: Bounds.h:32
VTKM_EXEC_CONT Vector Gradient(const Vector &) const
Definition: ImplicitFunction.h:596
vtkm::Float64 Max
Definition: Range.h:34
Vector MaxPoint
Definition: ImplicitFunction.h:377
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:185
#define VTKM_ALWAYS_EXPORT
Definition: ExportMacros.h:92
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:108
VTKM_CONT Box(const vtkm::Bounds &bounds)
Definition: ImplicitFunction.h:162
Represent a plane with a base point (origin) and normal vector.
Definition: Geometry.h:25
VTKM_CONT void SetMaxPoint(const Vector &point)
Definition: ImplicitFunction.h:166
VTKM_CONT void SetOrigin(const Vector &origin)
Definition: ImplicitFunction.h:584
VTKM_EXEC_CONT Sphere(Vector center, Scalar radius)
Definition: ImplicitFunction.h:628
VTKM_CONT void SetRadius(Scalar radius)
Definition: ImplicitFunction.h:634
FunctionType Function
Definition: ImplicitFunction.h:96
VTKM_EXEC_CONT Scalar Value(const Vector &point) const
Definition: ImplicitFunction.h:591
VTKM_EXEC_CONT void GetPlanes(Vector points[6], Vector normals[6]) const
Definition: ImplicitFunction.h:478
VTKM_EXEC_CONT ImplicitFunctionMultiplexer(const vtkm::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:718
VTKM_CONT void SetCenter(const Vector ¢er)
Definition: ImplicitFunction.h:636
VTKM_CONT void SetNormal(const Vector &normal)
Definition: ImplicitFunction.h:586
VTKM_EXEC_CONT ImplicitFunctionGradientFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:118
Implicit function for a cylinder.
Definition: ImplicitFunction.h:391
Represent a continuous scalar range of values.
Definition: Range.h:31