Autoware.Auto
voxels.hpp
Go to the documentation of this file.
1 // Copyright 2017-2019 the Autoware Foundation
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 //    http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14 //
15 // Co-developed by Tier IV, Inc. and Apex.AI, Inc.
16 
19 
20 #ifndef VOXEL_GRID__VOXELS_HPP_
21 #define VOXEL_GRID__VOXELS_HPP_
22 
23 #include "common/types.hpp"
24 #include "voxel_grid/config.hpp"
26 #include "voxel_grid/voxel.hpp"
27 
28 namespace autoware
29 {
30 namespace perception
31 {
32 namespace filters
33 {
34 namespace voxel_grid
35 {
36 
39 
45 template<typename PointT>
46 VOXEL_GRID_PUBLIC PointT operator+(const PointT & lhs, const PointT & rhs)
47 {
48  PointT ret = lhs;
49  ret.x += rhs.x;
50  ret.y += rhs.y;
51  ret.z += rhs.z;
52  return ret;
53 }
54 
60 template<typename PointT>
61 VOXEL_GRID_PUBLIC PointT operator*(const PointT & lhs, const float32_t rhs)
62 {
63  PointT ret = lhs;
64  ret.x *= rhs;
65  ret.y *= rhs;
66  ret.z *= rhs;
67  return ret;
68 }
69 
74 template<>
75 inline VOXEL_GRID_PUBLIC PointXYZIF operator+(
76  //lint -e{9073} NOLINT This is a template specialization, not a token mismatch
77  const PointXYZIF & lhs,
78  //lint -e{9073} NOLINT This is a template specialization, not a token mismatch
79  const PointXYZIF & rhs)
80 {
81  PointXYZIF ret = lhs;
82  ret.x += rhs.x;
83  ret.y += rhs.y;
84  ret.z += rhs.z;
85  ret.intensity += rhs.intensity;
86  return ret;
87 }
92 template<>
93 inline VOXEL_GRID_PUBLIC PointXYZIF operator*(
94  //lint -e{9073} NOLINT This is a template specialization, not a token mismatch
95  const PointXYZIF & lhs,
96  const float32_t rhs)
97 {
98  PointXYZIF ret = lhs;
99  ret.x *= rhs;
100  ret.y *= rhs;
101  ret.z *= rhs;
102  ret.intensity *= rhs;
103  return ret;
104 }
105 
114 template<typename PointT>
115 class VOXEL_GRID_PUBLIC CentroidVoxel : public Voxel<PointT>
116 {
117 public:
118  using Voxel<PointT>::Voxel;
121  void add_observation(const PointT & pt)
122  {
123  const float32_t last = static_cast<float32_t>(Voxel<PointT>::count());
125  const float32_t count_inv = 1.0F / static_cast<float32_t>(Voxel<PointT>::count());
126  // Incremental update: u' = ((u * n) + x) / (n + 1), u = mean, x = obs, n = count
127  const PointT tmp = ((Voxel<PointT>::get() * last) + pt) * count_inv;
129  }
133  //lint -e{9175} NOLINT this is to match a parent API
134  void configure(const Config & cfg, const uint64_t idx)
135  {
136  (void)cfg;
137  (void)idx;
138  }
139 }; // class CentroidVoxel
140 
143 template<typename PointT>
144 class VOXEL_GRID_PUBLIC ApproximateVoxel : public Voxel<PointT>
145 {
146 public:
147  using Voxel<PointT>::Voxel;
150  void add_observation(const PointT & pt)
151  {
153  (void)pt;
154  }
159  void configure(const Config & cfg, const uint64_t idx)
160  {
161  Voxel<PointT>::set_centroid(cfg.centroid<PointT>(idx));
162  }
163 }; // class ApproximateVoxel
164 
165 
166 } // namespace voxel_grid
167 } // namespace filters
168 } // namespace perception
169 } // namespace autoware
170 
171 #endif // VOXEL_GRID__VOXELS_HPP_
autoware::perception::filters::voxel_grid::operator*
VOXEL_GRID_PUBLIC PointT operator*(const PointT &lhs, const float32_t rhs)
Default scalar multiplication operator for a point type for use with CentroidVoxel.
Definition: voxels.hpp:61
autoware::common::types::PointXYZIF::x
float32_t x
Definition: types.hpp:58
types.hpp
This file includes common type definition.
voxel.hpp
This file defines the core Voxel class.
config.hpp
This file defines the configuration class for the voxel grid data structure.
visibility_control.hpp
autoware::common::types::PointXYZIF::intensity
float32_t intensity
Definition: types.hpp:61
autoware::perception::filters::voxel_grid::Voxel::set_centroid
void set_centroid(const PointT &pt)
Sets the centroid. This is to properly encapsulate the member variables. Intended to be used by child...
Definition: voxel.hpp:114
autoware::perception::filters::voxel_grid::Voxel::count
uint32_t count() const
Get the current number of points associated with this voxel.
Definition: voxel.hpp:97
autoware::perception::filters::voxel_grid::ApproximateVoxel
A specialization of the Voxel class, only returns centroid of voxel.
Definition: voxels.hpp:144
autoware::common::types::PointXYZIF
Definition: types.hpp:56
autoware
This file defines the lanelet2_map_provider_node class.
Definition: quick_sort.hpp:24
autoware::perception::filters::voxel_grid::Voxel::get
const PointT & get() const
Emit the centroid.
Definition: voxel.hpp:87
autoware::perception::filters::voxel_grid::Voxel::set_count
void set_count(const uint32_t next)
Sets the count. This is to properly encapsulate the member variables. Intended to be used by child cl...
Definition: voxel.hpp:106
autoware::perception::filters::voxel_grid::Config::centroid
PointT centroid(const uint64_t index) const
Computes the centroid for a given voxel index.
Definition: perception/filters/voxel_grid/include/voxel_grid/config.hpp:111
autoware::perception::filters::voxel_grid::Voxel
A simple class to accumulate points for a voxel and emit the centroid.
Definition: voxel.hpp:42
autoware::common::types::float32_t
float float32_t
Definition: types.hpp:45
autoware::perception::filters::voxel_grid::Config
A configuration class for the VoxelGrid data structure, also includes some helper functionality for c...
Definition: perception/filters/voxel_grid/include/voxel_grid/config.hpp:52
autoware::perception::filters::voxel_grid::CentroidVoxel::add_observation
void add_observation(const PointT &pt)
Update the state of this voxel by incrementally updating the mean.
Definition: voxels.hpp:121
autoware::perception::filters::voxel_grid::operator+
VOXEL_GRID_PUBLIC PointT operator+(const PointT &lhs, const PointT &rhs)
Default addition operator for a point type for use with CentroidVoxel.
Definition: voxels.hpp:46
autoware::perception::filters::voxel_grid::CentroidVoxel::configure
void configure(const Config &cfg, const uint64_t idx)
Use Config and index to set up any important information, in this case no-op.
Definition: voxels.hpp:134
autoware::perception::filters::voxel_grid::CentroidVoxel
A specialization of the Voxel class, accumulates points to a moving centroid.
Definition: voxels.hpp:115
autoware::common::types::PointXYZIF::z
float32_t z
Definition: types.hpp:60
autoware::perception::filters::voxel_grid::ApproximateVoxel::configure
void configure(const Config &cfg, const uint64_t idx)
Use Config and index to set up any important information, in this case sets the centroid.
Definition: voxels.hpp:159
autoware::perception::filters::voxel_grid::ApproximateVoxel::add_observation
void add_observation(const PointT &pt)
Update the state of the voxel, only increments internal counter.
Definition: voxels.hpp:150
autoware::common::types::PointXYZIF::y
float32_t y
Definition: types.hpp:59