voxel_grid_main.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 <sys/time.h>
00039 #include <ros/console.h>
00040 
00041 int main(int argc, char *argv[]){
00042   ROS_INFO("Initializing voxel grid.\n");
00043   //int size_x = 50, size_y = 10, size_z = 5;
00044   int size_x = 1000, size_y = 1000, size_z = 5;
00045   voxel_grid::VoxelGrid *v = new voxel_grid::VoxelGrid(size_x, size_y, size_z);
00046 
00047   unsigned char *costMap = new unsigned char[size_x * size_y]; //initialize cost map
00048   for(int x = 0; x < size_x; x++){
00049     for(int y = 0; y < size_y; y++){
00050       costMap[y * size_x + x] = 128;
00051     }
00052   }
00053 
00054 
00055   //Put a "tabletop" into the scene.  A flat rectangle of set voxels at z = 12.
00056   int table_z = 1;
00057   int table_x_min = 5, table_x_max = 15;
00058   int table_y_min = 0, table_y_max = 3;
00059   for(int x = table_x_min; x <= table_x_max; x++){
00060     v->markVoxelLine(x, table_y_min, table_z, x, table_y_max, table_z);
00061   }
00062 
00063   struct timeval start, end;
00064   double start_t, end_t, t_diff;
00065   gettimeofday(&start, NULL);
00066   for(unsigned int j = 0; j < 1000; ++j){
00067     for(unsigned int i = 0; i < 700; ++i){
00068       //Add a few synthetic obstacles (diagonal line on the floor) just to demonstrate line drawing
00069       v->markVoxelLine(size_x - 1, size_y - 1, 0, 0, 0, 0);
00070     }
00071   }
00072   gettimeofday(&end, NULL);
00073   start_t = start.tv_sec + double(start.tv_usec) / 1e6;
00074   end_t = end.tv_sec + double(end.tv_usec) / 1e6;
00075   t_diff = end_t - start_t;
00076   ROS_INFO("Cycle time: %.9f\n", t_diff);
00077 
00078   //clear a scan next to the table (will clear obstacles out)
00079   v->clearVoxelLineInMap(table_x_max + 1, 0, table_z, table_x_max + 1, size_y - 1, table_z, costMap, 16, 0);
00080 
00081   //clear a scan over the table (will not clear obstacles out until it passes the edge of the table)
00082   v->clearVoxelLineInMap(table_x_min + 1, 0, table_z + 1, table_x_min + 1, size_y - 1, table_z, costMap, 16, 0);
00083 
00084   //clear a scan through the table (will only clear obstacles where it passes through the table
00085   v->clearVoxelLineInMap(table_x_min, table_y_min, 0, table_x_max, table_y_max, size_z - 1, costMap, 16, 0);
00086 
00087   //clear a scan that clears out a whole line of the table, to show that it doesnt clear out the diagonal line underneath it
00088   v->clearVoxelLineInMap(table_x_max - 2, 0, table_z, table_x_max - 2, size_y - 1, table_z, costMap, 16, 0);
00089 
00090   //Visualize the output
00091   /*
00092      v->printVoxelGrid();
00093      v->printColumnGrid();
00094 
00095      printf("CostMap:\n===========\n");
00096      for(int y = 0; y < size_y; y++){
00097      for(int x = 0; x < size_x; x++){
00098      printf((costMap[y * size_x + x] > 0 ? "#" : " "));
00099      }printf("|\n");
00100      }
00101      */
00102 }


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