Gazebo Sim

API Reference

8.14.0
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 <string_view>
25 #include <unordered_set>
26 #include <vector>
27 
28 #include <gz/common/Mesh.hh>
29 #include <gz/math/AxisAlignedBox.hh>
30 #include <gz/math/Pose3.hh>
31 #include <sdf/Mesh.hh>
32 
34 #include "gz/sim/config.hh"
35 #include "gz/sim/Entity.hh"
37 #include "gz/sim/Export.hh"
38 #include "gz/sim/Types.hh"
39 
40 
41 namespace gz
42 {
43  namespace sim
44  {
45  // Inline bracket to help doxygen filtering.
46  inline namespace GZ_SIM_VERSION_NAMESPACE {
47  //
52  math::Pose3d GZ_SIM_VISIBLE worldPose(const Entity &_entity,
53  const EntityComponentManager &_ecm);
54 
59  math::Vector3d GZ_SIM_VISIBLE relativeVel(const Entity &_entity,
60  const EntityComponentManager &_ecm);
61 
68  std::string GZ_SIM_VISIBLE scopedName(const Entity &_entity,
69  const EntityComponentManager &_ecm, const std::string &_delim = "/",
70  bool _includePrefix = true);
71 
96  const std::string &_scopedName, const EntityComponentManager &_ecm,
97  Entity _relativeTo = kNullEntity,
98  const std::string &_delim = "::");
99 
120  ComponentTypeId GZ_SIM_VISIBLE entityTypeId(const Entity &_entity,
121  const EntityComponentManager &_ecm);
122 
140  std::string_view GZ_SIM_VISIBLE entityTypeStrView(const Entity &_entity,
141  const EntityComponentManager &_ecm);
142 
161  std::string GZ_SIM_VISIBLE entityTypeStr(
162  const Entity &_entity,
163  const EntityComponentManager &_ecm);
164 
169  Entity GZ_SIM_VISIBLE worldEntity(const Entity &_entity,
170  const EntityComponentManager &_ecm);
171 
175  Entity GZ_SIM_VISIBLE worldEntity(
176  const EntityComponentManager &_ecm);
177 
184  const std::string &_name, const std::string &_delim);
185 
194  std::string GZ_SIM_VISIBLE asFullPath(const std::string &_uri,
195  const std::string &_filePath);
196 
200 
205  void GZ_SIM_VISIBLE addResourcePaths(
206  const std::vector<std::string> &_paths = {});
207 
214  const Entity &_entity,
215  const EntityComponentManager &_ecm);
216 
229  std::string GZ_SIM_VISIBLE validTopic(
230  const std::vector<std::string> &_topics);
231 
248  const Entity &_entity,
249  const EntityComponentManager &_ecm,
250  bool _excludeWorld = true);
251 
268  const std::string &_sdfFilename,
269  const std::string &_fuelResourceCache = "");
270 
281  template <class ComponentType>
283  Entity _entity,
284  bool _enable = true,
285  const ComponentType &_comp = ComponentType())
286  {
287  bool changed{false};
288 
289  auto exists = _ecm.Component<ComponentType>(_entity);
290  if (_enable && !exists)
291  {
292  _ecm.CreateComponent(_entity, _comp);
293  changed = true;
294  }
295  else if (!_enable && exists)
296  {
297  _ecm.RemoveComponent<ComponentType>(_entity);
298  changed = true;
299  }
300  return changed;
301  }
302 
320  Entity GZ_SIM_VISIBLE entityFromMsg(
321  const EntityComponentManager &_ecm, const msgs::Entity &_msg);
322 
329  std::optional<math::Vector3d> GZ_SIM_VISIBLE sphericalCoordinates(
330  Entity _entity, const EntityComponentManager &_ecm);
331 
337  std::optional<math::Vector3d> GZ_SIM_VISIBLE getGridFieldCoordinates(
338  const EntityComponentManager &_ecm,
339  const math::Vector3d& _worldPosition,
341 
345  GZ_SIM_VISIBLE const common::Mesh *loadMesh(const sdf::Mesh &_meshSdf);
346 
351  GZ_SIM_VISIBLE const common::Mesh *optimizeMesh(const sdf::Mesh &_meshSdf,
352  const common::Mesh &_mesh);
353 
359  const math::AxisAlignedBox & _aabb,
360  const math::Pose3d & _pose);
361 
365  GZ_SIM_VISIBLE std::optional<math::AxisAlignedBox> meshAxisAlignedBox(
366  const sdf::Mesh &_sdfMesh);
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  }
382  }
383 }
384 #endif