All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
OsgCamera.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_OSGCAMERA_H
17 #define SURGSIM_GRAPHICS_OSGCAMERA_H
18 
19 #include <unordered_map>
20 
26 
27 
28 #include <osg/Camera>
29 #include <osg/Switch>
30 
31 #if defined(_MSC_VER)
32 #pragma warning(push)
33 #pragma warning(disable:4250)
34 #endif
35 
36 namespace SurgSim
37 {
38 namespace Graphics
39 {
40 
41 class Material;
42 class Texture;
43 class RenderTarget;
44 
45 template <class T>
46 class OsgUniform;
47 
49 
54 class OsgCamera : public OsgRepresentation, public Camera
55 {
56 public:
62  explicit OsgCamera(const std::string& name);
63 
65 
66  virtual bool setRenderGroup(std::shared_ptr<Group> group) override;
67 
68  virtual void setVisible(bool visible) override;
69 
70  virtual bool isVisible() const override;
71 
73 
75 
76  virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d& matrix) override;
77 
78  virtual const SurgSim::Math::Matrix44d& getProjectionMatrix() const override;
79 
80  virtual void update(double dt) override;
81 
83  osg::ref_ptr<osg::Camera> getOsgCamera() const;
84 
86  osg::ref_ptr<osg::Node> getOsgNode() const;
87 
88  virtual bool setRenderTarget(std::shared_ptr<RenderTarget> renderTarget) override;
89 
90  virtual std::shared_ptr<RenderTarget> getRenderTarget() const override;
91 
92  virtual bool setMaterial(std::shared_ptr<Material> material) override;
93 
94  virtual std::shared_ptr<Material> getMaterial() const override;
95 
96  virtual void clearMaterial() override;
97 
98  virtual void setRenderOrder(RenderOrder order, int value) override;
99 
100  virtual void setAmbientColor(const SurgSim::Math::Vector4d& color) override;
101 
102  virtual SurgSim::Math::Vector4d getAmbientColor() override;
103 
104 private:
105 
106  osg::ref_ptr<osg::Camera> m_camera;
107  osg::ref_ptr<osg::Group> m_materialProxy;
108 
111 
112  std::unordered_map<int, std::shared_ptr<Texture>> m_textureMap;
113  std::shared_ptr<RenderTarget> m_renderTarget;
114 
118  void attachRenderTargetTexture(osg::Camera::BufferComponent buffer, std::shared_ptr<Texture> texture);
119 
122 
124  std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_viewMatrixUniform;
125 
127  std::shared_ptr<OsgUniform<SurgSim::Math::Matrix44f>> m_inverseViewMatrixUniform;
128 
130  std::shared_ptr<OsgUniform<SurgSim::Math::Vector4f>> m_ambientColorUniform;
131 
134 
135 
136 };
137 
138 }; // namespace Graphics
139 }; // namespace SurgSim
140 
141 #if defined(_MSC_VER)
142 #pragma warning(pop)
143 #endif
144 
145 #endif // SURGSIM_GRAPHICS_OSGCAMERA_H
std::unordered_map< int, std::shared_ptr< Texture > > m_textureMap
Definition: OsgCamera.h:112
virtual void setProjectionMatrix(const SurgSim::Math::Matrix44d &matrix) override
Sets the projection matrix of the camera.
Definition: OsgCamera.cpp:144
virtual bool setMaterial(std::shared_ptr< Material > material) override
Sets the material that defines the visual appearance of the representation.
Definition: OsgCamera.cpp:219
SURGSIM_STATIC_REGISTRATION(OsgBoxRepresentation)
virtual std::shared_ptr< RenderTarget > getRenderTarget() const override
Gets RenderTarget that is currently being used by the camera.
Definition: OsgCamera.cpp:213
virtual void clearMaterial() override
Removes the material from the representation.
Definition: OsgCamera.cpp:237
osg::ref_ptr< osg::Camera > m_camera
Definition: OsgCamera.h:106
osg::ref_ptr< osg::Camera > getOsgCamera() const
Definition: OsgCamera.cpp:284
osg::ref_ptr< osg::Group > m_materialProxy
Definition: OsgCamera.h:107
virtual void setRenderOrder(RenderOrder order, int value) override
Determine when this camera will render.
Definition: OsgCamera.cpp:276
OSG implementation of a graphics camera.
Definition: OsgCamera.h:54
Eigen::Matrix< double, 4, 4, Eigen::RowMajor > Matrix44d
A 4x4 matrix of doubles.
Definition: Matrix.h:55
Base graphics camera class, which defines the basic interface for all graphics cameras.
Definition: Camera.h:49
void detachCurrentRenderTarget()
Detach the current render target from the camera.
Definition: OsgCamera.cpp:242
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgCamera)
virtual 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:170
OSG implementation of graphics uniform with a value of type T.
Definition: OsgCamera.h:46
virtual std::shared_ptr< Material > getMaterial() const override
Gets the material that defines the visual appearance of the representation.
Definition: OsgCamera.cpp:232
virtual void setVisible(bool visible) override
Sets whether the representation is currently visible.
Definition: OsgCamera.cpp:129
SurgSim::Math::Matrix44d m_projectionMatrix
Projection matrix of the camera.
Definition: OsgCamera.h:110
virtual void update(double dt) override
Updates the representation.
Definition: OsgCamera.cpp:155
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_inverseViewMatrixUniform
Uniform to carry the inverse view matrix.
Definition: OsgCamera.h:127
std::shared_ptr< OsgUniform< SurgSim::Math::Vector4f > > m_ambientColorUniform
Uniform to carry the ambient color.
Definition: OsgCamera.h:130
std::shared_ptr< RenderTarget > m_renderTarget
Definition: OsgCamera.h:113
virtual const SurgSim::Math::Matrix44d & getProjectionMatrix() const override
Gets the projection matrix of the camera.
Definition: OsgCamera.cpp:150
SurgSim::Math::Vector4d m_ambientColor
Value for ambient color.
Definition: OsgCamera.h:133
OsgCamera(const std::string &name)
Constructor.
Definition: OsgCamera.cpp:75
virtual bool isVisible() const override
Gets whether the representation is currently visible.
Definition: OsgCamera.cpp:134
std::shared_ptr< OsgUniform< SurgSim::Math::Matrix44f > > m_viewMatrixUniform
Uniform to carry the view matrix.
Definition: OsgCamera.h:124
virtual 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:299
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:258
virtual SurgSim::Math::Matrix44d getInverseViewMatrix() const
Gets the inverse view matrix of the camera.
Definition: OsgCamera.cpp:294
virtual SurgSim::Math::Vector4d getAmbientColor() override
Definition: OsgCamera.cpp:305
osg::ref_ptr< osg::Node > getOsgNode() const
Definition: OsgCamera.cpp:289
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:60
RenderOrder
Definition: Camera.h:53
virtual bool setRenderGroup(std::shared_ptr< Group > group) override
Sets the group of representations that will be seen by this camera.
Definition: OsgCamera.cpp:109
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:42
virtual SurgSim::Math::Matrix44d getViewMatrix() const
Gets the view matrix of the camera.
Definition: OsgCamera.cpp:139