mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-16 17:22:55 +00:00
Add ImplicitFunction for Cylinder and Frustum
This commit is contained in:
parent
d6e354382c
commit
67febc27ad
@ -125,63 +125,28 @@ protected:
|
||||
class VTKM_ALWAYS_EXPORT Box : public ImplicitFunctionImpl<Box>
|
||||
{
|
||||
public:
|
||||
Box() : MinPoint(vtkm::Vec<FloatDefault,3>(FloatDefault(0), FloatDefault(0), FloatDefault(0))),
|
||||
MaxPoint(vtkm::Vec<FloatDefault,3>(FloatDefault(1), FloatDefault(1), FloatDefault(1)))
|
||||
{ }
|
||||
|
||||
Box(vtkm::Vec<FloatDefault, 3> minPoint, vtkm::Vec<FloatDefault, 3> maxPoint)
|
||||
: MinPoint(minPoint), MaxPoint(maxPoint)
|
||||
{ }
|
||||
|
||||
Box();
|
||||
Box(vtkm::Vec<FloatDefault, 3> minPoint, vtkm::Vec<FloatDefault, 3> maxPoint);
|
||||
Box(FloatDefault xmin, FloatDefault xmax,
|
||||
FloatDefault ymin, FloatDefault ymax,
|
||||
FloatDefault zmin, FloatDefault zmax)
|
||||
{
|
||||
MinPoint[0] = xmin; MaxPoint[0] = xmax;
|
||||
MinPoint[1] = ymin; MaxPoint[1] = ymax;
|
||||
MinPoint[2] = zmin; MaxPoint[2] = zmax;
|
||||
}
|
||||
FloatDefault zmin, FloatDefault zmax);
|
||||
|
||||
void SetMinPoint(const vtkm::Vec<FloatDefault, 3> &point)
|
||||
{
|
||||
this->MinPoint = point;
|
||||
this->Modified();
|
||||
}
|
||||
void SetMinPoint(const vtkm::Vec<FloatDefault, 3> &point);
|
||||
void SetMaxPoint(const vtkm::Vec<FloatDefault, 3> &point);
|
||||
|
||||
void SetMaxPoint(const vtkm::Vec<FloatDefault, 3> &point)
|
||||
{
|
||||
this->MaxPoint = point;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetMinPoint() const
|
||||
{
|
||||
return this->MinPoint;
|
||||
}
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetMaxPoint() const
|
||||
{
|
||||
return this->MaxPoint;
|
||||
}
|
||||
const vtkm::Vec<FloatDefault, 3>& GetMinPoint() const;
|
||||
const vtkm::Vec<FloatDefault, 3>& GetMaxPoint() const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return this->Value(vtkm::Vec<vtkm::FloatDefault,3>(x, y, z));
|
||||
}
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(FloatDefault x, FloatDefault y, FloatDefault z)
|
||||
const
|
||||
{
|
||||
return this->Gradient(vtkm::Vec<FloatDefault, 3>(x, y, z));
|
||||
}
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
|
||||
private:
|
||||
vtkm::Vec<FloatDefault, 3> MinPoint;
|
||||
@ -189,73 +154,109 @@ private:
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \brief Implicit function for a cylinder
|
||||
class VTKM_ALWAYS_EXPORT Cylinder : public ImplicitFunctionImpl<Cylinder>
|
||||
{
|
||||
public:
|
||||
Cylinder();
|
||||
Cylinder(const vtkm::Vec<FloatDefault, 3> &axis, FloatDefault radius);
|
||||
Cylinder(const vtkm::Vec<FloatDefault, 3> ¢er,
|
||||
const vtkm::Vec<FloatDefault, 3> &axis,
|
||||
FloatDefault radius);
|
||||
|
||||
void SetCenter(const vtkm::Vec<FloatDefault, 3> ¢er);
|
||||
void SetAxis(const vtkm::Vec<FloatDefault, 3> &axis);
|
||||
void SetRadius(FloatDefault radius);
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetCenter() const;
|
||||
const vtkm::Vec<FloatDefault, 3>& GetAxis() const;
|
||||
FloatDefault GetRadius() const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
|
||||
private:
|
||||
vtkm::Vec<FloatDefault, 3> Center;
|
||||
vtkm::Vec<FloatDefault, 3> Axis;
|
||||
FloatDefault Radius;
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \brief Implicit function for a frustum
|
||||
class VTKM_ALWAYS_EXPORT Frustum : public ImplicitFunctionImpl<Frustum>
|
||||
{
|
||||
public:
|
||||
Frustum();
|
||||
Frustum(const vtkm::Vec<FloatDefault, 3> points[6],
|
||||
const vtkm::Vec<FloatDefault, 3> normals[6]);
|
||||
explicit Frustum(const vtkm::Vec<FloatDefault, 3> points[8]);
|
||||
|
||||
void SetPlanes(const vtkm::Vec<FloatDefault, 3> points[6],
|
||||
const vtkm::Vec<FloatDefault, 3> normals[6]);
|
||||
void SetPlane(int idx, vtkm::Vec<FloatDefault, 3> &point,
|
||||
vtkm::Vec<FloatDefault, 3> &normal);
|
||||
|
||||
void GetPlanes(vtkm::Vec<FloatDefault, 3> points[6],
|
||||
vtkm::Vec<FloatDefault, 3> normals[6]) const;
|
||||
const vtkm::Vec<FloatDefault, 3>* GetPoints() const;
|
||||
const vtkm::Vec<FloatDefault, 3>* GetNormals() const;
|
||||
|
||||
// The points should be specified in the order of hex-cell vertices
|
||||
void CreateFromPoints(const vtkm::Vec<FloatDefault, 3> points[8]);
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(FloatDefault, FloatDefault, FloatDefault) const;
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3>&) const;
|
||||
|
||||
private:
|
||||
vtkm::Vec<FloatDefault, 3> Points[6];
|
||||
vtkm::Vec<FloatDefault, 3> Normals[6];
|
||||
};
|
||||
|
||||
|
||||
//============================================================================
|
||||
/// \brief Implicit function for a plane
|
||||
class VTKM_ALWAYS_EXPORT Plane : public ImplicitFunctionImpl<Plane>
|
||||
{
|
||||
public:
|
||||
Plane()
|
||||
: Origin(FloatDefault(0)),
|
||||
Normal(FloatDefault(0), FloatDefault(0), FloatDefault(1))
|
||||
{ }
|
||||
|
||||
explicit Plane(const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
: Origin(FloatDefault(0)),
|
||||
Normal(normal)
|
||||
{ }
|
||||
|
||||
Plane();
|
||||
explicit Plane(const vtkm::Vec<FloatDefault, 3> &normal);
|
||||
Plane(const vtkm::Vec<FloatDefault, 3> &origin,
|
||||
const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
: Origin(origin), Normal(normal)
|
||||
{ }
|
||||
const vtkm::Vec<FloatDefault, 3> &normal);
|
||||
|
||||
void SetOrigin(const vtkm::Vec<FloatDefault, 3> &origin)
|
||||
{
|
||||
this->Origin = origin;
|
||||
this->Modified();
|
||||
}
|
||||
void SetOrigin(const vtkm::Vec<FloatDefault, 3> &origin);
|
||||
void SetNormal(const vtkm::Vec<FloatDefault, 3> &normal);
|
||||
|
||||
void SetNormal(const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
{
|
||||
this->Normal = normal;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetOrigin() const
|
||||
{
|
||||
return this->Origin;
|
||||
}
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetNormal() const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
const vtkm::Vec<FloatDefault, 3>& GetOrigin() const;
|
||||
const vtkm::Vec<FloatDefault, 3>& GetNormal() const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return ((x - this->Origin[0]) * this->Normal[0]) +
|
||||
((y - this->Origin[1]) * this->Normal[1]) +
|
||||
((z - this->Origin[2]) * this->Normal[2]);
|
||||
}
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Value(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(FloatDefault, FloatDefault, FloatDefault) const;
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(FloatDefault, FloatDefault, FloatDefault) const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3>&) const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3>&) const;
|
||||
|
||||
private:
|
||||
vtkm::Vec<FloatDefault, 3> Origin;
|
||||
@ -268,65 +269,27 @@ private:
|
||||
class VTKM_ALWAYS_EXPORT Sphere : public ImplicitFunctionImpl<Sphere>
|
||||
{
|
||||
public:
|
||||
Sphere() : Radius(FloatDefault(0.2)), Center(FloatDefault(0))
|
||||
{ }
|
||||
Sphere();
|
||||
explicit Sphere(FloatDefault radius);
|
||||
Sphere(vtkm::Vec<FloatDefault, 3> center, FloatDefault radius);
|
||||
|
||||
explicit Sphere(FloatDefault radius) : Radius(radius), Center(FloatDefault(0))
|
||||
{ }
|
||||
void SetRadius(FloatDefault radius);
|
||||
void SetCenter(const vtkm::Vec<FloatDefault, 3> ¢er);
|
||||
|
||||
Sphere(vtkm::Vec<FloatDefault, 3> center, FloatDefault radius)
|
||||
: Radius(radius), Center(center)
|
||||
{ }
|
||||
|
||||
void SetRadius(FloatDefault radius)
|
||||
{
|
||||
this->Radius = radius;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
void SetCenter(const vtkm::Vec<FloatDefault, 3> ¢er)
|
||||
{
|
||||
this->Center = center;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
FloatDefault GetRadius() const
|
||||
{
|
||||
return this->Radius;
|
||||
}
|
||||
|
||||
const vtkm::Vec<FloatDefault, 3>& GetCenter() const
|
||||
{
|
||||
return this->Center;
|
||||
}
|
||||
FloatDefault GetRadius() const;
|
||||
const vtkm::Vec<FloatDefault, 3>& GetCenter() const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return ((x - this->Center[0]) * (x - this->Center[0]) +
|
||||
(y - this->Center[1]) * (y - this->Center[1]) +
|
||||
(z - this->Center[2]) * (z - this->Center[2])) -
|
||||
(this->Radius * this->Radius);
|
||||
}
|
||||
FloatDefault Value(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
FloatDefault Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Value(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const;
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(FloatDefault x, FloatDefault y, FloatDefault z)
|
||||
const
|
||||
{
|
||||
return this->Gradient(vtkm::Vec<FloatDefault, 3>(x, y, z));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
vtkm::Vec<FloatDefault, 3> Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return FloatDefault(2) * (x - this->Center);
|
||||
}
|
||||
vtkm::Vec<FloatDefault, 3>
|
||||
Gradient(const vtkm::Vec<FloatDefault, 3> &x) const;
|
||||
|
||||
private:
|
||||
FloatDefault Radius;
|
||||
|
@ -17,12 +17,72 @@
|
||||
// Laboratory (LANL), the U.S. Government retains certain rights in
|
||||
// this software.
|
||||
//============================================================================
|
||||
#include <vtkm/cont/ErrorBadValue.h>
|
||||
#include <vtkm/VectorAnalysis.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
|
||||
|
||||
namespace vtkm {
|
||||
namespace cont {
|
||||
|
||||
//============================================================================
|
||||
inline Box::Box()
|
||||
: MinPoint(vtkm::Vec<FloatDefault,3>(FloatDefault(0))),
|
||||
MaxPoint(vtkm::Vec<FloatDefault,3>(FloatDefault(1)))
|
||||
{ }
|
||||
|
||||
inline Box::Box(vtkm::Vec<FloatDefault, 3> minPoint,
|
||||
vtkm::Vec<FloatDefault, 3> maxPoint)
|
||||
: MinPoint(minPoint), MaxPoint(maxPoint)
|
||||
{ }
|
||||
|
||||
inline Box::Box(FloatDefault xmin, FloatDefault xmax,
|
||||
FloatDefault ymin, FloatDefault ymax,
|
||||
FloatDefault zmin, FloatDefault zmax)
|
||||
{
|
||||
MinPoint[0] = xmin; MaxPoint[0] = xmax;
|
||||
MinPoint[1] = ymin; MaxPoint[1] = ymax;
|
||||
MinPoint[2] = zmin; MaxPoint[2] = zmax;
|
||||
}
|
||||
|
||||
inline void Box::SetMinPoint(const vtkm::Vec<FloatDefault, 3> &point)
|
||||
{
|
||||
this->MinPoint = point;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Box::SetMaxPoint(const vtkm::Vec<FloatDefault, 3> &point)
|
||||
{
|
||||
this->MaxPoint = point;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Box::GetMinPoint() const
|
||||
{
|
||||
return this->MinPoint;
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Box::GetMaxPoint() const
|
||||
{
|
||||
return this->MaxPoint;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Box::Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return this->Value(vtkm::Vec<vtkm::FloatDefault,3>(x, y, z));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Box::Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return this->Gradient(vtkm::Vec<FloatDefault, 3>(x, y, z));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Box::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
@ -93,7 +153,6 @@ Box::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
}
|
||||
}
|
||||
|
||||
//============================================================================
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Box::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
@ -103,11 +162,9 @@ Box::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
FloatDefault minDist = vtkm::Infinity32();
|
||||
vtkm::Vec<vtkm::IdComponent,3> location;
|
||||
vtkm::Vec<FloatDefault,3> normal;
|
||||
vtkm::Vec<FloatDefault,3> inside(FloatDefault(0), FloatDefault(0), FloatDefault(0));
|
||||
vtkm::Vec<FloatDefault,3> outside(FloatDefault(0), FloatDefault(0), FloatDefault(0));
|
||||
vtkm::Vec<FloatDefault,3> center((this->MaxPoint[0] + this->MinPoint[0]) * FloatDefault(0.5),
|
||||
(this->MaxPoint[1] + this->MinPoint[1]) * FloatDefault(0.5),
|
||||
(this->MaxPoint[2] + this->MinPoint[2]) * FloatDefault(0.5));
|
||||
vtkm::Vec<FloatDefault,3> inside(FloatDefault(0));
|
||||
vtkm::Vec<FloatDefault,3> outside(FloatDefault(0));
|
||||
vtkm::Vec<FloatDefault,3> center((this->MaxPoint + this->MinPoint) * FloatDefault(0.5));
|
||||
|
||||
// Compute the location of the point with respect to the box
|
||||
// Point will lie in one of 27 separate regions around or within the box
|
||||
@ -200,5 +257,350 @@ Box::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
inline Cylinder::Cylinder()
|
||||
: Center(FloatDefault(0)),
|
||||
Axis(vtkm::make_Vec(FloatDefault(1), FloatDefault(0), FloatDefault(0))),
|
||||
Radius(FloatDefault(0.2))
|
||||
{ }
|
||||
|
||||
inline Cylinder::Cylinder(const vtkm::Vec<FloatDefault, 3> &axis,
|
||||
FloatDefault radius)
|
||||
: Center(FloatDefault(0)), Axis(vtkm::Normal(axis)), Radius(radius)
|
||||
{ }
|
||||
|
||||
inline Cylinder::Cylinder(const vtkm::Vec<FloatDefault, 3> ¢er,
|
||||
const vtkm::Vec<FloatDefault, 3> &axis,
|
||||
FloatDefault radius)
|
||||
: Center(center), Axis(vtkm::Normal(axis)), Radius(radius)
|
||||
{ }
|
||||
|
||||
inline void Cylinder::SetCenter(const vtkm::Vec<FloatDefault, 3> ¢er)
|
||||
{
|
||||
this->Center = center;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Cylinder::SetAxis(const vtkm::Vec<FloatDefault, 3> &axis)
|
||||
{
|
||||
this->Axis = vtkm::Normal(axis);
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Cylinder::SetRadius(FloatDefault radius)
|
||||
{
|
||||
this->Radius = radius;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Cylinder::GetCenter() const
|
||||
{
|
||||
return this->Center;
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Cylinder::GetAxis() const
|
||||
{
|
||||
return this->Axis;
|
||||
}
|
||||
|
||||
inline FloatDefault Cylinder::GetRadius() const
|
||||
{
|
||||
return this->Radius;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault Cylinder::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
vtkm::Vec<FloatDefault, 3> x2c = x - this->Center;
|
||||
FloatDefault proj = vtkm::dot(this->Axis, x2c);
|
||||
return vtkm::dot(x2c, x2c) - (proj * proj) - (this->Radius * this->Radius);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Cylinder::Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return this->Value(vtkm::Vec<vtkm::FloatDefault,3>(x, y, z));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Cylinder::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
vtkm::Vec<FloatDefault, 3> x2c = x - this->Center;
|
||||
FloatDefault t = this->Axis[0] * x2c[0] +
|
||||
this->Axis[1] * x2c[1] +
|
||||
this->Axis[2] * x2c[2];
|
||||
vtkm::Vec<FloatDefault, 3> closestPoint = this->Center + (this->Axis * t);
|
||||
return (x - closestPoint) * FloatDefault(2);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Cylinder::Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return this->Gradient(vtkm::Vec<FloatDefault, 3>(x, y, z));
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
inline Frustum::Frustum()
|
||||
{
|
||||
std::fill(this->Points, this->Points + 6, vtkm::Vec<FloatDefault, 3>{});
|
||||
std::fill(this->Normals, this->Normals + 6, vtkm::Vec<FloatDefault, 3>{});
|
||||
}
|
||||
|
||||
inline Frustum::Frustum(const vtkm::Vec<FloatDefault, 3> points[6],
|
||||
const vtkm::Vec<FloatDefault, 3> normals[6])
|
||||
{
|
||||
std::copy(points, points + 6, this->Points);
|
||||
std::copy(normals, normals + 6, this->Normals);
|
||||
}
|
||||
|
||||
inline Frustum::Frustum(const vtkm::Vec<FloatDefault, 3> points[8])
|
||||
{
|
||||
this->CreateFromPoints(points);
|
||||
}
|
||||
|
||||
inline void Frustum::SetPlanes(const vtkm::Vec<FloatDefault, 3> points[6],
|
||||
const vtkm::Vec<FloatDefault, 3> normals[6])
|
||||
{
|
||||
std::copy(points, points + 6, this->Points);
|
||||
std::copy(normals, normals + 6, this->Normals);
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Frustum::GetPlanes(vtkm::Vec<FloatDefault, 3> points[6],
|
||||
vtkm::Vec<FloatDefault, 3> normals[6]) const
|
||||
{
|
||||
std::copy(this->Points, this->Points + 6, points);
|
||||
std::copy(this->Normals, this->Normals + 6, normals);
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>* Frustum::GetPoints() const
|
||||
{
|
||||
return this->Points;
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>* Frustum::GetNormals() const
|
||||
{
|
||||
return this->Normals;
|
||||
}
|
||||
|
||||
inline void Frustum::SetPlane(int idx, vtkm::Vec<FloatDefault, 3> &point,
|
||||
vtkm::Vec<FloatDefault, 3> &normal)
|
||||
{
|
||||
if (idx < 0 || idx >= 6)
|
||||
{
|
||||
std::string msg = "Plane idx ";
|
||||
msg += std::to_string(idx) + " is out of range [0, 5]";
|
||||
throw vtkm::cont::ErrorBadValue(msg);
|
||||
}
|
||||
|
||||
this->Points[idx] = point;
|
||||
this->Normals[idx] = normal;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Frustum::CreateFromPoints(const vtkm::Vec<FloatDefault, 3> points[8])
|
||||
{
|
||||
int planes[6][3] = {{3, 2, 0}, {4, 5, 7}, {0, 1, 4},
|
||||
{1, 2, 5}, {2, 3, 6}, {3, 0, 7}};
|
||||
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
auto &v0 = points[planes[i][0]];
|
||||
auto &v1 = points[planes[i][1]];
|
||||
auto &v2 = points[planes[i][2]];
|
||||
|
||||
this->Points[i] = v0;
|
||||
this->Normals[i] = vtkm::Normal(vtkm::Cross(v2 - v0, v1 - v0));
|
||||
this->Modified();
|
||||
}
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Frustum::Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
FloatDefault maxVal = -std::numeric_limits<FloatDefault>::max();
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
auto &p = this->Points[i];
|
||||
auto &n = this->Normals[i];
|
||||
FloatDefault val = ((x - p[0]) * n[0]) + ((y - p[1]) * n[1]) + ((z - p[2]) * n[2]);
|
||||
maxVal = vtkm::Max(maxVal, val);
|
||||
}
|
||||
return maxVal;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault Frustum::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Value(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Frustum::Gradient(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
FloatDefault maxVal = -std::numeric_limits<FloatDefault>::max();
|
||||
int maxValIdx = 0;
|
||||
for (int i = 0; i < 6; ++i)
|
||||
{
|
||||
auto &p = this->Points[i];
|
||||
auto &n = this->Normals[i];
|
||||
FloatDefault val = ((x - p[0]) * n[0]) + ((y - p[1]) * n[1]) + ((z - p[2]) * n[2]);
|
||||
if (val > maxVal)
|
||||
{
|
||||
maxVal = val;
|
||||
maxValIdx = i;
|
||||
}
|
||||
}
|
||||
return this->Normals[maxValIdx];
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Frustum::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Gradient(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
inline Plane::Plane()
|
||||
: Origin(FloatDefault(0)),
|
||||
Normal(FloatDefault(0), FloatDefault(0), FloatDefault(1))
|
||||
{ }
|
||||
|
||||
inline Plane::Plane(const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
: Origin(FloatDefault(0)),
|
||||
Normal(normal)
|
||||
{ }
|
||||
|
||||
inline Plane::Plane(const vtkm::Vec<FloatDefault, 3> &origin,
|
||||
const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
: Origin(origin), Normal(normal)
|
||||
{ }
|
||||
|
||||
inline void Plane::SetOrigin(const vtkm::Vec<FloatDefault, 3> &origin)
|
||||
{
|
||||
this->Origin = origin;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Plane::SetNormal(const vtkm::Vec<FloatDefault, 3> &normal)
|
||||
{
|
||||
this->Normal = normal;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Plane::GetOrigin() const
|
||||
{
|
||||
return this->Origin;
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Plane::GetNormal() const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Plane::Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return ((x - this->Origin[0]) * this->Normal[0]) +
|
||||
((y - this->Origin[1]) * this->Normal[1]) +
|
||||
((z - this->Origin[2]) * this->Normal[2]);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault Plane::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Value(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Plane::Gradient(FloatDefault, FloatDefault, FloatDefault) const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Plane::Gradient(const vtkm::Vec<FloatDefault, 3>&) const
|
||||
{
|
||||
return this->Normal;
|
||||
}
|
||||
|
||||
|
||||
//============================================================================
|
||||
inline Sphere::Sphere()
|
||||
: Radius(FloatDefault(0.2)), Center(FloatDefault(0))
|
||||
{ }
|
||||
|
||||
inline Sphere::Sphere(FloatDefault radius)
|
||||
: Radius(radius), Center(FloatDefault(0))
|
||||
{ }
|
||||
|
||||
inline Sphere::Sphere(vtkm::Vec<FloatDefault, 3> center, FloatDefault radius)
|
||||
: Radius(radius), Center(center)
|
||||
{ }
|
||||
|
||||
inline void Sphere::SetRadius(FloatDefault radius)
|
||||
{
|
||||
this->Radius = radius;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline void Sphere::SetCenter(const vtkm::Vec<FloatDefault, 3> ¢er)
|
||||
{
|
||||
this->Center = center;
|
||||
this->Modified();
|
||||
}
|
||||
|
||||
inline FloatDefault Sphere::GetRadius() const
|
||||
{
|
||||
return this->Radius;
|
||||
}
|
||||
|
||||
inline const vtkm::Vec<FloatDefault, 3>& Sphere::GetCenter() const
|
||||
{
|
||||
return this->Center;
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault
|
||||
Sphere::Value(FloatDefault x, FloatDefault y, FloatDefault z) const
|
||||
{
|
||||
return ((x - this->Center[0]) * (x - this->Center[0]) +
|
||||
(y - this->Center[1]) * (y - this->Center[1]) +
|
||||
(z - this->Center[2]) * (z - this->Center[2])) -
|
||||
(this->Radius * this->Radius);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline FloatDefault Sphere::Value(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return this->Value(x[0], x[1], x[2]);
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Sphere::Gradient(FloatDefault x, FloatDefault y, FloatDefault z)
|
||||
const
|
||||
{
|
||||
return this->Gradient(vtkm::Vec<FloatDefault, 3>(x, y, z));
|
||||
}
|
||||
|
||||
VTKM_EXEC_CONT
|
||||
inline vtkm::Vec<FloatDefault, 3>
|
||||
Sphere::Gradient(const vtkm::Vec<FloatDefault, 3> &x) const
|
||||
{
|
||||
return FloatDefault(2) * (x - this->Center);
|
||||
}
|
||||
|
||||
}
|
||||
} // vtkm::cont
|
||||
|
@ -79,21 +79,40 @@ template <std::size_t N>
|
||||
bool TestArrayEqual(const vtkm::cont::ArrayHandle<vtkm::FloatDefault> &result,
|
||||
const std::array<vtkm::FloatDefault, N> &expected)
|
||||
{
|
||||
if (result.GetNumberOfValues() != N)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
bool success = false;
|
||||
auto portal = result.GetPortalConstControl();
|
||||
vtkm::Id count = portal.GetNumberOfValues();
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault>::PortalConstControl portal =
|
||||
result.GetPortalConstControl();
|
||||
for (std::size_t i = 0; i < N; ++i)
|
||||
if (static_cast<std::size_t>(count) == N)
|
||||
{
|
||||
if (!test_equal(portal.Get(static_cast<vtkm::Id>(i)), expected[i]))
|
||||
success = true;
|
||||
for (vtkm::Id i = 0; i < count; ++i)
|
||||
{
|
||||
return false;
|
||||
if (!test_equal(portal.Get(i), expected[static_cast<std::size_t>(i)]))
|
||||
{
|
||||
success = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return true;
|
||||
if (!success)
|
||||
{
|
||||
if (count == 0)
|
||||
{
|
||||
std::cout << "result: <empty>\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "result: " << portal.Get(0);
|
||||
for (vtkm::Id i = 1; i < count; ++i)
|
||||
{
|
||||
std::cout << ", " << portal.Get(i);
|
||||
}
|
||||
std::cout << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
} // anonymous namespace
|
||||
@ -109,26 +128,80 @@ public:
|
||||
template<typename DeviceAdapter>
|
||||
void Run(DeviceAdapter device)
|
||||
{
|
||||
this->TestSphere(device);
|
||||
this->TestPlane(device);
|
||||
this->TestBox(device);
|
||||
this->TestCylinder(device);
|
||||
this->TestFrustum(device);
|
||||
this->TestPlane(device);
|
||||
this->TestSphere(device);
|
||||
}
|
||||
|
||||
private:
|
||||
template <typename DeviceAdapter>
|
||||
void TestSphere(DeviceAdapter device)
|
||||
void TestBox(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::cont::Sphere on "
|
||||
std::cout << "Testing vtkm::cont::Box on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< "\n";
|
||||
|
||||
vtkm::cont::Sphere sphere({0.0f, 0.0f, 0.0f}, 1.0f);
|
||||
vtkm::cont::Box box({0.0f, -0.5f, -0.5f}, {1.5f, 1.5f, 0.5f});
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), sphere, values, device);
|
||||
this->Input.GetCoordinateSystem(0), box, values, device);
|
||||
|
||||
std::array<vtkm::FloatDefault, 8> expected =
|
||||
{ {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 2.0f, 1.0f} };
|
||||
{ {0.0f, -0.5f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 0.5f} };
|
||||
VTKM_TEST_ASSERT(implicit_function_detail::TestArrayEqual(values, expected),
|
||||
"Result does not match expected values");
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestCylinder(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::cont::Cylinder on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< "\n";
|
||||
|
||||
vtkm::cont::Cylinder cylinder;
|
||||
cylinder.SetCenter({0.0f, 0.0f, 1.0f});
|
||||
cylinder.SetAxis({0.0f, 1.0f, 0.0f});
|
||||
cylinder.SetRadius(1.0f);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), cylinder, values, device);
|
||||
|
||||
std::array<vtkm::FloatDefault, 8> expected =
|
||||
{ {0.0f, 1.0f, 0.0f, -1.0f, 0.0f, 1.0f, 0.0f, -1.0f} };
|
||||
VTKM_TEST_ASSERT(implicit_function_detail::TestArrayEqual(values, expected),
|
||||
"Result does not match expected values");
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestFrustum(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::cont::Frustum on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< "\n";
|
||||
|
||||
vtkm::Vec<vtkm::FloatDefault, 3> points[8] = {
|
||||
{0.0f, 0.0f, 0.0f}, // 0
|
||||
{1.0f, 0.0f, 0.0f}, // 1
|
||||
{1.0f, 0.0f, 1.0f}, // 2
|
||||
{0.0f, 0.0f, 1.0f}, // 3
|
||||
{0.5f, 1.5f, 0.5f}, // 4
|
||||
{1.5f, 1.5f, 0.5f}, // 5
|
||||
{1.5f, 1.5f, 1.5f}, // 6
|
||||
{0.5f, 1.5f, 1.5f} // 7
|
||||
};
|
||||
vtkm::cont::Frustum frustum;
|
||||
frustum.CreateFromPoints(points);
|
||||
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), frustum, values, device);
|
||||
|
||||
std::array<vtkm::FloatDefault, 8> expected =
|
||||
{ {0.0f, 0.0f, 0.0f, 0.0f, 0.316228f, 0.316228f, -0.316228f, 0.316228f} };
|
||||
VTKM_TEST_ASSERT(implicit_function_detail::TestArrayEqual(values, expected),
|
||||
"Result does not match expected values");
|
||||
}
|
||||
@ -160,19 +233,19 @@ private:
|
||||
}
|
||||
|
||||
template <typename DeviceAdapter>
|
||||
void TestBox(DeviceAdapter device)
|
||||
void TestSphere(DeviceAdapter device)
|
||||
{
|
||||
std::cout << "Testing vtkm::cont::Box on "
|
||||
std::cout << "Testing vtkm::cont::Sphere on "
|
||||
<< vtkm::cont::DeviceAdapterTraits<DeviceAdapter>::GetName()
|
||||
<< "\n";
|
||||
|
||||
vtkm::cont::Box box({0.0f, -0.5f, -0.5f}, {1.5f, 1.5f, 0.5f});
|
||||
vtkm::cont::Sphere sphere({0.0f, 0.0f, 0.0f}, 1.0f);
|
||||
vtkm::cont::ArrayHandle<vtkm::FloatDefault> values;
|
||||
implicit_function_detail::EvaluateOnCoordinates(
|
||||
this->Input.GetCoordinateSystem(0), box, values, device);
|
||||
this->Input.GetCoordinateSystem(0), sphere, values, device);
|
||||
|
||||
std::array<vtkm::FloatDefault, 8> expected =
|
||||
{ {0.0f, -0.5f, 0.5f, 0.5f, 0.0f, -0.5f, 0.5f, 0.5f} };
|
||||
{ {-1.0f, 0.0f, 1.0f, 0.0f, 0.0f, 1.0f, 2.0f, 1.0f} };
|
||||
VTKM_TEST_ASSERT(implicit_function_detail::TestArrayEqual(values, expected),
|
||||
"Result does not match expected values");
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user