@@ -634,22 +634,57 @@ void GlobalMapping::save(const std::string& path) {
634634 GlobalConfig::instance ()->dump (path + " /config" );
635635}
636636
637- std::vector<Eigen::Vector4d> GlobalMapping::export_points () {
638- int num_all_points = 0 ;
637+
638+ gtsam_points::PointCloud::Ptr GlobalMapping::export_points () {
639+ auto merged = std::make_shared<gtsam_points::PointCloudCPU>();
640+
641+ size_t total_points = 0 ;
639642 for (const auto & submap : submaps) {
640- num_all_points += submap->frame ->size ();
643+ if (!submap || !submap->frame ) {
644+ continue ;
645+ }
646+ total_points += submap->frame ->size ();
641647 }
642648
643- std::vector<Eigen::Vector4d> all_points ;
644- all_points .reserve (num_all_points );
649+ std::vector<Eigen::Vector4d> points ;
650+ points .reserve (total_points );
645651
652+ bool export_intensities = true ;
646653 for (const auto & submap : submaps) {
647- std::transform (submap->frame ->points , submap->frame ->points + submap->frame ->size (), std::back_inserter (all_points), [&](const Eigen::Vector4d& p) {
648- return submap->T_world_origin * p;
649- });
654+ if (!submap || !submap->frame || !submap->frame ->has_intensities ()) {
655+ export_intensities = false ;
656+ break ;
657+ }
658+ }
659+
660+ std::vector<double > intensities;
661+ if (export_intensities) {
662+ intensities.reserve (total_points);
663+ }
664+
665+ for (const auto & submap : submaps) {
666+ if (!submap || !submap->frame ) {
667+ continue ;
668+ }
669+
670+ for (int i = 0 ; i < submap->frame ->size (); i++) {
671+ const Eigen::Vector4d point = submap->T_world_origin * submap->frame ->points [i];
672+ points.push_back (point);
673+
674+ if (export_intensities) {
675+ intensities.push_back (submap->frame ->intensities [i]);
676+ }
677+ }
678+ }
679+
680+ if (!points.empty ()) {
681+ merged->add_points (points);
682+ if (export_intensities) {
683+ merged->add_intensities (intensities);
684+ }
650685 }
651686
652- return all_points ;
687+ return merged ;
653688}
654689
655690bool GlobalMapping::load (const std::string& path) {
0 commit comments