src/utilities/geometry/Transformation.hpp
| Line | Branch | Exec | Source |
|---|---|---|---|
| 1 | /*********************************************************************************************************************** | ||
| 2 | * OpenStudio(R), Copyright (c) Alliance for Energy Innovation, LLC. | ||
| 3 | * See also https://openstudio.net/license | ||
| 4 | ***********************************************************************************************************************/ | ||
| 5 | |||
| 6 | #ifndef UTILITIES_GEOMETRY_TRANSFORMATION_HPP | ||
| 7 | #define UTILITIES_GEOMETRY_TRANSFORMATION_HPP | ||
| 8 | |||
| 9 | #include "../UtilitiesAPI.hpp" | ||
| 10 | #include "../data/Matrix.hpp" | ||
| 11 | #include "../data/Vector.hpp" | ||
| 12 | #include "../core/Logger.hpp" | ||
| 13 | |||
| 14 | #include <vector> | ||
| 15 | #include <boost/optional.hpp> | ||
| 16 | |||
| 17 | namespace openstudio { | ||
| 18 | |||
| 19 | // forward declaration | ||
| 20 | class Point3d; | ||
| 21 | class Vector3d; | ||
| 22 | class Plane; | ||
| 23 | class BoundingBox; | ||
| 24 | class EulerAngles; | ||
| 25 | |||
| 26 | class UTILITIES_API Transformation | ||
| 27 | { | ||
| 28 | public: | ||
| 29 | /// default constructor creates identity transformation | ||
| 30 | Transformation(); | ||
| 31 | |||
| 32 | /// constructor from storage, asserts matrix is 4x4 | ||
| 33 | Transformation(const Matrix& matrix); | ||
| 34 | |||
| 35 | /// constructor from storage, asserts vector is size 16 | ||
| 36 | Transformation(const Vector& vector); | ||
| 37 | |||
| 38 | // Copy and move operators are implicitly declared (Rule of 1), but we want the copy ctor for SWIG so we have to define all of them | ||
| 39 | 1143872 | Transformation(const Transformation& other) = default; | |
| 40 | 35255 | Transformation(Transformation&& other) noexcept = default; | |
| 41 |
2/2✓ Branch 1 taken 2127 times.
✓ Branch 4 taken 2127 times.
|
2127 | Transformation& operator=(const Transformation&) = default; |
| 42 |
2/2✓ Branch 1 taken 91019 times.
✓ Branch 4 taken 91019 times.
|
91019 | Transformation& operator=(Transformation&&) noexcept = default; |
| 43 | // ~Transformation() noexcept = default; | ||
| 44 | |||
| 45 | /// rotation about origin defined by axis and angle (radians) | ||
| 46 | static Transformation rotation(const Vector3d& axis, double radians); | ||
| 47 | |||
| 48 | /// rotation about point defined by axis and angle (radians) | ||
| 49 | static Transformation rotation(const Point3d& origin, const Vector3d& axis, double radians); | ||
| 50 | |||
| 51 | /// rotation specified by Euler angles | ||
| 52 | static Transformation rotation(const EulerAngles& angles); | ||
| 53 | |||
| 54 | /// translation along vector | ||
| 55 | static Transformation translation(const Vector3d& translation); | ||
| 56 | |||
| 57 | /// transforms system with z' to regular system | ||
| 58 | /// will try to align y' with z, but if that fails will align y' with y | ||
| 59 | static Transformation alignZPrime(const Vector3d& zPrime); | ||
| 60 | |||
| 61 | /// transforms face coordinates to regular system, face normal will be z' | ||
| 62 | /// will try to align y' with z, but if that fails will align y' with y | ||
| 63 | /// face origin will be minimum point in x', y' and z'=0 | ||
| 64 | /// will return identity transformation if cannot compute plane for vertices | ||
| 65 | static Transformation alignFace(const std::vector<Point3d>& vertices); | ||
| 66 | |||
| 67 | /// returns a transformation which is the inverse of this | ||
| 68 | Transformation inverse() const; | ||
| 69 | |||
| 70 | /// get the matrix representation directly | ||
| 71 | Matrix matrix() const; | ||
| 72 | |||
| 73 | /// get the vector representation directly | ||
| 74 | Vector vector() const; | ||
| 75 | |||
| 76 | /// get the Euler angles for the transformation, does not include translation | ||
| 77 | EulerAngles eulerAngles() const; | ||
| 78 | |||
| 79 | /// get the rotation matrix for the transformation, does not include translation | ||
| 80 | Matrix rotationMatrix() const; | ||
| 81 | |||
| 82 | /// get the translation for the transformation, does not include rotation | ||
| 83 | Vector3d translation() const; | ||
| 84 | |||
| 85 | /// apply the transformation to the point | ||
| 86 | Point3d operator*(const Point3d& point) const; | ||
| 87 | |||
| 88 | /// apply the transformation to the vector | ||
| 89 | Vector3d operator*(const Vector3d& vector) const; | ||
| 90 | |||
| 91 | /// apply the transformation to the bounding box | ||
| 92 | BoundingBox operator*(const BoundingBox& boundingBox) const; | ||
| 93 | |||
| 94 | /// apply the transformation to the plane | ||
| 95 | Plane operator*(const Plane& plane) const; | ||
| 96 | |||
| 97 | /// apply the transformation to a vector of points | ||
| 98 | std::vector<Point3d> operator*(const std::vector<Point3d>& points) const; | ||
| 99 | |||
| 100 | /// apply the transformation to a vector of vector | ||
| 101 | std::vector<Vector3d> operator*(const std::vector<Vector3d>& vectors) const; | ||
| 102 | |||
| 103 | /// apply the transformation to the other transformation | ||
| 104 | Transformation operator*(const Transformation& other) const; | ||
| 105 | |||
| 106 | private: | ||
| 107 | − | REGISTER_LOGGER("utilities.Transformation"); | |
| 108 | Matrix m_storage; | ||
| 109 | }; | ||
| 110 | |||
| 111 | /// ostream operator | ||
| 112 | UTILITIES_API std::ostream& operator<<(std::ostream& os, const Transformation& t); | ||
| 113 | |||
| 114 | // optional Transformation | ||
| 115 | using OptionalTransformation = boost::optional<Transformation>; | ||
| 116 | |||
| 117 | // vector of Transformation | ||
| 118 | using TransformationVector = std::vector<Transformation>; | ||
| 119 | |||
| 120 | /// create rotation about origin defined by axis and angle (radians) | ||
| 121 | UTILITIES_API Transformation createRotation(const Vector3d& axis, double radians); | ||
| 122 | |||
| 123 | /// create rotation about point defined by axis and angle (radians) | ||
| 124 | UTILITIES_API Transformation createRotation(const Point3d& origin, const Vector3d& axis, double radians); | ||
| 125 | |||
| 126 | /// create rotation specified by Euler angles | ||
| 127 | UTILITIES_API Transformation createRotation(const EulerAngles& angles); | ||
| 128 | |||
| 129 | /// create translation along vector | ||
| 130 | UTILITIES_API Transformation createTranslation(const Vector3d& translation); | ||
| 131 | |||
| 132 | } // namespace openstudio | ||
| 133 | |||
| 134 | #endif //UTILITIES_GEOMETRY_TRANSFORMATION_HPP | ||
| 135 |