From adbcc922c15436a67488b3b4275e5c8982fafce3 Mon Sep 17 00:00:00 2001 From: Ian Chen Date: Thu, 25 Jul 2024 18:47:12 +0000 Subject: [PATCH] Add projection matrix functions to ogre2 camera classes Signed-off-by: Ian Chen --- .../rendering/ogre2/Ogre2BoundingBoxCamera.hh | 7 +++++ .../ogre2/Ogre2SegmentationCamera.hh | 7 +++++ .../gz/rendering/ogre2/Ogre2ThermalCamera.hh | 7 +++++ ogre2/src/Ogre2BoundingBoxCamera.cc | 30 +++++++++---------- ogre2/src/Ogre2DepthCamera.cc | 20 +++---------- ogre2/src/Ogre2SegmentationCamera.cc | 28 ++++++++--------- ogre2/src/Ogre2ThermalCamera.cc | 28 ++++++++--------- 7 files changed, 68 insertions(+), 59 deletions(-) diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh b/ogre2/include/gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh index bc2ad35bf..4ea64d330 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2BoundingBoxCamera.hh @@ -67,6 +67,13 @@ namespace gz // Documentation inherited public: virtual void PostRender() override; + // Documentation inherited. + public: virtual math::Matrix4d ProjectionMatrix() const override; + + // Documentation inherited. + public: virtual void SetProjectionMatrix( + const math::Matrix4d &_matrix) override; + // Documentation inherited public: virtual const std::vector &BoundingBoxData() const override; diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2SegmentationCamera.hh b/ogre2/include/gz/rendering/ogre2/Ogre2SegmentationCamera.hh index 9b52b7212..b497b20c6 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2SegmentationCamera.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2SegmentationCamera.hh @@ -68,6 +68,13 @@ namespace gz // Documentation inherited public: virtual void PostRender() override; + // Documentation inherited. + public: virtual math::Matrix4d ProjectionMatrix() const override; + + // Documentation inherited. + public: virtual void SetProjectionMatrix( + const math::Matrix4d &_matrix) override; + // Documentation inherited public: virtual gz::common::ConnectionPtr ConnectNewSegmentationFrame( diff --git a/ogre2/include/gz/rendering/ogre2/Ogre2ThermalCamera.hh b/ogre2/include/gz/rendering/ogre2/Ogre2ThermalCamera.hh index 8fbc57a4f..b074eb8b5 100644 --- a/ogre2/include/gz/rendering/ogre2/Ogre2ThermalCamera.hh +++ b/ogre2/include/gz/rendering/ogre2/Ogre2ThermalCamera.hh @@ -75,6 +75,13 @@ namespace gz /// \brief Render the camera public: virtual void PostRender() override; + // Documentation inherited. + public: virtual math::Matrix4d ProjectionMatrix() const override; + + // Documentation inherited. + public: virtual void SetProjectionMatrix( + const math::Matrix4d &_matrix) override; + /// \brief Connect to the new thermal image event /// \param[in] _subscriber Subscriber callback function /// \return Pointer to the new Connection. This must be kept in scope diff --git a/ogre2/src/Ogre2BoundingBoxCamera.cc b/ogre2/src/Ogre2BoundingBoxCamera.cc index 0adb97017..46ffb055b 100644 --- a/ogre2/src/Ogre2BoundingBoxCamera.cc +++ b/ogre2/src/Ogre2BoundingBoxCamera.cc @@ -465,21 +465,6 @@ void Ogre2BoundingBoxCamera::PreRender() if (!this->dataPtr->ogreRenderTexture) this->CreateBoundingBoxTexture(); - // todo(iche033) Override BaseCamera::SetProjectionMatrix() function in - // main / gz-rendering9 instead of checking and setting the custom - // projection matrix here - if (this->dataPtr->ogreCamera && - this->projectionMatrix != gz::math::Matrix4d::Zero) - { - if (this->projectionMatrix != - Ogre2Conversions::Convert( - this->dataPtr->ogreCamera->getProjectionMatrix())) - { - this->dataPtr->ogreCamera->setCustomProjectionMatrix(true, - Ogre2Conversions::Convert(this->projectionMatrix)); - } - } - this->dataPtr->outputBoxes.clear(); } @@ -1549,3 +1534,18 @@ BoundingBoxType Ogre2BoundingBoxCamera::Type() const { return this->dataPtr->type; } + +///////////////////////////////////////////////// +math::Matrix4d Ogre2BoundingBoxCamera::ProjectionMatrix() const +{ + return Ogre2Conversions::Convert( + this->dataPtr->ogreCamera->getProjectionMatrix()); +} + +///////////////////////////////////////////////// +void Ogre2BoundingBoxCamera::SetProjectionMatrix(const math::Matrix4d &_matrix) +{ + BaseBoundingBoxCamera::SetProjectionMatrix(_matrix); + this->dataPtr->ogreCamera->setCustomProjectionMatrix( + true, Ogre2Conversions::Convert(this->projectionMatrix)); +} diff --git a/ogre2/src/Ogre2DepthCamera.cc b/ogre2/src/Ogre2DepthCamera.cc index 38d0b29a5..f591b3c94 100644 --- a/ogre2/src/Ogre2DepthCamera.cc +++ b/ogre2/src/Ogre2DepthCamera.cc @@ -1021,12 +1021,14 @@ void Ogre2DepthCamera::CreateWorkspaceInstance() } ///////////////////////////////////////////////// -math::Matrix4d Ogre2DepthCamera::ProjectionMatrix() const { +math::Matrix4d Ogre2DepthCamera::ProjectionMatrix() const +{ return Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix()); } ///////////////////////////////////////////////// -void Ogre2DepthCamera::SetProjectionMatrix(const math::Matrix4d &_matrix) { +void Ogre2DepthCamera::SetProjectionMatrix(const math::Matrix4d &_matrix) +{ BaseDepthCamera::SetProjectionMatrix(_matrix); this->ogreCamera->setCustomProjectionMatrix( true, Ogre2Conversions::Convert(this->projectionMatrix)); @@ -1069,20 +1071,6 @@ void Ogre2DepthCamera::PreRender() if (!this->dataPtr->ogreCompositorWorkspace) this->CreateWorkspaceInstance(); - // todo(iche033) Override BaseCamera::SetProjectionMatrix() function in - // main / gz-rendering9 instead of checking and setting the custom - // projection matrix here - if (this->ogreCamera && - this->projectionMatrix != gz::math::Matrix4d::Zero) - { - if (this->projectionMatrix != - Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix())) - { - this->ogreCamera->setCustomProjectionMatrix(true, - Ogre2Conversions::Convert(this->projectionMatrix)); - } - } - // Disable color target (set to clear pass) if there are no rgb point cloud // connections if (this->dataPtr->colorTargetDef) diff --git a/ogre2/src/Ogre2SegmentationCamera.cc b/ogre2/src/Ogre2SegmentationCamera.cc index 4028daccc..f3c3fc352 100644 --- a/ogre2/src/Ogre2SegmentationCamera.cc +++ b/ogre2/src/Ogre2SegmentationCamera.cc @@ -165,20 +165,6 @@ void Ogre2SegmentationCamera::PreRender() { if (!this->dataPtr->ogreSegmentationTexture) this->CreateSegmentationTexture(); - - // todo(iche033) Override BaseCamera::SetProjectionMatrix() function in - // main / gz-rendering9 instead of checking and setting the custom - // projection matrix here - if (this->ogreCamera && - this->projectionMatrix != gz::math::Matrix4d::Zero) - { - if (this->projectionMatrix != - Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix())) - { - this->ogreCamera->setCustomProjectionMatrix(true, - Ogre2Conversions::Convert(this->projectionMatrix)); - } - } } ///////////////////////////////////////////////// @@ -439,3 +425,17 @@ Ogre::Camera *Ogre2SegmentationCamera::OgreCamera() const { return this->ogreCamera; } + +///////////////////////////////////////////////// +math::Matrix4d Ogre2SegmentationCamera::ProjectionMatrix() const +{ + return Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix()); +} + +///////////////////////////////////////////////// +void Ogre2SegmentationCamera::SetProjectionMatrix(const math::Matrix4d &_matrix) +{ + BaseSegmentationCamera::SetProjectionMatrix(_matrix); + this->ogreCamera->setCustomProjectionMatrix( + true, Ogre2Conversions::Convert(this->projectionMatrix)); +} diff --git a/ogre2/src/Ogre2ThermalCamera.cc b/ogre2/src/Ogre2ThermalCamera.cc index fa06f380f..2a888071d 100644 --- a/ogre2/src/Ogre2ThermalCamera.cc +++ b/ogre2/src/Ogre2ThermalCamera.cc @@ -1131,20 +1131,6 @@ void Ogre2ThermalCamera::PreRender() { if (!this->dataPtr->ogreThermalTexture) this->CreateThermalTexture(); - - // todo(iche033) Override BaseCamera::SetProjectionMatrix() function in - // main / gz-rendering9 instead of checking and setting the custom - // projection matrix here - if (this->ogreCamera && - this->projectionMatrix != gz::math::Matrix4d::Zero) - { - if (this->projectionMatrix != - Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix())) - { - this->ogreCamera->setCustomProjectionMatrix(true, - Ogre2Conversions::Convert(this->projectionMatrix)); - } - } } ////////////////////////////////////////////////// @@ -1236,3 +1222,17 @@ Ogre::Camera *Ogre2ThermalCamera::OgreCamera() const { return this->ogreCamera; } + +///////////////////////////////////////////////// +math::Matrix4d Ogre2ThermalCamera::ProjectionMatrix() const +{ + return Ogre2Conversions::Convert(this->ogreCamera->getProjectionMatrix()); +} + +///////////////////////////////////////////////// +void Ogre2ThermalCamera::SetProjectionMatrix(const math::Matrix4d &_matrix) +{ + BaseThermalCamera::SetProjectionMatrix(_matrix); + this->ogreCamera->setCustomProjectionMatrix( + true, Ogre2Conversions::Convert(this->projectionMatrix)); +}