Skip to content

Commit

Permalink
Frustum Visual ABI compatibility changes (#1102)
Browse files Browse the repository at this point in the history
Signed-off-by: Ian Chen <[email protected]>
  • Loading branch information
iche033 authored Jan 17, 2025
1 parent 8eddd04 commit d2c0e0a
Show file tree
Hide file tree
Showing 13 changed files with 219 additions and 67 deletions.
2 changes: 1 addition & 1 deletion examples/frustum_visual/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.22.1 FATAL_ERROR)
project(gz-rendering-frustum-visual)
find_package(gz-rendering10 REQUIRED)
find_package(gz-rendering9 REQUIRED)

find_package(GLUT REQUIRED)
include_directories(SYSTEM ${GLUT_INCLUDE_DIRS})
Expand Down
7 changes: 6 additions & 1 deletion examples/frustum_visual/Main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,12 @@ NodePtr createMainNode(ScenePtr _scene)
root->AddChild(box);

// create frustum visual and attach to main node
FrustumVisualPtr frustumVisual = _scene->CreateFrustumVisual();
// \todo(iche033) Commented out for ABI compatibility. Uncomment in
// gz-rendering10.
// \todo(iche033) uncomment and use official API in gz-rendering10
// FrustumVisualPtr frustumVisual = scene->CreateFrustumVisual();
FrustumVisualPtr frustumVisual = std::dynamic_pointer_cast<FrustumVisual>(
_scene->Extension()->CreateExt("frustum_visual"));
frustumVisual->SetNearClipPlane(1);
frustumVisual->SetFarClipPlane(5);
frustumVisual->SetHFOV(0.7);
Expand Down
2 changes: 0 additions & 2 deletions include/gz/rendering/FrustumVisual.hh
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@
#define GZ_RENDERING_FRUSTUMVISUAL_HH_

#include <gz/math/Angle.hh>
#include <gz/math/AxisAlignedBox.hh>
#include <gz/math/Plane.hh>
#include <gz/math/Pose3.hh>
#include <gz/utils/ImplPtr.hh>
#include "gz/rendering/config.hh"
#include "gz/rendering/Visual.hh"
#include "gz/rendering/Object.hh"
#include "gz/rendering/RenderTypes.hh"
#include "gz/rendering/Marker.hh"

namespace gz
{
Expand Down
24 changes: 17 additions & 7 deletions include/gz/rendering/Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -1108,34 +1108,44 @@ namespace gz
public: virtual LidarVisualPtr CreateLidarVisual(
unsigned int _id, const std::string &_name) = 0;

/// \cond PRIVATE
/// \brief Create new frusum visual. A unique ID and name will
/// automatically be assigned to the frustum visual.
/// \return The created frustum visual
public: virtual FrustumVisualPtr CreateFrustumVisual() = 0;
/// \todo(iche033) Commented out for ABI compatibility. Uncomment in
/// gz-rendering10
/// public: virtual FrustumVisualPtr CreateFrustumVisual() = 0;

/// \brief Create new frustum visual with the given ID. A unique name
/// will automatically be assigned to the frustum visual. If the given
/// ID is already in use, NULL will be returned.
/// \param[in] _id ID of the new frustum visual
/// \return The created frustum visual
public: virtual FrustumVisualPtr CreateFrustumVisual(
unsigned int _id) = 0;
/// \todo(iche033) Commented out for ABI compatibility. Uncomment in
/// gz-rendering10
/// public: virtual FrustumVisualPtr CreateFrustumVisual(
/// unsigned int _id) = 0;

/// \brief Create new frustum visual with the given name. A unique ID
/// will automatically be assigned to the frustum visual. If the given
/// name is already in use, NULL will be returned.
/// \param[in] _name Name of the new frustum visual
/// \return The created frustum visual
public: virtual FrustumVisualPtr CreateFrustumVisual(
const std::string &_name) = 0;
/// \todo(iche033) Commented out for ABI compatibility. Uncomment in
/// gz-rendering10
/// public: virtual FrustumVisualPtr CreateFrustumVisual(
/// const std::string &_name) = 0;

/// \brief Create new frustum visual with the given name. If either
/// the given ID or name is already in use, NULL will be returned.
/// \param[in] _id ID of the frustum visual.
/// \param[in] _name Name of the new frustum visual.
/// \return The created frustum visual
public: virtual FrustumVisualPtr CreateFrustumVisual(
unsigned int _id, const std::string &_name) = 0;
/// \todo(iche033) Commented out for ABI compatibility. Uncomment in
/// gz-rendering10
/// public: virtual FrustumVisualPtr CreateFrustumVisual(
/// unsigned int _id, const std::string &_name) = 0;
/// \endcond

/// \brief Create new heightmap geomerty. The rendering::Heightmap will be
/// created from the given HeightmapDescriptor.
Expand Down
33 changes: 24 additions & 9 deletions include/gz/rendering/base/BaseScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -538,19 +538,23 @@ namespace gz
const std::string &_name) override;

// Documentation inherited.
public: virtual FrustumVisualPtr CreateFrustumVisual() override;
// \todo(iche033) commented out for ABI compatibility
// public: virtual FrustumVisualPtr CreateFrustumVisual() override;

// Documentation inherited.
public: virtual FrustumVisualPtr CreateFrustumVisual(
unsigned int _id) override;
// \todo(iche033) commented out for ABI compatibility
// public: virtual FrustumVisualPtr CreateFrustumVisual(
// unsigned int _id) override;

// Documentation inherited.
public: virtual FrustumVisualPtr CreateFrustumVisual(
const std::string &_name) override;
// \todo(iche033) commented out for ABI compatibility
// public: virtual FrustumVisualPtr CreateFrustumVisual(
// const std::string &_name) override;

// Documentation inherited.
public: virtual FrustumVisualPtr CreateFrustumVisual(unsigned int _id,
const std::string &_name) override;
// \todo(iche033) commented out for ABI compatibility
// public: virtual FrustumVisualPtr CreateFrustumVisual(unsigned int _id,
// const std::string &_name) override;

// Documentation inherited.
public: virtual HeightmapPtr CreateHeightmap(
Expand Down Expand Up @@ -843,12 +847,23 @@ namespace gz
protected: virtual LidarVisualPtr CreateLidarVisualImpl(unsigned int _id,
const std::string &_name) = 0;

/// \cond PRIVATE
/// \brief Implementation for creating a frustum visual
/// \param[in] _id unique object id.
/// \param[in] _name unique object name.
/// \return Pointer to a frustum visual
protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(
unsigned int _id, const std::string &_name) = 0;
/// \todo(iche033) Commented out for ABI compatibility. Uncomment in
/// gz-rendering10
/// protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(
/// unsigned int _id, const std::string &_name)
/// {
/// (void)_id;
/// (void)_name;
/// gzerr << "FrustumVisual not supported by: "
/// << this->Engine()->Name() << std::endl;
/// return FrustumVisualPtr();
/// }
/// \endcond

/// \brief Implementation for creating a heightmap geometry
/// \param[in] _id Unique object id.
Expand Down
5 changes: 3 additions & 2 deletions ogre/include/gz/rendering/ogre/OgreScene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -181,8 +181,9 @@ namespace gz
const std::string &_name) override;

// Documentation inherited
protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(
unsigned int _id, const std::string &_name) override;
// \todo(iche033) make this virtual in gz-rendering10
protected: FrustumVisualPtr CreateFrustumVisualImpl(
unsigned int _id, const std::string &_name);

// Documentation inherited
protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id,
Expand Down
10 changes: 5 additions & 5 deletions ogre/src/OgreScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -781,22 +781,22 @@ OgreSceneExt::OgreSceneExt(Scene *_scene)
ObjectPtr OgreSceneExt::CreateExt(const std::string &_type,
const std::string &_name)
{
if (_type == "projector")
if (_type == "frustum_visual")
{
OgreScene *ogreScene = dynamic_cast<OgreScene *>(this->scene);
unsigned int objId = ogreScene->CreateObjectId();
std::string objName = _name;
if (objName.empty())
{
std::stringstream ss;
ss << ogreScene->Name() << "::" << "Projector";
ss << ogreScene->Name() << "::" << "FrustumVisual";
ss << "(" << std::to_string(objId) << ")";
objName = ss.str();
}
ProjectorPtr projector = ogreScene->CreateProjectorImpl(
FrustumVisualPtr frustumVisual = ogreScene->CreateFrustumVisualImpl(
objId, objName);
bool result = ogreScene->Visuals()->Add(projector);
return (result) ? projector : nullptr;
bool result = ogreScene->Visuals()->Add(frustumVisual);
return (result) ? frustumVisual : nullptr;
}

return ObjectPtr();
Expand Down
5 changes: 3 additions & 2 deletions ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -344,8 +344,9 @@ namespace gz
const std::string &_name) override;

// Documentation inherited
protected: virtual FrustumVisualPtr CreateFrustumVisualImpl(
unsigned int _id, const std::string &_name) override;
// \todo(iche033) make this virtual in gz-rendering10
protected: FrustumVisualPtr CreateFrustumVisualImpl(
unsigned int _id, const std::string &_name);

// Documentation inherited
protected: virtual WireBoxPtr CreateWireBoxImpl(unsigned int _id,
Expand Down
4 changes: 0 additions & 4 deletions ogre2/src/Ogre2FrustumVisual.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,6 @@ class gz::rendering::Ogre2FrustumVisualPrivate
/// \brief Frustum Ray DynamicLines Object to display
public: std::vector<std::shared_ptr<Ogre2DynamicRenderable>> rayLines;

/// \brief Frustum visual type
// public: FrustumVisualPlane frustumVisPlane =
// FrustumVisualPlane::FRUSTUM_PLANE_TOP;

/// \brief The visibility of the visual
public: bool visible = true;

Expand Down
10 changes: 5 additions & 5 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1694,22 +1694,22 @@ Ogre2SceneExt::Ogre2SceneExt(Scene *_scene)
ObjectPtr Ogre2SceneExt::CreateExt(const std::string &_type,
const std::string &_name)
{
if (_type == "projector")
if (_type == "frustum_visual")
{
Ogre2Scene *ogreScene = dynamic_cast<Ogre2Scene *>(this->scene);
unsigned int objId = ogreScene->CreateObjectId();
std::string objName = _name;
if (objName.empty())
{
std::stringstream ss;
ss << ogreScene->Name() << "::" << "Projector";
ss << ogreScene->Name() << "::" << "FrustumVisual";
ss << "(" << std::to_string(objId) << ")";
objName = ss.str();
}
ProjectorPtr projector = ogreScene->CreateProjectorImpl(
FrustumVisualPtr frustumVisual = ogreScene->CreateFrustumVisualImpl(
objId, objName);
bool result = ogreScene->Visuals()->Add(projector);
return (result) ? projector : nullptr;
bool result = ogreScene->Visuals()->Add(frustumVisual);
return (result) ? frustumVisual : nullptr;
}

return ObjectPtr();
Expand Down
60 changes: 31 additions & 29 deletions src/base/BaseScene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1263,35 +1263,37 @@ LidarVisualPtr BaseScene::CreateLidarVisual(unsigned int _id,
return (result) ? lidar : nullptr;
}

//////////////////////////////////////////////////
FrustumVisualPtr BaseScene::CreateFrustumVisual()
{
unsigned int objId = this->CreateObjectId();
return this->CreateFrustumVisual(objId);
}

//////////////////////////////////////////////////
FrustumVisualPtr BaseScene::CreateFrustumVisual(unsigned int _id)
{
const std::string objName = this->CreateObjectName(_id, "FrustumVisual");
return this->CreateFrustumVisual(_id, objName);
}

//////////////////////////////////////////////////
FrustumVisualPtr BaseScene::CreateFrustumVisual(const std::string &_name)
{
unsigned int objId = this->CreateObjectId();
return this->CreateFrustumVisual(objId, _name);
}

//////////////////////////////////////////////////
FrustumVisualPtr BaseScene::CreateFrustumVisual(unsigned int _id,
const std::string &_name)
{
FrustumVisualPtr frustum = this->CreateFrustumVisualImpl(_id, _name);
bool result = this->RegisterVisual(frustum);
return (result) ? frustum : nullptr;
}
// \todo(iche033) Commented out for ABI compatibility. Uncomment in
// gz-rendering10
// //////////////////////////////////////////////////
// FrustumVisualPtr BaseScene::CreateFrustumVisual()
// {
// unsigned int objId = this->CreateObjectId();
// return this->CreateFrustumVisual(objId);
// }
//
// //////////////////////////////////////////////////
// FrustumVisualPtr BaseScene::CreateFrustumVisual(unsigned int _id)
// {
// const std::string objName = this->CreateObjectName(_id, "FrustumVisual");
// return this->CreateFrustumVisual(_id, objName);
// }
//
// //////////////////////////////////////////////////
// FrustumVisualPtr BaseScene::CreateFrustumVisual(const std::string &_name)
// {
// unsigned int objId = this->CreateObjectId();
// return this->CreateFrustumVisual(objId, _name);
// }
//
// //////////////////////////////////////////////////
// FrustumVisualPtr BaseScene::CreateFrustumVisual(unsigned int _id,
// const std::string &_name)
// {
// FrustumVisualPtr frustum = this->CreateFrustumVisualImpl(_id, _name);
// bool result = this->RegisterVisual(frustum);
// return (result) ? frustum : nullptr;
// }

//////////////////////////////////////////////////
WireBoxPtr BaseScene::CreateWireBox()
Expand Down
1 change: 1 addition & 0 deletions test/common_test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ set(tests
Camera_TEST
Capsule_TEST
COMVisual_TEST
FrustumVisual_TEST
GaussianNoisePass_TEST
GizmoVisual_TEST
GlobalIllumination_TEST
Expand Down
Loading

0 comments on commit d2c0e0a

Please sign in to comment.