cspace3_cache.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2014-2017, the neonavigation authors
00003  * All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions are met:
00007  *
00008  *     * Redistributions of source code must retain the above copyright
00009  *       notice, this list of conditions and the following disclaimer.
00010  *     * Redistributions in binary form must reproduce the above copyright
00011  *       notice, this list of conditions and the following disclaimer in the
00012  *       documentation and/or other materials provided with the distribution.
00013  *     * Neither the name of the copyright holder nor the names of its 
00014  *       contributors may be used to endorse or promote products derived from 
00015  *       this software without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00018  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00021  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00022  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00023  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00024  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00025  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00026  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00027  * POSSIBILITY OF SUCH DAMAGE.
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 }  // namespace costmap_cspace
00099 
00100 #endif  // COSTMAP_CSPACE_CSPACE3_CACHE_H


costmap_cspace
Author(s): Atsushi Watanabe
autogenerated on Sat Jun 22 2019 20:07:13