OsgCurveRepresentation.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_OSGCURVEREPRESENTATION_H
17 #define SURGSIM_GRAPHICS_OSGCURVEREPRESENTATION_H
18 
21 
22 #include <osg/Array>
23 #include <osg/ref_ptr>
24 
25 #if defined(_MSC_VER)
26 #pragma warning(push)
27 #pragma warning(disable:4250)
28 #endif
29 
30 namespace osg
31 {
32 class Geometry;
33 class DrawArrays;
34 }
35 
36 namespace SurgSim
37 {
38 
39 namespace Graphics
40 {
41 
42 SURGSIM_STATIC_REGISTRATION(OsgCurveRepresentation)
43 
44 class OsgCurveRepresentation : public OsgRepresentation, public CurveRepresentation
48 {
49 public:
52  explicit OsgCurveRepresentation(const std::string& name);
53 
55 
57 
58  bool doInitialize() override;
59 
60  bool doWakeUp() override;
61 
62  void doUpdate(double dt) override;
63 
64  void setSubdivisions(size_t num) override;
65 
66  size_t getSubdivisions() const override;
67 
68  void setTension(double tension) override;
69 
70  double getTension() const override;
71 
72  void setColor(const SurgSim::Math::Vector4d& color) override;
73 
74  Math::Vector4d getColor() const override;
75 
76  void setWidth(double width) override;
77 
78  double getWidth() const override;
79 
80  void setAntiAliasing(bool val) override;
81 
82  bool isAntiAliasing() const override;
83 
84 private:
85 
88  void updateGraphics(const DataStructures::VerticesPlain& controlPoints);
89 
92  osg::ref_ptr<osg::Geometry> m_geometry;
93  osg::ref_ptr<osg::Vec3Array> m_vertexData;
94  osg::ref_ptr<osg::Vec3Array> m_normalData;
95  osg::ref_ptr<osg::DrawArrays> m_drawArrays;
97 
102  double m_tension;
103  double m_width;
105 
108  std::vector<Math::Vector3d> m_controlPoints;
109  std::vector<Math::Vector3d> m_vertices;
111 
112 };
113 
114 #if defined(_MSC_VER)
115 #pragma warning(pop)
116 #endif
117 
118 }
119 }
120 
121 #endif
SurgSim::Graphics::OsgCurveRepresentation::setColor
void setColor(const SurgSim::Math::Vector4d &color) override
Sets the color for the curve.
Definition: OsgCurveRepresentation.cpp:193
CurveRepresentation.h
SurgSim::Graphics::OsgCurveRepresentation::setAntiAliasing
void setAntiAliasing(bool val) override
Sets up whether to use anti aliasing on the curve or not.
Definition: OsgCurveRepresentation.cpp:173
SurgSim::Graphics::OsgCurveRepresentation::m_normalData
osg::ref_ptr< osg::Vec3Array > m_normalData
Definition: OsgCurveRepresentation.h:94
SurgSim::Graphics::OsgCurveRepresentation::doWakeUp
bool doWakeUp() override
Interface to be implemented by derived classes.
Definition: OsgCurveRepresentation.cpp:80
SurgSim::DataStructures::Vertices
Base class for mesh structures, handling basic vertex functionality.
Definition: Vertices.h:52
SurgSim::Graphics::OsgCurveRepresentation::m_geometry
osg::ref_ptr< osg::Geometry > m_geometry
Definition: OsgCurveRepresentation.h:92
SurgSim::Graphics::OsgCurveRepresentation::doInitialize
bool doInitialize() override
Interface to be implemented by derived classes.
Definition: OsgCurveRepresentation.cpp:75
SurgSim::Graphics::OsgCurveRepresentation::m_width
double m_width
Definition: OsgCurveRepresentation.h:103
SurgSim::Graphics::OsgCurveRepresentation::setWidth
void setWidth(double width) override
Sets the line width to be used for drawing this curve.
Definition: OsgCurveRepresentation.cpp:161
SurgSim::Graphics::OsgCurveRepresentation::m_subdivision
size_t m_subdivision
Definition: OsgCurveRepresentation.h:101
osg
Definition: OculusView.h:26
SurgSim::Graphics::OsgCurveRepresentation::SURGSIM_CLASSNAME
SURGSIM_CLASSNAME(SurgSim::Graphics::OsgCurveRepresentation)
SurgSim::Graphics::OsgCurveRepresentation::m_controlPoints
std::vector< Math::Vector3d > m_controlPoints
Definition: OsgCurveRepresentation.h:108
SurgSim::Graphics::OsgCurveRepresentation::doUpdate
void doUpdate(double dt) override
Definition: OsgCurveRepresentation.cpp:85
SurgSim
Definition: CompoundShapeToGraphics.cpp:30
SurgSim::Graphics::OsgCurveRepresentation::~OsgCurveRepresentation
~OsgCurveRepresentation()
Definition: OsgCurveRepresentation.cpp:71
SurgSim::Graphics::OsgCurveRepresentation::setSubdivisions
void setSubdivisions(size_t num) override
Sets the number of intermediate points the get generated between each two control points.
Definition: OsgCurveRepresentation.cpp:94
SurgSim::Graphics::OsgCurveRepresentation::m_vertices
std::vector< Math::Vector3d > m_vertices
Definition: OsgCurveRepresentation.h:109
SurgSim::Graphics::OsgCurveRepresentation::setTension
void setTension(double tension) override
Sets the tension (tau) parameter of the Catmull Rom interpolation, needs to be between 0....
Definition: OsgCurveRepresentation.cpp:104
SurgSim::Math::Vector4d
Eigen::Matrix< double, 4, 1 > Vector4d
A 4D vector of doubles.
Definition: Vector.h:61
SurgSim::Graphics::OsgCurveRepresentation::getTension
double getTension() const override
Definition: OsgCurveRepresentation.cpp:109
SurgSim::Graphics::OsgCurveRepresentation::getSubdivisions
size_t getSubdivisions() const override
Definition: OsgCurveRepresentation.cpp:99
SurgSim::Graphics::OsgCurveRepresentation::OsgCurveRepresentation
OsgCurveRepresentation(const std::string &name)
Constructor.
Definition: OsgCurveRepresentation.cpp:39
SurgSim::Graphics::OsgCurveRepresentation
Implements the CurveRepresentation for OpenSceneGraph, it uses Catmull Rom interpolation,...
Definition: OsgCurveRepresentation.h:48
SurgSim::Graphics::OsgCurveRepresentation::m_drawArrays
osg::ref_ptr< osg::DrawArrays > m_drawArrays
Definition: OsgCurveRepresentation.h:95
SurgSim::Graphics::OsgCurveRepresentation::m_color
Math::Vector4d m_color
Definition: OsgCurveRepresentation.h:100
SurgSim::Graphics::OsgCurveRepresentation::m_tension
double m_tension
Definition: OsgCurveRepresentation.h:102
SurgSim::Graphics::OsgCurveRepresentation::getWidth
double getWidth() const override
Definition: OsgCurveRepresentation.cpp:168
SurgSim::Graphics::OsgCurveRepresentation::getColor
Math::Vector4d getColor() const override
Definition: OsgCurveRepresentation.cpp:206
string
string(TOUPPER ${DEVICE} DEVICE_UPPER_CASE) option(BUILD_DEVICE_$
Definition: CMakeLists.txt:38
SurgSim::Graphics::OsgCurveRepresentation::updateGraphics
void updateGraphics(const DataStructures::VerticesPlain &controlPoints)
Update the OSG structure with the information of the control points.
Definition: OsgCurveRepresentation.cpp:114
SurgSim::Graphics::OsgCurveRepresentation::isAntiAliasing
bool isAntiAliasing() const override
Definition: OsgCurveRepresentation.cpp:188
OsgRepresentation.h
SurgSim::Graphics::OsgCurveRepresentation::m_vertexData
osg::ref_ptr< osg::Vec3Array > m_vertexData
Definition: OsgCurveRepresentation.h:93