Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for wide-angle cameras in ogre2 #733

Merged
merged 8 commits into from
Oct 31, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2RenderTarget.hh
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ namespace gz
/// \return Value in range [1; 256). 1 means no antialiasing.
protected: uint8_t TargetFSAA() const;

/// \brief Returns the FSAA to use based on supported specs by HW
/// and value specified in _fsaa
/// \param[in] _fsaa Value in range [1; 256). 1 means no antialiasing.
/// \return Value in range [1; 256). 1 means no antialiasing.
public: static uint8_t TargetFSAA(uint8_t _fsaa);

/// \brief Get a pointer to the ogre render target containing
/// the results of the render (implemented separately
/// to avoid breaking ABI of the pure virtual function)
Expand Down
2 changes: 2 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2RenderTypes.hh
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ namespace gz
class Ogre2SubMesh;
class Ogre2ThermalCamera;
class Ogre2Visual;
class Ogre2WideAngleCamera;
class Ogre2WireBox;

typedef BaseGeometryStore<Ogre2Geometry> Ogre2GeometryStore;
Expand Down Expand Up @@ -120,6 +121,7 @@ namespace gz
typedef shared_ptr<Ogre2SubMesh> Ogre2SubMeshPtr;
typedef shared_ptr<Ogre2ThermalCamera> Ogre2ThermalCameraPtr;
typedef shared_ptr<Ogre2Visual> Ogre2VisualPtr;
typedef shared_ptr<Ogre2WideAngleCamera> Ogre2WideAngleCameraPtr;
typedef shared_ptr<Ogre2WireBox> Ogre2WireBoxPtr;

typedef shared_ptr<Ogre2GeometryStore> Ogre2GeometryStorePtr;
Expand Down
4 changes: 4 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2Scene.hh
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ namespace gz
protected: virtual ThermalCameraPtr CreateThermalCameraImpl(
unsigned int _id, const std::string &_name) override;

// Documentation inherited
protected: virtual WideAngleCameraPtr CreateWideAngleCameraImpl(
unsigned int _id, const std::string &_name) override;

// Documentation inherited
protected: virtual BoundingBoxCameraPtr CreateBoundingBoxCameraImpl(
unsigned int _id, const std::string &_name) override;
Expand Down
129 changes: 129 additions & 0 deletions ogre2/include/gz/rendering/ogre2/Ogre2WideAngleCamera.hh
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
* Copyright (C) 2022 Open Source Robotics Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
*/
#ifndef GZ_RENDERING_OGRE2_WIDEANGLECAMERA_HH_
#define GZ_RENDERING_OGRE2_WIDEANGLECAMERA_HH_

#include <memory>
#include <string>

#include <gz/utils/ImplPtr.hh>

#include "gz/rendering/base/BaseWideAngleCamera.hh"
#include "gz/rendering/ogre2/Export.hh"
#include "gz/rendering/ogre2/Ogre2RenderTarget.hh"
#include "gz/rendering/ogre2/Ogre2Sensor.hh"

namespace gz
{
namespace rendering
{
inline namespace GZ_RENDERING_VERSION_NAMESPACE {
//
/// \brief Ogre implementation of WideAngleCamera
class GZ_RENDERING_OGRE2_VISIBLE Ogre2WideAngleCamera :
public BaseWideAngleCamera<Ogre2Sensor>
{
/// \brief Constructor
protected: Ogre2WideAngleCamera();

/// \brief Destructor
public: virtual ~Ogre2WideAngleCamera() override;

// Documentation inherited
public: virtual void Init() override;

/// \brief Create a texture
public: virtual void CreateRenderTexture();

/// \brief Render the camera
public: virtual void PostRender() override;

// Documentation inherited
public: virtual void Destroy() override;

/// \brief Gets the environment texture size
/// \return Texture size
public: uint32_t EnvTextureSize() const;

/// \brief Sets environment texture size
/// \param[in] _size Texture size
public: void SetEnvTextureSize(uint32_t _size);

/// \brief Project 3D world coordinates to screen coordinates
/// \param[in] _pt 3D world coodinates
/// \return Screen coordinates. Z is the distance of point from camera
/// optical center.
public: math::Vector3d Project3d(const math::Vector3d &_pt) const
override;

// Documentation inherited.
public: virtual void PreRender() override;

/// \brief Implementation of the render call
public: virtual void Render() override;

// Documentation inherited
public: common::ConnectionPtr ConnectNewWideAngleFrame(
std::function<void(const unsigned char *, unsigned int, unsigned int,
unsigned int, const std::string &)> _subscriber) override;

/// \brief Set the camera's render target
protected: void CreateWideAngleTexture() override;

/// \brief Create the camera.
protected: void CreateCamera();

/// \brief Get a pointer to the render target.
/// \return Pointer to the render target
protected: virtual RenderTargetPtr RenderTarget() const override;

/// \brief Changes the Compositor Definition to use the MSAA
/// settings we need. Do not call this if not using MSAA.
/// \param[in] _ogreCompMgr Ogre's Compositor Manager
/// \param[in] _msaa Value in range [2; 256)
protected: void SetupMSAA(Ogre::CompositorManager2 *_ogreCompMgr,
uint8_t _msaa);

/// \brief Saves the CompositorPassSceneDef of each of the 6 passes
/// defined in WideAngleCamera.compositor data file for later
/// manipulation.
/// \param[in] _ogreCompMgr Ogre's Compositor Manager
/// \param[in] _withMsaa Whether the version we're retrieving is the MSAA
/// one
private: void RetrieveCubePassSceneDefs(
Ogre::CompositorManager2 *_ogreCompMgr, bool _withMsaa);

/// \brief Called before each cubemap face is about to be rendered
/// \param[in] _pass Compositor pass to set its clear colour
private: void PrepareForCubemapFacePass(Ogre::CompositorPass *_pass);

/// \brief Called before the final pass is about to be rendered
/// \param[in] _pass Material Pass to setup
private: void PrepareForFinalPass(Ogre::Pass *_pass);

/// \cond warning
/// \brief Private data pointer
GZ_UTILS_UNIQUE_IMPL_PTR(dataPtr)
/// \endcond

private: friend class Ogre2Scene;
private: friend class Ogre2WideAngleCameraWorkspaceListenerPrivate;
};
}
}
}
#endif
20 changes: 13 additions & 7 deletions ogre2/src/Ogre2RenderTarget.cc
Original file line number Diff line number Diff line change
Expand Up @@ -594,12 +594,18 @@ void Ogre2RenderTarget::PrepareForExternalSampling()

//////////////////////////////////////////////////
uint8_t Ogre2RenderTarget::TargetFSAA() const
{
return Ogre2RenderTarget::TargetFSAA(
static_cast<uint8_t>(this->antiAliasing));
}

//////////////////////////////////////////////////
uint8_t Ogre2RenderTarget::TargetFSAA(uint8_t _fsaa)
{
// check if target fsaa is supported
std::vector<unsigned int> fsaaLevels =
Ogre2RenderEngine::Instance()->FSAALevels();
unsigned int targetFSAA = this->antiAliasing;
auto const it = std::find(fsaaLevels.begin(), fsaaLevels.end(), targetFSAA);
auto const it = std::find(fsaaLevels.begin(), fsaaLevels.end(), _fsaa);

if (it == fsaaLevels.end())
{
Expand All @@ -615,18 +621,18 @@ uint8_t Ogre2RenderTarget::TargetFSAA() const
}
os << "]";

gzwarn << "Anti-aliasing level of '" << this->antiAliasing << "' "
gzwarn << "Anti-aliasing level of '" << _fsaa << "' "
<< "is not supported; valid FSAA levels are: " << os.str()
<< ". Setting to 1" << std::endl;
ogre2FSAAWarn = true;
}
targetFSAA = 0u;
_fsaa = 0u;
}

if (targetFSAA == 0u)
targetFSAA = 1u;
if (_fsaa == 0u)
_fsaa = 1u;

return static_cast<uint8_t>(targetFSAA);
return _fsaa;
}

//////////////////////////////////////////////////
Expand Down
10 changes: 10 additions & 0 deletions ogre2/src/Ogre2Scene.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#include "gz/rendering/ogre2/Ogre2ThermalCamera.hh"
#include "gz/rendering/ogre2/Ogre2SegmentationCamera.hh"
#include "gz/rendering/ogre2/Ogre2Visual.hh"
#include "gz/rendering/ogre2/Ogre2WideAngleCamera.hh"
#include "gz/rendering/ogre2/Ogre2WireBox.hh"

#ifdef _MSC_VER
Expand Down Expand Up @@ -1029,6 +1030,15 @@ ThermalCameraPtr Ogre2Scene::CreateThermalCameraImpl(const unsigned int _id,
return (result) ? camera : nullptr;
}

//////////////////////////////////////////////////
WideAngleCameraPtr Ogre2Scene::CreateWideAngleCameraImpl(const unsigned int _id,
const std::string &_name)
{
Ogre2WideAngleCameraPtr camera(new Ogre2WideAngleCamera);
bool result = this->InitObject(camera, _id, _name);
return (result) ? camera : nullptr;
}

//////////////////////////////////////////////////
BoundingBoxCameraPtr Ogre2Scene::CreateBoundingBoxCameraImpl(
const unsigned int _id, const std::string &_name)
Expand Down