Gazebo Msgs

API Reference

11.0.1
GeometryType.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2023 Open Source Robotics Foundation
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 */
17#ifndef GZ_MSGS_CONVERT_GEOMETRYTYPE_HH_
18#define GZ_MSGS_CONVERT_GEOMETRYTYPE_HH_
19
20#include <gz/msgs/config.hh>
21
22// Message Headers
23#include "gz/msgs/geometry.pb.h"
24
25// Data Headers
26#include <string>
27
28namespace gz::msgs {
29// Inline bracket to help doxygen filtering.
30inline namespace GZ_MSGS_VERSION_NAMESPACE {
31
33inline msgs::Geometry::Type ConvertGeometryType(const std::string &_str)
34{
35 msgs::Geometry::Type result = msgs::Geometry::BOX;
36 if (_str == "box")
37 {
38 result = msgs::Geometry::BOX;
39 }
40 else if (_str == "capsule")
41 {
42 result = msgs::Geometry::CAPSULE;
43 }
44 else if (_str == "cone")
45 {
46 result = msgs::Geometry::CONE;
47 }
48 else if (_str == "cylinder")
49 {
50 result = msgs::Geometry::CYLINDER;
51 }
52 else if (_str == "ellipsoid")
53 {
54 result = msgs::Geometry::ELLIPSOID;
55 }
56 else if (_str == "sphere")
57 {
58 result = msgs::Geometry::SPHERE;
59 }
60 else if (_str == "plane")
61 {
62 result = msgs::Geometry::PLANE;
63 }
64 else if (_str == "image")
65 {
66 result = msgs::Geometry::IMAGE;
67 }
68 else if (_str == "heightmap")
69 {
70 result = msgs::Geometry::HEIGHTMAP;
71 }
72 else if (_str == "mesh")
73 {
74 result = msgs::Geometry::MESH;
75 }
76 else if (_str == "polyline")
77 {
78 result = msgs::Geometry::POLYLINE;
79 }
80 else
81 {
82 std::cerr << "Unrecognized Geometry::Type ["
83 << _str
84 << "], returning msgs::Geometry::BOX"
85 << std::endl;
86 }
87
88 return result;
89}
90
92inline std::string ConvertGeometryType(const msgs::Geometry::Type _type)
93{
94 std::string result;
95 switch (_type)
96 {
97 case msgs::Geometry::BOX:
98 {
99 result = "box";
100 break;
101 }
102 case msgs::Geometry::CAPSULE:
103 {
104 result = "capsule";
105 break;
106 }
107 case msgs::Geometry::CONE:
108 {
109 result = "cone";
110 break;
111 }
112 case msgs::Geometry::CYLINDER:
113 {
114 result = "cylinder";
115 break;
116 }
117 case msgs::Geometry::ELLIPSOID:
118 {
119 result = "ellipsoid";
120 break;
121 }
122 case msgs::Geometry::SPHERE:
123 {
124 result = "sphere";
125 break;
126 }
127 case msgs::Geometry::PLANE:
128 {
129 result = "plane";
130 break;
131 }
132 case msgs::Geometry::IMAGE:
133 {
134 result = "image";
135 break;
136 }
137 case msgs::Geometry::HEIGHTMAP:
138 {
139 result = "heightmap";
140 break;
141 }
142 case msgs::Geometry::MESH:
143 {
144 result = "mesh";
145 break;
146 }
147 case msgs::Geometry::POLYLINE:
148 {
149 result = "polyline";
150 break;
151 }
152 default:
153 {
154 result = "unknown";
155 std::cerr << "Unrecognized Geometry::Type ["
156 << _type
157 << "], returning 'unknown'"
158 << std::endl;
159 break;
160 }
161 }
162 return result;
163}
164} // namespce
165} // namespace gz::msgs
166
167#endif // GZ_MSGS_CONVERT_GEOMETRYTYPE_HH_