perception_interfaces 1.2.0
Loading...
Searching...
No Matches
utils.hpp
Go to the documentation of this file.
1// Copyright Institute for Automotive Engineering (ika), RWTH Aachen University
2// SPDX-License-Identifier: MIT
3
9#pragma once
10
11#include <cmath>
12
14
15
16namespace perception_msgs {
17
18namespace object_access {
19
20 // --- state size ------------------------------------------------------------
21
22 const std::string kExceptionUnknownModel = "Unknown model ID: ";
23
30 inline int getContinuousStateSize(const ObjectState& state) {
31 return state.continuous_state.size();
32 }
33
41 template <typename T>
42 inline int getContinuousStateSize(const T& obj) {
43 return getContinuousStateSize(obj.state);
44 }
45
52 inline int getContinuousStateSize(const unsigned char& model_id) {
53 switch(model_id) {
54 case EGO::MODEL_ID:
55 return EGO::CONTINUOUS_STATE_SIZE;
56 case EGORWS::MODEL_ID:
57 return EGORWS::CONTINUOUS_STATE_SIZE;
58 case ISCACTR::MODEL_ID:
59 return ISCACTR::CONTINUOUS_STATE_SIZE;
60 case HEXAMOTION::MODEL_ID:
61 return HEXAMOTION::CONTINUOUS_STATE_SIZE;
62 case TRAFFICLIGHT::MODEL_ID:
63 return TRAFFICLIGHT::CONTINUOUS_STATE_SIZE;
64 default:
65 throw std::invalid_argument(kExceptionUnknownModel + std::to_string(model_id));
66 }
67 }
68
75 inline int getDiscreteStateSize(const ObjectState& state) {
76 return state.discrete_state.size();
77 }
78
86 template <typename T>
87 inline int getDiscreteStateSize(const T& obj) {
88 return getDiscreteStateSize(obj.state);
89 }
90
97 inline int getDiscreteStateSize(const unsigned char& model_id) {
98 switch(model_id) {
99 case EGO::MODEL_ID:
100 return EGO::DISCRETE_STATE_SIZE;
101 case EGORWS::MODEL_ID:
102 return EGORWS::DISCRETE_STATE_SIZE;
103 case ISCACTR::MODEL_ID:
104 return ISCACTR::DISCRETE_STATE_SIZE;
105 case HEXAMOTION::MODEL_ID:
106 return HEXAMOTION::DISCRETE_STATE_SIZE;
107 case TRAFFICLIGHT::MODEL_ID:
108 return TRAFFICLIGHT::DISCRETE_STATE_SIZE;
109 default:
110 throw std::invalid_argument(kExceptionUnknownModel + std::to_string(model_id));
111 }
112 }
113
121 inline int getContinuousStateCovarianceSize(const ObjectState& state) {
122 if (!state.continuous_state_covariance.empty()) return state.continuous_state_covariance.size();
123 const int n = getContinuousStateSize(state.model_id);
124 return n * n;
125 }
126
134 template <typename T>
135 inline int getContinuousStateCovarianceSize(const T& obj) {
136 return getContinuousStateCovarianceSize(obj.state);
137 }
138
145 inline int getContinuousStateCovarianceSize(const unsigned char& model_id) {
146 return std::pow(getContinuousStateSize(model_id), 2);
147 }
148
157 inline void setContinuousStateCovarianceToUnknownAt(ObjectState& state, const unsigned int i, const unsigned int j) {
158 if (state.continuous_state_covariance.empty()) return;
159 const int n = getContinuousStateSize(state);
160 state.continuous_state_covariance.at(n * i + j) = CONTINUOUS_STATE_COVARIANCE_UNKNOWN;
161 }
162
163} // namespace object_access
164
165} // namespace perception_msgs
Object state constants.
int getDiscreteStateSize(const ObjectState &state)
Get the discrete state size for a given object state.
Definition utils.hpp:75
void setContinuousStateCovarianceToUnknownAt(ObjectState &state, const unsigned int i, const unsigned int j)
Set the continuous state covariance to unknown at (i,j) for a given object state. Empty storage remai...
Definition utils.hpp:157
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.
Definition utils.hpp:30
int getContinuousStateCovarianceSize(const ObjectState &state)
Get the continuous state covariance size for a given object state. Empty storage exposes the full mod...
Definition utils.hpp:121