Skip to content

Commit 023c4b4

Browse files
committed
Visualize Frustum
1 parent 9e874c0 commit 023c4b4

File tree

17 files changed

+1141
-0
lines changed

17 files changed

+1141
-0
lines changed
Lines changed: 180 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,180 @@
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

include/gz/rendering/RenderTypes.hh

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ namespace gz
7272
class LightVisual;
7373
class JointVisual;
7474
class LidarVisual;
75+
class FrustumVisual;
7576
class Light;
7677
class Marker;
7778
class Material;
@@ -206,6 +207,10 @@ namespace gz
206207
/// \brief Shared pointer to LidarVisual
207208
typedef shared_ptr<LidarVisual> LidarVisualPtr;
208209

210+
/// \typedef FrustumVisualPtr
211+
/// \brief Shared pointer to FrustumVisual
212+
typedef shared_ptr<FrustumVisual> FrustumVisualPtr;
213+
209214
/// \typedef MaterialPtr
210215
/// \brief Shared pointer to Material
211216
typedef shared_ptr<Material> MaterialPtr;
@@ -384,6 +389,10 @@ namespace gz
384389
/// \brief Shared pointer to const LidarVisual
385390
typedef shared_ptr<const LidarVisual> ConstLidarVisualPtr;
386391

392+
/// \typedef const FrustumVisualPtr
393+
/// \brief Shared pointer to const FrustumVisual
394+
typedef shared_ptr<const FrustumVisual> ConstFrustumVisualPtr;
395+
387396
/// \typedef const MaterialPtr
388397
/// \brief Shared pointer to const Material
389398
typedef shared_ptr<const Material> ConstMaterialPtr;

include/gz/rendering/Scene.hh

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1108,6 +1108,34 @@ namespace gz
11081108
public: virtual LidarVisualPtr CreateLidarVisual(
11091109
unsigned int _id, const std::string &_name) = 0;
11101110

1111+
/// \brief Create new frusum visual. A unique ID and name will
1112+
/// automatically be assigned to the frustum visual.
1113+
/// \return The created frustum visual
1114+
public: virtual FrustumVisualPtr CreateFrustumVisual() = 0;
1115+
1116+
/// \brief Create new frustum visual with the given ID. A unique name
1117+
/// will automatically be assigned to the frustum visual. If the given
1118+
/// ID is already in use, NULL will be returned.
1119+
/// \param[in] _id ID of the new frustum visual
1120+
/// \return The created frustum visual
1121+
public: virtual FrustumVisualPtr CreateFrustumVisual(unsigned int _id) = 0;
1122+
1123+
/// \brief Create new frustum visual with the given name. A unique ID
1124+
/// will automatically be assigned to the frustum visual. If the given
1125+
/// name is already in use, NULL will be returned.
1126+
/// \param[in] _name Name of the new frustum visual
1127+
/// \return The created frustum visual
1128+
public: virtual FrustumVisualPtr CreateFrustumVisual(
1129+
const std::string &_name) = 0;
1130+
1131+
/// \brief Create new frustum visual with the given name. If either
1132+
/// the given ID or name is already in use, NULL will be returned.
1133+
/// \param[in] _id ID of the frustum visual.
1134+
/// \param[in] _name Name of the new frustum visual.
1135+
/// \return The created frustum visual
1136+
public: virtual FrustumVisualPtr CreateFrustumVisual(
1137+
unsigned int _id, const std::string &_name) = 0;
1138+
11111139
/// \brief Create new heightmap geomerty. The rendering::Heightmap will be
11121140
/// created from the given HeightmapDescriptor.
11131141
/// \param[in] _desc Data about the heightmap

0 commit comments

Comments
 (0)