@@ -106,32 +106,22 @@ void BBS3D::calc_angular_info(std::vector<AngularInfo>& ang_info_vec) {
106106 }
107107}
108108
109- std::vector<DiscreteTransformation> BBS3D::create_init_transset (const AngularInfo& init_ang_info) {
109+ std::vector<DiscreteTransformation< double > > BBS3D::create_init_transset (const AngularInfo& init_ang_info) {
110110 const int init_transset_size = (init_tx_range_.second - init_tx_range_.first + 1 ) * (init_ty_range_.second - init_ty_range_.first + 1 ) *
111111 (init_tz_range_.second - init_tz_range_.first + 1 ) * (init_ang_info.num_division .x ()) *
112112 (init_ang_info.num_division .y ()) * (init_ang_info.num_division .z ());
113113
114114 const int max_level = voxelmaps_ptr_->get_max_level ();
115- const double init_trans_res = voxelmaps_ptr_->voxelmaps_res_ [max_level];
116115
117- std::vector<DiscreteTransformation> transset;
116+ std::vector<DiscreteTransformation< double > > transset;
118117 transset.reserve (init_transset_size);
119118 for (int tx = init_tx_range_.first ; tx <= init_tx_range_.second ; tx++) {
120119 for (int ty = init_ty_range_.first ; ty <= init_ty_range_.second ; ty++) {
121120 for (int tz = init_tz_range_.first ; tz <= init_tz_range_.second ; tz++) {
122121 for (int roll = 0 ; roll < init_ang_info.num_division .x (); roll++) {
123122 for (int pitch = 0 ; pitch < init_ang_info.num_division .y (); pitch++) {
124123 for (int yaw = 0 ; yaw < init_ang_info.num_division .z (); yaw++) {
125- transset.emplace_back (DiscreteTransformation (
126- 0 ,
127- max_level,
128- init_trans_res,
129- tx * init_trans_res,
130- ty * init_trans_res,
131- tz * init_trans_res,
132- roll * init_ang_info.rpy_res .x () + init_ang_info.min_rpy .x (),
133- pitch * init_ang_info.rpy_res .y () + init_ang_info.min_rpy .y (),
134- yaw * init_ang_info.rpy_res .z () + init_ang_info.min_rpy .z ()));
124+ transset.emplace_back (DiscreteTransformation<double >(0 , max_level, tx, ty, tz, roll, pitch, yaw));
135125 }
136126 }
137127 }
@@ -141,6 +131,40 @@ std::vector<DiscreteTransformation> BBS3D::create_init_transset(const AngularInf
141131 return transset;
142132}
143133
134+ void BBS3D::calc_score (
135+ DiscreteTransformation<double >& trans,
136+ const double trans_res,
137+ const Eigen::Vector3d& rpy_res,
138+ const Eigen::Vector3d& min_rpy,
139+ const std::vector<Eigen::Vector4i>& buckets,
140+ const int max_bucket_scan_count,
141+ const std::vector<Eigen::Vector3d>& points) {
142+ const int num_buckets = buckets.size ();
143+ const double inv_res = 1.0 / trans_res;
144+ Eigen::Transform<double , 3 , Eigen::Affine> transform;
145+ transform = trans.create_matrix (trans_res, rpy_res, min_rpy);
146+
147+ for (int i = 0 ; i < points.size (); i++) {
148+ const Eigen::Vector3d transed_point = transform * points[i];
149+ const Eigen::Vector3i coord = (transed_point.array () * inv_res).floor ().cast <int >();
150+ const std::uint32_t hash = (coord[0 ] * 73856093 ) ^ (coord[1 ] * 19349669 ) ^ (coord[2 ] * 83492791 );
151+
152+ for (int j = 0 ; j < max_bucket_scan_count; j++) {
153+ const std::uint32_t bucket_index = (hash + j) % num_buckets;
154+ const Eigen::Vector4i& bucket = buckets[bucket_index];
155+
156+ if (bucket.x () != coord.x () || bucket.y () != coord.y () || bucket.z () != coord.z ()) {
157+ continue ;
158+ }
159+
160+ if (bucket.w () == 1 ) {
161+ trans.score ++;
162+ break ;
163+ }
164+ }
165+ }
166+ }
167+
144168void BBS3D::localize () {
145169 // Calc localize time limit
146170 const auto start_time = std::chrono::system_clock::now ();
@@ -150,7 +174,7 @@ void BBS3D::localize() {
150174 best_score_ = 0 ;
151175 const int score_threshold = std::floor (src_points_.size () * score_threshold_percentage_);
152176 int best_score = score_threshold;
153- DiscreteTransformation best_trans (best_score);
177+ DiscreteTransformation< double > best_trans (best_score);
154178
155179 // Preapre initial transset
156180 const int max_bucket_scan_count = voxelmaps_ptr_->get_max_bucket_scan_count ();
@@ -161,12 +185,15 @@ void BBS3D::localize() {
161185
162186 // Calc initial transset scores
163187 const auto & top_buckets = voxelmaps_ptr_->multi_buckets_ [max_level];
188+ double init_trans_res = voxelmaps_ptr_->voxelmaps_res_ [max_level];
189+ const Eigen::Vector3d& rpy_res = ang_info_vec[max_level].rpy_res ;
190+ const Eigen::Vector3d& min_rpy = ang_info_vec[max_level].min_rpy ;
164191#pragma omp parallel for num_threads(num_threads_)
165192 for (int i = 0 ; i < init_transset.size (); i++) {
166- init_transset[i]. calc_score ( top_buckets, max_bucket_scan_count, src_points_);
193+ calc_score ( init_transset[i], init_trans_res, rpy_res, min_rpy, top_buckets, max_bucket_scan_count, src_points_);
167194 }
168195
169- std::priority_queue<DiscreteTransformation> trans_queue (init_transset.begin (), init_transset.end ());
196+ std::priority_queue<DiscreteTransformation< double > > trans_queue (init_transset.begin (), init_transset.end ());
170197
171198 while (!trans_queue.empty ()) {
172199 if (use_timeout_ && std::chrono::system_clock::now () > time_limit) {
@@ -187,14 +214,17 @@ void BBS3D::localize() {
187214 best_score = trans.score ;
188215 } else {
189216 const int child_level = trans.level - 1 ;
190- const double child_res = trans.resolution * inv_v_rate_;
191- auto children = trans.branch (child_level, child_res, static_cast <int >(v_rate_), ang_info_vec[child_level]);
217+ const Eigen::Vector3i& num_division = ang_info_vec[child_level].num_division ;
218+ const Eigen::Vector3d& rpy_res = ang_info_vec[child_level].rpy_res ;
219+ const Eigen::Vector3d& min_rpy = ang_info_vec[child_level].min_rpy ;
220+ auto children = trans.branch (child_level, static_cast <int >(v_rate_), num_division);
192221
193222 const auto & buckets = voxelmaps_ptr_->multi_buckets_ [child_level];
223+ double trans_res = voxelmaps_ptr_->voxelmaps_res_ [child_level];
194224
195225#pragma omp parallel for num_threads(num_threads_)
196226 for (int i = 0 ; i < children.size (); i++) {
197- children[i]. calc_score ( buckets, max_bucket_scan_count, src_points_);
227+ calc_score ( children[i], trans_res, rpy_res, min_rpy, buckets, max_bucket_scan_count, src_points_);
198228 }
199229
200230 for (const auto & child : children) {
@@ -218,7 +248,8 @@ void BBS3D::localize() {
218248 return ;
219249 }
220250
221- global_pose_ = best_trans.create_matrix ();
251+ double min_res = voxelmaps_ptr_->get_min_res ();
252+ global_pose_ = best_trans.create_matrix (min_res, ang_info_vec[0 ].rpy_res , ang_info_vec[0 ].min_rpy );
222253 best_score_ = best_score;
223254 has_timed_out_ = false ;
224255 has_localized_ = true ;
0 commit comments