-
Notifications
You must be signed in to change notification settings - Fork 640
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into 602-evaluate-performance-of-localization-pip…
…eline
- Loading branch information
Showing
68 changed files
with
2,639 additions
and
292 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
common/interpolation/include/interpolation/zero_order_hold.hpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
// Copyright 2022 Tier IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#ifndef INTERPOLATION__ZERO_ORDER_HOLD_HPP_ | ||
#define INTERPOLATION__ZERO_ORDER_HOLD_HPP_ | ||
|
||
#include "interpolation/interpolation_utils.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace interpolation | ||
{ | ||
std::vector<double> zero_order_hold( | ||
const std::vector<double> & base_keys, const std::vector<double> & base_values, | ||
const std::vector<double> & query_keys, const double overlap_threshold = 1e-3); | ||
} // namespace interpolation | ||
|
||
#endif // INTERPOLATION__ZERO_ORDER_HOLD_HPP_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2022 Tier IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "interpolation/zero_order_hold.hpp" | ||
|
||
#include <vector> | ||
|
||
namespace interpolation | ||
{ | ||
std::vector<double> zero_order_hold( | ||
const std::vector<double> & base_keys, const std::vector<double> & base_values, | ||
const std::vector<double> & query_keys, const double overlap_threshold) | ||
{ | ||
// throw exception for invalid arguments | ||
interpolation_utils::validateKeys(base_keys, query_keys); | ||
interpolation_utils::validateKeysAndValues(base_keys, base_values); | ||
|
||
std::vector<double> query_values; | ||
size_t closest_segment_idx = 0; | ||
for (size_t i = 0; i < query_keys.size(); ++i) { | ||
// Check if query_key is closes to the terminal point of the base keys | ||
if (base_keys.back() - overlap_threshold < query_keys.at(i)) { | ||
closest_segment_idx = base_keys.size() - 1; | ||
} else { | ||
for (size_t j = closest_segment_idx; j < base_keys.size() - 1; ++j) { | ||
if ( | ||
base_keys.at(j) - overlap_threshold < query_keys.at(i) && | ||
query_keys.at(i) < base_keys.at(j + 1)) { | ||
// find closest segment in base keys | ||
closest_segment_idx = j; | ||
} | ||
} | ||
} | ||
|
||
query_values.push_back(base_values.at(closest_segment_idx)); | ||
} | ||
|
||
return query_values; | ||
} | ||
|
||
} // namespace interpolation |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
// Copyright 2022 Tier IV, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include "interpolation/zero_order_hold.hpp" | ||
|
||
#include <gtest/gtest.h> | ||
|
||
#include <limits> | ||
#include <vector> | ||
|
||
constexpr double epsilon = 1e-6; | ||
|
||
TEST(zero_order_hold_interpolation, vector_interpolation) | ||
{ | ||
{ // straight: query_keys is same as base_keys | ||
const std::vector<double> base_keys{0.0, 1.0, 2.0, 3.0, 4.0}; | ||
const std::vector<double> base_values{0.0, 1.5, 2.5, 3.5, 0.0}; | ||
const std::vector<double> query_keys = base_keys; | ||
const std::vector<double> ans = base_values; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
|
||
{ // straight: query_keys is random | ||
const std::vector<double> base_keys{0.0, 1.0, 2.0, 3.0, 4.0}; | ||
const std::vector<double> base_values{0.0, 1.5, 3.0, 4.5, 6.0}; | ||
const std::vector<double> query_keys{0.0, 0.7, 1.9, 4.0}; | ||
const std::vector<double> ans{0.0, 0.0, 1.5, 6.0}; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
|
||
{ // curve: query_keys is same as base_keys | ||
const std::vector<double> base_keys{-1.5, 1.0, 5.0, 10.0, 15.0, 20.0}; | ||
const std::vector<double> base_values{-1.2, 0.5, 1.0, 1.2, 2.0, 1.0}; | ||
const std::vector<double> query_keys = base_keys; | ||
const std::vector<double> ans = base_values; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
|
||
{ // curve: query_keys is same as random | ||
const std::vector<double> base_keys{-1.5, 1.0, 5.0, 10.0, 15.0, 20.0}; | ||
const std::vector<double> base_values{-1.2, 0.5, 1.0, 1.2, 2.0, 1.0}; | ||
const std::vector<double> query_keys{0.0, 8.0, 18.0}; | ||
const std::vector<double> ans{-1.2, 1.0, 2.0}; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
|
||
{ // Boundary Condition | ||
const std::vector<double> base_keys{0.0, 1.0, 2.0, 3.0, 4.0}; | ||
const std::vector<double> base_values{0.0, 1.5, 2.5, 3.5, 0.0}; | ||
const std::vector<double> query_keys{0.0, 1.0, 2.0, 3.0, 4.0 - 0.001}; | ||
const std::vector<double> ans = {0.0, 1.5, 2.5, 3.5, 3.5}; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
|
||
{ // Boundary Condition | ||
const std::vector<double> base_keys{0.0, 1.0, 2.0, 3.0, 4.0}; | ||
const std::vector<double> base_values{0.0, 1.5, 2.5, 3.5, 0.0}; | ||
const std::vector<double> query_keys{0.0, 1.0, 2.0, 3.0, 4.0 - 0.0001}; | ||
const std::vector<double> ans = {0.0, 1.5, 2.5, 3.5, 0.0}; | ||
|
||
const auto query_values = interpolation::zero_order_hold(base_keys, base_values, query_keys); | ||
for (size_t i = 0; i < query_values.size(); ++i) { | ||
EXPECT_NEAR(query_values.at(i), ans.at(i), epsilon); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -142,7 +142,7 @@ public: | |
```c++ | ||
bool SampleNode::sampleFunc1() | ||
bool SampleNode::sampleFunc() | ||
{ | ||
... | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.