Apollo  6.0
Open source self driving car software
evaluator.h
Go to the documentation of this file.
1 /******************************************************************************
2  * Copyright 2017 The Apollo Authors. All Rights Reserved.
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 
22 #pragma once
23 
24 #include <string>
25 #include <utility>
26 #include <vector>
27 
29 
31 
36 namespace apollo {
37 namespace prediction {
38 
39 class Evaluator {
40  public:
44  Evaluator() = default;
45 
49  virtual ~Evaluator() = default;
50 
51  // TODO(all): Need to merge the following two functions into a single one.
52  // Can try using proto to pass static/dynamic env info.
53 
59  virtual bool Evaluate(Obstacle* obstacle,
60  ObstaclesContainer* obstacles_container) = 0;
61 
68  virtual bool Evaluate(Obstacle* obstacle,
69  ObstaclesContainer* obstacles_container,
70  std::vector<Obstacle*> dynamic_env) {
71  return Evaluate(obstacle, obstacles_container);
72  }
73 
77  virtual std::string GetName() = 0;
78 
79  protected:
80  // Helper function to convert world coordinates to relative coordinates
81  // around the obstacle of interest.
82  std::pair<double, double> WorldCoordToObjCoord(
83  std::pair<double, double> input_world_coord,
84  std::pair<double, double> obj_world_coord, double obj_world_angle) {
85  double x_diff = input_world_coord.first - obj_world_coord.first;
86  double y_diff = input_world_coord.second - obj_world_coord.second;
87  double rho = std::sqrt(x_diff * x_diff + y_diff * y_diff);
88  double theta = std::atan2(y_diff, x_diff) - obj_world_angle;
89 
90  return std::make_pair(std::cos(theta) * rho, std::sin(theta) * rho);
91  }
92 
93  double WorldAngleToObjAngle(double input_world_angle,
94  double obj_world_angle) {
95  return common::math::NormalizeAngle(input_world_angle - obj_world_angle);
96  }
97 
98  Eigen::MatrixXf VectorToMatrixXf(const std::vector<double>& nums,
99  const int start_index, const int end_index) {
100  CHECK_LT(start_index, end_index);
101  CHECK_GE(start_index, 0);
102  CHECK_LE(end_index, static_cast<int>(nums.size()));
103  Eigen::MatrixXf output_matrix;
104  output_matrix.resize(1, end_index - start_index);
105  for (int i = start_index; i < end_index; ++i) {
106  output_matrix(0, i - start_index) = static_cast<float>(nums[i]);
107  }
108  return output_matrix;
109  }
110 
111  Eigen::MatrixXf VectorToMatrixXf(const std::vector<double>& nums,
112  const int start_index, const int end_index,
113  const int output_num_row,
114  const int output_num_col) {
115  CHECK_LT(start_index, end_index);
116  CHECK_GE(start_index, 0);
117  CHECK_LE(end_index, static_cast<int>(nums.size()));
118  CHECK_EQ(end_index - start_index, output_num_row * output_num_col);
119  Eigen::MatrixXf output_matrix;
120  output_matrix.resize(output_num_row, output_num_col);
121  int input_index = start_index;
122  for (int i = 0; i < output_num_row; ++i) {
123  for (int j = 0; j < output_num_col; ++j) {
124  output_matrix(i, j) = static_cast<float>(nums[input_index]);
125  ++input_index;
126  }
127  }
128  CHECK_EQ(input_index, end_index);
129  return output_matrix;
130  }
131 
132  protected:
133  ObstacleConf::EvaluatorType evaluator_type_;
134 };
135 
136 } // namespace prediction
137 } // namespace apollo
float sin(Angle16 a)
Prediction obstacle.
Definition: obstacle.h:52
ObstacleConf::EvaluatorType evaluator_type_
Definition: evaluator.h:133
Definition: obstacles_container.h:39
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
Obstacle.
double NormalizeAngle(const double angle)
Normalize angle to [-PI, PI).
Eigen::MatrixXf VectorToMatrixXf(const std::vector< double > &nums, const int start_index, const int end_index, const int output_num_row, const int output_num_col)
Definition: evaluator.h:111
Evaluator()=default
Constructor.
virtual std::string GetName()=0
Get the name of evaluator.
virtual bool Evaluate(Obstacle *obstacle, ObstaclesContainer *obstacles_container)=0
Evaluate an obstacle.
virtual ~Evaluator()=default
Destructor.
double WorldAngleToObjAngle(double input_world_angle, double obj_world_angle)
Definition: evaluator.h:93
float cos(Angle16 a)
virtual bool Evaluate(Obstacle *obstacle, ObstaclesContainer *obstacles_container, std::vector< Obstacle *> dynamic_env)
Evaluate an obstacle.
Definition: evaluator.h:68
Eigen::MatrixXf VectorToMatrixXf(const std::vector< double > &nums, const int start_index, const int end_index)
Definition: evaluator.h:98
Obstacles container.
Definition: evaluator.h:39
std::pair< double, double > WorldCoordToObjCoord(std::pair< double, double > input_world_coord, std::pair< double, double > obj_world_coord, double obj_world_angle)
Definition: evaluator.h:82