Camera.h
Go to the documentation of this file.
1 // This file is a part of the OpenSurgSim project.
2 // Copyright 2013, SimQuest Solutions Inc.
3 //
4 // Licensed under the Apache License, Version 2.0 (the "License");
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
7 //
8 // http://www.apache.org/licenses/LICENSE-2.0
9 //
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
15 
16 #ifndef SURGSIM_GRAPHICS_CAMERA_H
17 #define SURGSIM_GRAPHICS_CAMERA_H
18 
20 
21 #include "SurgSim/Math/Matrix.h"
22 #include "SurgSim/Math/Vector.h"
23 
24 #include <array>
25 
26 namespace SurgSim
27 {
28 
29 namespace Graphics
30 {
31 
32 class Group;
33 class Texture;
34 class RenderTarget;
35 
51 class Camera : public virtual Representation
52 {
53 public:
54 
56  {
61  };
62 
65  explicit Camera(const std::string& name);
66 
70  void setRenderGroupReference(const std::string& name);
71 
74  void setRenderGroupReferences(const std::vector<std::string>& names);
75 
78  std::vector<std::string> getRenderGroupReferences() const;
79 
82  void addRenderGroupReference(const std::string& name);
83 
89  virtual bool setRenderGroup(std::shared_ptr<Group> group);
90 
94  virtual bool setRenderGroups(const std::vector<std::shared_ptr<Group>>& groups);
95 
98  virtual bool addRenderGroup(std::shared_ptr<Group> group);
99 
103  std::vector<std::shared_ptr<Group>> getRenderGroups() const;
104 
107  virtual SurgSim::Math::Matrix44d getViewMatrix() const = 0;
108 
112 
115  virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d& matrix) = 0;
116 
120  virtual void setViewport(int x, int y, int width, int height) = 0;
121 
124  virtual void getViewport(int* x, int* y, int* width, int* height) const = 0;
125 
128  virtual void setViewportSize(std::array<double, 2> dimensions) = 0;
129 
131  virtual std::array<double, 2> getViewportSize() const = 0;
132 
137  virtual void setPerspectiveProjection(double fovy, double aspect, double near, double far) = 0;
138 
143  virtual void setOrthogonalProjection(
144  double left, double right,
145  double bottom, double top,
146  double near, double far) = 0;
147 
150  virtual const SurgSim::Math::Matrix44d& getProjectionMatrix() const = 0;
151 
155 
158  virtual bool setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) = 0;
159 
162  virtual std::shared_ptr<RenderTarget> getRenderTarget() const = 0;
163 
170  virtual void setRenderOrder(RenderOrder order, int value) = 0;
171 
172  bool addGroupReference(const std::string& name) override;
173 
176  virtual void setAmbientColor(const SurgSim::Math::Vector4d& color) = 0;
177 
180 
193  virtual void setMainCamera(bool val) = 0;
194 
196  virtual bool isMainCamera() = 0;
197 
198 private:
199 
200  void setPerspectiveProjection(const std::array<double, 4>& val);
201 
202  void setOrthogonalProjection(const std::array<double, 6>& val);
203 
204  void setViewport(std::array<int, 4> val);
205 
206  std::array<int, 4> getViewport() const;
207 
208 
209  bool doInitialize() override;
210 
213  std::vector<std::shared_ptr<Group>> m_renderGroups;
214 
217  std::vector<std::string> m_renderGroupReferences;
218 };
219 
220 }; // namespace Graphics
221 
222 }; // namespace SurgSim
223 
224 #endif // SURGSIM_GRAPHICS_CAMERA_H
SurgSim::Graphics::Camera::getAmbientColor
virtual SurgSim::Math::Vector4d getAmbientColor()=0
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::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...
Vector.h
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::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::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
Matrix.h
SurgSim::Graphics::Camera
Base graphics camera class, which defines the basic interface for all graphics cameras.
Definition: Camera.h:51
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
Representation.h
SurgSim::Graphics::Camera::RENDER_ORDER_IN_ORDER
@ RENDER_ORDER_IN_ORDER
Definition: Camera.h:58
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
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::RENDER_ORDER_PRE_RENDER
@ RENDER_ORDER_PRE_RENDER
Definition: Camera.h:57
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::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::setViewport
virtual void setViewport(int x, int y, int width, int height)=0
Sets the viewport size for this camera.
SurgSim::Math::Matrix44d
Eigen::Matrix< double, 4, 4, Eigen::RowMajor > Matrix44d
A 4x4 matrix of doubles.
Definition: Matrix.h:55
SurgSim::Graphics::Camera::getViewport
std::array< int, 4 > getViewport() const
Definition: Camera.cpp:170
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::Camera::setViewportSize
virtual void setViewportSize(std::array< double, 2 > dimensions)=0
Sets the width and height of the viewport.
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::isMainCamera
virtual bool isMainCamera()=0
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::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: Camera.cpp:177
SurgSim::Graphics::Camera::setRenderOrder
virtual void setRenderOrder(RenderOrder order, int value)=0
Determine when this camera will render.
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::RenderOrder
RenderOrder
Definition: Camera.h:55
SurgSim::Graphics::Camera::RENDER_ORDER_COUNT
@ RENDER_ORDER_COUNT
Definition: Camera.h:60
SurgSim::Graphics::Camera::setProjectionMatrix
virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d &matrix)=0
Sets the projection matrix of the camera.
SurgSim::Graphics::Camera::RENDER_ORDER_POST_RENDER
@ RENDER_ORDER_POST_RENDER
Definition: Camera.h:59
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::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::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::getInverseProjectionMatrix
virtual SurgSim::Math::Matrix44d getInverseProjectionMatrix() const =0
Gets the inverse 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
SurgSim::Graphics::Camera::getViewportSize
virtual std::array< double, 2 > getViewportSize() const =0
Gets the dimensions of the viewport.
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::Camera::getViewMatrix
virtual SurgSim::Math::Matrix44d getViewMatrix() const =0
Gets the view matrix of the camera.
SurgSim::Graphics::Camera::getInverseViewMatrix
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const =0
Gets the inverse view matrix of the camera.
SurgSim::Graphics::Camera::getRenderTarget
virtual std::shared_ptr< RenderTarget > getRenderTarget() const =0
Gets RenderTarget that is currently being used by the camera.