opensurgsim
OsgMeshRepresentation.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_OSGMESHREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
18 
19 #include <memory>
20 
21 #include <osg/Array>
22 #include <osg/ref_ptr>
23 
24 #include "SurgSim/Framework/Macros.h"
25 #include "SurgSim/Framework/ObjectFactory.h"
26 #include "SurgSim/Graphics/OsgRepresentation.h"
27 #include "SurgSim/Graphics/MeshRepresentation.h"
28 #include "SurgSim/Framework/LockedContainer.h"
29 
30 #if defined(_MSC_VER)
31 #pragma warning(push)
32 #pragma warning(disable:4250)
33 #endif
34 
35 namespace osg
36 {
37 class Geode;
38 class Geometry;
39 class DrawElementsUInt;
40 }
41 
42 namespace SurgSim
43 {
44 namespace Graphics
45 {
46 class Mesh;
47 
48 SURGSIM_STATIC_REGISTRATION(OsgMeshRepresentation);
49 
52 {
53 public:
56  explicit OsgMeshRepresentation(const std::string& name);
57 
60 
62 
63  std::shared_ptr<Mesh> getMesh() override;
64 
65  void setMesh(std::shared_ptr<SurgSim::Framework::Asset> mesh) override;
66 
67  void loadMesh(const std::string& fileName) override;
68 
69  void setShape(std::shared_ptr<SurgSim::Math::Shape> shape) override;
70 
71  void setUpdateOptions(int val) override;
72  int getUpdateOptions() const override;
73 
74  osg::ref_ptr<osg::Geometry> getOsgGeometry() const;
75 
76  void updateMesh(const SurgSim::Graphics::Mesh& mesh) override;
77 
78 protected:
79  void doUpdate(double dt) override;
80 
82  bool doInitialize() override;
83 
84  void privateUpdateMesh(const SurgSim::Graphics::Mesh& mesh);
85 
86 private:
88  int m_updateOptions;
89 
91  std::shared_ptr<Mesh> m_mesh;
92 
94  std::string m_filename;
95 
98  osg::ref_ptr<osg::Switch> m_meshSwitch;
99  osg::ref_ptr<osg::Geometry> m_geometry;
101 
107  int updateOsgArrays(const Mesh& mesh, osg::Geometry* geometry);
108 
114  void updateVertices(const Mesh& mesh, osg::Geometry* geometry, int updateOptions);
115 
118  void updateNormals(osg::Geometry* geometry);
119 
123  void updateTriangles(const Mesh& mesh, osg::Geometry* geometry);
124 
128  osg::Object::DataVariance getDataVariance(int updateOption);
129 
131  void buildGeometry();
132 
134  size_t m_updateCount;
135 
136  Framework::LockedContainer<Mesh> m_writeBuffer;
137 
138 };
139 
140 #if defined(_MSC_VER)
141 #pragma warning(pop)
142 #endif
143 
144 }; // Graphics
145 }; // SurgSim
146 
147 #endif // SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Implementation of a MeshRepresentation for rendering under osg.
Definition: OsgMeshRepresentation.h:51
Graphics representation of a mesh, can be initialized from a Mesh structure.
Definition: MeshRepresentation.h:34
Definition: Mesh.h:57
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
Definition: OsgImGuiHandler.h:8
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55