diff --git a/vtkm/Geometry.hxx b/vtkm/Geometry.hxx index c766d32dd..bc9cdc41d 100644 --- a/vtkm/Geometry.hxx +++ b/vtkm/Geometry.hxx @@ -16,7 +16,7 @@ namespace vtkm template template ::type> -Ray::Ray() +VTKM_EXEC_CONT Ray::Ray() : Origin{ 0.f } , Direction{ 1.f, 0.f } { @@ -24,50 +24,42 @@ Ray::Ray() template template ::type> -Ray::Ray() +VTKM_EXEC_CONT Ray::Ray() : Origin{ 0.f } , Direction{ 1.f, 0.f, 0.f } { } template -Ray::Ray(const LineSegment& segment) +VTKM_EXEC_CONT Ray::Ray(const LineSegment& segment) : Origin(segment.Endpoints[0]) , Direction(vtkm::Normal(segment.Direction())) { } template -Ray::Ray(const Vector& point, const Vector& direction) +VTKM_EXEC_CONT Ray::Ray(const Vector& point, const Vector& direction) : Origin(point) , Direction(vtkm::Normal(direction)) { } template -typename Ray::Vector Ray::Evaluate( - CoordType param) const +VTKM_EXEC_CONT typename Ray::Vector +Ray::Evaluate(CoordType param) const { auto pointOnLine = this->Origin + this->Direction * param; return pointOnLine; } template -bool Ray::IsValid() const +VTKM_EXEC_CONT bool Ray::IsValid() const { -// At least on Ubuntu 17.10, cuda 9.1 will fail with an internal -// compiler error when calling vtkm::IsInf() here. But the fix -// below works. The fix should be removed as soon as our dashboards -// allow it. -#if __CUDACC_VER_MAJOR__ == 9 && __CUDACC_VER_MINOR__ == 1 - return !isinf(this->Direction[0]); -#else return !vtkm::IsInf(this->Direction[0]); -#endif } template -CoordType Ray::DistanceTo(const Vector& point) const +VTKM_EXEC_CONT CoordType Ray::DistanceTo(const Vector& point) const { Vector closest; CoordType param; @@ -75,9 +67,9 @@ CoordType Ray::DistanceTo(const Vector& point) const } template -CoordType Ray::DistanceTo(const Vector& point, - CoordType& param, - Vector& projectedPoint) const +VTKM_EXEC_CONT CoordType Ray::DistanceTo(const Vector& point, + CoordType& param, + Vector& projectedPoint) const { const auto& dir = this->Direction; auto mag2 = vtkm::MagnitudeSquared(dir); @@ -105,9 +97,10 @@ CoordType Ray::DistanceTo(const Vector& point, template template ::type> -bool Ray::Intersect(const Ray& other, - Vector& point, - CoordType tol) +VTKM_EXEC_CONT bool Ray::Intersect( + const Ray& other, + Vector& point, + CoordType tol) { auto d1 = this->Direction; auto d2 = other.Direction; @@ -139,33 +132,33 @@ bool Ray::Intersect(const Ray template ::type> -LineSegment::LineSegment() +VTKM_EXEC_CONT LineSegment::LineSegment() : Endpoints{ { 0.f }, { 1.f, 0.f } } { } template template ::type> -LineSegment::LineSegment() +VTKM_EXEC_CONT LineSegment::LineSegment() : Endpoints{ { 0.f }, { 1.f, 0.f, 0.f } } { } template -LineSegment::LineSegment(const Vector& p0, const Vector& p1) +VTKM_EXEC_CONT LineSegment::LineSegment(const Vector& p0, const Vector& p1) : Endpoints{ p0, p1 } { } template -bool LineSegment::IsSingular(CoordType tol2) const +VTKM_EXEC_CONT bool LineSegment::IsSingular(CoordType tol2) const { return vtkm::MagnitudeSquared(this->Direction()) < tol2; } template template ::type> -Ray LineSegment::PerpendicularBisector() const +VTKM_EXEC_CONT Ray LineSegment::PerpendicularBisector() const { const Vector dir = this->Direction(); const Vector perp(-dir[1], dir[0]); @@ -175,13 +168,13 @@ Ray LineSegment::PerpendicularBisector() c template template ::type> -Plane LineSegment::PerpendicularBisector() const +VTKM_EXEC_CONT Plane LineSegment::PerpendicularBisector() const { return Plane(this->Center(), this->Direction()); } template -typename LineSegment::Vector LineSegment::Evaluate( +VTKM_EXEC_CONT typename LineSegment::Vector LineSegment::Evaluate( CoordType param) const { auto pointOnLine = this->Endpoints[0] * (1.0f - param) + this->Endpoints[1] * param; @@ -189,7 +182,7 @@ typename LineSegment::Vector LineSegment::Evalua } template -CoordType LineSegment::DistanceTo(const Vector& point) const +VTKM_EXEC_CONT CoordType LineSegment::DistanceTo(const Vector& point) const { Vector closest; CoordType param; @@ -197,9 +190,9 @@ CoordType LineSegment::DistanceTo(const Vector& point) const } template -CoordType LineSegment::DistanceTo(const Vector& point, - CoordType& param, - Vector& projectedPoint) const +VTKM_EXEC_CONT CoordType LineSegment::DistanceTo(const Vector& point, + CoordType& param, + Vector& projectedPoint) const { auto dir = this->Endpoints[1] - this->Endpoints[0]; auto mag2 = vtkm::MagnitudeSquared(dir); @@ -224,9 +217,10 @@ CoordType LineSegment::DistanceTo(const Vector& point, template template ::type> -bool LineSegment::IntersectInfinite(const LineSegment& other, - Vector& point, - CoordType tol) +VTKM_EXEC_CONT bool LineSegment::IntersectInfinite( + const LineSegment& other, + Vector& point, + CoordType tol) { auto d1 = this->Direction(); auto d2 = other.Direction(); @@ -249,14 +243,14 @@ bool LineSegment::IntersectInfinite(const LineSegment -Plane::Plane() +VTKM_EXEC_CONT VTKM_EXEC_CONT Plane::Plane() : Origin{ 0.f, 0.f, 0.f } , Normal{ 0.f, 0.f, 1.f } { } template -Plane::Plane(const Vector& origin, const Vector& normal, CoordType tol2) +VTKM_EXEC_CONT Plane::Plane(const Vector& origin, const Vector& normal, CoordType tol2) : Origin(origin) , Normal(vtkm::Normal(normal)) { @@ -268,14 +262,15 @@ Plane::Plane(const Vector& origin, const Vector& normal, CoordType to } template -CoordType Plane::DistanceTo(const Vector& point) const +VTKM_EXEC_CONT CoordType Plane::DistanceTo(const Vector& point) const { auto dist = vtkm::Dot(point - this->Origin, this->Normal); return dist; } template -typename Plane::Vector Plane::ClosestPoint(const Vector& point) const +VTKM_EXEC_CONT typename Plane::Vector Plane::ClosestPoint( + const Vector& point) const { auto vop = vtkm::Project(point - this->Origin, this->Normal); auto closest = point - vop; @@ -284,11 +279,11 @@ typename Plane::Vector Plane::ClosestPoint(const Vector& p template template -bool Plane::Intersect(const Ray& ray, - CoordType& parameter, - Vector& point, - bool& lineInPlane, - CoordType tol) const +VTKM_EXEC_CONT bool Plane::Intersect(const Ray& ray, + CoordType& parameter, + Vector& point, + bool& lineInPlane, + CoordType tol) const { CoordType d0 = this->DistanceTo(ray.Origin); CoordType dirDot = vtkm::Dot(this->Normal, ray.Direction); @@ -330,19 +325,19 @@ bool Plane::Intersect(const Ray& ray, } template -bool Plane::Intersect(const LineSegment& segment, - CoordType& parameter, - bool& lineInPlane) const +VTKM_EXEC_CONT bool Plane::Intersect(const LineSegment& segment, + CoordType& parameter, + bool& lineInPlane) const { Vector point; return this->Intersect(segment, parameter, point, lineInPlane); } template -bool Plane::Intersect(const LineSegment& segment, - CoordType& parameter, - Vector& point, - bool& lineInPlane) const +VTKM_EXEC_CONT bool Plane::Intersect(const LineSegment& segment, + CoordType& parameter, + Vector& point, + bool& lineInPlane) const { CoordType d0 = this->DistanceTo(segment.Endpoints[0]); CoordType d1 = this->DistanceTo(segment.Endpoints[1]); @@ -394,10 +389,10 @@ bool Plane::Intersect(const LineSegment& segment, } template -bool Plane::Intersect(const Plane& other, - Ray& ray, - bool& coincident, - CoordType tol2) const +VTKM_EXEC_CONT bool Plane::Intersect(const Plane& other, + Ray& ray, + bool& coincident, + CoordType tol2) const { auto dir = vtkm::Cross(this->Normal, other.Normal); auto mag2 = vtkm::MagnitudeSquared(dir); @@ -434,27 +429,27 @@ bool Plane::Intersect(const Plane& other, // Sphere template -Sphere::Sphere() +VTKM_EXEC_CONT Sphere::Sphere() : Center{ 0.f } , Radius(static_cast(1.f)) { } template -Sphere::Sphere(const Vector& center, CoordType radius) +VTKM_EXEC_CONT Sphere::Sphere(const Vector& center, CoordType radius) : Center(center) , Radius(radius <= 0.f ? static_cast(-1.0f) : radius) { } template -bool Sphere::Contains(const Vector& point, CoordType tol2) const +VTKM_EXEC_CONT bool Sphere::Contains(const Vector& point, CoordType tol2) const { return this->Classify(point, tol2) < 0; } template -int Sphere::Classify(const Vector& point, CoordType tol2) const +VTKM_EXEC_CONT int Sphere::Classify(const Vector& point, CoordType tol2) const { if (!this->IsValid()) { @@ -469,16 +464,17 @@ int Sphere::Classify(const Vector& point, CoordType tol2) const // Construction techniques template -vtkm::Plane make_PlaneFromPointAndLine(const vtkm::Vec& point, - const vtkm::Ray& ray, - CoordType tol2) +VTKM_EXEC_CONT vtkm::Plane make_PlaneFromPointAndLine( + const vtkm::Vec& point, + const vtkm::Ray& ray, + CoordType tol2) { auto tmpDir = point - ray.Origin; return vtkm::Plane(point, vtkm::Cross(ray.Direction, tmpDir), tol2); } template -vtkm::Plane make_PlaneFromPointAndLineSegment( +VTKM_EXEC_CONT vtkm::Plane make_PlaneFromPointAndLineSegment( const vtkm::Vec& point, const vtkm::LineSegment3& segment, CoordType tol2) @@ -488,10 +484,11 @@ vtkm::Plane make_PlaneFromPointAndLineSegment( } template -vtkm::Circle make_CircleFrom3Points(const typename vtkm::Vec& p0, - const typename vtkm::Vec& p1, - const typename vtkm::Vec& p2, - CoordType tol) +VTKM_EXEC_CONT vtkm::Circle make_CircleFrom3Points( + const typename vtkm::Vec& p0, + const typename vtkm::Vec& p1, + const typename vtkm::Vec& p2, + CoordType tol) { constexpr int Dim = 2; using Vector = typename vtkm::Circle::Vector; @@ -518,11 +515,11 @@ vtkm::Circle make_CircleFrom3Points(const typename vtkm::Vec -vtkm::Sphere make_SphereFrom4Points(const vtkm::Vec& a0, - const vtkm::Vec& a1, - const vtkm::Vec& a2, - const vtkm::Vec& a3, - CoordType tol) +VTKM_EXEC_CONT vtkm::Sphere make_SphereFrom4Points(const vtkm::Vec& a0, + const vtkm::Vec& a1, + const vtkm::Vec& a2, + const vtkm::Vec& a3, + CoordType tol) { // Choose p3 such that the min(p3 - p[012]) is larger than any other choice of p3. // From: http://steve.hollasch.net/cgindex/geometry/sphere4pts.html,