opensurgsim
MathConvert.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_MATH_MATHCONVERT_H
17 #define SURGSIM_MATH_MATHCONVERT_H
18 
19 #include <Eigen/Core>
20 #include <Eigen/Geometry>
21 
22 #include <yaml-cpp/yaml.h>
23 #include <boost/any.hpp>
24 
25 #include "SurgSim/Framework/Macros.h"
26 #include "SurgSim/Math/LinearSparseSolveAndInverse.h"
27 #include "SurgSim/Math/OdeSolver.h"
28 
29 namespace SurgSim
30 {
31 namespace Math
32 {
33 class Shape;
34 
36 void toBytes(double d, std::vector<uint8_t>* result);
37 
39 size_t fromBytes(const std::vector<uint8_t>& bytes, double* out, size_t start = 0);
40 
44 void toBytes(SurgSim::Math::Vector3d in, std::vector<uint8_t>* result);
45 
47 size_t fromBytes(const std::vector<uint8_t>& bytes, SurgSim::Math::Vector3d* out, size_t start = 0);
48 }
49 }
50 
58 
59 namespace YAML
60 {
61 
63 SURGSIM_DOUBLE_SPECIALIZATION
64 template <typename Type, int Rows, int Cols, int MOpt>
65 struct convert<typename Eigen::Matrix<Type, Rows, Cols, MOpt>>
66 {
67  static Node encode(const typename Eigen::Matrix<Type, Rows, Cols, MOpt>& rhs);
68  static bool decode(const Node& node, typename Eigen::Matrix<Type, Rows, Cols, MOpt>& rhs); //NOLINT
69 };
70 
72 SURGSIM_DOUBLE_SPECIALIZATION
73 template <class Type, int QOpt>
74 struct convert<typename Eigen::Quaternion<Type, QOpt>>
75 {
76  static Node encode(const typename Eigen::Quaternion<Type, QOpt>& rhs);
77  static bool decode(const Node& node, typename Eigen::Quaternion<Type, QOpt>& rhs); //NOLINT
78 };
79 
81 SURGSIM_DOUBLE_SPECIALIZATION
82 template <class Type, int Dim, int TMode, int TOptions>
83 struct convert<typename Eigen::Transform<Type, Dim, TMode, TOptions>>
84 {
85  static Node encode(const typename Eigen::Transform<Type, Dim, TMode, TOptions>& rhs);
86  static bool decode(const Node& node, typename Eigen::Transform<Type, Dim, TMode, TOptions>& rhs); //NOLINT
87 };
88 
90 SURGSIM_DOUBLE_SPECIALIZATION
91 template <typename Type>
92 struct convert<typename Eigen::AngleAxis<Type>>
93 {
94  static Node encode(const typename Eigen::AngleAxis<Type>& rhs);
95  static bool decode(const Node& node, typename Eigen::AngleAxis<Type>& rhs); //NOLINT
96 };
97 
98 template <>
99 struct convert<std::shared_ptr<SurgSim::Math::Shape>>
100 {
101  static Node encode(const std::shared_ptr<SurgSim::Math::Shape>& rhs);
102  static bool decode(const Node& node, std::shared_ptr<SurgSim::Math::Shape>& rhs); //NOLINT
103 };
104 
105 template <>
106 struct convert<SurgSim::Math::IntegrationScheme>
107 {
108  static Node encode(const SurgSim::Math::IntegrationScheme& rhs);
109  static bool decode(const Node& node, SurgSim::Math::IntegrationScheme& rhs); //NOLINT
110 };
111 
112 template <>
113 struct convert<SurgSim::Math::LinearSolver>
114 {
115  static Node encode(const SurgSim::Math::LinearSolver& rhs);
116  static bool decode(const Node& node, SurgSim::Math::LinearSolver& rhs); //NOLINT
117 };
118 
119 template<class T>
120 bool tryConvert(const boost::any& any, YAML::Node* node);
121 
122 template <>
123 struct convert<boost::any>
124 {
125  static Node encode(const boost::any rhs);
126 };
127 
128 
129 };
130 
131 #include "SurgSim/Math/MathConvert-inl.h"
132 
133 #endif // SURGSIM_MATH_MATHCONVERT_H
Wraps glewInit() to separate the glew opengl definitions from the osg opengl definitions only imgui n...
Definition: AddRandomSphereBehavior.cpp:36
Definition: ApplicationData.h:23
Definition: Aabb.h:118
Definition: MockObjects.h:47
Eigen::Matrix< double, 3, 1 > Vector3d
A 3D vector of doubles.
Definition: Vector.h:57
Definition: DataStructuresConvert.h:28