voxel_grid_tests.cpp
Go to the documentation of this file.
00001 /*********************************************************************
00002 *
00003 * Software License Agreement (BSD License)
00004 *
00005 *  Copyright (c) 2009, Willow Garage, Inc.
00006 *  All rights reserved.
00007 *
00008 *  Redistribution and use in source and binary forms, with or without
00009 *  modification, are permitted provided that the following conditions
00010 *  are met:
00011 *
00012 *   * Redistributions of source code must retain the above copyright
00013 *     notice, this list of conditions and the following disclaimer.
00014 *   * Redistributions in binary form must reproduce the above
00015 *     copyright notice, this list of conditions and the following
00016 *     disclaimer in the documentation and/or other materials provided
00017 *     with the distribution.
00018 *   * Neither the name of Willow Garage, Inc. nor the names of its
00019 *     contributors may be used to endorse or promote products derived
00020 *     from this software without specific prior written permission.
00021 *
00022 *  THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
00023 *  "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
00024 *  LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
00025 *  FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
00026 *  COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
00027 *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
00028 *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
00029 *  LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00030 *  CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00031 *  LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
00032 *  ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00033 *  POSSIBILITY OF SUCH DAMAGE.
00034 *
00035 * Author: Eitan Marder-Eppstein
00036 *********************************************************************/
00037 #include <voxel_grid/voxel_grid.h>
00038 #include <gtest/gtest.h>
00039 
00040 TEST(voxel_grid, basicMarkingAndClearing){
00041   int size_x = 50, size_y = 10, size_z = 16;
00042   voxel_grid::VoxelGrid vg(size_x, size_y, size_z);
00043 
00044   //Put a "tabletop" into the scene.  A flat rectangle of set voxels at z = 12.
00045   int table_z = 12;
00046   int table_x_min = 5, table_x_max = 15;
00047   int table_y_min = 0, table_y_max = 3;
00048   for(int x = table_x_min; x <= table_x_max; x++){
00049     vg.markVoxelLine(x, table_y_min, table_z, x, table_y_max, table_z);
00050   }
00051 
00052   for(int i = table_x_min; i <= table_x_max; ++i){
00053     for(int j = table_y_min; j <= table_y_max; ++j){
00054       //check that each cell of the table is marked
00055       ASSERT_EQ(voxel_grid::MARKED, vg.getVoxel(i, j, table_z));
00056     }
00057   }
00058 
00059   int mark_count = 0;
00060   unsigned int unknown_count = 0;
00061   //go through each cell in the voxel grid and make sure that only 44 are filled in
00062   for(unsigned int i = 0; i < vg.sizeX(); ++i){
00063     for(unsigned int j = 0; j < vg.sizeY(); ++j){
00064       for(unsigned int k = 0; k < vg.sizeZ(); ++k){
00065         if(vg.getVoxel(i, j, k) == voxel_grid::MARKED){
00066           mark_count++;
00067         }
00068         else if(vg.getVoxel(i, j, k) == voxel_grid::UNKNOWN){
00069           unknown_count++;
00070         }
00071       }
00072     }
00073   }
00074   ASSERT_EQ(mark_count, 44);
00075 
00076   //the rest of the cells should be unknown
00077   ASSERT_EQ(unknown_count, vg.sizeX() * vg.sizeY() * vg.sizeZ() - 44);
00078 
00079   //now, let's clear one of the rows of the table
00080   vg.clearVoxelLine(table_x_min, table_y_min, table_z, table_x_max, table_y_min, table_z);
00081 
00082   mark_count = 0;
00083   unknown_count = 0;
00084   int free_count = 0;
00085   //go through each cell in the voxel grid and make sure that only 33 are now filled in
00086   for(unsigned int i = 0; i < vg.sizeX(); ++i){
00087     for(unsigned int j = 0; j < vg.sizeY(); ++j){
00088       for(unsigned int k = 0; k < vg.sizeZ(); ++k){
00089         if(vg.getVoxel(i, j, k) == voxel_grid::MARKED){
00090           mark_count++;
00091         }
00092         else if(vg.getVoxel(i, j, k) == voxel_grid::FREE){
00093           free_count++;
00094         }
00095         else if(vg.getVoxel(i, j, k) == voxel_grid::UNKNOWN){
00096           unknown_count++;
00097         }
00098       }
00099     }
00100   }
00101 
00102   //we've switched 11 cells from marked to free
00103   ASSERT_EQ(mark_count, 33);
00104 
00105   //we've just explicitly seen through 11 cells
00106   ASSERT_EQ(free_count, 11);
00107 
00108   //the rest of the cells should still be unknown
00109   ASSERT_EQ(unknown_count, vg.sizeX() * vg.sizeY() * vg.sizeZ() - 44);
00110 
00111   //now let's put in a vertical column manually to test markVoxel
00112   for(unsigned int i = 0; i < vg.sizeZ(); ++i){
00113     vg.markVoxel(0, 0, i);
00114     ASSERT_EQ(vg.getVoxel(0, 0, i), voxel_grid::MARKED);
00115   }
00116 
00117   vg.printColumnGrid();
00118   vg.printVoxelGrid();
00119 
00120   //now, let's clear that line of voxels and make sure that they clear out OK
00121   vg.clearVoxelLine(0, 0, 0, 0, 0, vg.sizeZ() - 1);
00122 
00123   for(unsigned int i = 0; i < vg.sizeZ(); ++i){
00124     ASSERT_EQ(vg.getVoxel(0, 0, i), voxel_grid::FREE);
00125   }
00126 
00127   mark_count = 0;
00128 
00129 
00130 }
00131 
00132 int main(int argc, char** argv){
00133   testing::InitGoogleTest(&argc, argv);
00134   return RUN_ALL_TESTS();
00135 }


voxel_grid
Author(s): Eitan Marder-Eppstein, Eric Berger
autogenerated on Mon Oct 6 2014 02:44:13