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 Willow Garage, Inc. 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: test_operators.cpp 5297 2012-03-26 02:56:37Z nizar $
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 
00046 TEST (PointOperators, PointXYZI)
00047 {
00048   using namespace pcl::common;
00049   PointXYZI p0; p0.x = 0.1f; p0.y = 0.2f;  p0.z = 0.3f; p0.intensity = 123;
00050   PointXYZI p1; p1.x = 0.05f; p1.y = 0.05f; p1.z = 0.05f; p1.intensity = 133;
00051   PointXYZI p2 = p0 + p1;
00052 
00053   EXPECT_EQ (p2.x, p0.x + p1.x);
00054   EXPECT_EQ (p2.y, p0.y + p1.y);
00055   EXPECT_EQ (p2.z, p0.z + p1.z);
00056   EXPECT_EQ (p2.intensity, p0.intensity + p1.intensity);
00057   p2 = 0.1f * p1;
00058   EXPECT_NEAR (p2.x, 0.1 * p1.x, 1e-4);
00059   EXPECT_NEAR (p2.y, 0.1 * p1.y, 1e-4);
00060   EXPECT_NEAR (p2.z, 0.1 * p1.z, 1e-4);
00061   EXPECT_NEAR (p2.intensity, 0.1 * p1.intensity, 1e-4);
00062   PointXYZI p3 = p1 * 0.1f;
00063   EXPECT_EQ_VECTORS (p2.getVector3fMap (), p3.getVector3fMap ());
00064   EXPECT_EQ (p2.intensity, p3.intensity);
00065 }
00066 
00067 TEST (PointOperators, PointXYZRGB)
00068 {
00069   using namespace pcl::common;
00070   PointXYZRGB p0; p0.x = 0.1f; p0.y = 0.2f;  p0.z = 0.3f; p0.r = 123; p0.g = 125; p0.b = 127;
00071   PointXYZRGB p1; p1.x = 0.05f; p1.y = 0.05f; p1.z = 0.05f; p1.r = 123; p1.g = 125; p1.b = 127;
00072   PointXYZRGB p2 = p0 + p1;
00073 
00074   EXPECT_EQ (p2.x, p0.x + p1.x);
00075   EXPECT_EQ (p2.y, p0.y + p1.y);
00076   EXPECT_EQ (p2.z, p0.z + p1.z);
00077   EXPECT_EQ (p2.r, p0.r + p1.r);
00078   EXPECT_EQ (p2.g, p0.g + p1.g);
00079   EXPECT_EQ (p2.b, p0.b + p1.b);
00080   p2 = 0.1f * p1;
00081   EXPECT_NEAR (p2.x, 0.1 * p1.x, 1e-4);
00082   EXPECT_NEAR (p2.y, 0.1 * p1.y, 1e-4);
00083   EXPECT_NEAR (p2.z, 0.1 * p1.z, 1e-4);
00084   EXPECT_EQ (p2.r, static_cast<pcl::uint8_t> (0.1 * p1.r));
00085   EXPECT_EQ (p2.g, static_cast<pcl::uint8_t> (0.1 * p1.g));
00086   EXPECT_EQ (p2.b, static_cast<pcl::uint8_t> (0.1 * p1.b));
00087   PointXYZRGB p3 = p1 * 0.1f;
00088   EXPECT_EQ_VECTORS (p2.getVector3fMap (), p3.getVector3fMap ());
00089   EXPECT_EQ (p2.r, p3.r);
00090   EXPECT_EQ (p2.g, p3.g);
00091   EXPECT_EQ (p2.b, p3.b);
00092 }
00093 
00094 int
00095 main (int argc, char** argv)
00096 {
00097   testing::InitGoogleTest (&argc, argv);
00098   return (RUN_ALL_TESTS ());
00099 }


pcl
Author(s): Open Perception
autogenerated on Mon Oct 6 2014 03:18:23