forked from tier4/autoware.universe
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(map_tf_generator): accelerate the 'viewer' coordinate calculation (
tier4#890) * add random point sampling function to quickly calculate the 'viewer' coordinate Signed-off-by: IshitaTakeshi <ishitah.takeshi@gmail.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Kenji Miyake <31987104+kenji-miyake@users.noreply.github.com>
- Loading branch information
Showing
5 changed files
with
107 additions
and
5 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
33 changes: 33 additions & 0 deletions
33
map/map_tf_generator/include/map_tf_generator/uniform_random.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,33 @@ | ||
// 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 MAP_TF_GENERATOR__UNIFORM_RANDOM_HPP_ | ||
#define MAP_TF_GENERATOR__UNIFORM_RANDOM_HPP_ | ||
|
||
#include <random> | ||
#include <vector> | ||
|
||
std::vector<size_t> UniformRandom(const size_t max_exclusive, const size_t n) | ||
{ | ||
std::default_random_engine generator; | ||
std::uniform_int_distribution<size_t> distribution(0, max_exclusive - 1); | ||
|
||
std::vector<size_t> v(n); | ||
for (size_t i = 0; i < n; i++) { | ||
v[i] = distribution(generator); | ||
} | ||
return v; | ||
} | ||
|
||
#endif // MAP_TF_GENERATOR__UNIFORM_RANDOM_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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
// 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 "map_tf_generator/uniform_random.hpp" | ||
|
||
#include <gmock/gmock.h> | ||
|
||
using testing::AllOf; | ||
using testing::Each; | ||
using testing::Ge; | ||
using testing::Lt; | ||
|
||
TEST(UniformRandom, UniformRandom) | ||
{ | ||
{ | ||
const std::vector<size_t> random = UniformRandom(4, 0); | ||
ASSERT_EQ(random.size(), static_cast<size_t>(0)); | ||
} | ||
|
||
// checks if the returned values are in range of [min, max) | ||
// note that the minimun range is always zero and the max value is exclusive | ||
{ | ||
const size_t min_inclusive = 0; | ||
const size_t max_exclusive = 4; | ||
|
||
for (int i = 0; i < 50; i++) { | ||
const std::vector<size_t> random = UniformRandom(4, 10); | ||
ASSERT_EQ(random.size(), 10U); | ||
ASSERT_THAT(random, Each(AllOf(Ge(min_inclusive), Lt(max_exclusive)))); // in range [0, 4) | ||
} | ||
} | ||
} |