Skip to content
Snippets Groups Projects
Commit 5a9f213e authored by Tobias Gröger's avatar Tobias Gröger
Browse files

Add simple test for feature merger

parent a89f196d
No related branches found
No related tags found
1 merge request!74Add laser scanner features to teb planning
# we can't let tests depend on the component so we create a dummy library
# with the same code (except the component itself)
armarx_add_library(laser_scanner_feature_extraction_test_library
SOURCES
#../Component.cpp
../FeatureExtractor.cpp
../FeatureMerger.cpp
../ArVizDrawer.cpp
../ScanClustering.cpp
../ChainApproximation.cpp
../conversions/eigen.cpp
../conversions/pcl.cpp
../conversions/features.cpp
../EnclosingEllipsoid.cpp
../Path.cpp
../UnionFind.cpp
HEADERS
#../Component.h
../FeatureExtractor.h
../FeatureMerger.h
../ArVizDrawer.h
../ScanClustering.h
../ChainApproximation.h
../EnclosingEllipsoid.h
../Path.h
../geometry.h
../conversions/eigen.h
../conversions/pcl_eigen.h
../conversions/opencv_eigen.h
../conversions/opencv_pcl.h
../conversions/pcl.h
../conversions/features.h
../UnionFind.h
DEPENDENCIES
ArmarXCore
ArmarXCoreComponentPlugins
ArmarXCoreLogging
RobotAPIComponentPlugins
RobotComponentsInterfaces
armarx_navigation::memory
armem_laser_scans
range-v3::range-v3
DEPENDENCIES_LEGACY
PCL
)
# Libs required for the tests
SET(LIBS ${LIBS} ArmarXCore LaserScannerFeatureExtraction)
armarx_add_test(LaserScannerFeatureExtractionTest LaserScannerFeatureExtractionTest.cpp "${LIBS}")
armarx_add_test(laser_scanner_feature_extraction_test
TEST_FILES
LaserScannerFeatureExtractionTest.cpp
DEPENDENCIES
ArmarXCore
armarx_navigation::laser_scanner_feature_extraction_test_library
)
armarx_add_test(laser_scanner_feature_extraction_merger_test
TEST_FILES
MergerTest.cpp
DEPENDENCIES
ArmarXCore
armarx_navigation::laser_scanner_feature_extraction_test_library
)
......@@ -20,46 +20,52 @@
* GNU General Public License
*/
#include "ArmarXCore/core/logging/Logging.h"
#include "armarx/navigation/components/laser_scanner_feature_extraction/FeatureExtractor.h"
#include <boost/test/tools/old/interface.hpp>
#define BOOST_TEST_MODULE RobotComponents::ArmarXObjects::LaserScannerFeatureExtraction
#define ARMARX_BOOST_TEST
#include <iostream>
#include <RobotComponents/Test.h>
#include <ArmarXCore/core/logging/Logging.h>
#include <pcl/point_types.h>
#include <armarx/navigation/components/laser_scanner_feature_extraction/FeatureExtractor.h>
#include "../EnclosingEllipsoid.h"
#include <iostream>
BOOST_AUTO_TEST_CASE(testExample)
// test includes
#define BOOST_TEST_MODULE Navigation::ArmarXObjects::LaserScannerFeatureExtraction
#define ARMARX_BOOST_TEST
#include <armarx/navigation/Test.h>
namespace armarx::navigation::components::laser_scanner_feature_extraction
{
// Ground truth (GT) ellipsoid with params:
// center = (0,0)
// radii = (4,2)
// angle = 0
armarx::laser_scanner_feature_extraction::FeatureExtractor::Points points;
points.push_back(Eigen::Vector2f{-4.F, 0});
points.push_back(Eigen::Vector2f{0, 2.F});
points.push_back(Eigen::Vector2f{4.F, 0});
points.push_back(Eigen::Vector2f{0, -2.F});
const Eigen::Vector2f radii(4, 2);
armarx::laser_scanner_feature_extraction::EnclosingEllipsoid ee(points);
// The computed ellipsoid must contain the GT ellipsoid
BOOST_CHECK_GE(ee.radii.x(), 4.F);
BOOST_CHECK_GE(ee.radii.y(), 2.F);
// ... but should not be too large
BOOST_CHECK_LE(ee.radii.x(), 4.1F);
BOOST_CHECK_LE(ee.radii.y(), 2.1F);
// The computed ellipsoid must be roughly at the position of the GT ellipsoid
BOOST_CHECK_LT(std::fabs(ee.pose.translation().x()), 0.1);
BOOST_CHECK_LT(std::fabs(ee.pose.translation().y()), 0.1);
}
BOOST_AUTO_TEST_CASE(testExample)
{
// Ground truth (GT) ellipsoid with params:
// center = (0,0)
// radii = (4,2)
// angle = 0
FeatureExtractor::Points points;
points.push_back(Eigen::Vector2f{-4.F, 0});
points.push_back(Eigen::Vector2f{0, 2.F});
points.push_back(Eigen::Vector2f{4.F, 0});
points.push_back(Eigen::Vector2f{0, -2.F});
const Eigen::Vector2f radii(4, 2);
EnclosingEllipsoid ee(points);
// The computed ellipsoid must contain the GT ellipsoid
BOOST_CHECK_GE(ee.radii.x(), 4.F);
BOOST_CHECK_GE(ee.radii.y(), 2.F);
// ... but should not be too large
BOOST_CHECK_LE(ee.radii.x(), 4.1F);
BOOST_CHECK_LE(ee.radii.y(), 2.1F);
// The computed ellipsoid must be roughly at the position of the GT ellipsoid
BOOST_CHECK_LT(std::fabs(ee.pose.translation().x()), 0.1);
BOOST_CHECK_LT(std::fabs(ee.pose.translation().y()), 0.1);
}
} // namespace armarx::navigation::components::laser_scanner_feature_extraction
/*
* This file is part of ArmarX.
*
* ArmarX is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* ArmarX is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
* @package RobotComponents::ArmarXObjects::LaserScannerFeatureExtraction
* @author Fabian Reister ( fabian dot reister at kit dot edu )
* @date 2021
* @copyright http://www.gnu.org/licenses/gpl-2.0.txt
* GNU General Public License
*/
#include <iostream>
#include <ArmarXCore/core/logging/Logging.h>
#include <armarx/navigation/components/laser_scanner_feature_extraction/FeatureMerger.h>
#include "../EnclosingEllipsoid.h"
// test includes
#define BOOST_TEST_MODULE Navigation::ArmarXObjects::LaserScannerFeatureExtraction
#define ARMARX_BOOST_TEST
#include <armarx/navigation/Test.h>
namespace armarx::navigation::components::laser_scanner_feature_extraction
{
BOOST_AUTO_TEST_CASE(insideConvexPolyTest)
{
std::vector<Eigen::Vector2f> polygon;
polygon.push_back({0, 0});
polygon.push_back({1, 1});
polygon.push_back({0, 2});
polygon.push_back({-1, 1});
BOOST_CHECK(FeatureMerger::insideConvexPoly({0, 1}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({0.5, 1}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({-0.5, 1}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({0, 2}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({1, 1}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({-0.5, 0.5}, polygon));
BOOST_CHECK(FeatureMerger::insideConvexPoly({-0.5, 0.51}, polygon));
BOOST_CHECK(!FeatureMerger::insideConvexPoly({-0.5, 0.49}, polygon));
BOOST_CHECK(!FeatureMerger::insideConvexPoly({1.1, 1}, polygon));
BOOST_CHECK(!FeatureMerger::insideConvexPoly({0, 2.1}, polygon));
BOOST_CHECK(!FeatureMerger::insideConvexPoly({0, -0.1}, polygon));
BOOST_CHECK(!FeatureMerger::insideConvexPoly({-1, 2}, polygon));
}
} // namespace armarx::navigation::components::laser_scanner_feature_extraction
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment