motion_cache.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2018-2019, 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 PLANNER_CSPACE_PLANNER_3D_MOTION_CACHE_H
31 #define PLANNER_CSPACE_PLANNER_3D_MOTION_CACHE_H
32 
33 #include <memory>
34 #include <unordered_map>
35 #include <vector>
36 
38 
39 namespace planner_cspace
40 {
41 namespace planner_3d
42 {
44 {
45 public:
46  class Page
47  {
48  protected:
49  friend class MotionCache;
50 
51  std::vector<CyclicVecInt<3, 2>> motion_;
52  float distance_;
53 
54  public:
55  inline float getDistance() const
56  {
57  return distance_;
58  }
59  const std::vector<CyclicVecInt<3, 2>>& getMotion() const
60  {
61  return motion_;
62  }
63  };
64 
65  using Cache =
66  std::unordered_map<CyclicVecInt<3, 2>, Page, CyclicVecInt<3, 2>>;
67 
68  using Ptr = std::shared_ptr<MotionCache>;
69 
70  inline const typename Cache::const_iterator find(
71  const int start_yaw,
72  const CyclicVecInt<3, 2>& goal) const
73  {
74  int i = start_yaw % page_size_;
75  if (i < 0)
76  i += page_size_;
77  return cache_[i].find(goal);
78  }
79  inline const typename Cache::const_iterator end(
80  const int start_yaw) const
81  {
82  int i = start_yaw % page_size_;
83  if (i < 0)
84  i += page_size_;
85  return cache_[i].cend();
86  }
87 
88  inline const CyclicVecInt<3, 2>& getMaxRange() const
89  {
90  return max_range_;
91  }
92 
93  void reset(
94  const float linear_resolution,
95  const float angular_resolution,
96  const int range,
97  const std::function<void(CyclicVecInt<3, 2>, size_t&, size_t&)> gm_addr);
98 
99 protected:
100  std::vector<Cache> cache_;
102  CyclicVecInt<3, 2> max_range_;
103 };
104 } // namespace planner_3d
105 } // namespace planner_cspace
106 
107 #endif // PLANNER_CSPACE_PLANNER_3D_MOTION_CACHE_H
const Cache::const_iterator end(const int start_yaw) const
Definition: motion_cache.h:79
const CyclicVecInt< 3, 2 > & getMaxRange() const
Definition: motion_cache.h:88
std::vector< CyclicVecInt< 3, 2 > > motion_
Definition: motion_cache.h:51
void reset(const float linear_resolution, const float angular_resolution, const int range, const std::function< void(CyclicVecInt< 3, 2 >, size_t &, size_t &)> gm_addr)
const std::vector< CyclicVecInt< 3, 2 > > & getMotion() const
Definition: motion_cache.h:59
std::unordered_map< CyclicVecInt< 3, 2 >, Page, CyclicVecInt< 3, 2 >> Cache
Definition: motion_cache.h:66
std::shared_ptr< MotionCache > Ptr
Definition: motion_cache.h:68
const Cache::const_iterator find(const int start_yaw, const CyclicVecInt< 3, 2 > &goal) const
Definition: motion_cache.h:70


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Wed May 12 2021 02:20:42