OsgScreenSpaceQuadRepresentation.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_OSGSCREENSPACEQUADREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGSCREENSPACEQUADREPRESENTATION_H
18 
24 
25 #include <array>
26 #include <osg/Vec3>
27 
28 #if defined(_MSC_VER)
29 #pragma warning(push)
30 #pragma warning(disable:4250)
31 #endif
32 
33 namespace osg
34 {
35 class Projection;
36 class Geode;
37 class Geometry;
38 }
39 
40 namespace SurgSim
41 {
42 namespace Graphics
43 {
44 
45 class UniformBase;
46 class Texture;
47 class OsgTexture2d;
48 class OsgTextureRectangle;
49 
50 
54 {
55 public:
56 
58  explicit OsgScreenSpaceQuadRepresentation(const std::string& name);
60 
63  virtual void setLocation(double x, double y);
64 
67  virtual void getLocation(double* x, double* y);
68 
72  void setSize(double width, double height) override;
73 
77  void getSize(double* width, double* height) const override;
78 
84  bool setTexture(std::shared_ptr<Texture> texture) override;
85 
91  bool setTexture(std::shared_ptr<OsgTexture2d> texture);
92 
98  bool setTexture(std::shared_ptr<OsgTextureRectangle> texture);
99 
102  void setTransparent(bool value);
103 
106  bool isTransparent();
107 
108 protected:
109  void doUpdate(double dt) override;
110 
111  bool doInitialize() override;
112 
113 private:
114 
116  osg::ref_ptr<osg::Geode> m_geode;
117 
119  osg::ref_ptr<osg::Geometry> m_geometry;
120 
122  osg::ref_ptr<osg::Projection> m_projection;
123 
125  osg::Vec3 m_scale;
126 
132 
135  void setTextureCoordinates(float left, float bottom, float right, float top);
136 
141  bool replaceUniform(const std::string& name, std::shared_ptr<SurgSim::Graphics::UniformBase> newUniform);
142 
144  std::shared_ptr<OsgUniform<std::shared_ptr<OsgTexture2d>>> m_textureUniform;
145 
147  std::shared_ptr<OsgUniform<std::shared_ptr<OsgTextureRectangle>>> m_rectangleTextureUniform;
148 
151 };
152 
153 }; // Graphics
154 }; // SurgSim
155 
156 #if defined(_MSC_VER)
157 #pragma warning(pop)
158 #endif
159 
160 #endif
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgScreenSpaceQuadRepresentation.cpp:232
OsgUniform.h
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::replaceUniform
bool replaceUniform(const std::string &name, std::shared_ptr< SurgSim::Graphics::UniformBase > newUniform)
Replace a uniform in the material, will create the material if necessary.
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_projection
osg::ref_ptr< osg::Projection > m_projection
Projection matrix, needs to be updated when the view is changed.
Definition: OsgScreenSpaceQuadRepresentation.h:122
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_displayHeight
int m_displayHeight
Definition: OsgScreenSpaceQuadRepresentation.h:130
SurgSim::DataStructures::OptionalValue< int >
osg
Definition: OculusView.h:25
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::isTransparent
bool isTransparent()
Gets whether or not the alpha component of the texture should be used for transparancy blending.
Definition: OsgScreenSpaceQuadRepresentation.cpp:220
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation
Implements the ScreenSpaceQuadRepresentation, provides the uniform 'texture' for the texture that it ...
Definition: OsgScreenSpaceQuadRepresentation.h:53
ScreenSpaceQuadRepresentation.h
Representation.h
OptionalValue.h
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_rectangleTextureUniform
std::shared_ptr< OsgUniform< std::shared_ptr< OsgTextureRectangle > > > m_rectangleTextureUniform
Uniform to carry the rectangle texture "texture".
Definition: OsgScreenSpaceQuadRepresentation.h:147
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::setLocation
virtual void setLocation(double x, double y)
Sets the location in screen space.
Definition: OsgScreenSpaceQuadRepresentation.cpp:192
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_geometry
osg::ref_ptr< osg::Geometry > m_geometry
Local geometry pointer.
Definition: OsgScreenSpaceQuadRepresentation.h:119
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::OsgScreenSpaceQuadRepresentation
OsgScreenSpaceQuadRepresentation(const std::string &name)
Constructor.
Definition: OsgScreenSpaceQuadRepresentation.cpp:52
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_displayWidth
int m_displayWidth
Definition: OsgScreenSpaceQuadRepresentation.h:129
SurgSim::Graphics::ScreenSpaceQuadRepresentation
A quad to display on the screen in screen space coordinates, use setPose() to set the position but x,...
Definition: ScreenSpaceQuadRepresentation.h:36
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_textureUniform
std::shared_ptr< OsgUniform< std::shared_ptr< OsgTexture2d > > > m_textureUniform
Uniform to carry the power of two texture, "texture".
Definition: OsgScreenSpaceQuadRepresentation.h:144
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_geode
osg::ref_ptr< osg::Geode > m_geode
Local geode to contain geometry.
Definition: OsgScreenSpaceQuadRepresentation.h:116
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::setTexture
bool setTexture(std::shared_ptr< Texture > texture) override
Sets a Texture for this quad, this should replace a current texture, this is a convenience function a...
Definition: OsgScreenSpaceQuadRepresentation.cpp:121
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::getSize
void getSize(double *width, double *height) const override
Gets the size of the quad.
Definition: OsgScreenSpaceQuadRepresentation.cpp:114
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::doUpdate
void doUpdate(double dt) override
Definition: OsgScreenSpaceQuadRepresentation.cpp:226
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::getLocation
virtual void getLocation(double *x, double *y)
Gets the location in screen space.
Definition: OsgScreenSpaceQuadRepresentation.cpp:199
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::~OsgScreenSpaceQuadRepresentation
~OsgScreenSpaceQuadRepresentation()
Definition: OsgScreenSpaceQuadRepresentation.cpp:102
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::setTextureCoordinates
void setTextureCoordinates(float left, float bottom, float right, float top)
Sets texture coordinates for the quad.
Definition: OsgScreenSpaceQuadRepresentation.cpp:182
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::setSize
void setSize(double width, double height) override
Sets the size for the quad in screen coordinates.
Definition: OsgScreenSpaceQuadRepresentation.cpp:107
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::setTransparent
void setTransparent(bool value)
Sets whether or not the alpha component of the texture should be used for transparancy blending.
Definition: OsgScreenSpaceQuadRepresentation.cpp:208
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
OsgRepresentation.h
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_scale
osg::Vec3 m_scale
Size of the quad.
Definition: OsgScreenSpaceQuadRepresentation.h:125
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::OsgScreenSpaceQuadRepresentation::m_texureType
SurgSim::DataStructures::OptionalValue< int > m_texureType
Indicate which type of texture is currently being used.
Definition: OsgScreenSpaceQuadRepresentation.h:150