OsgMeshRepresentation.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_OSGMESHREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
18 
19 #include <memory>
20 
21 #include <osg/Array>
22 #include <osg/ref_ptr>
23 
28 
29 #if defined(_MSC_VER)
30 #pragma warning(push)
31 #pragma warning(disable:4250)
32 #endif
33 
34 namespace osg
35 {
36 class Geometry;
37 class DrawElementsUInt;
38 }
39 
40 namespace SurgSim
41 {
42 namespace Graphics
43 {
44 class Mesh;
45 
46 SURGSIM_STATIC_REGISTRATION(OsgMeshRepresentation);
47 
50 {
51 public:
54  explicit OsgMeshRepresentation(const std::string& name);
55 
58 
60 
61  virtual std::shared_ptr<Mesh> getMesh() override;
62 
63  virtual void setUpdateOptions(int val) override;
64  virtual int getUpdateOptions() const override;
65 
66  osg::ref_ptr<osg::Geometry> getOsgGeometry();
67 
68  virtual void setFilename(std::string filename) override;
69  virtual std::string getFilename() const override;
70 
71 protected:
72  virtual void doUpdate(double dt) override;
73 
75  virtual bool doInitialize() override;
76 
77 private:
80 
82  std::shared_ptr<Mesh> m_mesh;
83 
86 
89  osg::ref_ptr<osg::Geometry> m_geometry;
90  osg::ref_ptr<osg::Vec3Array> m_vertices;
91  osg::ref_ptr<osg::Vec4Array> m_colors;
92  osg::ref_ptr<osg::Vec3Array> m_normals;
93  osg::ref_ptr<osg::Vec2Array> m_textureCoordinates;
94  osg::ref_ptr<osg::DrawElementsUInt> m_triangles;
96 
100  int updateOsgArrays();
101 
105  void updateVertices(int updateOptions);
106 
108  void updateNormals();
109 
111  void updateTriangles();
112 
116  osg::Object::DataVariance getDataVariance(int updateOption);
117 };
118 
119 #if defined(_MSC_VER)
120 #pragma warning(pop)
121 #endif
122 
123 }; // Graphics
124 }; // SurgSim
125 
126 #endif // SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
Definition: DriveElementFromInputBehavior.cpp:27
Implementation of a MeshRepresentation for rendering under osg.
Definition: OsgMeshRepresentation.h:49
Graphics representation of a mesh, can be initialized from a Mesh structure.
Definition: MeshRepresentation.h:28
int m_updateOptions
Indicates which elements of the mesh should be updated on every frame.
Definition: OsgMeshRepresentation.h:79
SURGSIM_STATIC_REGISTRATION(SerializationMockComponent)
osg::ref_ptr< osg::DrawElementsUInt > m_triangles
Definition: OsgMeshRepresentation.h:94
std::string m_filename
File name of the external file which contains the mesh to be used by this class.
Definition: OsgMeshRepresentation.h:85
string(TOUPPER ${DEVICE}DEVICE_UPPER_CASE) option(BUILD_DEVICE_ $
Definition: CMakeLists.txt:35
osg::ref_ptr< osg::Vec2Array > m_textureCoordinates
Definition: OsgMeshRepresentation.h:93
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
osg::ref_ptr< osg::Vec3Array > m_vertices
Definition: OsgMeshRepresentation.h:90
std::shared_ptr< Mesh > m_mesh
The mesh.
Definition: OsgMeshRepresentation.h:82
osg::ref_ptr< osg::Geometry > m_geometry
Definition: OsgMeshRepresentation.h:89
osg::ref_ptr< osg::Vec3Array > m_normals
Definition: OsgMeshRepresentation.h:92
Definition: OsgLight.h:33
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:42
osg::ref_ptr< osg::Vec4Array > m_colors
Definition: OsgMeshRepresentation.h:91