Camera.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, 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_CAMERA_H
#define SURGSIM_GRAPHICS_CAMERA_H
#include "SurgSim/Graphics/Representation.h"
#include "SurgSim/Math/Matrix.h"
#include "SurgSim/Math/Vector.h"
#include <array>
namespace SurgSim
{
namespace Graphics
{
class Group;
class Texture;
class RenderTarget;
class Camera : public virtual Representation
{
public:
enum RenderOrder
{
RENDER_ORDER_PRE_RENDER = 0,
RENDER_ORDER_IN_ORDER,
RENDER_ORDER_POST_RENDER,
RENDER_ORDER_COUNT
};
explicit Camera(const std::string& name);
void setRenderGroupReference(const std::string& name);
void setRenderGroupReferences(const std::vector<std::string>& names);
std::vector<std::string> getRenderGroupReferences() const;
void addRenderGroupReference(const std::string& name);
virtual bool setRenderGroup(std::shared_ptr<Group> group);
virtual bool setRenderGroups(const std::vector<std::shared_ptr<Group>>& groups);
virtual bool addRenderGroup(std::shared_ptr<Group> group);
std::vector<std::shared_ptr<Group>> getRenderGroups() const;
virtual SurgSim::Math::Matrix44d getViewMatrix() const = 0;
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const = 0;
virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d& matrix) = 0;
virtual void setViewport(int x, int y, int width, int height) = 0;
virtual void getViewport(int* x, int* y, int* width, int* height) const = 0;
virtual void setViewportSize(std::array<double, 2> dimensions) = 0;
virtual std::array<double, 2> getViewportSize() const = 0;
virtual void setPerspectiveProjection(double fovy, double aspect, double near, double far) = 0;
virtual void setOrthogonalProjection(
double left, double right,
double bottom, double top,
double near, double far) = 0;
virtual const SurgSim::Math::Matrix44d& getProjectionMatrix() const = 0;
virtual SurgSim::Math::Matrix44d getInverseProjectionMatrix() const = 0;
virtual bool setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) = 0;
virtual std::shared_ptr<RenderTarget> getRenderTarget() const = 0;
virtual void setRenderOrder(RenderOrder order, int value) = 0;
bool addGroupReference(const std::string& name) override;
virtual void setAmbientColor(const SurgSim::Math::Vector4d& color) = 0;
virtual SurgSim::Math::Vector4d getAmbientColor() = 0;
virtual void setMainCamera(bool val) = 0;
virtual bool isMainCamera() = 0;
private:
void setPerspectiveProjection(const std::array<double, 4>& val);
void setOrthogonalProjection(const std::array<double, 6>& val);
void setViewport(std::array<int, 4> val);
std::array<int, 4> getViewport() const;
bool doInitialize() override;
std::vector<std::shared_ptr<Group>> m_renderGroups;
std::vector<std::string> m_renderGroupReferences;
};
}; // namespace Graphics
}; // namespace SurgSim
#endif // SURGSIM_GRAPHICS_CAMERA_H
SurgSim::Graphics::Camera::getViewportSize
virtual std::array< double, 2 > getViewportSize() const =0
Gets the dimensions of the viewport.
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::Camera::getRenderGroups
std::vector< std::shared_ptr< Group > > getRenderGroups() const
Gets all groups of representations that will be seen by this camera.
Definition: Camera.cpp:138
SurgSim::Graphics::Camera::setOrthogonalProjection
virtual void setOrthogonalProjection(double left, double right, double bottom, double top, double near, double far)=0
Set the projection matrix with the appropriate orthogonal projection parameters.
SurgSim::Graphics::Camera::RENDER_ORDER_IN_ORDER
Definition: Camera.h:58
SurgSim::Graphics::Camera::Camera
Camera(const std::string &name)
Constructor.
Definition: Camera.cpp:26
SurgSim::Graphics::Camera::getProjectionMatrix
virtual const SurgSim::Math::Matrix44d & getProjectionMatrix() const =0
Gets the projection matrix of the camera.
SurgSim::Graphics::Camera::getViewMatrix
virtual SurgSim::Math::Matrix44d getViewMatrix() const =0
Gets the view matrix of the camera.
SurgSim::Graphics::Camera::m_renderGroupReferences
std::vector< std::string > m_renderGroupReferences
The names of the groups that the camera wants to use for rendering, the graphics manager will actuall...
Definition: Camera.h:217
SurgSim::Graphics::Camera::getInverseProjectionMatrix
virtual SurgSim::Math::Matrix44d getInverseProjectionMatrix() const =0
Gets the inverse projection matrix of the camera.
SurgSim::Graphics::Camera::setRenderGroups
virtual bool setRenderGroups(const std::vector< std::shared_ptr< Group >> &groups)
Sets the representation groups that will be seen by this camera.
Definition: Camera.cpp:110
SurgSim::Graphics::Camera::addRenderGroupReference
void addRenderGroupReference(const std::string &name)
Adds a single group reference to the collection of group references for rendering.
Definition: Camera.cpp:95
SurgSim::Graphics::Camera::getInverseViewMatrix
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const =0
Gets the inverse view matrix of the camera.
SurgSim::Graphics::Camera::RENDER_ORDER_POST_RENDER
Definition: Camera.h:59
SurgSim::Graphics::Camera::setAmbientColor
virtual void setAmbientColor(const SurgSim::Math::Vector4d &color)=0
Sets a value for the ambient lighting term, this can add light to the scene when there is no lighting...
SurgSim::Graphics::Camera::m_renderGroups
std::vector< std::shared_ptr< Group > > m_renderGroups
Group of representations that this camera sees Only the representations in this group will be rendere...
Definition: Camera.h:213
SurgSim::Graphics::Camera::setRenderGroup
virtual bool setRenderGroup(std::shared_ptr< Group > group)
Sets the group of representations that will be seen by this camera.
Definition: Camera.cpp:104
SurgSim::Graphics::Camera::getViewport
std::array< int, 4 > getViewport() const
Definition: Camera.cpp:170
SurgSim::Graphics::Camera::addGroupReference
bool addGroupReference(const std::string &name) override
Add a reference to a group, this will eventual add this representation to the group with the the same...
Definition: Camera.cpp:143
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
Representation.h
SurgSim::Graphics::Camera::isMainCamera
virtual bool isMainCamera()=0
SurgSim::Graphics::Camera::setRenderGroupReferences
void setRenderGroupReferences(const std::vector< std::string > &names)
Set the collections of group references that this camera wants to use for rendering.
Definition: Camera.cpp:80
SurgSim::Graphics::Camera::getRenderGroupReferences
std::vector< std::string > getRenderGroupReferences() const
Gets the collection of names of render groups used for rendering.
Definition: Camera.cpp:90
SurgSim::Graphics::Camera::setPerspectiveProjection
virtual void setPerspectiveProjection(double fovy, double aspect, double near, double far)=0
Set the projection matrix with the appropriate perspective projection parameters. ...
SurgSim::Graphics::Camera::setRenderTarget
virtual bool setRenderTarget(std::shared_ptr< RenderTarget > renderTarget)=0
Sets RenderTarget for the current camera, enables the camera to render to off-screen textures...
SurgSim::Graphics::Camera::setProjectionMatrix
virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d &matrix)=0
Sets the projection matrix of the camera.
SurgSim::Graphics::Representation
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:39
Matrix.h
Definitions of small fixed-size square matrix types.
Vector.h
Definitions of small fixed-size vector types.
SurgSim::Graphics::Camera::setViewport
virtual void setViewport(int x, int y, int width, int height)=0
Sets the viewport size for this camera.
SurgSim::Graphics::Camera::getAmbientColor
virtual SurgSim::Math::Vector4d getAmbientColor()=0
SurgSim::Graphics::Camera::setViewportSize
virtual void setViewportSize(std::array< double, 2 > dimensions)=0
Sets the width and height of the viewport.
SurgSim::Graphics::Camera::addRenderGroup
virtual bool addRenderGroup(std::shared_ptr< Group > group)
Add a group of representations that will seen by this camera.
Definition: Camera.cpp:125
SurgSim::Graphics::Camera::RENDER_ORDER_PRE_RENDER
Definition: Camera.h:57
SurgSim::Graphics::Camera::setRenderOrder
virtual void setRenderOrder(RenderOrder order, int value)=0
Determine when this camera will render.
SurgSim::Graphics::Camera::getRenderTarget
virtual std::shared_ptr< RenderTarget > getRenderTarget() const =0
Gets RenderTarget that is currently being used by the camera.
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::Camera::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: Camera.cpp:177
SurgSim::Graphics::Camera::setRenderGroupReference
void setRenderGroupReference(const std::string &name)
Set the group reference that this camera wants to use as the group for rendering. ...
Definition: Camera.cpp:74
SurgSim::Graphics::Camera::setMainCamera
virtual void setMainCamera(bool val)=0
Marks the camera as a main view camera, this means that view dependent passes should follow this came...
SurgSim::Graphics::Camera::RENDER_ORDER_COUNT
Definition: Camera.h:60