opensurgsim
Camera.h
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 
19 #include "SurgSim/Graphics/Representation.h"
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 
55  enum RenderOrder
56  {
57  RENDER_ORDER_PRE_RENDER = 0,
58  RENDER_ORDER_IN_ORDER,
59  RENDER_ORDER_POST_RENDER,
60  RENDER_ORDER_COUNT
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
virtual std::array< double, 2 > getViewportSize() const =0
Gets the dimensions of the viewport.
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
std::vector< std::shared_ptr< Group > > getRenderGroups() const
Gets all groups of representations that will be seen by this camera.
Definition: Camera.cpp:138
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.
Camera(const std::string &name)
Constructor.
Definition: Camera.cpp:26
virtual const SurgSim::Math::Matrix44d & getProjectionMatrix() const =0
Gets the projection matrix of the camera.
virtual SurgSim::Math::Matrix44d getViewMatrix() const =0
Gets the view matrix of the camera.
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
virtual SurgSim::Math::Matrix44d getInverseProjectionMatrix() const =0
Gets the inverse projection matrix of the camera.
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
void addRenderGroupReference(const std::string &name)
Adds a single group reference to the collection of group references for rendering.
Definition: Camera.cpp:95
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const =0
Gets the inverse view matrix of the camera.
Eigen::Matrix< double, 4, 4, Eigen::RowMajor > Matrix44d
A 4x4 matrix of doubles.
Definition: Matrix.h:55
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...
virtual bool setRenderGroup(std::shared_ptr< Group > group)
Sets the group of representations that will be seen by this camera.
Definition: Camera.cpp:104
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
Base graphics camera class, which defines the basic interface for all graphics cameras.
Definition: Camera.h:51
virtual bool isMainCamera()=0
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
std::vector< std::string > getRenderGroupReferences() const
Gets the collection of names of render groups used for rendering.
Definition: Camera.cpp:90
virtual void getViewport(int *x, int *y, int *width, int *height) const =0
collect the viewport values
virtual void setPerspectiveProjection(double fovy, double aspect, double near, double far)=0
Set the projection matrix with the appropriate perspective projection parameters. ...
virtual bool setRenderTarget(std::shared_ptr< RenderTarget > renderTarget)=0
Sets RenderTarget for the current camera, enables the camera to render to off-screen textures...
virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d &matrix)=0
Sets the projection matrix of the camera.
Base graphics representation class, which defines the interface that all graphics representations mus...
Definition: Representation.h:40
Definitions of small fixed-size square matrix types.
Definitions of small fixed-size vector types.
virtual void setViewport(int x, int y, int width, int height)=0
Sets the viewport size for this camera.
virtual SurgSim::Math::Vector4d getAmbientColor()=0
virtual void setViewportSize(std::array< double, 2 > dimensions)=0
Sets the width and height of the viewport.
virtual bool addRenderGroup(std::shared_ptr< Group > group)
Add a group of representations that will seen by this camera.
Definition: Camera.cpp:125
virtual void setRenderOrder(RenderOrder order, int value)=0
Determine when this camera will render.
virtual std::shared_ptr< RenderTarget > getRenderTarget() const =0
Gets RenderTarget that is currently being used by the camera.
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
virtual void setMainCamera(bool val)=0
Marks the camera as a main view camera, this means that view dependent passes should follow this came...