Fawkes API  Fawkes Development Version
map.c
00001 
00002 /***************************************************************************
00003  *  map.h: Global map (grid-based)
00004  *
00005  *  Created: Thu May 24 18:44:56 2012
00006  *  Copyright  2000  Brian Gerkey
00007  *             2000  Kasper Stoy
00008  *             2012  Tim Niemueller [www.niemueller.de]
00009  ****************************************************************************/
00010 
00011 /*  This program is free software; you can redistribute it and/or modify
00012  *  it under the terms of the GNU General Public License as published by
00013  *  the Free Software Foundation; either version 2 of the License, or
00014  *  (at your option) any later version.
00015  *
00016  *  This program is distributed in the hope that it will be useful,
00017  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00018  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00019  *  GNU Library General Public License for more details.
00020  *
00021  *  Read the full text in the LICENSE.GPL file in the doc directory.
00022  */
00023 
00024 /*  From:
00025  *  Player - One Hell of a Robot Server (LGPL)
00026  *  Copyright (C) 2000  Brian Gerkey   &  Kasper Stoy
00027  *                      gerkey@usc.edu    kaspers@robotics.usc.edu
00028  */
00029 /**************************************************************************
00030  * Desc: Global map (grid-based)
00031  * Author: Andrew Howard
00032  * Date: 6 Feb 2003
00033  **************************************************************************/
00034 
00035 #include <math.h>
00036 #include <stdlib.h>
00037 #include <string.h>
00038 #include <stdio.h>
00039 
00040 #include "map.h"
00041 
00042 /// @cond EXTERNAL
00043 
00044 // Create a new map
00045 map_t *map_alloc(void)
00046 {
00047   map_t *map;
00048 
00049   map = (map_t*) malloc(sizeof(map_t));
00050 
00051   // Assume we start at (0, 0)
00052   map->origin_x = 0;
00053   map->origin_y = 0;
00054   
00055   // Make the size odd
00056   map->size_x = 0;
00057   map->size_y = 0;
00058   map->scale = 0;
00059   
00060   // Allocate storage for main map
00061   map->cells = (map_cell_t*) NULL;
00062   
00063   return map;
00064 }
00065 
00066 
00067 // Destroy a map
00068 void map_free(map_t *map)
00069 {
00070   free(map->cells);
00071   free(map);
00072   return;
00073 }
00074 
00075 
00076 // Get the cell at the given point
00077 map_cell_t *map_get_cell(map_t *map, double ox, double oy, double oa)
00078 {
00079   int i, j;
00080   map_cell_t *cell;
00081 
00082   i = MAP_GXWX(map, ox);
00083   j = MAP_GYWY(map, oy);
00084   
00085   if (!MAP_VALID(map, i, j))
00086     return NULL;
00087 
00088   cell = map->cells + MAP_INDEX(map, i, j);
00089   return cell;
00090 }
00091 
00092 /// @endcond