Skip to content

Commit d3ba535

Browse files
committed
Removed unsupported SpaceMap constructor.
Added SpaceMap traits unit tests. Updated unit tests.
1 parent eb549c8 commit d3ba535

File tree

6 files changed

+62
-48
lines changed

6 files changed

+62
-48
lines changed

src/pico_tree/pico_tree/map.hpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,11 +120,13 @@ class SpaceMap : protected internal::Map<Point_, kDynamicSize> {
120120
static_assert(
121121
Dim != kDynamicSize, "SPACE_MAP_OF_POINT_DOES_NOT_SUPPORT_DYNAMIC_DIM");
122122

123-
using internal::Map<Point_, kDynamicSize>::Map;
124123
using internal::Map<Point_, kDynamicSize>::operator[];
125124
using internal::Map<Point_, kDynamicSize>::data;
126125
using internal::Map<Point_, kDynamicSize>::size;
127126

127+
constexpr SpaceMap(CvPointType* data, SizeType size) noexcept
128+
: internal::Map<Point_, kDynamicSize>::Map(data, size) {}
129+
128130
constexpr SizeType sdim() const { return Dim; }
129131
};
130132

test/pico_tree/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ set(TEST_TARGET_SOURCES
2121
${CMAKE_CURRENT_LIST_DIR}/metric_test.cpp
2222
${CMAKE_CURRENT_LIST_DIR}/point_map_test.cpp
2323
${CMAKE_CURRENT_LIST_DIR}/space_map_test.cpp
24+
${CMAKE_CURRENT_LIST_DIR}/space_map_traits_test.cpp
2425
${CMAKE_CURRENT_LIST_DIR}/vector_traits_test.cpp
2526
)
2627

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
#include <gtest/gtest.h>
22

33
#include <pico_tree/eigen3_traits.hpp>
4-
#include <pico_tree/kd_tree.hpp>
54

65
#include "common.hpp"
76

@@ -11,20 +10,7 @@ void CheckEigenAdaptorInterface() {
1110
RowMatrix row_matrix = RowMatrix::Random(4, 8);
1211

1312
CheckSpaceAdaptor<static_cast<pico_tree::Size>(ColMatrix::RowsAtCompileTime)>(
14-
col_matrix,
15-
col_matrix.rows(),
16-
col_matrix.cols(),
17-
static_cast<Eigen::Index>(0),
18-
col_matrix.col(0).data());
19-
CheckSpaceAdaptor<static_cast<pico_tree::Size>(RowMatrix::ColsAtCompileTime)>(
20-
row_matrix,
21-
row_matrix.cols(),
22-
row_matrix.rows(),
23-
static_cast<Eigen::Index>(0),
24-
row_matrix.row(0).data());
25-
26-
CheckSpaceAdaptor<static_cast<pico_tree::Size>(ColMatrix::RowsAtCompileTime)>(
27-
std::ref(col_matrix),
13+
std::cref(col_matrix),
2814
col_matrix.rows(),
2915
col_matrix.cols(),
3016
col_matrix.cols() - 1,
@@ -33,11 +19,11 @@ void CheckEigenAdaptorInterface() {
3319
std::cref(row_matrix),
3420
row_matrix.cols(),
3521
row_matrix.rows(),
36-
col_matrix.rows() - 1,
22+
row_matrix.rows() - 1,
3723
row_matrix.row(row_matrix.rows() - 1).data());
3824
}
3925

40-
TEST(EigenTest, Interface) {
26+
TEST(Eigen3TraitsTest, Interface) {
4127
// Spatial dimension known.
4228
CheckEigenAdaptorInterface<
4329
Eigen::Matrix<float, 4, Eigen::Dynamic, Eigen::ColMajor>,
@@ -47,11 +33,3 @@ TEST(EigenTest, Interface) {
4733
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::ColMajor>,
4834
Eigen::Matrix<float, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor>>();
4935
}
50-
51-
TEST(EigenTest, TreeCompatibility) {
52-
Eigen::Matrix4Xd matrix = Eigen::Matrix4Xd::Random(4, 8);
53-
54-
pico_tree::KdTree<Eigen::Matrix4Xd> tree(std::move(matrix), 10);
55-
56-
TestKnn(tree, 2);
57-
}
Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#include <gtest/gtest.h>
22

3-
#include <pico_tree/kd_tree.hpp>
43
#include <pico_tree/opencv_traits.hpp>
54

65
#include "common.hpp"
76

8-
TEST(OpenCvTest, Interface) {
7+
TEST(OpenCvTraitsTest, Interface) {
98
using Scalar = float;
109
int constexpr Dim = 3;
1110

@@ -20,14 +19,3 @@ TEST(OpenCvTest, Interface) {
2019
matrix.rows - 1,
2120
row.ptr<Scalar>());
2221
}
23-
24-
TEST(OpenCvTest, TreeCompatibility) {
25-
using Scalar = float;
26-
27-
cv::Mat random(1024, 4, cv::DataType<Scalar>::type);
28-
cv::randu(random, -Scalar(1.0), Scalar(1.0));
29-
30-
pico_tree::KdTree<pico_tree::MatWrapper<Scalar, 4>> tree(random, 10);
31-
32-
TestKnn(tree, 20);
33-
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#include <gtest/gtest.h>
2+
3+
#include <pico_toolshed/point.hpp>
4+
#include <pico_tree/map_traits.hpp>
5+
6+
#include "common.hpp"
7+
8+
TEST(SpaceMapTraitsTest, PointMap) {
9+
constexpr pico_tree::Size Dim = 2;
10+
std::vector<double> scalars = {1.0, 2.0, 3.0, 4.0};
11+
pico_tree::SpaceMap<pico_tree::PointMap<double, Dim>> map_ct(
12+
scalars.data(), scalars.size() / Dim);
13+
pico_tree::SpaceMap<pico_tree::PointMap<double, pico_tree::kDynamicSize>>
14+
map_rt(scalars.data(), scalars.size() / Dim, Dim);
15+
16+
CheckSpaceAdaptor<Dim>(
17+
map_ct,
18+
map_ct.sdim(),
19+
map_ct.size(),
20+
static_cast<pico_tree::Size>(0),
21+
map_ct[0].data());
22+
CheckSpaceAdaptor<pico_tree::kDynamicSize>(
23+
map_rt,
24+
map_rt.sdim(),
25+
map_rt.size(),
26+
static_cast<pico_tree::Size>(0),
27+
map_rt[0].data());
28+
}
29+
30+
TEST(SpaceMapTraitsTest, Point) {
31+
std::vector<Point2f> points = {{1.0f, 2.0f}, {3.0f, 4.0f}};
32+
pico_tree::SpaceMap<Point2f> map(points.data(), points.size());
33+
34+
CheckSpaceAdaptor<Point2f::Dim>(
35+
map,
36+
map.sdim(),
37+
map.size(),
38+
static_cast<pico_tree::Size>(0),
39+
map[0].data());
40+
}

test/pico_tree/vector_traits_test.cpp

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,29 @@
55

66
#include "common.hpp"
77

8-
std::vector<Point2f> GetStdVector() { return {{1.0f, 2.0f}}; }
8+
TEST(VectorTraitsTest, Interface) {
9+
std::vector<Point2f> points = {{1.0f, 2.0f}, {3.0f, 4.0f}};
910

10-
TEST(StdTraitsTest, StdVector) {
11-
std::vector<Point2f> points = GetStdVector();
1211
CheckSpaceAdaptor<Point2f::Dim>(
1312
points,
1413
Point2f::Dim,
1514
points.size(),
16-
static_cast<std::size_t>(0),
15+
static_cast<pico_tree::Size>(0),
1716
points[0].data());
18-
}
19-
20-
TEST(StdTraitsTest, StdRefVector) {
21-
std::vector<Point2f> points = GetStdVector();
17+
// VectorTraitsTest is used to test the default std::reference_wrapper<>
18+
// specialization.
2219
CheckSpaceAdaptor<Point2f::Dim>(
2320
std::ref(points),
2421
Point2f::Dim,
2522
points.size(),
26-
static_cast<std::size_t>(0),
23+
static_cast<pico_tree::Size>(0),
24+
points[0].data());
25+
// VectorTraitsTest is used to test the default std::reference_wrapper<const>
26+
// specialization.
27+
CheckSpaceAdaptor<Point2f::Dim>(
28+
std::cref(points),
29+
Point2f::Dim,
30+
points.size(),
31+
static_cast<pico_tree::Size>(0),
2732
points[0].data());
2833
}

0 commit comments

Comments
 (0)