Apollo  6.0
Open source self driving car software
interpolation_1d.h
Go to the documentation of this file.
1 /* Copyright 2017 The Apollo Authors. All Rights Reserved.
2 
3 Licensed under the Apache License, Version 2.0 (the "License");
4 you may not use this file except in compliance with the License.
5 You may obtain a copy of the License at
6 
7  http://www.apache.org/licenses/LICENSE-2.0
8 
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
14 ==============================================================================*/
15 
16 #pragma once
17 
18 #include <memory>
19 #include <utility>
20 #include <vector>
21 
22 #include "Eigen/Core"
23 #include "unsupported/Eigen/Splines"
24 
25 namespace apollo {
26 namespace control {
27 
29  public:
30  typedef std::vector<std::pair<double, double>> DataType;
31 
32  Interpolation1D() = default;
33 
34  // Return true if init is ok.
35  bool Init(const DataType& xy);
36 
37  // Only interpolate x between [x_min, x_max]
38  // For x out of range, start or end y value is returned.
39  double Interpolate(double x) const;
40 
41  private:
42  // Helpers to scale X values down to [0, 1]
43  double ScaledValue(double x) const;
44 
45  Eigen::RowVectorXd ScaledValues(Eigen::VectorXd const& x_vec) const;
46 
47  double x_min_ = 0.0;
48  double x_max_ = 0.0;
49  double y_start_ = 0.0;
50  double y_end_ = 0.0;
51 
52  // Spline of one-dimensional "points."
53  std::unique_ptr<Eigen::Spline<double, 1>> spline_;
54 };
55 
56 } // namespace control
57 } // namespace apollo
double Interpolate(double x) const
Definition: interpolation_1d.h:28
PlanningContext is the runtime context in planning. It is persistent across multiple frames...
Definition: atomic_hash_map.h:25
bool Init(const DataType &xy)
std::vector< std::pair< double, double > > DataType
Definition: interpolation_1d.h:30