Gazebo Msgs

API Reference

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