map_draw.c
Go to the documentation of this file.
1 //this package is based on amcl and has been modified to fit gmcl
2 /*
3  * Author: Mhd Ali Alshikh Khalil
4  * Date: 20 June 2021
5  *
6 */
7 
8 //amcl author clarification
9 /*
10  * Player - One Hell of a Robot Server
11  * Copyright (C) 2000 Brian Gerkey & Kasper Stoy
12  * gerkey@usc.edu kaspers@robotics.usc.edu
13  *
14  * This library is free software; you can redistribute it and/or
15  * modify it under the terms of the GNU Lesser General Public
16  * License as published by the Free Software Foundation; either
17  * version 2.1 of the License, or (at your option) any later version.
18  *
19  * This library is distributed in the hope that it will be useful,
20  * but WITHOUT ANY WARRANTY; without even the implied warranty of
21  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22  * Lesser General Public License for more details.
23  *
24  * You should have received a copy of the GNU Lesser General Public
25  * License along with this library; if not, write to the Free Software
26  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
27  *
28  */
29 /**************************************************************************
30  * Desc: Local map GUI functions
31  * Author: Andrew Howard
32  * Date: 18 Jan 2003
33  * CVS: $Id: map_draw.c 7057 2008-10-02 00:44:06Z gbiggs $
34 **************************************************************************/
35 
36 #ifdef INCLUDE_RTKGUI
37 
38 #include <errno.h>
39 #include <math.h>
40 #include <stdlib.h>
41 #include <string.h>
42 
43 #include <rtk.h>
44 #include "gmcl/map/map.h"
45 
46 
48 // Draw the occupancy map
49 void map_draw_occ(map_t *map, rtk_fig_t *fig)
50 {
51  int i, j;
52  int col;
53  map_cell_t *cell;
54  uint16_t *image;
55  uint16_t *pixel;
56 
57  image = malloc(map->size_x * map->size_y * sizeof(image[0]));
58 
59  // Draw occupancy
60  for (j = 0; j < map->size_y; j++)
61  {
62  for (i = 0; i < map->size_x; i++)
63  {
64  cell = map->cells + MAP_INDEX(map, i, j);
65  pixel = image + (j * map->size_x + i);
66 
67  col = 127 - 127 * cell->occ_state;
68  *pixel = RTK_RGB16(col, col, col);
69  }
70  }
71 
72  // Draw the entire occupancy map as an image
73  rtk_fig_image(fig, map->origin_x, map->origin_y, 0,
74  map->scale, map->size_x, map->size_y, 16, image, NULL);
75 
76  free(image);
77 
78  return;
79 }
80 
81 
83 // Draw the cspace map
84 void map_draw_cspace(map_t *map, rtk_fig_t *fig)
85 {
86  int i, j;
87  int col;
88  map_cell_t *cell;
89  uint16_t *image;
90  uint16_t *pixel;
91 
92  image = malloc(map->size_x * map->size_y * sizeof(image[0]));
93 
94  // Draw occupancy
95  for (j = 0; j < map->size_y; j++)
96  {
97  for (i = 0; i < map->size_x; i++)
98  {
99  cell = map->cells + MAP_INDEX(map, i, j);
100  pixel = image + (j * map->size_x + i);
101 
102  col = 255 * cell->occ_dist / map->max_occ_dist;
103 
104  *pixel = RTK_RGB16(col, col, col);
105  }
106  }
107 
108  // Draw the entire occupancy map as an image
109  rtk_fig_image(fig, map->origin_x, map->origin_y, 0,
110  map->scale, map->size_x, map->size_y, 16, image, NULL);
111 
112  free(image);
113 
114  return;
115 }
116 
117 
119 // Draw a wifi map
120 void map_draw_wifi(map_t *map, rtk_fig_t *fig, int index)
121 {
122  int i, j;
123  int level, col;
124  map_cell_t *cell;
125  uint16_t *image, *mask;
126  uint16_t *ipix, *mpix;
127 
128  image = malloc(map->size_x * map->size_y * sizeof(image[0]));
129  mask = malloc(map->size_x * map->size_y * sizeof(mask[0]));
130 
131  // Draw wifi levels
132  for (j = 0; j < map->size_y; j++)
133  {
134  for (i = 0; i < map->size_x; i++)
135  {
136  cell = map->cells + MAP_INDEX(map, i, j);
137  ipix = image + (j * map->size_x + i);
138  mpix = mask + (j * map->size_x + i);
139 
140  level = cell->wifi_levels[index];
141 
142  if (cell->occ_state == -1 && level != 0)
143  {
144  col = 255 * (100 + level) / 100;
145  *ipix = RTK_RGB16(col, col, col);
146  *mpix = 1;
147  }
148  else
149  {
150  *mpix = 0;
151  }
152  }
153  }
154 
155  // Draw the entire occupancy map as an image
156  rtk_fig_image(fig, map->origin_x, map->origin_y, 0,
157  map->scale, map->size_x, map->size_y, 16, image, mask);
158 
159  free(mask);
160  free(image);
161 
162  return;
163 }
164 
165 
166 #endif
map_draw_wifi
void map_draw_wifi(map_t *map, struct _rtk_fig_t *fig, int index)
map_t::max_occ_dist
double max_occ_dist
Definition: map.h:83
map_cell_t::occ_dist
double occ_dist
Definition: map.h:58
map_t::origin_x
double origin_x
Definition: map.h:70
map_t::cells
map_cell_t * cells
Definition: map.h:79
map_cell_t::occ_state
int occ_state
Definition: map.h:55
MAP_INDEX
#define MAP_INDEX(map, i, j)
Definition: map.h:207
map.h
map_t::scale
double scale
Definition: map.h:73
map_draw_occ
void map_draw_occ(map_t *map, struct _rtk_fig_t *fig)
map_t::size_x
int size_x
Definition: map.h:76
map_t
Definition: map.h:67
map_t::size_y
int size_y
Definition: map.h:76
map_t::origin_y
double origin_y
Definition: map.h:70
map_draw_cspace
void map_draw_cspace(map_t *map, struct _rtk_fig_t *fig)
map_cell_t
Definition: map.h:52


gmcl
Author(s): Mhd Ali Alshikh Khalil, adler1994@gmail.com
autogenerated on Wed Mar 2 2022 00:20:14