joint_image_interpolator_unittest.cpp
Go to the documentation of this file.
1 /*********************************************************************
2 * Software License Agreement (BSD License)
3 *
4 * Copyright (c) 2008, Willow Garage, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
17 * * Neither the name of the Willow Garage nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31 * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
33 *********************************************************************/
34 
35 #include <gtest/gtest.h>
37 
38 using namespace std;
39 using namespace laser_joint_processor;
40 
41 static const float eps = 1e-6;
42 
43 
44 float& pixel(IplImage* image, int row, int col, int chan)
45 {
46  return *(((float*)(image->imageData + row*image->widthStep))+image->nChannels*col + chan);
47 }
48 
49 class JointImageInterpolator_EasyTests : public ::testing::Test
50 {
51 protected:
52  virtual void SetUp()
53  {
54  source_image_ = cvCreateImage( cvSize(3,3), IPL_DEPTH_32F, 2);
55  pixel(source_image_, 0, 0, 0) = 10;
56  pixel(source_image_, 0, 1, 0) = 20;
57  pixel(source_image_, 0, 2, 0) = 30;
58  pixel(source_image_, 1, 0, 0) = 40;
59  pixel(source_image_, 1, 1, 0) = 50;
60  pixel(source_image_, 1, 2, 0) = 60;
61  pixel(source_image_, 2, 0, 0) = 70;
62  pixel(source_image_, 2, 1, 0) = 80;
63  pixel(source_image_, 2, 2, 0) = 90;
64 
65  pixel(source_image_, 0, 0, 1) = 1;
66  pixel(source_image_, 0, 1, 1) = 2;
67  pixel(source_image_, 0, 2, 1) = 3;
68  pixel(source_image_, 1, 0, 1) = 4;
69  pixel(source_image_, 1, 1, 1) = 5;
70  pixel(source_image_, 1, 2, 1) = 6;
71  pixel(source_image_, 2, 0, 1) = 7;
72  pixel(source_image_, 2, 1, 1) = 8;
73  pixel(source_image_, 2, 2, 1) = 9;
74 
75  // Pixel Values:
76  // 1 2 3
77  // 4 5 6
78  // 7 8 9
79 
80  image_points_.resize(3);
81  image_points_[0].x = 0.0;
82  image_points_[0].y = 0.0;
83 
84  image_points_[1].x = 0.5;
85  image_points_[1].y = 0.5;
86 
87  image_points_[2].x = 1;
88  image_points_[2].y = 0.75;
89 
90  bool success;
91  success = interp_.interp(image_points_, source_image_, positions_, velocities_);
92  ASSERT_TRUE(success);
93  }
94 
95  virtual void TearDown()
96  {
97  cvReleaseImage(&source_image_);
98  }
99 
100  IplImage* source_image_;
101  vector<geometry_msgs::Point> image_points_;
103  vector<float> positions_;
104  vector<float> velocities_;
105 };
106 
108 {
109  ASSERT_EQ(positions_.size(), (unsigned int) 3);
110  EXPECT_NEAR(positions_[0], 10.0, eps);
111  EXPECT_NEAR(positions_[1], 30.0, eps);
112  EXPECT_NEAR(positions_[2], 42.5, eps);
113 }
114 
116 {
117  ASSERT_EQ(velocities_.size(), (unsigned int) 3);
118  EXPECT_NEAR(velocities_[0], 1.0, eps);
119  EXPECT_NEAR(velocities_[1], 3.0, eps);
120  EXPECT_NEAR(velocities_[2], 4.25, eps);
121 }
122 
123 
124 int main(int argc, char **argv){
125  testing::InitGoogleTest(&argc, argv);
126  return RUN_ALL_TESTS();
127 }
float & pixel(IplImage *image, int row, int col, int chan)
int main(int argc, char **argv)
TEST_F(JointImageInterpolator_EasyTests, positionTests)
static const float eps


laser_joint_processor
Author(s): Vijay Pradeep
autogenerated on Tue Jun 1 2021 02:50:55