Go to the documentation of this file.
18 #ifndef viskores_ImplicitFunction_h
19 #define viskores_ImplicitFunction_h
46 template <
typename Derived>
55 return reinterpret_cast<const Derived*
>(
this)->Value(Vector(x, y, z));
60 return reinterpret_cast<const Derived*
>(
this)->Gradient(Vector(x, y, z));
66 return *
reinterpret_cast<const Derived*
>(
this);
71 return *
reinterpret_cast<const Derived*
>(
this);
82 template <
typename FunctionType>
86 using Scalar =
typename FunctionType::Scalar;
87 using Vector =
typename FunctionType::Vector;
92 const viskores::internal::ImplicitFunctionBase<FunctionType>&
function)
93 :
Function(reinterpret_cast<const FunctionType&>(function))
115 template <
typename FunctionType>
119 using Scalar =
typename FunctionType::Scalar;
120 using Vector =
typename FunctionType::Vector;
125 const viskores::internal::ImplicitFunctionBase<FunctionType>&
function)
126 :
Function(reinterpret_cast<const FunctionType&>(function))
137 return this->
Function->Gradient(point);
152 class VISKORES_ALWAYS_EXPORT
Box :
public internal::ImplicitFunctionBase<Box>
157 : MinPoint(Vector(Scalar(-0.5)))
158 , MaxPoint(Vector(Scalar(0.5)))
176 : MinPoint(xmin, ymin, zmin)
177 , MaxPoint(xmax, ymax, zmax)
199 this->SetMinPoint({ Scalar(bounds.
X.
Min), Scalar(bounds.
Y.
Min), Scalar(bounds.
Z.
Min) });
200 this->SetMaxPoint({ Scalar(bounds.
X.
Max), Scalar(bounds.
Y.
Max), Scalar(bounds.
Z.
Max) });
222 Scalar minDistance = viskores::NegativeInfinity32();
223 Scalar diff, t, dist;
224 Scalar distance = Scalar(0.0);
229 diff = this->MaxPoint[d] - this->MinPoint[d];
230 if (diff != Scalar(0.0))
232 t = (point[d] - this->MinPoint[d]) / diff;
237 dist = this->MinPoint[d] - point[d];
240 else if (t > Scalar(1.0))
243 dist = point[d] - this->MaxPoint[d];
248 if (t <= Scalar(0.5))
250 dist = MinPoint[d] - point[d];
255 dist = point[d] - MaxPoint[d];
257 if (dist > minDistance)
265 dist = viskores::Abs(point[d] - MinPoint[d]);
266 if (dist > Scalar(0.0))
271 if (dist > Scalar(0.0))
273 distance += dist * dist;
299 Scalar minDist = viskores::Infinity32();
301 Vector normal(Scalar(0));
302 Vector inside(Scalar(0));
303 Vector outside(Scalar(0));
304 Vector center((this->MaxPoint + this->MinPoint) * Scalar(0.5));
311 if (point[d] < this->MinPoint[d])
317 else if (point[d] > this->MaxPoint[d])
326 if (point[d] <= center[d])
329 dist = point[d] - this->MinPoint[d];
335 dist = this->MaxPoint[d] - point[d];
346 viskores::Id indx = location[0] + 3 * location[1] + 9 * location[2];
360 normal[d] = point[d] - center[d];
380 if (outside[d] != 0.0)
382 normal[d] = point[d] - center[d];
401 normal[d] = outside[d];
407 normal[0] = normal[1] = normal[2] = 0.0;
408 normal[minAxis] = inside[minAxis];
433 class VISKORES_ALWAYS_EXPORT
Cylinder :
public viskores::internal::ImplicitFunctionBase<Cylinder>
440 , Axis(Scalar(0), Scalar(1), Scalar(0))
441 , Radius(Scalar(0.5))
484 Vector x2c = point - this->Center;
486 return viskores::Dot(x2c, x2c) - (proj * proj) - (this->Radius * this->Radius);
498 Vector x2c = point - this->Center;
499 FloatDefault t = this->Axis[0] * x2c[0] + this->Axis[1] * x2c[1] + this->Axis[2] * x2c[2];
512 class VISKORES_ALWAYS_EXPORT
Frustum :
public viskores::internal::ImplicitFunctionBase<Frustum>
521 this->SetPlanes(points, normals);
534 this->Points[index] = points[index];
538 this->Normals[index] = normals[index];
546 this->Points[idx] = point;
547 this->Normals[idx] = normal;
555 points[index] = this->Points[index];
559 normals[index] = this->Normals[index];
575 { 3, 2, 0 }, { 4, 5, 7 }, { 0, 1, 4 }, { 1, 2, 5 }, { 2, 3, 6 }, { 3, 0, 7 }
579 for (
int i = 0; i < 6; ++i)
581 const Vector& v0 = points[planes[i][0]];
582 const Vector& v1 = points[planes[i][1]];
583 const Vector& v2 = points[planes[i][2]];
585 this->Points[i] = v0;
601 Scalar maxVal = viskores::NegativeInfinity<Scalar>();
604 const Vector& p = this->Points[index];
605 const Vector& n = this->Normals[index];
606 const Scalar val = viskores::Dot(point - p, n);
607 maxVal = viskores::Max(maxVal, val);
621 Scalar maxVal = viskores::NegativeInfinity<Scalar>();
625 const Vector& p = this->Points[index];
626 const Vector& n = this->Normals[index];
627 Scalar val = viskores::Dot(point - p, n);
634 return this->Normals[maxValIdx];
638 Vector Points[6] = { { -0.5f, 0.0f, 0.0f }, { 0.5f, 0.0f, 0.0f }, { 0.0f, -0.5f, 0.0f },
639 { 0.0f, 0.5f, 0.0f }, { 0.0f, 0.0f, -0.5f }, { 0.0f, 0.0f, 0.5f } };
640 Vector Normals[6] = { { -1.0f, 0.0f, 0.0f }, { 1.0f, 0.0f, 0.0f }, { 0.0f, -1.0f, 0.0f },
641 { 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, -1.0f }, { 0.0f, 0.0f, 1.0f } };
651 class VISKORES_ALWAYS_EXPORT Plane :
public viskores::internal::ImplicitFunctionBase<Plane>
697 return viskores::Dot(point - this->Origin, this->
Normal);
722 class VISKORES_ALWAYS_EXPORT Sphere :
public viskores::internal::ImplicitFunctionBase<Sphere>
774 return Scalar(2) * (point - this->Center);
788 template <viskores::IdComponent MaxNumPlanes>
790 :
public viskores::internal::ImplicitFunctionBase<MultiPlane<MaxNumPlanes>>
796 template <viskores::IdComponent SrcMaxPlanes>
798 : Planes(src.GetPlanes())
801 template <viskores::IdComponent SrcMaxPlanes>
809 this->Planes.Append(
Plane(origin, normal));
814 return this->Planes[idx];
832 Scalar maxVal = viskores::NegativeInfinity<Scalar>();
836 const Vector& p = this->Planes[index].GetOrigin();
837 const Vector& n = this->Planes[index].GetNormal();
838 const Scalar val = viskores::Dot(point - p, n);
839 maxVal = viskores::Max(maxVal, val);
853 Scalar maxVal = viskores::NegativeInfinity<Scalar>();
858 const Vector& p = this->Planes[index].GetOrigin();
859 const Vector& n = this->Planes[index].GetNormal();
860 Scalar val = viskores::Dot(point - p, n);
867 return this->Planes[maxValIdx].GetNormal();
879 template <
typename ImplicitFunctionType>
881 const ImplicitFunctionType&
function,
882 const typename ImplicitFunctionType::Vector& point)
const
884 return function.Value(point);
888 struct ImplicitFunctionGradientFunctor
890 template <
typename ImplicitFunctionType>
892 const ImplicitFunctionType&
function,
893 const typename ImplicitFunctionType::Vector& point)
const
895 return function.Gradient(point);
918 template <
typename... ImplicitFunctionTypes>
920 :
public viskores::internal::ImplicitFunctionBase<
921 ImplicitFunctionMultiplexer<ImplicitFunctionTypes...>>
923 viskores::exec::Variant<ImplicitFunctionTypes...>
Variant;
929 using Scalar =
typename Superclass::Scalar;
930 using Vector =
typename Superclass::Vector;
934 template <
typename FunctionType>
936 const viskores::internal::ImplicitFunctionBase<FunctionType>&
function)
937 :
Variant(reinterpret_cast<const FunctionType&>(function))
952 return this->
Variant.CastAndCall(detail::ImplicitFunctionValueFunctor{}, point);
964 return this->
Variant.CastAndCall(detail::ImplicitFunctionGradientFunctor{}, point);
991 viskores::MultiPlane<3>>
1006 #endif //viskores_ImplicitFunction_h
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:619
Implicit function for a box.
Definition: ImplicitFunction.h:152
void SetNormal(const Vector &normal)
Specify the normal vector to the plane.
Definition: ImplicitFunction.h:679
ImplicitFunctionValueFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:97
Implicit function that can switch among known implicit function types.
Definition: ImplicitFunction.h:985
Implicit function for a MultiPlane.
Definition: ImplicitFunction.h:789
Vector operator()(const Vector &point) const
Definition: ImplicitFunction.h:135
Represent an axis-aligned 3D bounds in space.
Definition: Bounds.h:37
T Normal(const T &x)
Returns a normalized version of the given vector.
Definition: VectorAnalysis.h:166
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:851
void SetMaxPoint(const Vector &point)
Specify the maximum coordinate of the box.
Definition: ImplicitFunction.h:188
void AddPlane(const Vector &origin, const Vector &normal)
Definition: ImplicitFunction.h:806
void GetPlanes(Vector points[6], Vector normals[6]) const
Specifies the 6 planes of the frustum.
Definition: ImplicitFunction.h:551
void SetRadius(Scalar radius)
Specify the radius of the cylinder.
Definition: ImplicitFunction.h:471
viskores::Float64 Min
The minumum value of the range (inclusive).
Definition: Range.h:42
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:599
void SetCenter(const Vector ¢er)
Specify the center of the sphere.
Definition: ImplicitFunction.h:743
Scalar GetRadius() const
Specify the radius of the sphere.
Definition: ImplicitFunction.h:746
Plane(const Vector &normal={ 0, 0, 1 })
Construct a plane through the origin with the given normal.
Definition: ImplicitFunction.h:655
void Normalize(T &x)
Changes a vector to be normal.
Definition: VectorAnalysis.h:177
const Vector & GetCenter() const
Specify the center of the sphere.
Definition: ImplicitFunction.h:749
Cylinder()
Construct cylinder radius of 0.5; centered at origin with axis along y coordinate axis.
Definition: ImplicitFunction.h:438
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:86
ImplicitFunctionGradientFunctor()=default
MultiPlane(const MultiPlane< SrcMaxPlanes > &src)
Definition: ImplicitFunction.h:797
ImplicitFunctionMultiplexer()=default
typename FunctionType::Scalar Scalar
Definition: ImplicitFunction.h:119
viskores::Int32 IdComponent
Base type to use to index small lists.
Definition: Types.h:202
A helpful functor that calls the gradient method of a given ImplicitFunction.
Definition: ImplicitFunction.h:116
const Vector * GetPoints() const
Definition: ImplicitFunction.h:563
#define VISKORES_EXEC_CONT
Definition: ExportMacros.h:60
void SetMinPoint(const Vector &point)
Specify the minimum coordinate of the box.
Definition: ImplicitFunction.h:185
viskores::Float32 Sqrt(viskores::Float32 x)
Definition: Math.h:951
Implicit function that can switch among different types.
Definition: ImplicitFunction.h:919
Cylinder(const Vector &axis, Scalar radius)
Construct a cylinder with the given axis and radius.
Definition: ImplicitFunction.h:447
viskores::Float64 Max
Tha maximum value of the range (inclusive).
Definition: Range.h:44
Sphere(Vector center, Scalar radius)
Construct a sphere with the given center and radius.
Definition: ImplicitFunction.h:733
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:950
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:120
ImplicitFunctionMultiplexer(const viskores::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:935
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:295
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:962
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:695
viskores::FloatDefault Scalar
Definition: ImplicitFunction.h:793
Box(const Vector &minPoint, const Vector &maxPoint)
Construct a box with the specified minimum and maximum point.
Definition: ImplicitFunction.h:163
typename Superclass::Vector Vector
Definition: ImplicitFunction.h:930
viskores::Int64 Id
Base type to use to index arrays.
Definition: Types.h:235
Sphere(Scalar radius=0.5)
Construct a sphere with center at (0,0,0) and the given radius.
Definition: ImplicitFunction.h:726
void SetCenter(const Vector ¢er)
Specify the center of the cylinder.
Definition: ImplicitFunction.h:465
Box(const viskores::Bounds &bounds)
Construct a box that encompasses the given bounds.
Definition: ImplicitFunction.h:182
viskores::Bounds GetBounds() const
Specify the size and location of the box by the bounds it encompasses.
Definition: ImplicitFunction.h:204
#define VISKORES_CONT
Definition: ExportMacros.h:65
viskores::VecVariable< viskores::Plane, MaxNumPlanes > GetPlanes() const
Definition: ImplicitFunction.h:816
Groups connected points that have the same field value.
Definition: Atomic.h:27
const Vector & GetOrigin() const
Specify the origin of the plane.
Definition: ImplicitFunction.h:682
void SetRadius(Scalar radius)
Specify the radius of the sphere.
Definition: ImplicitFunction.h:740
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:519
Implicit function for a frustum.
Definition: ImplicitFunction.h:512
FunctionType Function
Definition: ImplicitFunction.h:141
Base ExecutionAndControlObjectBase class.
Definition: ExecutionAndControlObjectBase.h:36
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:830
typename Superclass::Scalar Scalar
Definition: ImplicitFunction.h:929
A helpful functor that calls the value method of a given ImplicitFunction.
Definition: ImplicitFunction.h:83
ImplicitFunctionGradientFunctor(const viskores::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:124
Vector Center
Definition: ImplicitFunction.h:505
ImplicitFunctionGradientFunctor(const FunctionType &function)
Definition: ImplicitFunction.h:130
void SetPlanes(const Vector points[6], const Vector normals[6])
Specifies the 6 planes of the frustum.
Definition: ImplicitFunction.h:530
Scalar operator()(const Vector &point) const
Definition: ImplicitFunction.h:102
Plane(const Vector &origin, const Vector &normal)
Construct a plane through the given point with the given normal.
Definition: ImplicitFunction.h:662
Vector MaxPoint
Definition: ImplicitFunction.h:419
Box()
Construct box with center at (0,0,0) and each side of length 1.0.
Definition: ImplicitFunction.h:156
#define VISKORES_ASSERT(condition)
Definition: Assert.h:51
void SetPlane(int idx, const Vector &point, const Vector &normal)
Set one of the 6 planes of the frustum.
Definition: ImplicitFunction.h:543
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:496
Scalar Radius
Definition: ImplicitFunction.h:507
ImplicitFunctionValueFunctor(const viskores::internal::ImplicitFunctionBase< FunctionType > &function)
Definition: ImplicitFunction.h:91
viskores::Range Z
The range of values in the Z direction.
Definition: Bounds.h:47
Vector MinPoint
Definition: ImplicitFunction.h:418
An object used to specify a device.
Definition: DeviceAdapterTag.h:66
Represent a continuous scalar range of values.
Definition: Range.h:39
viskores::VecVariable< viskores::Plane, MaxNumPlanes > Planes
Definition: ImplicitFunction.h:871
void CreateFromPoints(const Vector points[8])
Specifies the frustum as the 8 points of the bounding hexahedron.
Definition: ImplicitFunction.h:570
viskores::Plane GetPlane(int idx)
Definition: ImplicitFunction.h:811
const Vector * GetNormals() const
Definition: ImplicitFunction.h:565
viskores::Float32 FloatDefault
The floating point type to use when no other precision is specified.
Definition: Types.h:244
void SetAxis(const Vector &axis)
Specify the direction of the axis of the cylinder.
Definition: ImplicitFunction.h:468
viskores::Range Y
The range of values in the Y direction.
Definition: Bounds.h:44
MultiPlane & operator=(const MultiPlane< SrcMaxPlanes > &src)
Definition: ImplicitFunction.h:802
void SetOrigin(const Vector &origin)
Specify the origin of the plane.
Definition: ImplicitFunction.h:671
const Vector & GetMinPoint() const
Specify the minimum coordinate of the box.
Definition: ImplicitFunction.h:191
Implicit function for a cylinder.
Definition: ImplicitFunction.h:433
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:170
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:760
Scalar Radius
Definition: ImplicitFunction.h:778
detail::FloatingPointReturnType< T >::Type MagnitudeSquared(const T &x)
Returns the square of the magnitude of a vector.
Definition: VectorAnalysis.h:72
viskores::internal::ImplicitFunctionBase< ImplicitFunctionMultiplexer< ImplicitFunctionTypes... > > Superclass
Definition: ImplicitFunction.h:926
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:220
ImplicitFunctionValueFunctor()=default
Scalar Value(const Vector &point) const
Evaluate the value of the implicit function.
Definition: ImplicitFunction.h:482
viskores::Vec< typename detail::FloatingPointReturnType< T >::Type, 3 > TriangleNormal(const viskores::Vec< T, 3 > &a, const viskores::Vec< T, 3 > &b, const viskores::Vec< T, 3 > &c)
Find the normal of a triangle.
Definition: VectorAnalysis.h:211
Vector Axis
Definition: ImplicitFunction.h:506
typename FunctionType::Vector Vector
Definition: ImplicitFunction.h:87
Vector Gradient(const Vector &point) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:772
void SetBounds(const viskores::Bounds &bounds)
Specify the size and location of the box by the bounds it encompasses.
Definition: ImplicitFunction.h:197
A short fixed-length array.
Definition: Types.h:365
A token to hold the scope of an ArrayHandle or other object.
Definition: Token.h:43
Cylinder(const Vector ¢er, const Vector &axis, Scalar radius)
Construct a cylinder at the given center, axis, and radius.
Definition: ImplicitFunction.h:455
FunctionType Function
Definition: ImplicitFunction.h:108
#define VISKORES_EXEC
Definition: ExportMacros.h:59
Vector Gradient(const Vector &) const
Evaluate the gradient of the implicit function.
Definition: ImplicitFunction.h:707
viskores::exec::Variant< ImplicitFunctionTypes... > Variant
Definition: ImplicitFunction.h:923
viskores::Range X
The range of values in the X direction.
Definition: Bounds.h:41
Represent a plane with a base point (origin) and normal vector.
Definition: Geometry.h:33
const Vector & GetMaxPoint() const
Specify the maximum coordinate of the box.
Definition: ImplicitFunction.h:194
const Vector & GetNormal() const
Specify the normal vector to the plane.
Definition: ImplicitFunction.h:684
Frustum(const Vector points[8])
Construct a frustum defined by the 8 points of the bounding hexahedron.
Definition: ImplicitFunction.h:527
Represent a sphere of the given Dimension.
Definition: Geometry.h:35