|
| 1 | +/* |
| 2 | + * Copyright (C) 2015 Open Source Robotics Foundation |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | +*/ |
| 17 | +#ifndef GZ_RENDERING_FRUSTUMVISUAL_HH_ |
| 18 | +#define GZ_RENDERING_FRUSTUMVISUAL_HH_ |
| 19 | + |
| 20 | +#include <gz/math/Angle.hh> |
| 21 | +#include <gz/math/AxisAlignedBox.hh> |
| 22 | +#include <gz/math/Plane.hh> |
| 23 | +#include <gz/math/Pose3.hh> |
| 24 | +#include <gz/utils/ImplPtr.hh> |
| 25 | +#include "gz/rendering/config.hh" |
| 26 | +#include "gz/rendering/Visual.hh" |
| 27 | +#include "gz/rendering/Object.hh" |
| 28 | +#include "gz/rendering/RenderTypes.hh" |
| 29 | +#include "gz/rendering/Marker.hh" |
| 30 | + |
| 31 | +namespace gz |
| 32 | +{ |
| 33 | + namespace rendering |
| 34 | + { |
| 35 | + inline namespace GZ_RENDERING_VERSION_NAMESPACE { |
| 36 | + // |
| 37 | + /// \brief Planes that define the boundaries of the frustum. |
| 38 | + enum GZ_RENDERING_VISIBLE FrustumVisualPlane |
| 39 | + { |
| 40 | + /// \brief Near plane |
| 41 | + FRUSTUM_PLANE_NEAR = 0, |
| 42 | + |
| 43 | + /// \brief Far plane |
| 44 | + FRUSTUM_PLANE_FAR = 1, |
| 45 | + |
| 46 | + /// \brief Left plane |
| 47 | + FRUSTUM_PLANE_LEFT = 2, |
| 48 | + |
| 49 | + /// \brief Right plane |
| 50 | + FRUSTUM_PLANE_RIGHT = 3, |
| 51 | + |
| 52 | + /// \brief Top plane |
| 53 | + FRUSTUM_PLANE_TOP = 4, |
| 54 | + |
| 55 | + /// \brief Bottom plane |
| 56 | + FRUSTUM_PLANE_BOTTOM = 5 |
| 57 | + }; |
| 58 | + |
| 59 | + /// \brief Mathematical representation of a frustum and related functions. |
| 60 | + /// This is also known as a view frustum. |
| 61 | + class GZ_RENDERING_VISIBLE FrustumVisual : public virtual Visual |
| 62 | + { |
| 63 | + /// \brief Default constructor. With the following default values: |
| 64 | + /// |
| 65 | + /// * near: 0.0 |
| 66 | + /// * far: 1.0 |
| 67 | + /// * fov: 0.78539 radians (45 degrees) |
| 68 | + /// * aspect ratio: 1.0 |
| 69 | + /// * pose: Pose3d::Zero |
| 70 | + protected: FrustumVisual(); |
| 71 | + |
| 72 | + /// \brief Destructor |
| 73 | + public: virtual ~FrustumVisual(); |
| 74 | + |
| 75 | + /// \brief Constructor |
| 76 | + /// \param[in] _near Near plane distance. This is the distance from |
| 77 | + /// the frustum's vertex to the closest plane |
| 78 | + /// \param[in] _far Far plane distance. This is the distance from the |
| 79 | + /// frustum's vertex to the farthest plane. |
| 80 | + /// \param[in] _fov Field of view. The field of view is the |
| 81 | + /// angle between the frustum's vertex and the edges of the near or far |
| 82 | + /// plane. This value represents the horizontal angle. |
| 83 | + /// \param[in] _aspectRatio The aspect ratio, which is the width divided |
| 84 | + /// by height of the near or far planes. |
| 85 | + /// \param[in] _pose Pose of the frustum, which is the vertex (top of |
| 86 | + /// the pyramid). |
| 87 | + /*protected: FrustumVisual(double _near, |
| 88 | + double _far, |
| 89 | + const math::Angle &_fov, |
| 90 | + double _aspectRatio, |
| 91 | + const gz::math::Pose3d &_pose = gz::math::Pose3d::Zero);*/ |
| 92 | + |
| 93 | + public: virtual void Update() = 0; |
| 94 | + |
| 95 | + /// \brief Get the near distance. This is the distance from the |
| 96 | + /// frustum's vertex to the closest plane. |
| 97 | + /// \return Near distance. |
| 98 | + /// \sa SetNear |
| 99 | + public: virtual double Near() const = 0; |
| 100 | + |
| 101 | + /// \brief Set the near distance. This is the distance from the |
| 102 | + /// frustum's vertex to the closest plane. |
| 103 | + /// \param[in] _near Near distance. |
| 104 | + /// \sa Near |
| 105 | + public: virtual void SetNear(double _near) = 0; |
| 106 | + |
| 107 | + /// \brief Get the far distance. This is the distance from the |
| 108 | + /// frustum's vertex to the farthest plane. |
| 109 | + /// \return Far distance. |
| 110 | + /// \sa SetFar |
| 111 | + public: virtual double Far() const = 0; |
| 112 | + |
| 113 | + /// \brief Set the far distance. This is the distance from the |
| 114 | + /// frustum's vertex to the farthest plane. |
| 115 | + /// \param[in] _far Far distance. |
| 116 | + /// \sa Far |
| 117 | + public: virtual void SetFar(double _far) = 0; |
| 118 | + |
| 119 | + /// \brief Get the horizontal field of view. The field of view is the |
| 120 | + /// angle between the frustum's vertex and the edges of the near or far |
| 121 | + /// plane. This value represents the horizontal angle. |
| 122 | + /// \return The field of view. |
| 123 | + /// \sa SetFOV |
| 124 | + public: virtual gz::math::Angle FOV() const = 0; |
| 125 | + |
| 126 | + /// \brief Set the horizontal field of view. The field of view is the |
| 127 | + /// angle between the frustum's vertex and the edges of the near or far |
| 128 | + /// plane. This value represents the horizontal angle. |
| 129 | + /// \param[in] _fov The field of view. |
| 130 | + /// \sa FOV |
| 131 | + public: virtual void SetFOV(const gz::math::Angle &_fov) = 0; |
| 132 | + |
| 133 | + /// \brief Get the aspect ratio, which is the width divided by height |
| 134 | + /// of the near or far planes. |
| 135 | + /// \return The frustum's aspect ratio. |
| 136 | + /// \sa SetAspectRatio |
| 137 | + public: virtual double AspectRatio() const = 0; |
| 138 | + |
| 139 | + /// \brief Set the aspect ratio, which is the width divided by height |
| 140 | + /// of the near or far planes. |
| 141 | + /// \param[in] _aspectRatio The frustum's aspect ratio. |
| 142 | + /// \sa AspectRatio |
| 143 | + public: virtual void SetAspectRatio(double _aspectRatio) = 0; |
| 144 | + |
| 145 | + /// \brief Get a plane of the frustum. |
| 146 | + /// \param[in] _plane The plane to return. |
| 147 | + /// \return Plane of the frustum. |
| 148 | + public: virtual gz::math::Planed Plane(const FrustumVisualPlane _plane) const = 0; |
| 149 | + |
| 150 | + /// \brief Check if a box lies inside the pyramid frustum. |
| 151 | + /// \param[in] _b Box to check. |
| 152 | + /// \return True if the box is inside the pyramid frustum. |
| 153 | + //public: virtual bool Contains(const gz::math::AxisAlignedBox &_b) const = 0; //TO-DO |
| 154 | + |
| 155 | + /// \brief Check if a point lies inside the pyramid frustum. |
| 156 | + /// \param[in] _p Point to check. |
| 157 | + /// \return True if the point is inside the pyramid frustum. |
| 158 | + //public: virtual bool Contains(const gz::math::Vector3d &_p) const = 0; //TO-DO |
| 159 | + |
| 160 | + /// \brief Get the pose of the frustum |
| 161 | + /// \return Pose of the frustum |
| 162 | + /// \sa SetPose |
| 163 | + public: virtual gz::math::Pose3d Pose() const = 0; |
| 164 | + |
| 165 | + /// \brief Set the pose of the frustum |
| 166 | + /// \param[in] _pose Pose of the frustum, top vertex. |
| 167 | + /// \sa Pose |
| 168 | + public: virtual void SetPose(const gz::math::Pose3d &_pose) = 0; |
| 169 | + |
| 170 | + /// \brief Compute the planes of the frustum. This is called whenever |
| 171 | + /// a property of the frustum is changed. |
| 172 | + private: void ComputePlanes(); |
| 173 | + |
| 174 | + /// \brief Private data pointer |
| 175 | + //GZ_UTILS_IMPL_PTR(dataPtr) |
| 176 | + }; |
| 177 | + } |
| 178 | + } |
| 179 | +} |
| 180 | +#endif |
0 commit comments