Go to the documentation of this file.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 #include <gtest/gtest.h>
00036 
00037 
00038 #include <calibration_msgs/DenseLaserSnapshot.h>
00039 #include <laser_cb_detector/cv_laser_bridge.h>
00040 
00041 using namespace std;
00042 using namespace laser_cb_detector;
00043 
00044 static const bool DEBUG=false;
00045 
00046 calibration_msgs::DenseLaserSnapshot buildSnapshot(double start_range, double start_intensity, double increment,
00047                                                    const unsigned int H, const unsigned int W)
00048 {
00049   calibration_msgs::DenseLaserSnapshot snapshot;
00050 
00051   snapshot.readings_per_scan = W;
00052   snapshot.num_scans = H;
00053 
00054   snapshot.ranges.resize(H*W);
00055   snapshot.intensities.resize(H*W);
00056 
00057   for (unsigned int i=0; i<H*W; i++)
00058   {
00059     snapshot.ranges[i]      = start_range     + i*increment;
00060     snapshot.intensities[i] = start_intensity + i*increment;
00061   }
00062 
00063   return snapshot;
00064 }
00065 
00066 static const unsigned int NUM_SCANS = 5;
00067 static const unsigned int RAYS_PER_SCAN = 10;
00068 static const double eps = 1e-8;
00069 
00070 void displayImage(IplImage* image)
00071 {
00072   for (int i=0; i<image->height; i++)
00073   {
00074     for (int j=0; j<image->width; j++)
00075     {
00076       printf("%3u  ", *((unsigned char*)(image->imageData)+ i*image->widthStep + j));
00077     }
00078     printf("\n");
00079   }
00080 }
00081 
00082 TEST(CvLaserBridge, easy)
00083 {
00084   CvLaserBridge bridge;
00085 
00086   calibration_msgs::DenseLaserSnapshot snapshot;
00087 
00088   snapshot = buildSnapshot(100.0, 0.0, 1.0, NUM_SCANS, RAYS_PER_SCAN);
00089 
00090   bool result;
00091 
00092   result = bridge.fromIntensity(snapshot, 0, 49);
00093   IplImage* image = bridge.toIpl();
00094 
00095   ASSERT_TRUE(result);
00096   ASSERT_TRUE(image);
00097 
00098   EXPECT_EQ(image->height, (int) NUM_SCANS);
00099   EXPECT_EQ(image->width,  (int) RAYS_PER_SCAN);
00100 
00101   if (DEBUG)
00102     displayImage(image);
00103 
00104   
00105   EXPECT_EQ( (int) *((unsigned char*)(image->imageData)+0), 0);
00106   EXPECT_EQ( (int) *((unsigned char*)(image->imageData)+4*image->widthStep + 9), 255);
00107 }
00108 
00109 TEST(CvLaserBridge, saturationTest)
00110 {
00111   CvLaserBridge bridge;
00112   calibration_msgs::DenseLaserSnapshot snapshot;
00113   snapshot = buildSnapshot(100.0, 0.0, 1.0, NUM_SCANS, RAYS_PER_SCAN);
00114 
00115   bool result;
00116   result = bridge.fromIntensity(snapshot, 10, 20);
00117   IplImage* image = bridge.toIpl();
00118   ASSERT_TRUE(result);
00119   ASSERT_TRUE(image);
00120 
00121   EXPECT_EQ(image->height, (int) NUM_SCANS);
00122   EXPECT_EQ(image->width,  (int) RAYS_PER_SCAN);
00123 
00124   if (DEBUG)
00125     displayImage(image);
00126 
00127   
00128   EXPECT_EQ( (int) *((unsigned char*)(image->imageData)+5), 0);
00129   EXPECT_EQ( (int) *((unsigned char*)(image->imageData)+45), 255);
00130 }
00131 
00132 
00133 
00134 int main(int argc, char **argv){
00135   testing::InitGoogleTest(&argc, argv);
00136   return RUN_ALL_TESTS();
00137 }