Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #ifndef COSTMAP_CSPACE_CSPACE3_CACHE_H
00031 #define COSTMAP_CSPACE_CSPACE3_CACHE_H
00032
00033 #include <ros/ros.h>
00034
00035 namespace costmap_cspace
00036 {
00037 class CSpace3Cache
00038 {
00039 protected:
00040 std::unique_ptr<char[]> c_;
00041 int size_[3];
00042 int center_[3];
00043 int stride_[3];
00044 size_t array_size_;
00045
00046 public:
00047 CSpace3Cache()
00048 : c_(nullptr)
00049 , array_size_(0)
00050 {
00051 size_[0] = size_[1] = size_[2] = 0;
00052 center_[0] = center_[1] = center_[2] = 0;
00053 stride_[0] = stride_[1] = stride_[2] = 0;
00054 }
00055 void reset(const int& x, const int& y, const int& yaw)
00056 {
00057 size_[0] = x * 2 + 1;
00058 size_[1] = y * 2 + 1;
00059 size_[2] = yaw;
00060 center_[0] = x;
00061 center_[1] = y;
00062 center_[2] = 0;
00063 array_size_ = size_[0] * size_[1] * size_[2];
00064 c_.reset(new char[array_size_]);
00065 memset(c_.get(), 0, array_size_ * sizeof(char));
00066 stride_[0] = 1;
00067 stride_[1] = size_[0];
00068 stride_[2] = size_[0] * size_[1];
00069 }
00070
00071 char& e(const int& x, const int& y, const int& yaw)
00072 {
00073 const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
00074 ROS_ASSERT(addr < array_size_);
00075
00076 return c_[addr];
00077 }
00078 const char& e(const int& x, const int& y, const int& yaw) const
00079 {
00080 const size_t addr = yaw * stride_[2] + (y + center_[1]) * stride_[1] + (x + center_[0]);
00081 ROS_ASSERT(addr < array_size_);
00082
00083 return c_[addr];
00084 }
00085 void getSize(int& x, int& y, int& a) const
00086 {
00087 x = size_[0];
00088 y = size_[1];
00089 a = size_[2];
00090 }
00091 void getCenter(int& x, int& y, int& a) const
00092 {
00093 x = center_[0];
00094 y = center_[1];
00095 a = center_[2];
00096 }
00097 };
00098 }
00099
00100 #endif // COSTMAP_CSPACE_CSPACE3_CACHE_H