00001 #include "Eigen/Eigen"
00002 #include "surface_perception/shape_extraction.h"
00003
00004 #include "pcl/ModelCoefficients.h"
00005
00006 #include <gtest/gtest.h>
00007
00008 namespace surface_perception {
00009
00010 const double kLongSide = 2.0;
00011 const double kShortSide = 1.0;
00012
00013 TEST(TestStandardizeBoxOrientation, IdentityMatrix) {
00014 Eigen::Matrix3f expected_matrix = Eigen::Matrix3f::Identity();
00015 Eigen::Matrix3f input_matrix = Eigen::Matrix3f::Identity();
00016
00017 double x_dim, y_dim;
00018 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00019 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00020
00021 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00022 EXPECT_EQ(kShortSide, x_dim);
00023 EXPECT_EQ(kLongSide, y_dim);
00024 }
00025
00026 TEST(TestStandardizeBoxOrientation, IdentityMatrixRotate180DegreesAroundYAxis) {
00027
00028 Eigen::Matrix3f expected_matrix;
00029 expected_matrix << 1.0, 0.0, 0.0,
00030 0.0, -1.0, 0.0,
00031 0.0, 0.0, -1.0;
00032
00033 Eigen::Matrix3f input_matrix;
00034 input_matrix << -1.0, 0.0, 0.0,
00035 0.0, 1.0, 0.0,
00036 0.0, 0.0, -1.0;
00037
00038
00039 double x_dim, y_dim;
00040 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00041 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00042
00043 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00044 EXPECT_EQ(kShortSide, x_dim);
00045 EXPECT_EQ(kLongSide, y_dim);
00046 }
00047
00048 TEST(TestStandardizeBoxOrientation, IdentityMatrixRotate45DegreesAroundZAxis) {
00049
00050 Eigen::Matrix3f expected_matrix;
00051 expected_matrix << 0.70711, -0.70711, 0.0,
00052 0.70711, 0.70711, 0.0,
00053 0.0, 0.0, 1.0;
00054
00055 Eigen::Matrix3f input_matrix;
00056 input_matrix << 0.70711, -0.70711, 0.0,
00057 0.70711, 0.70711, 0.0,
00058 0.0, 0.0, 1.0;
00059
00060
00061 double x_dim, y_dim;
00062 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00063 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00064
00065 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00066 EXPECT_EQ(kShortSide, x_dim);
00067 EXPECT_EQ(kLongSide, y_dim);
00068 }
00069
00070 TEST(TestStandardizeBoxOrientation, IdentityMatrixRotate135DegreesAroundZAxis) {
00071
00072 Eigen::Matrix3f expected_matrix;
00073 expected_matrix << 0.70711, -0.70711, 0.0,
00074 0.70711, 0.70711, 0.0,
00075 0.0, 0.0, 1.0;
00076
00077 Eigen::Matrix3f input_matrix;
00078 input_matrix << -0.70711, 0.70711, 0.0,
00079 -0.70711, -0.70711, 0.0,
00080 0.0, 0.0, 1.0;
00081
00082
00083 double x_dim, y_dim;
00084 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00085 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00086
00087 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00088 EXPECT_EQ(kShortSide, x_dim);
00089 EXPECT_EQ(kLongSide, y_dim);
00090 }
00091
00092 TEST(TestStandardizeBoxOrientation, TiltedMatrix) {
00093
00094 Eigen::Matrix3f expected_matrix;
00095 expected_matrix << 0.99980, 0.01732, 0.01,
00096 -0.02, 0.86580, 0.5,
00097 0.0, -0.5001, 0.86597;
00098
00099 Eigen::Matrix3f input_matrix;
00100 input_matrix << 0.99980, 0.01732, 0.01,
00101 -0.02, 0.86580, 0.5,
00102 0.0, -0.5001, 0.86597;
00103
00104
00105 double x_dim, y_dim;
00106 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00107 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00108
00109 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00110 EXPECT_EQ(kShortSide, x_dim);
00111 EXPECT_EQ(kLongSide, y_dim);
00112 }
00113
00114 TEST(TestStandardizeBoxOrientation, TiltedMatrixRotate180DegreesAroundYAxis) {
00115
00116 Eigen::Matrix3f expected_matrix;
00117 expected_matrix << 0.99980, -0.01732, -0.01,
00118 -0.02, -0.86580, -0.5,
00119 0.0, 0.5001, -0.86597;
00120
00121 Eigen::Matrix3f input_matrix;
00122 input_matrix << -0.99980, 0.01732, -0.01,
00123 0.02, 0.86580, -0.5,
00124 0.0, -0.5001, -0.86597;
00125
00126
00127 double x_dim, y_dim;
00128 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00129 input_matrix, kShortSide, kLongSide, &x_dim, &y_dim);
00130
00131 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00132 EXPECT_EQ(kShortSide, x_dim);
00133 EXPECT_EQ(kLongSide, y_dim);
00134 }
00135
00136 TEST(TestStandardizeBoxOrientation, IdentityMatrixWithXLongSideYShortSdie) {
00137
00138 Eigen::Matrix3f expected_matrix;
00139 expected_matrix << 0.0, -1.0, 0.0,
00140 1.0, 0.0, 0.0,
00141 0.0, 0.0, 1.0;
00142
00143 Eigen::Matrix3f input_matrix;
00144 input_matrix << 1.0, 0.0, 0.0,
00145 0.0, 1.0, 0.0,
00146 0.0, 0.0, 1.0;
00147
00148
00149 double x_dim, y_dim;
00150 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00151 input_matrix, kLongSide, kShortSide, &x_dim, &y_dim);
00152
00153 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00154 EXPECT_EQ(kShortSide, x_dim);
00155 EXPECT_EQ(kLongSide, y_dim);
00156 }
00157
00158 TEST(TestStandardizeBoxOrientation, TiltedMatrixWithXLongSideYShortSide) {
00159
00160 Eigen::Matrix3f expected_matrix;
00161 expected_matrix << 0.01732, -0.99980, 0.01,
00162 0.86580, 0.02, 0.5,
00163 -0.5001, 0.0, 0.86597;
00164
00165 Eigen::Matrix3f input_matrix;
00166 input_matrix << 0.99980, 0.01732, 0.01,
00167 -0.02, 0.86580, 0.5,
00168 0.0, -0.5001, 0.86597;
00169
00170
00171 double x_dim, y_dim;
00172 Eigen::Matrix3f actual_matrix = StandardizeBoxOrientation(
00173 input_matrix, kLongSide, kShortSide, &x_dim, &y_dim);
00174
00175 EXPECT_TRUE(expected_matrix.isApprox(actual_matrix, 0.0001));
00176 EXPECT_EQ(kShortSide, x_dim);
00177 EXPECT_EQ(kLongSide, y_dim);
00178 }
00179 }
00180
00181 int main(int argc, char** argv) {
00182 testing::InitGoogleTest(&argc, argv);
00183
00184 return RUN_ALL_TESTS();
00185 }