Gazebo Sim

API Reference

10.1.1
Util.hh
Go to the documentation of this file.
1/*
2 * Copyright (C) 2019 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_SIM_UTIL_HH_
18#define GZ_SIM_UTIL_HH_
19
20#include <gz/msgs/entity.pb.h>
21
22#include <memory>
23#include <string>
24#include <unordered_set>
25#include <vector>
26
27#include <gz/common/Mesh.hh>
29#include <gz/math/Pose3.hh>
30#include <sdf/Mesh.hh>
31
33#include "gz/sim/config.hh"
34#include "gz/sim/Entity.hh"
36#include "gz/sim/Export.hh"
37#include "gz/sim/Types.hh"
38
39
40namespace gz
41{
42 namespace sim
43 {
44 // Inline bracket to help doxygen filtering.
45 inline namespace GZ_SIM_VERSION_NAMESPACE {
46 //
51 math::Pose3d GZ_SIM_VISIBLE worldPose(const Entity &_entity,
52 const EntityComponentManager &_ecm);
53
58 math::Vector3d GZ_SIM_VISIBLE relativeVel(const Entity &_entity,
59 const EntityComponentManager &_ecm);
60
67 std::string GZ_SIM_VISIBLE scopedName(const Entity &_entity,
68 const EntityComponentManager &_ecm, const std::string &_delim = "/",
69 bool _includePrefix = true);
70
95 const std::string &_scopedName, const EntityComponentManager &_ecm,
96 Entity _relativeTo = kNullEntity,
97 const std::string &_delim = "::");
98
119 ComponentTypeId GZ_SIM_VISIBLE entityTypeId(const Entity &_entity,
120 const EntityComponentManager &_ecm);
121
139 std::string GZ_SIM_VISIBLE entityTypeStr(const Entity &_entity,
140 const EntityComponentManager &_ecm);
141
146 Entity GZ_SIM_VISIBLE worldEntity(const Entity &_entity,
147 const EntityComponentManager &_ecm);
148
152 Entity GZ_SIM_VISIBLE worldEntity(
153 const EntityComponentManager &_ecm);
154
161 const std::string &_name, const std::string &_delim);
162
168 const std::string &_name);
169
175 const std::string &_filename);
176
185 std::string GZ_SIM_VISIBLE asFullPath(const std::string &_uri,
186 const std::string &_filePath);
187
191
196 void GZ_SIM_VISIBLE addResourcePaths(
197 const std::vector<std::string> &_paths = {});
198
205 const Entity &_entity,
206 const EntityComponentManager &_ecm);
207
220 std::string GZ_SIM_VISIBLE validTopic(
221 const std::vector<std::string> &_topics);
222
239 const Entity &_entity,
240 const EntityComponentManager &_ecm,
241 bool _excludeWorld = true);
242
259 const std::string &_sdfFilename,
260 const std::string &_fuelResourceCache = "");
261
272 template <class ComponentType>
274 Entity _entity,
275 bool _enable = true,
276 const ComponentType &_comp = ComponentType())
277 {
278 bool changed{false};
279
280 auto exists = _ecm.Component<ComponentType>(_entity);
281 if (_enable && !exists)
282 {
283 _ecm.CreateComponent(_entity, _comp);
284 changed = true;
285 }
286 else if (!_enable && exists)
287 {
288 _ecm.RemoveComponent<ComponentType>(_entity);
289 changed = true;
290 }
291 return changed;
292 }
293
311 Entity GZ_SIM_VISIBLE entityFromMsg(
312 const EntityComponentManager &_ecm, const msgs::Entity &_msg);
313
320 std::optional<math::Vector3d> GZ_SIM_VISIBLE sphericalCoordinates(
321 Entity _entity, const EntityComponentManager &_ecm);
322
328 std::optional<math::Vector3d> GZ_SIM_VISIBLE getGridFieldCoordinates(
329 const EntityComponentManager &_ecm,
330 const math::Vector3d& _worldPosition,
332
336 GZ_SIM_VISIBLE const common::Mesh *loadMesh(const sdf::Mesh &_meshSdf);
337
342 GZ_SIM_VISIBLE const common::Mesh *optimizeMesh(const sdf::Mesh &_meshSdf,
343 const common::Mesh &_mesh);
344
350 const math::AxisAlignedBox & _aabb,
351 const math::Pose3d & _pose);
352
356 GZ_SIM_VISIBLE std::optional<math::AxisAlignedBox> meshAxisAlignedBox(
357 const sdf::Mesh &_sdfMesh);
358
361 GZ_SIM_VISIBLE const std::string &staticPluginPrefixStr();
362
366 GZ_SIM_VISIBLE bool isStaticPlugin(const std::string &_filename);
367
369 const std::string kResourcePathEnv{"GZ_SIM_RESOURCE_PATH"};
370
373 const std::string kSdfPathEnv{"SDF_PATH"};
374
376 const std::string kServerConfigPathEnv{"GZ_SIM_SERVER_CONFIG_PATH"};
377
380 const std::string kRenderPluginPathEnv{"GZ_SIM_RENDER_ENGINE_PATH"};
381
384 }
385 }
386}
387#endif