Gazebo Msgs

API Reference

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