perception_interfaces 1.1.2
Loading...
Searching...
No Matches
utils.h
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
120 inline int getContinuousStateCovarianceSize(const ObjectState& state) {
121 return state.continuous_state_covariance.size();
122 }
123
131 template <typename T>
132 inline int getContinuousStateCovarianceSize(const T& obj) {
133 return getContinuousStateCovarianceSize(obj.state);
134 }
135
142 inline int getContinuousStateCovarianceSize(const unsigned char& model_id) {
143 return std::pow(getContinuousStateSize(model_id), 2);
144 }
145
153 inline void setContinuousStateCovarianceToUnknownAt(ObjectState& state, const unsigned int i, const unsigned int j) {
154 const int n = getContinuousStateSize(state);
155 state.continuous_state_covariance[n * i + j] = CONTINUOUS_STATE_COVARIANCE_UNKNOWN;
156 }
157
158} // namespace object_access
159
160} // namespace perception_msgs
Object state constants.
int getDiscreteStateSize(const ObjectState &state)
Get the discrete state size for a given object state.
Definition utils.h: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.
Definition utils.h:153
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.
Definition utils.h:30
int getContinuousStateCovarianceSize(const ObjectState &state)
Get the continuous state covariance size for a given object state.
Definition utils.h:120