cspace3_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014-2017, the neonavigation authors
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions are met:
7  *
8  * * Redistributions of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  * * Redistributions in binary form must reproduce the above copyright
11  * notice, this list of conditions and the following disclaimer in the
12  * documentation and/or other materials provided with the distribution.
13  * * Neither the name of the copyright holder nor the names of its
14  * contributors may be used to endorse or promote products derived from
15  * this software without specific prior written permission.
16  *
17  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
21  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
22  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
23  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
24  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
25  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
26  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
27  * POSSIBILITY OF SUCH DAMAGE.
28  */
29 
30 #ifndef COSTMAP_CSPACE_CSPACE3_CACHE_H
31 #define COSTMAP_CSPACE_CSPACE3_CACHE_H
32 
33 #include <memory>
34 
35 #include <ros/ros.h>
36 
37 namespace costmap_cspace
38 {
40 {
41 protected:
42  std::unique_ptr<char[]> c_;
43  int size_[3];
44  int center_[3];
45  int stride_[3];
46  size_t array_size_;
47 
48 public:
50  : c_(nullptr)
51  , array_size_(0)
52  {
53  size_[0] = size_[1] = size_[2] = 0;
54  center_[0] = center_[1] = center_[2] = 0;
55  stride_[0] = stride_[1] = stride_[2] = 0;
56  }
57  void reset(const int& x, const int& y, const int& yaw)
58  {
59  size_[0] = x * 2 + 1;
60  size_[1] = y * 2 + 1;
61  size_[2] = yaw;
62  center_[0] = x;
63  center_[1] = y;
64  center_[2] = 0;
65  array_size_ = size_[0] * size_[1] * size_[2];
66  c_.reset(new char[array_size_]);
67  memset(c_.get(), 0, array_size_ * sizeof(char));
68  stride_[0] = 1;
69  stride_[1] = size_[0];
70  stride_[2] = size_[0] * size_[1];
71  }
72 
73  char& e(const int& x, const int& y, const int& yaw)
74  {
75  const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
76  ROS_ASSERT(addr < array_size_);
77 
78  return c_[addr];
79  }
80  const char& e(const int& x, const int& y, const int& yaw) const
81  {
82  const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
83  ROS_ASSERT(addr < array_size_);
84 
85  return c_[addr];
86  }
87  void getSize(int& x, int& y, int& a) const
88  {
89  x = size_[0];
90  y = size_[1];
91  a = size_[2];
92  }
93  void getCenter(int& x, int& y, int& a) const
94  {
95  x = center_[0];
96  y = center_[1];
97  a = center_[2];
98  }
99 };
100 } // namespace costmap_cspace
101 
102 #endif // COSTMAP_CSPACE_CSPACE3_CACHE_H
void getCenter(int &x, int &y, int &a) const
Definition: cspace3_cache.h:93
std::unique_ptr< char[]> c_
Definition: cspace3_cache.h:42
void getSize(int &x, int &y, int &a) const
Definition: cspace3_cache.h:87
const char & e(const int &x, const int &y, const int &yaw) const
Definition: cspace3_cache.h:80
void reset(const int &x, const int &y, const int &yaw)
Definition: cspace3_cache.h:57
#define ROS_ASSERT(cond)
char & e(const int &x, const int &y, const int &yaw)
Definition: cspace3_cache.h:73


costmap_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:29