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 
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 
85 
86 private:
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 
135 
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
SurgSim::Graphics::OsgMeshRepresentation::privateUpdateMesh
void privateUpdateMesh(const SurgSim::Graphics::Mesh &mesh)
Definition: OsgMeshRepresentation.cpp:112
SurgSim::Graphics::OsgMeshRepresentation::m_geometry
osg::ref_ptr< osg::Geometry > m_geometry
Definition: OsgMeshRepresentation.h:99
SurgSim::Graphics::OsgMeshRepresentation::getDataVariance
osg::Object::DataVariance getDataVariance(int updateOption)
Gets data variance for a given update option.
Definition: OsgMeshRepresentation.cpp:304
SurgSim::Graphics::OsgMeshRepresentation::setMesh
void setMesh(std::shared_ptr< SurgSim::Framework::Asset > mesh) override
Sets the mesh.
Definition: OsgMeshRepresentation.cpp:67
SurgSim::Graphics::OsgMeshRepresentation::getUpdateOptions
int getUpdateOptions() const override
Gets update options for this mesh.
Definition: OsgMeshRepresentation.cpp:289
Macros.h
SurgSim::Graphics::OsgMeshRepresentation::getOsgGeometry
osg::ref_ptr< osg::Geometry > getOsgGeometry() const
Definition: OsgMeshRepresentation.cpp:294
MeshRepresentation.h
SurgSim::Graphics::OsgMeshRepresentation::doInitialize
bool doInitialize() override
Definition: OsgMeshRepresentation.cpp:144
LockedContainer.h
SurgSim::Graphics::OsgMeshRepresentation::setUpdateOptions
void setUpdateOptions(int val) override
Sets the structures that are expected to change during the lifetime of the mesh, these will be update...
Definition: OsgMeshRepresentation.cpp:281
SurgSim::Graphics::OsgMeshRepresentation::updateOsgArrays
int updateOsgArrays(const Mesh &mesh, osg::Geometry *geometry)
Updates the internal arrays in accordance to the sizes given in the mesh.
Definition: OsgMeshRepresentation.cpp:218
SurgSim::Graphics::OsgMeshRepresentation::setShape
void setShape(std::shared_ptr< SurgSim::Math::Shape > shape) override
Sets the shape of the representation param shape the shape of this representation.
Definition: OsgMeshRepresentation.cpp:82
SurgSim::Graphics::OsgMeshRepresentation::updateMesh
void updateMesh(const SurgSim::Graphics::Mesh &mesh) override
Definition: OsgMeshRepresentation.cpp:299
SurgSim::Graphics::OsgMeshRepresentation::m_mesh
std::shared_ptr< Mesh > m_mesh
The mesh.
Definition: OsgMeshRepresentation.h:91
osg
Definition: OculusView.h:25
SurgSim::Graphics::OsgMeshRepresentation::loadMesh
void loadMesh(const std::string &fileName) override
Convenience function to trigger the load of the mesh with the given filename.
Definition: OsgMeshRepresentation.cpp:60
SurgSim::Graphics::OsgMeshRepresentation::m_writeBuffer
Framework::LockedContainer< Mesh > m_writeBuffer
Definition: OsgMeshRepresentation.h:136
SurgSim::Graphics::OsgMeshRepresentation::updateVertices
void updateVertices(const Mesh &mesh, osg::Geometry *geometry, int updateOptions)
Copies the attributes for each mesh vertex in the appropriate osg structure, this will only be done f...
Definition: OsgMeshRepresentation.cpp:149
SurgSim::Graphics::OsgMeshRepresentation
Implementation of a MeshRepresentation for rendering under osg.
Definition: OsgMeshRepresentation.h:51
ObjectFactory.h
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgMeshRepresentation::m_meshSwitch
osg::ref_ptr< osg::Switch > m_meshSwitch
Definition: OsgMeshRepresentation.h:98
SurgSim::Graphics::OsgMeshRepresentation::getMesh
std::shared_ptr< Mesh > getMesh() override
Gets the mesh.
Definition: OsgMeshRepresentation.cpp:77
SurgSim::Framework::LockedContainer
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
SurgSim::Graphics::OsgMeshRepresentation::m_updateCount
size_t m_updateCount
Cache for the update count pull from the mesh.
Definition: OsgMeshRepresentation.h:134
SurgSim::Graphics::OsgMeshRepresentation::m_updateOptions
int m_updateOptions
Indicates which elements of the mesh should be updated on every frame.
Definition: OsgMeshRepresentation.h:88
SurgSim::Graphics::Mesh
Definition: Mesh.h:57
SurgSim::Graphics::OsgMeshRepresentation::updateTriangles
void updateTriangles(const Mesh &mesh, osg::Geometry *geometry)
Updates the triangles.
Definition: OsgMeshRepresentation.cpp:199
SurgSim::Graphics::OsgMeshRepresentation::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMeshRepresentation)
SurgSim::Graphics::OsgMeshRepresentation::m_filename
std::string m_filename
File name of the external file which contains the mesh to be used by this class.
Definition: OsgMeshRepresentation.h:94
SurgSim::Graphics::OsgMeshRepresentation::buildGeometry
void buildGeometry()
Create the appropriate geometry nodes.
Definition: OsgMeshRepresentation.cpp:309
SurgSim::Graphics::OsgMeshRepresentation::doUpdate
void doUpdate(double dt) override
Definition: OsgMeshRepresentation.cpp:91
SurgSim::Graphics::OsgMeshRepresentation::OsgMeshRepresentation
OsgMeshRepresentation(const std::string &name)
Constructor.
Definition: OsgMeshRepresentation.cpp:43
SurgSim::Graphics::OsgMeshRepresentation::~OsgMeshRepresentation
~OsgMeshRepresentation()
Destructor.
Definition: OsgMeshRepresentation.cpp:56
OsgRepresentation.h
SurgSim::Graphics::OsgMeshRepresentation::updateNormals
void updateNormals(osg::Geometry *geometry)
Updates the normals.
Definition: OsgMeshRepresentation.cpp:188
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
SurgSim::Graphics::MeshRepresentation
Graphics representation of a mesh, can be initialized from a Mesh structure.
Definition: MeshRepresentation.h:34