cost_interpretation_tables.cpp
Go to the documentation of this file.
1 /*
2  * Software License Agreement (BSD License)
3  *
4  * Copyright (c) 2018, Locus Robotics
5  * All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  *
11  * * Redistributions of source code must retain the above copyright
12  * notice, this list of conditions and the following disclaimer.
13  * * Redistributions in binary form must reproduce the above
14  * copyright notice, this list of conditions and the following
15  * disclaimer in the documentation and/or other materials provided
16  * with the distribution.
17  * * Neither the name of the copyright holder nor the names of its
18  * contributors may be used to endorse or promote products derived
19  * from this software without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25  * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
28  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
29  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
31  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32  * POSSIBILITY OF SUCH DAMAGE.
33  */
34 
36 #include <vector>
37 
38 namespace nav_grid_pub_sub
39 {
40 
41 std::vector<unsigned char> pixelColoringInterpretation(const double free_threshold, const double occupied_threshold)
42 {
43  std::vector<unsigned char> cost_interpretation_table(256);
44  for (unsigned int i = 0; i < cost_interpretation_table.size(); i++)
45  {
46  double intensity = static_cast<double>(i) / 255.0;
47  if (intensity > occupied_threshold)
48  {
49  cost_interpretation_table[i] = +100;
50  }
51  else if (intensity < free_threshold)
52  {
53  cost_interpretation_table[i] = 0;
54  }
55  else
56  {
57  cost_interpretation_table[i] = -1;
58  }
59  }
60  return cost_interpretation_table;
61 }
62 
63 std::vector<unsigned char> grayScaleInterpretation(const double free_threshold, const double occupied_threshold)
64 {
65  std::vector<unsigned char> cost_interpretation_table(256);
66  for (unsigned int i = 0; i < cost_interpretation_table.size(); i++)
67  {
68  double intensity = static_cast<double>(i) / 255.0;
69  if (intensity > occupied_threshold)
70  {
71  cost_interpretation_table[i] = +100;
72  }
73  else if (intensity < free_threshold)
74  {
75  cost_interpretation_table[i] = 0;
76  }
77  else
78  {
79  // scale from [free_threshold, occupied_threshold] to [1, 99]
80  cost_interpretation_table[i] = 99 * (intensity - free_threshold) / (occupied_threshold - free_threshold);
81  }
82  }
83  return cost_interpretation_table;
84 }
85 
86 std::vector<unsigned char> getOccupancyInput(bool trinary, bool use_unknown_value)
87 {
88  std::vector<unsigned char> cost_interpretation_table(256);
89  for (unsigned int i = 0; i < cost_interpretation_table.size(); i++)
90  {
91  unsigned char value;
92  if (use_unknown_value && i == 255)
93  value = 255;
94  else if (!use_unknown_value && i == 255)
95  value = 0;
96  else if (i >= 100)
97  value = 254;
98  else if (i == 99)
99  value = 253;
100  else if (trinary)
101  value = 0;
102  else
103  {
104  double scale = static_cast<double>(i) / 100.0;
105  value = static_cast<unsigned char>(scale * 254);
106  }
107  cost_interpretation_table[i] = value;
108  }
109  return cost_interpretation_table;
110 }
111 
112 } // namespace nav_grid_pub_sub
std::vector< unsigned char > pixelColoringInterpretation(const double free_threshold, const double occupied_threshold)
Above occupied_threshold is occupied, below free_threshold is free, and the middle gray is unknown...
std::vector< unsigned char > grayScaleInterpretation(const double free_threshold, const double occupied_threshold)
Above occupied_threshold is occupied, below free_threshold is free, and the middle is in between...
std::vector< unsigned char > getOccupancyInput(bool trinary=false, bool use_unknown_value=false)
Above 100 is occupied, -1 is sometimes unknown, and otherwise it is either scaled or freespace...


nav_grid_pub_sub
Author(s):
autogenerated on Sun Jan 10 2021 04:08:50