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