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 <ros/ros.h>
34 
35 namespace costmap_cspace
36 {
38 {
39 protected:
40  std::unique_ptr<char[]> c_;
41  int size_[3];
42  int center_[3];
43  int stride_[3];
44  size_t array_size_;
45 
46 public:
48  : c_(nullptr)
49  , array_size_(0)
50  {
51  size_[0] = size_[1] = size_[2] = 0;
52  center_[0] = center_[1] = center_[2] = 0;
53  stride_[0] = stride_[1] = stride_[2] = 0;
54  }
55  void reset(const int& x, const int& y, const int& yaw)
56  {
57  size_[0] = x * 2 + 1;
58  size_[1] = y * 2 + 1;
59  size_[2] = yaw;
60  center_[0] = x;
61  center_[1] = y;
62  center_[2] = 0;
63  array_size_ = size_[0] * size_[1] * size_[2];
64  c_.reset(new char[array_size_]);
65  memset(c_.get(), 0, array_size_ * sizeof(char));
66  stride_[0] = 1;
67  stride_[1] = size_[0];
68  stride_[2] = size_[0] * size_[1];
69  }
70 
71  char& e(const int& x, const int& y, const int& yaw)
72  {
73  const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
74  ROS_ASSERT(addr < array_size_);
75 
76  return c_[addr];
77  }
78  const char& e(const int& x, const int& y, const int& yaw) const
79  {
80  const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
81  ROS_ASSERT(addr < array_size_);
82 
83  return c_[addr];
84  }
85  void getSize(int& x, int& y, int& a) const
86  {
87  x = size_[0];
88  y = size_[1];
89  a = size_[2];
90  }
91  void getCenter(int& x, int& y, int& a) const
92  {
93  x = center_[0];
94  y = center_[1];
95  a = center_[2];
96  }
97 };
98 } // namespace costmap_cspace
99 
100 #endif // COSTMAP_CSPACE_CSPACE3_CACHE_H
void getCenter(int &x, int &y, int &a) const
Definition: cspace3_cache.h:91
std::unique_ptr< char[]> c_
Definition: cspace3_cache.h:40
void getSize(int &x, int &y, int &a) const
Definition: cspace3_cache.h:85
const char & e(const int &x, const int &y, const int &yaw) const
Definition: cspace3_cache.h:78
void reset(const int &x, const int &y, const int &yaw)
Definition: cspace3_cache.h:55
#define ROS_ASSERT(cond)
char & e(const int &x, const int &y, const int &yaw)
Definition: cspace3_cache.h:71


costmap_cspace
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 04:59:48