$darkmode
object.hpp
Go to the documentation of this file.
1 /*
2  * Copyright 2020 Robert Bosch GmbH
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  * SPDX-License-Identifier: Apache-2.0
17  */
22 #pragma once
23 
24 #include <memory> // for shared_ptr<>
25 #include <vector> // for vector<>
26 
27 #include <Eigen/Geometry> // for Isometry3d, Vector3d
28 #include <fable/enum.hpp> // for ENUM_SERIALIZATION
29 #include <fable/json.hpp> // for Json
30 #include <fable/utility/eigen.hpp> // for to_json
31 
32 namespace cloe {
33 
49 struct Object {
50  enum class Type { Unknown, Static, Dynamic };
51 
52  enum class Class { Unknown, Pedestrian, Bike, Motorbike, Car, Truck, Trailer };
53 
55  int id{-1};
56 
58  double exist_prob{1.0};
59 
61  Type type{Type::Unknown};
62 
64  Class classification{Class::Unknown};
65 
67  Eigen::Isometry3d pose{Eigen::Isometry3d()};
68 
70  Eigen::Vector3d dimensions{Eigen::Vector3d::Zero()};
71 
73  Eigen::Vector3d cog_offset{Eigen::Vector3d::Zero()};
74 
76  Eigen::Vector3d velocity{Eigen::Vector3d::Zero()};
77 
79  Eigen::Vector3d acceleration{Eigen::Vector3d::Zero()};
80 
82  Eigen::Vector3d angular_velocity{Eigen::Vector3d::Zero()};
83 
84  Object() = default;
85 
86  friend void to_json(fable::Json& j, const Object& o) {
87  j = fable::Json{
88  {"id", o.id},
89  {"exist_prob", o.exist_prob},
90  {"type", o.type},
91  {"class", o.classification},
92  {"pose", o.pose},
93  {"dimensions", o.dimensions},
94  {"cog_offset", o.cog_offset},
95  {"velocity", o.velocity},
96  {"velocity_norm", static_cast<double>(o.velocity.norm())},
97  {"acceleration", o.acceleration},
98  {"angular_velocity", o.angular_velocity},
99  };
100  }
101 };
102 
109 using Objects = std::vector<std::shared_ptr<Object>>;
110 
111 inline void to_json(fable::Json& j, const Objects& os) {
112  j = fable::Json::array();
113  for (const auto& o : os) {
114  assert(o != nullptr);
115  j.push_back(*o);
116  }
117 }
118 
119 // clang-format off
120 ENUM_SERIALIZATION(Object::Type, ({
121  {Object::Type::Static, "static"},
122  {Object::Type::Dynamic, "dynamic"},
123  {Object::Type::Unknown, "unknown"},
124 }))
125 
126 ENUM_SERIALIZATION(Object::Class, ({
127  {Object::Class::Unknown, "unknown"},
128  {Object::Class::Pedestrian, "pedestrian"},
129  {Object::Class::Bike, "bicycle"},
130  {Object::Class::Motorbike, "motorcycle"},
131  {Object::Class::Car, "car"},
132  {Object::Class::Truck, "truck"},
133  {Object::Class::Trailer, "trailer"},
134 }))
135 // clang-format on
136 
137 } // namespace cloe
#define ENUM_SERIALIZATION(xType, xMap)
Definition: enum.hpp:51
nlohmann::json Json
Definition: fable_fwd.hpp:35
std::vector< std::shared_ptr< Object > > Objects
Definition: object.hpp:109
Definition: object.hpp:49
Eigen::Vector3d dimensions
Dimensions in [m].
Definition: object.hpp:70
Eigen::Vector3d acceleration
Absolute acceleration in [m/(s*s)].
Definition: object.hpp:79
double exist_prob
Object existence probability.
Definition: object.hpp:58
Type type
Type of object.
Definition: object.hpp:61
Eigen::Vector3d angular_velocity
Angular velocity in [rad/s].
Definition: object.hpp:82
Eigen::Vector3d cog_offset
Center of geometry offset in [m].
Definition: object.hpp:73
Class classification
Classification of object.
Definition: object.hpp:64
Eigen::Isometry3d pose
Pose in [m] and [rad].
Definition: object.hpp:67
int id
ID of object, should be unique.
Definition: object.hpp:55
Eigen::Vector3d velocity
Absolute velocity in [m/s].
Definition: object.hpp:76