opensurgsim
OsgVectorFieldRepresentation.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_OSGVECTORFIELDREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGVECTORFIELDREPRESENTATION_H
18 
19 #include "SurgSim/Framework/LockedContainer.h"
20 #include "SurgSim/Graphics/OsgRepresentation.h"
21 #include "SurgSim/Graphics/VectorFieldRepresentation.h"
22 #include "SurgSim/Graphics/VectorField.h"
23 
24 #include <osg/Array>
25 #include <osg/Geometry>
26 #include <osg/LineWidth>
27 #include <osg/Point>
28 
29 namespace SurgSim
30 {
31 namespace Graphics
32 {
33 
34 SURGSIM_STATIC_REGISTRATION(OsgVectorFieldRepresentation);
35 
36 #if defined(_MSC_VER)
37 #pragma warning(push)
38 #pragma warning(disable:4250)
39 #endif
40 
43 {
44 public:
47  explicit OsgVectorFieldRepresentation(const std::string& name);
50 
52 
53  std::shared_ptr<VectorField> getVectorField() const override;
54 
55  void setLineWidth(double width) override;
56  double getLineWidth() const override;
57 
58  void setScale(double scale) override;
59  double getScale() const override;
60 
63  virtual void setPointSize(double size);
64 
67  virtual double getPointSize() const;
68 
69  void doUpdate(double dt) override;
70 
71  void updateVectorField(const VectorField& vectorfield) override;
72 
73 private:
74  void privateUpdate(const std::vector<DataStructures::Vertex<VectorFieldData>>& vertices);
75 
78  std::shared_ptr<SurgSim::Graphics::VectorField> m_vectorField;
79 
81 
83  osg::ref_ptr<osg::Vec3Array> m_vertexData;
84 
86  osg::ref_ptr<osg::Geometry> m_lineGeometry;
88  osg::ref_ptr<osg::Geometry> m_pointGeometry;
89 
91  osg::ref_ptr<osg::DrawArrays> m_drawArrays;
93  osg::ref_ptr<osg::DrawElementsUInt> m_drawPoints;
94 
96  osg::ref_ptr<osg::LineWidth> m_line;
98  osg::ref_ptr<osg::Point> m_point;
99 
101  osg::ref_ptr<osg::Vec4Array> m_colors;
102 
104  double m_scale;
105 };
106 
107 #if defined(_MSC_VER)
108 #pragma warning(pop)
109 #endif
110 
111 }; // Graphics
112 }; // SurgSim
113 
114 #endif // SURGSIM_GRAPHICS_OSGVECTORFIELDREPRESENTATION_H
double getScale() const override
Gets the scale applied to all vectors.
Definition: OsgVectorFieldRepresentation.cpp:184
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
OSG vector field representation, implements a VectorFieldRepresenation using OSG. ...
Definition: OsgVectorFieldRepresentation.h:42
virtual double getPointSize() const
Gets the size of starting point of a vector.
Definition: OsgVectorFieldRepresentation.cpp:194
Graphic representation of a vector field Each point/location, i.e.
Definition: VectorFieldRepresentation.h:30
void setLineWidth(double width) override
Sets vector line width.
Definition: OsgVectorFieldRepresentation.cpp:169
std::shared_ptr< VectorField > getVectorField() const override
Gets the vector field.
Definition: OsgVectorFieldRepresentation.cpp:164
Vertex structure for meshes.
Definition: Vertex.h:44
void setScale(double scale) override
Sets the scale to be applied to all vectors.
Definition: OsgVectorFieldRepresentation.cpp:179
virtual void setPointSize(double size)
Sets the size of point indicating the starting of vector.
Definition: OsgVectorFieldRepresentation.cpp:189
void updateVectorField(const VectorField &vectorfield) override
Updates the vector field in a threadsafe manner.
Definition: OsgVectorFieldRepresentation.cpp:159
A simple thread-safe data container that can support multiple writers and readers.
Definition: LockedContainer.h:54
OsgVectorFieldRepresentation(const std::string &name)
Constructor.
Definition: OsgVectorFieldRepresentation.cpp:36
~OsgVectorFieldRepresentation()
Destructor.
Definition: OsgVectorFieldRepresentation.cpp:78
double getLineWidth() const override
Gets line width.
Definition: OsgVectorFieldRepresentation.cpp:174
Base OSG implementation of a graphics representation.
Definition: OsgRepresentation.h:55
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:51