OsgMeshRepresentation.h
Go to the documentation of this file.
// This file is a part of the OpenSurgSim project.
// Copyright 2013, SimQuest Solutions Inc.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
#ifndef SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
#define SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
#include <memory>
#include <osg/Array>
#include <osg/ref_ptr>
#include "SurgSim/Framework/Macros.h"
#include "SurgSim/Framework/ObjectFactory.h"
#include "SurgSim/Graphics/OsgRepresentation.h"
#include "SurgSim/Graphics/MeshRepresentation.h"
#include "SurgSim/Framework/LockedContainer.h"
#if defined(_MSC_VER)
#pragma warning(push)
#pragma warning(disable:4250)
#endif
namespace osg
{
class Geode;
class Geometry;
class DrawElementsUInt;
}
namespace SurgSim
{
namespace Graphics
{
class Mesh;
SURGSIM_STATIC_REGISTRATION(OsgMeshRepresentation);
class OsgMeshRepresentation : public OsgRepresentation, public MeshRepresentation
{
public:
explicit OsgMeshRepresentation(const std::string& name);
~OsgMeshRepresentation();
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgMeshRepresentation);
std::shared_ptr<Mesh> getMesh() override;
void setMesh(std::shared_ptr<SurgSim::Framework::Asset> mesh) override;
void loadMesh(const std::string& fileName) override;
void setShape(std::shared_ptr<SurgSim::Math::Shape> shape) override;
void setUpdateOptions(int val) override;
int getUpdateOptions() const override;
osg::ref_ptr<osg::Geometry> getOsgGeometry() const;
void updateMesh(const SurgSim::Graphics::Mesh& mesh) override;
protected:
void doUpdate(double dt) override;
bool doInitialize() override;
void privateUpdateMesh(const SurgSim::Graphics::Mesh& mesh);
private:
int m_updateOptions;
std::shared_ptr<Mesh> m_mesh;
std::string m_filename;
osg::ref_ptr<osg::Switch> m_meshSwitch;
osg::ref_ptr<osg::Geometry> m_geometry;
int updateOsgArrays(const Mesh& mesh, osg::Geometry* geometry);
void updateVertices(const Mesh& mesh, osg::Geometry* geometry, int updateOptions);
void updateNormals(osg::Geometry* geometry);
void updateTriangles(const Mesh& mesh, osg::Geometry* geometry);
osg::Object::DataVariance getDataVariance(int updateOption);
void buildGeometry();
size_t m_updateCount;
Framework::LockedContainer<Mesh> m_writeBuffer;
};
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
}; // Graphics
}; // SurgSim
#endif // SURGSIM_GRAPHICS_OSGMESHREPRESENTATION_H
SurgSim
Definition: CompoundShapeToGraphics.cpp:29
SurgSim::Graphics::OsgMeshRepresentation
Implementation of a MeshRepresentation for rendering under osg.
Definition: OsgMeshRepresentation.h:51
SurgSim::Graphics::MeshRepresentation
Graphics representation of a mesh, can be initialized from a Mesh structure.
Definition: MeshRepresentation.h:34
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
ObjectFactory.h
LockedContainer.h
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_CLASSNAME
#define SURGSIM_CLASSNAME(ClassName)
Declare the class name of a class with the appropriate function header, do not use quotes...
Definition: Macros.h:21
SurgSim::Graphics::OsgMeshRepresentation::m_mesh
std::shared_ptr< Mesh > m_mesh
The mesh.
Definition: OsgMeshRepresentation.h:91
SurgSim::Graphics::OsgMeshRepresentation::m_meshSwitch
osg::ref_ptr< osg::Switch > m_meshSwitch
Definition: OsgMeshRepresentation.h:98
MeshRepresentation.h
Macros.h
SurgSim::Graphics::OsgMeshRepresentation::m_geometry
osg::ref_ptr< osg::Geometry > m_geometry
Definition: OsgMeshRepresentation.h:99
SurgSim::Graphics::OsgMeshRepresentation::m_writeBuffer
Framework::LockedContainer< Mesh > m_writeBuffer
Definition: OsgMeshRepresentation.h:136
SurgSim::Framework::LockedContainer
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
osg
Definition: OculusView.h:25
OsgRepresentation.h
SurgSim::Graphics::OsgRepresentation
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55