test_operators.cpp
Go to the documentation of this file.
00001 /*
00002  * Software License Agreement (BSD License)
00003  *
00004  *  Copyright (c) 2010-2011, Willow Garage, Inc.
00005  *  All rights reserved.
00006  *
00007  *  Redistribution and use in source and binary forms, with or without
00008  *  modification, are permitted provided that the following conditions
00009  *  are met:
00010  *
00011  *   * Redistributions of source code must retain the above copyright
00012  *     notice, this list of conditions and the following disclaimer.
00013  *   * Redistributions in binary form must reproduce the above
00014  *     copyright notice, this list of conditions and the following
00015  *     disclaimer in the documentation and/or other materials provided
00016  *     with the distribution.
00017  *   * Neither the name of the copyright holder(s) nor the names of its
00018  *     contributors may be used to endorse or promote products derived
00019  *     from this software without specific prior written permission.
00020  *
00021  *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00022  *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00023  *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00024  *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00025  *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00026  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00027  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00028  *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00029  *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00030  *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00031  *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00032  *  POSSIBILITY OF SUCH DAMAGE.
00033  *
00034  * $Id$
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   // Disabled. Doesn't make any sense
00133   //EXPECT_EQ (p2.r, p0.r + p1.r);
00134   //EXPECT_EQ (p2.g, p0.g + p1.g);
00135   //EXPECT_EQ (p2.b, p0.b + p1.b);
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   // Disabled. Doesn't make any sense
00141   //EXPECT_EQ (p3.r, p0.r - p1.r);
00142   //EXPECT_EQ (p3.g, p0.g - p1.g);
00143   //EXPECT_EQ (p3.b, p0.b - p1.b);
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   // Disabled. Doesn't make any sense
00151   //EXPECT_EQ (p2.r, static_cast<pcl::uint8_t> (0.1 * p1.r));
00152   //EXPECT_EQ (p2.g, static_cast<pcl::uint8_t> (0.1 * p1.g));
00153   //EXPECT_EQ (p2.b, static_cast<pcl::uint8_t> (0.1 * p1.b));
00154   PointXYZRGB p4 = p1 * 0.1f;
00155   EXPECT_EQ_VECTORS (p2.getVector3fMap (), p4.getVector3fMap ());
00156   // Disabled. Doesn't make any sense
00157   //EXPECT_EQ (p2.r, p4.r);
00158   //EXPECT_EQ (p2.g, p4.g);
00159   //EXPECT_EQ (p2.b, p4.b);
00160 }
00161 
00162 int
00163 main (int argc, char** argv)
00164 {
00165   testing::InitGoogleTest (&argc, argv);
00166   return (RUN_ALL_TESTS ());
00167 }


pcl
Author(s): Open Perception
autogenerated on Wed Aug 26 2015 15:35:17