Debian Codegraph @

src/atlas/interpolation/element/Triag3D.h

raw
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 /// Triangle structure
31 /// Implements @link
32 /// http://www.scratchapixel.com/lessons/3d-basic-lessons/lesson-9-ray-triangle-intersection/m-ller-trumbore-algorithm
33
34 class Triag3D {
35 public: // types
36 Triag3D(const double* x0, const double* x1, const double* x2): v0(x0), v1(x1), v2(x2) {}
37
38 Triag3D(const PointXYZ& x0, const PointXYZ& x1, const PointXYZ& x2): Triag3D(x0.data(), x1.data(), x2.data()) {}
39
40 Triag3D(const Vector3D& x0, const Vector3D& x1, const Vector3D& x2): Triag3D(x0.data(), x1.data(), x2.data()) {}
41
42 method::Intersect intersects(const method::Ray& r, double edgeEpsilon = 5 * std::numeric_limits<double>::epsilon(),
43 double epsilon = 5 * std::numeric_limits<double>::epsilon()) const;
44
45 double area() const;
46
47 void print(std::ostream& s) const;
48
49 friend std::ostream& operator<<(std::ostream& s, const Triag3D& p) {
50 p.print(s);
51 return s;
52 }
53
54 const Vector3D& p(int i) {
55 if (i == 0)
56 return v0;
57 if (i == 1)
58 return v1;
59 if (i == 2)
60 return v2;
61 throw_OutOfRange("Triag3D::p(i)", i, 3, Here());
62 }
63
64 private: // members
65 Vector3D v0;
66 Vector3D v1;
67 Vector3D v2;
68 };
69
70 //----------------------------------------------------------------------------------------------------------------------
71
72 } // namespace element
73 } // namespace interpolation
74 } // namespace atlas