00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include <gtest/gtest.h>
00039 #include <pcl/pcl_tests.h>
00040 #include <pcl/point_types.h>
00041 #include <pcl/common/point_operators.h>
00042
00043 using namespace pcl;
00044 using namespace pcl::test;
00045
00047 TEST (PointOperators, PointXYZ)
00048 {
00049 using namespace pcl::common;
00050 PointXYZ p0; p0.x = 0.1f; p0.y = 0.2f; p0.z = 0.3f;
00051 PointXYZ p1; p1.x = 0.05f; p1.y = 0.05f; p1.z = 0.05f;
00052 PointXYZ p2 = p0;
00053 p2 += p1;
00054 EXPECT_EQ (p2.x, p0.x + p1.x);
00055 EXPECT_EQ (p2.y, p0.y + p1.y);
00056 EXPECT_EQ (p2.z, p0.z + p1.z);
00057
00058 p2 = p0 + p1;
00059
00060 EXPECT_EQ (p2.x, p0.x + p1.x);
00061 EXPECT_EQ (p2.y, p0.y + p1.y);
00062 EXPECT_EQ (p2.z, p0.z + p1.z);
00063
00064 PointXYZ p3 = p0 - p1;
00065
00066 EXPECT_EQ (p3.x, p0.x - p1.x);
00067 EXPECT_EQ (p3.y, p0.y - p1.y);
00068 EXPECT_EQ (p3.z, p0.z - p1.z);
00069
00070 p3 = p0;
00071 p3 -= p1;
00072
00073 EXPECT_EQ (p3.x, p0.x - p1.x);
00074 EXPECT_EQ (p3.y, p0.y - p1.y);
00075 EXPECT_EQ (p3.z, p0.z - p1.z);
00076
00077 float scalar = 4;
00078 p2 *= scalar;
00079
00080 EXPECT_EQ (p2.x, scalar * p0.x + scalar * p1.x);
00081 EXPECT_EQ (p2.y, scalar * p0.y + scalar * p1.y);
00082 EXPECT_EQ (p2.z, scalar * p0.z + scalar * p1.z);
00083
00084 p2 /= 2;
00085
00086 EXPECT_EQ (p2.x, scalar / 2.0f * p0.x + scalar / 2.0f * p1.x);
00087 EXPECT_EQ (p2.y, scalar / 2.0f * p0.y + scalar / 2.0f * p1.y);
00088 EXPECT_EQ (p2.z, scalar / 2.0f * p0.z + scalar / 2.0f * p1.z);
00089 }
00090
00092 TEST (PointOperators, PointXYZI)
00093 {
00094 using namespace pcl::common;
00095 PointXYZI p0; p0.x = 0.1f; p0.y = 0.2f; p0.z = 0.3f; p0.intensity = 123;
00096 PointXYZI p1; p1.x = 0.05f; p1.y = 0.05f; p1.z = 0.05f; p1.intensity = 133;
00097 PointXYZI p2 = p0 + p1;
00098 PointXYZI p3 = p0 - p1;
00099
00100 EXPECT_EQ (p2.x, p0.x + p1.x);
00101 EXPECT_EQ (p2.y, p0.y + p1.y);
00102 EXPECT_EQ (p2.z, p0.z + p1.z);
00103 EXPECT_EQ (p2.intensity, p0.intensity + p1.intensity);
00104
00105 EXPECT_EQ (p3.x, p0.x - p1.x);
00106 EXPECT_EQ (p3.y, p0.y - p1.y);
00107 EXPECT_EQ (p3.z, p0.z - p1.z);
00108 EXPECT_EQ (p3.intensity, p0.intensity - p1.intensity);
00109
00110 p2 = 0.1f * p1;
00111 EXPECT_NEAR (p2.x, 0.1 * p1.x, 1e-4);
00112 EXPECT_NEAR (p2.y, 0.1 * p1.y, 1e-4);
00113 EXPECT_NEAR (p2.z, 0.1 * p1.z, 1e-4);
00114 EXPECT_NEAR (p2.intensity, 0.1 * p1.intensity, 1e-4);
00115 PointXYZI p4 = p1 * 0.1f;
00116 EXPECT_EQ_VECTORS (p2.getVector3fMap (), p4.getVector3fMap ());
00117 EXPECT_EQ (p2.intensity, p4.intensity);
00118 }
00119
00121 TEST (PointOperators, PointXYZRGB)
00122 {
00123 using namespace pcl::common;
00124 PointXYZRGB p0; p0.x = 0.1f; p0.y = 0.2f; p0.z = 0.3f; p0.r = 123; p0.g = 125; p0.b = 127;
00125 PointXYZRGB p1; p1.x = 0.05f; p1.y = 0.05f; p1.z = 0.05f; p1.r = 123; p1.g = 125; p1.b = 127;
00126 PointXYZRGB p2 = p0 + p1;
00127 PointXYZRGB p3 = p0 - p1;
00128
00129 EXPECT_EQ (p2.x, p0.x + p1.x);
00130 EXPECT_EQ (p2.y, p0.y + p1.y);
00131 EXPECT_EQ (p2.z, p0.z + p1.z);
00132
00133
00134
00135
00136
00137 EXPECT_EQ (p3.x, p0.x - p1.x);
00138 EXPECT_EQ (p3.y, p0.y - p1.y);
00139 EXPECT_EQ (p3.z, p0.z - p1.z);
00140
00141
00142
00143
00144
00145
00146 p2 = 0.1f * p1;
00147 EXPECT_NEAR (p2.x, 0.1 * p1.x, 1e-4);
00148 EXPECT_NEAR (p2.y, 0.1 * p1.y, 1e-4);
00149 EXPECT_NEAR (p2.z, 0.1 * p1.z, 1e-4);
00150
00151
00152
00153
00154 PointXYZRGB p4 = p1 * 0.1f;
00155 EXPECT_EQ_VECTORS (p2.getVector3fMap (), p4.getVector3fMap ());
00156
00157
00158
00159
00160 }
00161
00162 int
00163 main (int argc, char** argv)
00164 {
00165 testing::InitGoogleTest (&argc, argv);
00166 return (RUN_ALL_TESTS ());
00167 }