Ignition Gazebo

API Reference

5.0.0
CanonicalLinkModelTracker.hh
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2021 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 IGNITION_GAZEBO_SYSTEMS_PHYSICS_CANONICAL_LINK_MODEL_TRACKER_HH_
18 #define IGNITION_GAZEBO_SYSTEMS_PHYSICS_CANONICAL_LINK_MODEL_TRACKER_HH_
19 
20 #include <set>
21 #include <unordered_map>
22 
27 #include "ignition/gazebo/config.hh"
28 
29 namespace ignition::gazebo
30 {
31 inline namespace IGNITION_GAZEBO_VERSION_NAMESPACE {
32 namespace systems::physics_system
33 {
56  {
59  public: void AddNewModels(const EntityComponentManager &_ecm);
60 
66  public: const std::set<Entity> &CanonicalLinkModels(
67  const Entity _canonicalLink) const;
68 
72  public: void RemoveLink(const Entity &_link);
73 
78  private: std::unordered_map<Entity, std::set<Entity>> linkModelMap;
79 
82  private: const std::set<Entity> emptyModelOrdering{};
83  };
84 
85  void CanonicalLinkModelTracker::AddNewModels(
86  const EntityComponentManager &_ecm)
87  {
88  _ecm.EachNew<components::Model, components::ModelCanonicalLink>(
89  [this](const Entity &_model, const components::Model *,
90  const components::ModelCanonicalLink *_canonicalLinkComp)
91  {
92  this->linkModelMap[_canonicalLinkComp->Data()].insert(_model);
93  return true;
94  });
95  }
96 
97  const std::set<Entity> &CanonicalLinkModelTracker::CanonicalLinkModels(
98  const Entity _canonicalLink) const
99  {
100  auto it = this->linkModelMap.find(_canonicalLink);
101  if (it != this->linkModelMap.end())
102  return it->second;
103 
104  // if an invalid entity was given, it maps to no models
105  return this->emptyModelOrdering;
106  }
107 
108  void CanonicalLinkModelTracker::RemoveLink(const Entity &_link)
109  {
110  this->linkModelMap.erase(_link);
111  }
112 }
113 }
114 }
115 
116 #endif
Gazebo is a leading open source robotics simulator, that provides high fidelity physics, rendering, and sensor simulation.
Definition: Actor.hh:36
Helper class that keeps track of which models have a particular canonical link. This is useful in the...
Definition: CanonicalLinkModelTracker.hh:55
The EntityComponentManager constructs, deletes, and returns components and entities. A component can be of any class which inherits from components::BaseComponent.
Definition: EntityComponentManager.hh:65
Component< NoData, class ModelTag > Model
A component that identifies an entity as being a model.
Definition: components/Model.hh:35
T find(T... args)
void EachNew(typename identity< std::function< bool(const Entity &_entity, ComponentTypeTs *...)>>::type _f)
Get all newly created entities which contain given component types, as well as the components...
A component type that wraps any data type. The intention is for this class to be used to create simpl...
Definition: Component.hh:316
uint64_t Entity
An Entity identifies a single object in simulation such as a model, link, or light. At its core, an Entity is just an identifier.
Definition: Entity.hh:59