Skip to content

Commit d6b7e48

Browse files
azeeymergify[bot]
authored andcommitted
Add EntitySemantics system that enables setting categories and tags (#3005)
System for assigning semantics to entities, such as models, by classifying them into categories and assigning them tags. --------- Signed-off-by: Addisu Z. Taddese <[email protected]> Co-authored-by: Ian Chen <[email protected]> (cherry picked from commit a503633) # Conflicts: # BUILD.bazel
1 parent 071dec4 commit d6b7e48

File tree

11 files changed

+2760
-0
lines changed

11 files changed

+2760
-0
lines changed

BUILD.bazel

Lines changed: 1850 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
/*
2+
* Copyright (C) 2025 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_COMPONENTS_SEMANTIC_CATEGORY_HH_
18+
#define GZ_SIM_COMPONENTS_SEMANTIC_CATEGORY_HH_
19+
20+
#include <cstdint>
21+
22+
#include "gz/sim/components/Component.hh"
23+
#include "gz/sim/components/Factory.hh"
24+
#include "gz/sim/config.hh"
25+
26+
namespace gz
27+
{
28+
namespace sim
29+
{
30+
// Inline bracket to help doxygen filtering.
31+
inline namespace GZ_SIM_VERSION_NAMESPACE {
32+
namespace components
33+
{
34+
/// \brief A component that holds the semantic category of an entity. This is
35+
/// meant to be used by systems such as EntitySemantics to assign categories to
36+
/// entities.
37+
/// See
38+
/// https://github.com/ros-simulation/simulation_interfaces/blob/1.0.0/msg/EntityCategory.msg
39+
using SemanticCategory = Component<uint8_t, class SemanticCategoryTag>;
40+
GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticCategory",
41+
SemanticCategory)
42+
} // namespace components
43+
} // namespace GZ_SIM_VERSION_NAMESPACE
44+
} // namespace sim
45+
} // namespace gz
46+
#endif
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/*
2+
* Copyright (C) 2025 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_COMPONENTS_SEMANTIC_DESCRIPTION_HH_
18+
#define GZ_SIM_COMPONENTS_SEMANTIC_DESCRIPTION_HH_
19+
20+
#include <gz/msgs/stringmsg.pb.h>
21+
22+
#include <istream>
23+
#include <ostream>
24+
#include <string>
25+
26+
#include "gz/sim/components/Component.hh"
27+
#include "gz/sim/components/Factory.hh"
28+
#include "gz/sim/components/Serialization.hh"
29+
#include "gz/sim/config.hh"
30+
31+
namespace gz
32+
{
33+
namespace sim
34+
{
35+
// Inline bracket to help doxygen filtering.
36+
inline namespace GZ_SIM_VERSION_NAMESPACE
37+
{
38+
namespace serializers
39+
{
40+
class SemanticDescriptionSerializer
41+
{
42+
public:
43+
static std::ostream &Serialize(std::ostream &_out, const std::string &_desc)
44+
{
45+
msgs::StringMsg msg;
46+
msg.set_data(_desc);
47+
msg.SerializeToOstream(&_out);
48+
return _out;
49+
}
50+
51+
public:
52+
static std::istream &Deserialize(std::istream &_in, std::string &_desc)
53+
{
54+
msgs::StringMsg msg;
55+
msg.ParsePartialFromIstream(&_in);
56+
_desc = msg.data();
57+
return _in;
58+
}
59+
};
60+
} // namespace serializers
61+
namespace components
62+
{
63+
/// \brief A component that holds the semantic description of an entity. This is
64+
/// meant to be used by systems such as EntitySemantics to assign descriptions
65+
/// to entities. See
66+
/// https://github.com/ros-simulation/simulation_interfaces/blob/1.0.0/msg/EntityInfo.msg
67+
using SemanticDescription = Component<std::string, class SemanticDescriptionTag,
68+
serializers::StringSerializer>;
69+
GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticDescription",
70+
SemanticDescription)
71+
} // namespace components
72+
} // namespace GZ_SIM_VERSION_NAMESPACE
73+
} // namespace sim
74+
} // namespace gz
75+
#endif
Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
/*
2+
* Copyright (C) 2025 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_COMPONENTS_SEMANTIC_TAGS_HH_
18+
#define GZ_SIM_COMPONENTS_SEMANTIC_TAGS_HH_
19+
20+
#include <gz/msgs/stringmsg_v.pb.h>
21+
22+
#include <istream>
23+
#include <ostream>
24+
#include <string>
25+
#include <vector>
26+
27+
#include "gz/sim/components/Component.hh"
28+
#include "gz/sim/components/Factory.hh"
29+
#include "gz/sim/config.hh"
30+
31+
namespace gz
32+
{
33+
namespace sim
34+
{
35+
// Inline bracket to help doxygen filtering.
36+
inline namespace GZ_SIM_VERSION_NAMESPACE
37+
{
38+
namespace serializers
39+
{
40+
class SemanticTagsSerializer
41+
{
42+
public:
43+
static std::ostream &Serialize(std::ostream &_out,
44+
const std::vector<std::string> &_tags)
45+
{
46+
msgs::StringMsg_V msg;
47+
for (const auto &tag : _tags)
48+
{
49+
msg.add_data(tag);
50+
}
51+
msg.SerializeToOstream(&_out);
52+
return _out;
53+
}
54+
55+
public:
56+
static std::istream &Deserialize(std::istream &_in,
57+
std::vector<std::string> &_tags)
58+
{
59+
msgs::StringMsg_V msg;
60+
msg.ParsePartialFromIstream(&_in);
61+
_tags.clear();
62+
for (const auto &item : msg.data())
63+
{
64+
_tags.push_back(item);
65+
}
66+
return _in;
67+
}
68+
};
69+
} // namespace serializers
70+
//
71+
namespace components
72+
{
73+
74+
/// \brief A component that holds the semantic tag of an entity. This is
75+
/// meant to be used by systems such as EntitySemantics to assign tags to
76+
/// entities. See
77+
/// https://github.com/ros-simulation/simulation_interfaces/blob/1.0.0/msg/TagsFilter.msg
78+
using SemanticTags = Component<std::vector<std::string>, class SemanticTagsTag,
79+
serializers::SemanticTagsSerializer>;
80+
GZ_SIM_REGISTER_COMPONENT("gz_sim_components.SemanticTags", SemanticTags)
81+
} // namespace components
82+
} // namespace GZ_SIM_VERSION_NAMESPACE
83+
} // namespace sim
84+
} // namespace gz
85+
#endif

src/systems/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ add_subdirectory(dvl)
117117
if (NOT WIN32)
118118
add_subdirectory(elevator)
119119
endif()
120+
add_subdirectory(entity_semantics)
120121
add_subdirectory(environment_preload)
121122
add_subdirectory(environmental_sensor_system)
122123
add_subdirectory(follow_actor)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
gz_add_system(entity-semantics
2+
SOURCES
3+
EntitySemantics.cc
4+
)

0 commit comments

Comments
 (0)