OsgCamera.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013-2016, SimQuest Solutions Inc.
//
// 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 SURGSIM_GRAPHICS_OSGCAMERA_H
#define SURGSIM_GRAPHICS_OSGCAMERA_H
#include <unordered_map>
#include "SurgSim/Framework/Macros.h"
#include "SurgSim/Framework/ObjectFactory.h"
#include "SurgSim/Graphics/Camera.h"
#include "SurgSim/Graphics/OsgRepresentation.h"
#include "SurgSim/Graphics/Texture.h"
#include <osg/Camera>
#include <osg/Switch>
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif
namespace SurgSim
{
namespace Graphics
{
class Material;
class Texture;
class RenderTarget;
template <class T>
class OsgUniform;
SURGSIM_STATIC_REGISTRATION(OsgCamera);
class OsgCamera : public OsgRepresentation, public Camera
{
public:
explicit OsgCamera(const std::string& name);
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgCamera);
bool setRenderGroup(std::shared_ptr<Group> group) override;
bool setRenderGroups(const std::vector<std::shared_ptr<Group>>& groups) override;
void setLocalActive(bool val) override;
virtual SurgSim::Math::Matrix44d getViewMatrix() const;
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const;
void setProjectionMatrix(const SurgSim::Math::Matrix44d& matrix) override;
const SurgSim::Math::Matrix44d& getProjectionMatrix() const override;
SurgSim::Math::Matrix44d getInverseProjectionMatrix() const override;
void update(double dt) override;
osg::ref_ptr<osg::Camera> getOsgCamera() const;
osg::ref_ptr<osg::Node> getOsgNode() const;
bool setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) override;
std::shared_ptr<RenderTarget> getRenderTarget() const override;
bool setMaterial(std::shared_ptr<SurgSim::Framework::Component> material) override;
std::shared_ptr<Material> getMaterial() const override;
void clearMaterial() override;
void setRenderOrder(RenderOrder order, int value) override;
void setAmbientColor(const SurgSim::Math::Vector4d& color) override;
SurgSim::Math::Vector4d getAmbientColor() override;
void setGenerateTangents(bool value) override;
void setPerspectiveProjection(double fovy, double aspect, double near, double far) override;
void setOrthogonalProjection(
double left, double right,
double bottom, double top,
double near, double far) override;
void setViewport(int x, int y, int width, int height) override;
void getViewport(int* x, int* y, int* width, int* height) const override;
void setViewportSize(std::array<double, 2> dimensions) override;
std::array<double, 2> getViewportSize() const override;
void setMainCamera(bool val) override;
bool isMainCamera() override;
private:
osg::ref_ptr<osg::Camera> m_camera;
SurgSim::Math::Matrix44d m_projectionMatrix;
std::unordered_map<int, std::shared_ptr<Texture>> m_textureMap;
std::shared_ptr<RenderTarget> m_renderTarget;
void attachRenderTargetTexture(osg::Camera::BufferComponent buffer, std::shared_ptr<Texture> texture);
void detachCurrentRenderTarget();
std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_viewMatrixUniform;
std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_inverseViewMatrixUniform;
std::shared_ptr<OsgUniform<SurgSim::Math::Vector4f>> m_ambientColorUniform;
SurgSim::Math::Vector4d m_ambientColor;
bool m_isMainCamera;
};
}; // namespace Graphics
}; // namespace SurgSim
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
#endif // SURGSIM_GRAPHICS_OSGCAMERA_H
SurgSim::Graphics::OsgCamera::setMainCamera
void setMainCamera(bool val) override
Marks the camera as a main view camera, this means that view dependent passes should follow this came...
Definition: OsgCamera.cpp:411
SurgSim::Graphics::OsgCamera::setViewportSize
void setViewportSize(std::array< double, 2 > dimensions) override
Sets the width and height of the viewport.
Definition: OsgCamera.cpp:383
SurgSim::Graphics::OsgCamera::m_textureMap
std::unordered_map< int, std::shared_ptr< Texture > > m_textureMap
Definition: OsgCamera.h:135
SurgSim::Graphics::OsgCamera::setMaterial
bool setMaterial(std::shared_ptr< SurgSim::Framework::Component > material) override
Sets the material that defines the visual appearance of the representation.
Definition: OsgCamera.cpp:324
SurgSim::Graphics::OsgCamera::setProjectionMatrix
void setProjectionMatrix(const SurgSim::Math::Matrix44d &matrix) override
Sets the projection matrix of the camera.
Definition: OsgCamera.cpp:240
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgCamera::setPerspectiveProjection
void setPerspectiveProjection(double fovy, double aspect, double near, double far) override
Set the projection matrix with the appropriate perspective projection parameters. ...
Definition: OsgCamera.cpp:445
SurgSim::Graphics::OsgCamera::getRenderTarget
std::shared_ptr< RenderTarget > getRenderTarget() const override
Gets RenderTarget that is currently being used by the camera.
Definition: OsgCamera.cpp:318
Texture.h
Camera.h
SurgSim::Graphics::OsgCamera::clearMaterial
void clearMaterial() override
Removes the material from the representation.
Definition: OsgCamera.cpp:342
SurgSim::Graphics::OsgCamera::m_camera
osg::ref_ptr< osg::Camera > m_camera
Definition: OsgCamera.h:130
SurgSim::Graphics::OsgCamera::getInverseProjectionMatrix
SurgSim::Math::Matrix44d getInverseProjectionMatrix() const override
Gets the inverse projection matrix of the camera.
Definition: OsgCamera.cpp:251
SurgSim::Graphics::OsgCamera::getOsgNode
osg::ref_ptr< osg::Node > getOsgNode() const
Definition: OsgCamera.cpp:489
SurgSim::Graphics::OsgCamera::getOsgCamera
osg::ref_ptr< osg::Camera > getOsgCamera() const
Definition: OsgCamera.cpp:484
ObjectFactory.h
SurgSim::Graphics::Camera::getViewport
std::array< int, 4 > getViewport() const
Definition: Camera.cpp:170
SurgSim::Graphics::OsgCamera::setRenderOrder
void setRenderOrder(RenderOrder order, int value) override
Determine when this camera will render.
Definition: OsgCamera.cpp:476
SurgSim::Graphics::OsgCamera
OSG implementation of a graphics camera.
Definition: OsgCamera.h:54
SurgSim::Math::Matrix44d
Eigen::Matrix< double, 4, 4, Eigen::RowMajor > Matrix44d
A 4x4 matrix of doubles.
Definition: Matrix.h:55
SurgSim::Graphics::Camera
Base graphics camera class, which defines the basic interface for all graphics cameras.
Definition: Camera.h:51
SurgSim::Graphics::OsgCamera::detachCurrentRenderTarget
void detachCurrentRenderTarget()
Detach the current render target from the camera.
Definition: OsgCamera.cpp:347
SurgSim::Graphics::OsgCamera::setViewport
void setViewport(int x, int y, int width, int height) override
Sets the viewport size for this camera.
Definition: OsgCamera.cpp:363
SurgSim::Graphics::OsgCamera::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgCamera)
SurgSim::Graphics::OsgCamera::setGenerateTangents
void setGenerateTangents(bool value) override
Enable or disable the generation of tangents.
Definition: OsgCamera.cpp:510
SurgSim::Graphics::OsgCamera::setRenderTarget
bool setRenderTarget(std::shared_ptr< RenderTarget > renderTarget) override
Sets RenderTarget for the current camera, enables the camera to render to off-screen textures...
Definition: OsgCamera.cpp:276
SurgSim::Graphics::OsgUniform
OSG implementation of graphics uniform with a value of type T.
Definition: OsgCamera.h:46
SurgSim::Graphics::OsgCamera::getMaterial
std::shared_ptr< Material > getMaterial() const override
Gets the material that defines the visual appearance of the representation.
Definition: OsgCamera.cpp:337
SurgSim::Graphics::OsgCamera::m_projectionMatrix
SurgSim::Math::Matrix44d m_projectionMatrix
Projection matrix of the camera.
Definition: OsgCamera.h:133
SurgSim::Graphics::OsgCamera::setLocalActive
void setLocalActive(bool val) override
Set the component&#39;s active state.
Definition: OsgCamera.cpp:229
Macros.h
SurgSim::Graphics::OsgCamera::update
void update(double dt) override
Updates the representation.
Definition: OsgCamera.cpp:256
SurgSim::Graphics::OsgCamera::m_inverseViewMatrixUniform
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_inverseViewMatrixUniform
Uniform to carry the inverse view matrix.
Definition: OsgCamera.h:150
SurgSim::Graphics::OsgCamera::m_ambientColorUniform
std::shared_ptr< OsgUniform< SurgSim::Math::Vector4f > > m_ambientColorUniform
Uniform to carry the ambient color.
Definition: OsgCamera.h:153
SurgSim::Graphics::OsgCamera::m_renderTarget
std::shared_ptr< RenderTarget > m_renderTarget
Definition: OsgCamera.h:136
SurgSim::Graphics::OsgCamera::getViewportSize
std::array< double, 2 > getViewportSize() const override
Gets the dimensions of the viewport.
Definition: OsgCamera.cpp:400
SurgSim::Graphics::OsgCamera::getProjectionMatrix
const SurgSim::Math::Matrix44d & getProjectionMatrix() const override
Gets the projection matrix of the camera.
Definition: OsgCamera.cpp:246
SurgSim::Graphics::OsgCamera::isMainCamera
bool isMainCamera() override
Definition: OsgCamera.cpp:440
SurgSim::Graphics::OsgCamera::m_isMainCamera
bool m_isMainCamera
Definition: OsgCamera.h:158
SurgSim::Graphics::OsgCamera::m_ambientColor
SurgSim::Math::Vector4d m_ambientColor
Value for ambient color.
Definition: OsgCamera.h:156
SurgSim::Graphics::OsgCamera::OsgCamera
OsgCamera(const std::string &name)
Constructor.
Definition: OsgCamera.cpp:147
SurgSim::Graphics::OsgCamera::m_viewMatrixUniform
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_viewMatrixUniform
Uniform to carry the view matrix.
Definition: OsgCamera.h:147
SurgSim::Graphics::OsgCamera::getViewMatrix
virtual SurgSim::Math::Matrix44d getViewMatrix() const
Gets the view matrix of the camera.
Definition: OsgCamera.cpp:235
SurgSim::Graphics::OsgCamera::setAmbientColor
void setAmbientColor(const SurgSim::Math::Vector4d &color) override
Sets a value for the ambient lighting term, this can add light to the scene when there is no lighting...
Definition: OsgCamera.cpp:499
SurgSim::Graphics::OsgCamera::attachRenderTargetTexture
void attachRenderTargetTexture(osg::Camera::BufferComponent buffer, std::shared_ptr< Texture > texture)
Attach a specific texture to a specific BufferComponent, works for Depth and all the Colors...
Definition: OsgCamera.cpp:458
OsgRepresentation.h
SurgSim::Graphics::OsgCamera::setOrthogonalProjection
void setOrthogonalProjection(double left, double right, double bottom, double top, double near, double far) override
Set the projection matrix with the appropriate orthogonal projection parameters.
Definition: OsgCamera.cpp:452
SurgSim::Graphics::OsgCamera::getAmbientColor
SurgSim::Math::Vector4d getAmbientColor() override
Definition: OsgCamera.cpp:505
SurgSim::Graphics::OsgCamera::getInverseViewMatrix
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const
Gets the inverse view matrix of the camera.
Definition: OsgCamera.cpp:494
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::Camera::RenderOrder
RenderOrder
Definition: Camera.h:55
SurgSim::Graphics::OsgCamera::setRenderGroup
bool setRenderGroup(std::shared_ptr< Group > group) override
Sets the group of representations that will be seen by this camera.
Definition: OsgCamera.cpp:190
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::OsgCamera::setRenderGroups
bool setRenderGroups(const std::vector< std::shared_ptr< Group >> &groups) override
Sets the representation groups that will be seen by this camera.
Definition: OsgCamera.cpp:196