perception_interfaces 1.0.0
Loading...
Searching...
No Matches
utils.h
Go to the documentation of this file.
1
30#pragma once
31
32#include <cmath>
33
35
36
37namespace perception_msgs {
38
39namespace object_access {
40
41 // --- state size ------------------------------------------------------------
42
43 const std::string kExceptionUnknownModel = "Unknown model ID: ";
44
51 inline int getContinuousStateSize(const ObjectState& state) {
52 return state.continuous_state.size();
53 }
54
62 template <typename T>
63 inline int getContinuousStateSize(const T& obj) {
64 return getContinuousStateSize(obj.state);
65 }
66
73 inline int getContinuousStateSize(const unsigned char& model_id) {
74 switch(model_id) {
75 case EGO::MODEL_ID:
76 return EGO::CONTINUOUS_STATE_SIZE;
77 case EGORWS::MODEL_ID:
78 return EGORWS::CONTINUOUS_STATE_SIZE;
79 case ISCACTR::MODEL_ID:
80 return ISCACTR::CONTINUOUS_STATE_SIZE;
81 case HEXAMOTION::MODEL_ID:
82 return HEXAMOTION::CONTINUOUS_STATE_SIZE;
83 case TRAFFICLIGHT::MODEL_ID:
84 return TRAFFICLIGHT::CONTINUOUS_STATE_SIZE;
85 default:
86 throw std::invalid_argument(kExceptionUnknownModel + std::to_string(model_id));
87 }
88 }
89
96 inline int getDiscreteStateSize(const ObjectState& state) {
97 return state.discrete_state.size();
98 }
99
107 template <typename T>
108 inline int getDiscreteStateSize(const T& obj) {
109 return getDiscreteStateSize(obj.state);
110 }
111
118 inline int getDiscreteStateSize(const unsigned char& model_id) {
119 switch(model_id) {
120 case EGO::MODEL_ID:
121 return EGO::DISCRETE_STATE_SIZE;
122 case EGORWS::MODEL_ID:
123 return EGORWS::DISCRETE_STATE_SIZE;
124 case ISCACTR::MODEL_ID:
125 return ISCACTR::DISCRETE_STATE_SIZE;
126 case HEXAMOTION::MODEL_ID:
127 return HEXAMOTION::DISCRETE_STATE_SIZE;
128 case TRAFFICLIGHT::MODEL_ID:
129 return TRAFFICLIGHT::DISCRETE_STATE_SIZE;
130 default:
131 throw std::invalid_argument(kExceptionUnknownModel + std::to_string(model_id));
132 }
133 }
134
141 inline int getContinuousStateCovarianceSize(const ObjectState& state) {
142 return state.continuous_state_covariance.size();
143 }
144
152 template <typename T>
153 inline int getContinuousStateCovarianceSize(const T& obj) {
154 return getContinuousStateCovarianceSize(obj.state);
155 }
156
163 inline int getContinuousStateCovarianceSize(const unsigned char& model_id) {
164 return std::pow(getContinuousStateSize(model_id), 2);
165 }
166
174 inline void setContinuousStateCovarianceToUnknownAt(ObjectState& state, const unsigned int i, const unsigned int j) {
175 const int n = getContinuousStateSize(state);
176 state.continuous_state_covariance[n * i + j] = CONTINUOUS_STATE_COVARIANCE_UNKNOWN;
177 }
178
179} // namespace object_access
180
181} // namespace perception_msgs
Object state constants.
int getDiscreteStateSize(const ObjectState &state)
Get the discrete state size for a given object state.
Definition utils.h:96
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:174
int getContinuousStateSize(const ObjectState &state)
Get the continuous state size for a given object state.
Definition utils.h:51
int getContinuousStateCovarianceSize(const ObjectState &state)
Get the continuous state covariance size for a given object state.
Definition utils.h:141