| 1 |
/* |
| 2 |
* (C) Copyright 2013 ECMWF. |
| 3 |
* |
| 4 |
* This software is licensed under the terms of the Apache Licence Version 2.0 |
| 5 |
* which can be obtained at http://www.apache.org/licenses/LICENSE-2.0. |
| 6 |
* In applying this licence, ECMWF does not waive the privileges and immunities |
| 7 |
* granted to it by virtue of its status as an intergovernmental organisation |
| 8 |
* nor does it submit to any jurisdiction. |
| 9 |
*/ |
| 10 |
|
| 11 |
#pragma once |
| 12 |
|
| 13 |
#include <iosfwd> |
| 14 |
#include <limits> |
| 15 |
|
| 16 |
#include "atlas/interpolation/Vector3D.h" |
| 17 |
#include "atlas/interpolation/method/Intersect.h" |
| 18 |
#include "atlas/runtime/Exception.h" |
| 19 |
#include "atlas/util/Point.h" |
| 20 |
|
| 21 |
namespace atlas { |
| 22 |
namespace interpolation { |
| 23 |
namespace method { |
| 24 |
struct Ray; |
| 25 |
} |
| 26 |
namespace element { |
| 27 |
|
| 28 |
//---------------------------------------------------------------------------------------------------------------------- |
| 29 |
|
| 30 |
class Quad3D { |
| 31 |
public: |
| 32 |
Quad3D(const double* x0, const double* x1, const double* x2, const double* x3): |
| 33 |
v00(x0), v10(x1), v11(x2), v01(x3) {} |
| 34 |
|
| 35 |
Quad3D(const PointXYZ& x0, const PointXYZ& x1, const PointXYZ& x2, const PointXYZ& x3): |
| 36 |
Quad3D(x0.data(), x1.data(), x2.data(), x3.data()) {} |
| 37 |
|
| 38 |
method::Intersect intersects(const method::Ray& r, double edgeEpsilon = 5 * std::numeric_limits<double>::epsilon(), |
| 39 |
double epsilon = 5 * std::numeric_limits<double>::epsilon()) const; |
| 40 |
|
| 41 |
bool validate() const; |
| 42 |
|
| 43 |
double area() const; |
| 44 |
|
| 45 |
void print(std::ostream&) const; |
| 46 |
|
| 47 |
friend std::ostream& operator<<(std::ostream& s, const Quad3D& p) { |
| 48 |
p.print(s); |
| 49 |
return s; |
| 50 |
} |
| 51 |
|
| 52 |
const Vector3D& p(int i) { |
| 53 |
if (i == 0) |
| 54 |
return v00; |
| 55 |
if (i == 1) |
| 56 |
return v10; |
| 57 |
if (i == 2) |
| 58 |
return v11; |
| 59 |
if (i == 3) |
| 60 |
return v01; |
| 61 |
throw_OutOfRange("Quad3D::p(i)", i, 4, Here()); |
| 62 |
} |
| 63 |
|
| 64 |
private: // members |
| 65 |
Vector3D v00; // aka v0 |
| 66 |
Vector3D v10; // aka v1 |
| 67 |
Vector3D v11; // aka v2 |
| 68 |
Vector3D v01; // aka v3 |
| 69 |
}; |
| 70 |
|
| 71 |
//---------------------------------------------------------------------------------------------------------------------- |
| 72 |
|
| 73 |
} // namespace element |
| 74 |
} // namespace interpolation |
| 75 |
} // namespace atlas |