rotation_cache.cpp
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 #include <cmath>
31 #include <memory>
32 #include <utility>
33 #include <vector>
34 
36 
38 
40 {
41  size_t ser_size = 1;
42  for (int i = 0; i < 3; i++)
43  ser_size *= size[i];
44 
45  size_ = size;
46  ser_size_ = ser_size;
47 
48  c_.reset(new CyclicVecFloat<3, 2>[ser_size]);
49  r_.reset(new std::pair<float, float>[ser_size]);
50 }
51 
53  const float linear_resolution,
54  const float angular_resolution,
55  const int range)
56 {
57  const int angle = std::lround(M_PI * 2 / angular_resolution);
58 
59  pages_.resize(angle);
60  for (int i = 0; i < angle; i++)
61  {
62  Page& r = pages_[i];
63  r.reset(CyclicVecInt<3, 2>(range * 2 + 1, range * 2 + 1, angle));
64 
66 
67  for (d[0] = 0; d[0] <= range * 2; d[0]++)
68  {
69  for (d[1] = 0; d[1] <= range * 2; d[1]++)
70  {
71  for (d[2] = 0; d[2] < angle; d[2]++)
72  {
73  auto v = CyclicVecFloat<3, 2>(
74  (d[0] - range) * linear_resolution,
75  (d[1] - range) * linear_resolution,
76  d[2] * angular_resolution);
77  v.rotate(-i * angular_resolution);
78  r.motion(d) = v;
79 
80  const float sin_v = std::sin(v[2]);
81  const float cos_v = std::cos(v[2]);
82  const float r1 = v[1] + v[0] * cos_v / sin_v;
83  const float r2 = std::copysign(
84  sqrtf(powf(v[0], 2.0) + powf(v[0] * cos_v / sin_v, 2.0)),
85  v[0] * sin_v);
86  r.radiuses(d) = std::pair<float, float>(r1, r2);
87  }
88  }
89  }
90  }
91 }
d
std::vector< Page > pages_
CyclicVecFloat< 3, 2 > & motion(const CyclicVecInt< 3, 2 > &pos)
void rotate(const float ang)
Definition: cyclic_vec.h:258
CyclicVecInt< 3, 2 > size_
TFSIMD_FORCE_INLINE tfScalar angle(const Quaternion &q1, const Quaternion &q2)
std::unique_ptr< CyclicVecFloat< 3, 2 >[]> c_
std::unique_ptr< std::pair< float, float >[]> r_
void reset(const CyclicVecInt< 3, 2 > &size)
std::pair< float, float > & radiuses(const CyclicVecInt< 3, 2 > &pos)
void reset(const float linear_resolution, const float angular_resolution, const int range)


planner_cspace
Author(s): Atsushi Watanabe
autogenerated on Tue Jul 9 2019 05:00:13