three_dimensional_lidar_frustum.cpp
Go to the documentation of this file.
1 /*********************************************************************
2  *
3  * Software License Agreement
4  *
5  * Copyright (c) 2018, Simbe Robotics, Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * * Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  * * Redistributions in binary form must reproduce the above
15  * copyright notice, this list of conditions and the following
16  * disclaimer in the documentation and/or other materials provided
17  * with the distribution.
18  * * Neither the name of Simbe Robotics, Inc. nor the names of its
19  * contributors may be used to endorse or promote products derived
20  * from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26  * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
28  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
32  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  *
35  * Author: Nicolas Varas (nicovaras@gmail.com)
36  *********************************************************************/
37 
39 
40 namespace geometry
41 {
42 
43 /*****************************************************************************/
45  const double& vFOVPadding,
46  const double& hFOV,
47  const double& min_dist,
48  const double& max_dist)
49  : _vFOV(vFOV),
50  _vFOVPadding(vFOVPadding),
51  _hFOV(hFOV),
52  _min_d(min_dist),
53  _max_d(max_dist)
54 /*****************************************************************************/
55 {
56  _hFOVhalf = _hFOV / 2.0;
57  _tan_vFOVhalf = tan(_vFOV / 2.0);
61  _full_hFOV = false;
62  if (_hFOV > 6.27)
63  {
64  _full_hFOV = true;
65  }
66 }
67 
68 /*****************************************************************************/
70 /*****************************************************************************/
71 {
72 }
73 
74 /*****************************************************************************/
76 /*****************************************************************************/
77 {
79  _valid_frustum = true;
80 }
81 
82 /*****************************************************************************/
83 bool ThreeDimensionalLidarFrustum::IsInside(const openvdb::Vec3d &pt)
84 /*****************************************************************************/
85 {
86 
87  Eigen::Vector3d point_in_global_frame(pt[0], pt[1], pt[2]);
88  Eigen::Vector3d transformed_pt =
89  _orientation_conjugate * (point_in_global_frame - _position);
90 
91  const double radial_distance_squared = \
92  (transformed_pt[0] * transformed_pt[0]) + \
93  (transformed_pt[1] * transformed_pt[1]);
94 
95  // Check if inside frustum valid range
96  if (radial_distance_squared > _max_d_squared ||
97  radial_distance_squared < _min_d_squared)
98  {
99  return false;
100  }
101 
102  // // Check if inside frustum valid vFOV
103  const double v_padded = fabs(transformed_pt[2]) + _vFOVPadding;
104  if (( v_padded * v_padded / radial_distance_squared) > _tan_vFOVhalf_squared)
105  {
106  return false;
107  }
108 
109  // Check if inside frustum valid hFOV, unless hFOV is full-circle (360 degree)
110  if (!_full_hFOV)
111  {
112  if (transformed_pt[0] > 0)
113  {
114  if (fabs(atan(transformed_pt[1] / transformed_pt[0])) > _hFOVhalf)
115  {
116  return false;
117  }
118  }
119  else if ( \
120  fabs(atan(transformed_pt[0] / transformed_pt[1])) + M_PI/2 > _hFOVhalf)
121  {
122  return false;
123  }
124  }
125 
126  return true;
127 }
128 
129 /*****************************************************************************/
131  geometry_msgs::Point& origin)
132 /*****************************************************************************/
133 {
134  _position = Eigen::Vector3d(origin.x, origin.y, origin.z);
135 }
136 
137 /*****************************************************************************/
139  geometry_msgs::Quaternion& quat)
140 /*****************************************************************************/
141 {
142  _orientation = Eigen::Quaterniond(quat.w, quat.x, quat.y, quat.z);
143 }
144 
145 /*****************************************************************************/
147  const openvdb::Vec3d &query_pt) const
148 /*****************************************************************************/
149 {
150  return plane_pt.x*query_pt[0]+plane_pt.y*query_pt[1]+plane_pt.z*query_pt[2];
151 }
152 
153 /*****************************************************************************/
155  const Eigen::Vector3d &query_pt) const
156 /*****************************************************************************/
157 {
158  return plane_pt.x*query_pt[0]+plane_pt.y*query_pt[1]+plane_pt.z*query_pt[2];
159 }
160 
161 } // namespace geometry
ThreeDimensionalLidarFrustum(const double &vFOV, const double &vFOVPadding, const double &hFOV, const double &min_dist, const double &max_dist)
double Dot(const VectorWithPt3D &, const openvdb::Vec3d &) const
virtual void SetPosition(const geometry_msgs::Point &origin)
virtual bool IsInside(const openvdb::Vec3d &pt)
virtual void SetOrientation(const geometry_msgs::Quaternion &quat)


spatio_temporal_voxel_layer
Author(s):
autogenerated on Sat Dec 21 2019 04:06:19