Simplify 3D visualization code. (#88)
Removes the non-const Submaps accessor. Adds -Werror=missing-braces.master
parent
4b7e2efbd9
commit
5b16f4bcb6
|
@ -71,7 +71,7 @@ google_combined_library(cartographer
|
||||||
)
|
)
|
||||||
|
|
||||||
get_property(CARTOGRAPHER_LIBRARY_FILE TARGET cartographer PROPERTY LOCATION)
|
get_property(CARTOGRAPHER_LIBRARY_FILE TARGET cartographer PROPERTY LOCATION)
|
||||||
get_filename_component(CARTOGRAPHER_LIBRARY_FILE_BASENAME
|
get_filename_component(CARTOGRAPHER_LIBRARY_FILE_BASENAME
|
||||||
${CARTOGRAPHER_LIBRARY_FILE} NAME)
|
${CARTOGRAPHER_LIBRARY_FILE} NAME)
|
||||||
install(
|
install(
|
||||||
FILES
|
FILES
|
||||||
|
|
|
@ -50,10 +50,6 @@ const Submaps* CollatedTrajectoryBuilder::submaps() const {
|
||||||
return wrapped_trajectory_builder_->submaps();
|
return wrapped_trajectory_builder_->submaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
Submaps* CollatedTrajectoryBuilder::submaps() {
|
|
||||||
return wrapped_trajectory_builder_->submaps();
|
|
||||||
}
|
|
||||||
|
|
||||||
kalman_filter::PoseTracker* CollatedTrajectoryBuilder::pose_tracker() const {
|
kalman_filter::PoseTracker* CollatedTrajectoryBuilder::pose_tracker() const {
|
||||||
return wrapped_trajectory_builder_->pose_tracker();
|
return wrapped_trajectory_builder_->pose_tracker();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ class CollatedTrajectoryBuilder : public TrajectoryBuilder {
|
||||||
delete;
|
delete;
|
||||||
|
|
||||||
const Submaps* submaps() const override;
|
const Submaps* submaps() const override;
|
||||||
Submaps* submaps() override;
|
|
||||||
kalman_filter::PoseTracker* pose_tracker() const override;
|
kalman_filter::PoseTracker* pose_tracker() const override;
|
||||||
const PoseEstimate& pose_estimate() const override;
|
const PoseEstimate& pose_estimate() const override;
|
||||||
|
|
||||||
|
|
|
@ -48,7 +48,6 @@ class GlobalTrajectoryBuilderInterface {
|
||||||
const GlobalTrajectoryBuilderInterface&) = delete;
|
const GlobalTrajectoryBuilderInterface&) = delete;
|
||||||
|
|
||||||
virtual const Submaps* submaps() const = 0;
|
virtual const Submaps* submaps() const = 0;
|
||||||
virtual Submaps* submaps() = 0;
|
|
||||||
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
||||||
virtual const PoseEstimate& pose_estimate() const = 0;
|
virtual const PoseEstimate& pose_estimate() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -33,7 +33,7 @@ class FakeSubmaps : public Submaps {
|
||||||
|
|
||||||
void SubmapToProto(int, const std::vector<mapping::TrajectoryNode>&,
|
void SubmapToProto(int, const std::vector<mapping::TrajectoryNode>&,
|
||||||
const transform::Rigid3d&,
|
const transform::Rigid3d&,
|
||||||
proto::SubmapQuery::Response*) override {
|
proto::SubmapQuery::Response*) const override {
|
||||||
LOG(FATAL) << "Not implemented.";
|
LOG(FATAL) << "Not implemented.";
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -121,7 +121,7 @@ class Submaps {
|
||||||
virtual void SubmapToProto(
|
virtual void SubmapToProto(
|
||||||
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
||||||
const transform::Rigid3d& global_submap_pose,
|
const transform::Rigid3d& global_submap_pose,
|
||||||
proto::SubmapQuery::Response* response) = 0;
|
proto::SubmapQuery::Response* response) const = 0;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
static void AddProbabilityGridToResponse(
|
static void AddProbabilityGridToResponse(
|
||||||
|
|
|
@ -78,7 +78,6 @@ class TrajectoryBuilder {
|
||||||
TrajectoryBuilder& operator=(const TrajectoryBuilder&) = delete;
|
TrajectoryBuilder& operator=(const TrajectoryBuilder&) = delete;
|
||||||
|
|
||||||
virtual const Submaps* submaps() const = 0;
|
virtual const Submaps* submaps() const = 0;
|
||||||
virtual Submaps* submaps() = 0;
|
|
||||||
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
||||||
virtual const PoseEstimate& pose_estimate() const = 0;
|
virtual const PoseEstimate& pose_estimate() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -32,10 +32,6 @@ const Submaps* GlobalTrajectoryBuilder::submaps() const {
|
||||||
return local_trajectory_builder_.submaps();
|
return local_trajectory_builder_.submaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
Submaps* GlobalTrajectoryBuilder::submaps() {
|
|
||||||
return local_trajectory_builder_.submaps();
|
|
||||||
}
|
|
||||||
|
|
||||||
kalman_filter::PoseTracker* GlobalTrajectoryBuilder::pose_tracker() const {
|
kalman_filter::PoseTracker* GlobalTrajectoryBuilder::pose_tracker() const {
|
||||||
return local_trajectory_builder_.pose_tracker();
|
return local_trajectory_builder_.pose_tracker();
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,7 +35,6 @@ class GlobalTrajectoryBuilder
|
||||||
GlobalTrajectoryBuilder& operator=(const GlobalTrajectoryBuilder&) = delete;
|
GlobalTrajectoryBuilder& operator=(const GlobalTrajectoryBuilder&) = delete;
|
||||||
|
|
||||||
const Submaps* submaps() const override;
|
const Submaps* submaps() const override;
|
||||||
Submaps* submaps() override;
|
|
||||||
kalman_filter::PoseTracker* pose_tracker() const override;
|
kalman_filter::PoseTracker* pose_tracker() const override;
|
||||||
const mapping::GlobalTrajectoryBuilderInterface::PoseEstimate& pose_estimate()
|
const mapping::GlobalTrajectoryBuilderInterface::PoseEstimate& pose_estimate()
|
||||||
const override;
|
const override;
|
||||||
|
|
|
@ -72,8 +72,6 @@ LocalTrajectoryBuilder::~LocalTrajectoryBuilder() {}
|
||||||
|
|
||||||
const Submaps* LocalTrajectoryBuilder::submaps() const { return &submaps_; }
|
const Submaps* LocalTrajectoryBuilder::submaps() const { return &submaps_; }
|
||||||
|
|
||||||
Submaps* LocalTrajectoryBuilder::submaps() { return &submaps_; }
|
|
||||||
|
|
||||||
kalman_filter::PoseTracker* LocalTrajectoryBuilder::pose_tracker() const {
|
kalman_filter::PoseTracker* LocalTrajectoryBuilder::pose_tracker() const {
|
||||||
return pose_tracker_.get();
|
return pose_tracker_.get();
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,7 +71,6 @@ class LocalTrajectoryBuilder {
|
||||||
const kalman_filter::PoseCovariance& covariance);
|
const kalman_filter::PoseCovariance& covariance);
|
||||||
|
|
||||||
const Submaps* submaps() const;
|
const Submaps* submaps() const;
|
||||||
Submaps* submaps();
|
|
||||||
kalman_filter::PoseTracker* pose_tracker() const;
|
kalman_filter::PoseTracker* pose_tracker() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -140,7 +140,7 @@ int Submaps::size() const { return submaps_.size(); }
|
||||||
void Submaps::SubmapToProto(
|
void Submaps::SubmapToProto(
|
||||||
const int index, const std::vector<mapping::TrajectoryNode>&,
|
const int index, const std::vector<mapping::TrajectoryNode>&,
|
||||||
const transform::Rigid3d&,
|
const transform::Rigid3d&,
|
||||||
mapping::proto::SubmapQuery::Response* const response) {
|
mapping::proto::SubmapQuery::Response* const response) const {
|
||||||
AddProbabilityGridToResponse(Get(index)->local_pose(),
|
AddProbabilityGridToResponse(Get(index)->local_pose(),
|
||||||
Get(index)->probability_grid, response);
|
Get(index)->probability_grid, response);
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,7 +61,7 @@ class Submaps : public mapping::Submaps {
|
||||||
void SubmapToProto(
|
void SubmapToProto(
|
||||||
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
||||||
const transform::Rigid3d& global_submap_pose,
|
const transform::Rigid3d& global_submap_pose,
|
||||||
mapping::proto::SubmapQuery::Response* response) override;
|
mapping::proto::SubmapQuery::Response* response) const override;
|
||||||
|
|
||||||
// Inserts 'laser_fan' into the Submap collection.
|
// Inserts 'laser_fan' into the Submap collection.
|
||||||
void InsertLaserFan(const sensor::LaserFan& laser_fan);
|
void InsertLaserFan(const sensor::LaserFan& laser_fan);
|
||||||
|
|
|
@ -33,10 +33,6 @@ const mapping_3d::Submaps* GlobalTrajectoryBuilder::submaps() const {
|
||||||
return local_trajectory_builder_->submaps();
|
return local_trajectory_builder_->submaps();
|
||||||
}
|
}
|
||||||
|
|
||||||
mapping_3d::Submaps* GlobalTrajectoryBuilder::submaps() {
|
|
||||||
return local_trajectory_builder_->submaps();
|
|
||||||
}
|
|
||||||
|
|
||||||
kalman_filter::PoseTracker* GlobalTrajectoryBuilder::pose_tracker() const {
|
kalman_filter::PoseTracker* GlobalTrajectoryBuilder::pose_tracker() const {
|
||||||
return local_trajectory_builder_->pose_tracker();
|
return local_trajectory_builder_->pose_tracker();
|
||||||
}
|
}
|
||||||
|
|
|
@ -38,7 +38,6 @@ class GlobalTrajectoryBuilder
|
||||||
GlobalTrajectoryBuilder& operator=(const GlobalTrajectoryBuilder&) = delete;
|
GlobalTrajectoryBuilder& operator=(const GlobalTrajectoryBuilder&) = delete;
|
||||||
|
|
||||||
const mapping_3d::Submaps* submaps() const override;
|
const mapping_3d::Submaps* submaps() const override;
|
||||||
mapping_3d::Submaps* submaps() override;
|
|
||||||
kalman_filter::PoseTracker* pose_tracker() const override;
|
kalman_filter::PoseTracker* pose_tracker() const override;
|
||||||
void AddImuData(common::Time time, const Eigen::Vector3d& linear_acceleration,
|
void AddImuData(common::Time time, const Eigen::Vector3d& linear_acceleration,
|
||||||
const Eigen::Vector3d& angular_velocity) override;
|
const Eigen::Vector3d& angular_velocity) override;
|
||||||
|
|
|
@ -46,7 +46,7 @@ KalmanLocalTrajectoryBuilder::KalmanLocalTrajectoryBuilder(
|
||||||
|
|
||||||
KalmanLocalTrajectoryBuilder::~KalmanLocalTrajectoryBuilder() {}
|
KalmanLocalTrajectoryBuilder::~KalmanLocalTrajectoryBuilder() {}
|
||||||
|
|
||||||
mapping_3d::Submaps* KalmanLocalTrajectoryBuilder::submaps() {
|
const mapping_3d::Submaps* KalmanLocalTrajectoryBuilder::submaps() const {
|
||||||
return submaps_.get();
|
return submaps_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,7 +55,7 @@ class KalmanLocalTrajectoryBuilder : public LocalTrajectoryBuilderInterface {
|
||||||
const kalman_filter::PoseCovariance& covariance) override;
|
const kalman_filter::PoseCovariance& covariance) override;
|
||||||
|
|
||||||
void AddTrajectoryNodeIndex(int trajectory_node_index) override;
|
void AddTrajectoryNodeIndex(int trajectory_node_index) override;
|
||||||
mapping_3d::Submaps* submaps() override;
|
const mapping_3d::Submaps* submaps() const override;
|
||||||
const PoseEstimate& pose_estimate() const override;
|
const PoseEstimate& pose_estimate() const override;
|
||||||
kalman_filter::PoseTracker* pose_tracker() const override;
|
kalman_filter::PoseTracker* pose_tracker() const override;
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class LocalTrajectoryBuilderInterface {
|
||||||
// to the latest inserted laser scan. This is used to remember which
|
// to the latest inserted laser scan. This is used to remember which
|
||||||
// trajectory node should be used to visualize a Submap.
|
// trajectory node should be used to visualize a Submap.
|
||||||
virtual void AddTrajectoryNodeIndex(int trajectory_node_index) = 0;
|
virtual void AddTrajectoryNodeIndex(int trajectory_node_index) = 0;
|
||||||
virtual mapping_3d::Submaps* submaps() = 0;
|
virtual const mapping_3d::Submaps* submaps() const = 0;
|
||||||
virtual const PoseEstimate& pose_estimate() const = 0;
|
virtual const PoseEstimate& pose_estimate() const = 0;
|
||||||
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
virtual kalman_filter::PoseTracker* pose_tracker() const = 0;
|
||||||
|
|
||||||
|
|
|
@ -112,7 +112,7 @@ OptimizingLocalTrajectoryBuilder::OptimizingLocalTrajectoryBuilder(
|
||||||
|
|
||||||
OptimizingLocalTrajectoryBuilder::~OptimizingLocalTrajectoryBuilder() {}
|
OptimizingLocalTrajectoryBuilder::~OptimizingLocalTrajectoryBuilder() {}
|
||||||
|
|
||||||
mapping_3d::Submaps* OptimizingLocalTrajectoryBuilder::submaps() {
|
const mapping_3d::Submaps* OptimizingLocalTrajectoryBuilder::submaps() const {
|
||||||
return submaps_.get();
|
return submaps_.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -63,7 +63,7 @@ class OptimizingLocalTrajectoryBuilder
|
||||||
kalman_filter::PoseTracker* pose_tracker() const override { return nullptr; }
|
kalman_filter::PoseTracker* pose_tracker() const override { return nullptr; }
|
||||||
|
|
||||||
void AddTrajectoryNodeIndex(int trajectory_node_index) override;
|
void AddTrajectoryNodeIndex(int trajectory_node_index) override;
|
||||||
mapping_3d::Submaps* submaps() override;
|
const mapping_3d::Submaps* submaps() const override;
|
||||||
const PoseEstimate& pose_estimate() const override;
|
const PoseEstimate& pose_estimate() const override;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
|
@ -20,7 +20,6 @@
|
||||||
#include <limits>
|
#include <limits>
|
||||||
|
|
||||||
#include "cartographer/common/math.h"
|
#include "cartographer/common/math.h"
|
||||||
#include "cartographer/common/port.h"
|
|
||||||
#include "cartographer/sensor/laser.h"
|
#include "cartographer/sensor/laser.h"
|
||||||
#include "glog/logging.h"
|
#include "glog/logging.h"
|
||||||
|
|
||||||
|
@ -235,7 +234,7 @@ int Submaps::size() const { return submaps_.size(); }
|
||||||
void Submaps::SubmapToProto(
|
void Submaps::SubmapToProto(
|
||||||
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
||||||
const transform::Rigid3d& global_submap_pose,
|
const transform::Rigid3d& global_submap_pose,
|
||||||
mapping::proto::SubmapQuery::Response* const response) {
|
mapping::proto::SubmapQuery::Response* const response) const {
|
||||||
// Generate an X-ray view through the 'hybrid_grid', aligned to the xy-plane
|
// Generate an X-ray view through the 'hybrid_grid', aligned to the xy-plane
|
||||||
// in the global map frame.
|
// in the global map frame.
|
||||||
const HybridGrid& hybrid_grid = Get(index)->high_resolution_hybrid_grid;
|
const HybridGrid& hybrid_grid = Get(index)->high_resolution_hybrid_grid;
|
||||||
|
@ -244,20 +243,22 @@ void Submaps::SubmapToProto(
|
||||||
// Compute a bounding box for the texture.
|
// Compute a bounding box for the texture.
|
||||||
Eigen::Array2i min_index(INT_MAX, INT_MAX);
|
Eigen::Array2i min_index(INT_MAX, INT_MAX);
|
||||||
Eigen::Array2i max_index(INT_MIN, INT_MIN);
|
Eigen::Array2i max_index(INT_MIN, INT_MIN);
|
||||||
ExtractVoxelData(
|
const std::vector<Eigen::Array4i> voxel_indices_and_probabilities =
|
||||||
hybrid_grid,
|
ExtractVoxelData(hybrid_grid,
|
||||||
(global_submap_pose * Get(index)->local_pose().inverse()).cast<float>(),
|
(global_submap_pose * Get(index)->local_pose().inverse())
|
||||||
&min_index, &max_index);
|
.cast<float>(),
|
||||||
|
&min_index, &max_index);
|
||||||
|
|
||||||
const int width = max_index.y() - min_index.y() + 1;
|
const int width = max_index.y() - min_index.y() + 1;
|
||||||
const int height = max_index.x() - min_index.x() + 1;
|
const int height = max_index.x() - min_index.x() + 1;
|
||||||
response->set_width(width);
|
response->set_width(width);
|
||||||
response->set_height(height);
|
response->set_height(height);
|
||||||
|
|
||||||
AccumulatePixelData(width, height, min_index, max_index);
|
const std::vector<PixelData> accumulated_pixel_data = AccumulatePixelData(
|
||||||
ComputePixelValues(width, height);
|
width, height, min_index, max_index, voxel_indices_and_probabilities);
|
||||||
|
const string cell_data = ComputePixelValues(accumulated_pixel_data);
|
||||||
|
|
||||||
common::FastGzipString(celldata_, response->mutable_cells());
|
common::FastGzipString(cell_data, response->mutable_cells());
|
||||||
*response->mutable_slice_pose() =
|
*response->mutable_slice_pose() =
|
||||||
transform::ToProto(global_submap_pose.inverse() *
|
transform::ToProto(global_submap_pose.inverse() *
|
||||||
transform::Rigid3d::Translation(Eigen::Vector3d(
|
transform::Rigid3d::Translation(Eigen::Vector3d(
|
||||||
|
@ -315,13 +316,13 @@ void Submaps::AddSubmap(const Eigen::Vector3f& origin) {
|
||||||
num_laser_fans_in_last_submap_ = 0;
|
num_laser_fans_in_last_submap_ = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Submaps::AccumulatePixelData(const int width, const int height,
|
std::vector<Submaps::PixelData> Submaps::AccumulatePixelData(
|
||||||
const Eigen::Array2i& min_index,
|
const int width, const int height, const Eigen::Array2i& min_index,
|
||||||
const Eigen::Array2i& max_index) {
|
const Eigen::Array2i& max_index,
|
||||||
accumulated_pixel_data_.clear();
|
const std::vector<Eigen::Array4i>& voxel_indices_and_probabilities) const {
|
||||||
accumulated_pixel_data_.resize(width * height);
|
std::vector<PixelData> accumulated_pixel_data(width * height);
|
||||||
for (const Eigen::Array4i& voxel_index_and_probability :
|
for (const Eigen::Array4i& voxel_index_and_probability :
|
||||||
voxel_indices_and_probabilities_) {
|
voxel_indices_and_probabilities) {
|
||||||
const Eigen::Array2i pixel_index = voxel_index_and_probability.head<2>();
|
const Eigen::Array2i pixel_index = voxel_index_and_probability.head<2>();
|
||||||
if ((pixel_index < min_index).any() || (pixel_index > max_index).any()) {
|
if ((pixel_index < min_index).any() || (pixel_index > max_index).any()) {
|
||||||
// Out of bounds. This could happen because of floating point inaccuracy.
|
// Out of bounds. This could happen because of floating point inaccuracy.
|
||||||
|
@ -329,7 +330,7 @@ void Submaps::AccumulatePixelData(const int width, const int height,
|
||||||
}
|
}
|
||||||
const int x = max_index.x() - pixel_index[0];
|
const int x = max_index.x() - pixel_index[0];
|
||||||
const int y = max_index.y() - pixel_index[1];
|
const int y = max_index.y() - pixel_index[1];
|
||||||
PixelData& pixel = accumulated_pixel_data_[x * width + y];
|
PixelData& pixel = accumulated_pixel_data[x * width + y];
|
||||||
++pixel.count;
|
++pixel.count;
|
||||||
pixel.min_z = std::min(pixel.min_z, voxel_index_and_probability[2]);
|
pixel.min_z = std::min(pixel.min_z, voxel_index_and_probability[2]);
|
||||||
pixel.max_z = std::max(pixel.max_z, voxel_index_and_probability[2]);
|
pixel.max_z = std::max(pixel.max_z, voxel_index_and_probability[2]);
|
||||||
|
@ -338,13 +339,13 @@ void Submaps::AccumulatePixelData(const int width, const int height,
|
||||||
pixel.probability_sum += probability;
|
pixel.probability_sum += probability;
|
||||||
pixel.max_probability = std::max(pixel.max_probability, probability);
|
pixel.max_probability = std::max(pixel.max_probability, probability);
|
||||||
}
|
}
|
||||||
|
return accumulated_pixel_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Submaps::ExtractVoxelData(const HybridGrid& hybrid_grid,
|
std::vector<Eigen::Array4i> Submaps::ExtractVoxelData(
|
||||||
const transform::Rigid3f& transform,
|
const HybridGrid& hybrid_grid, const transform::Rigid3f& transform,
|
||||||
Eigen::Array2i* min_index,
|
Eigen::Array2i* min_index, Eigen::Array2i* max_index) const {
|
||||||
Eigen::Array2i* max_index) {
|
std::vector<Eigen::Array4i> voxel_indices_and_probabilities;
|
||||||
voxel_indices_and_probabilities_.clear();
|
|
||||||
const float resolution_inverse = 1. / hybrid_grid.resolution();
|
const float resolution_inverse = 1. / hybrid_grid.resolution();
|
||||||
|
|
||||||
constexpr double kXrayObstructedCellProbabilityLimit = 0.501;
|
constexpr double kXrayObstructedCellProbabilityLimit = 0.501;
|
||||||
|
@ -365,29 +366,28 @@ void Submaps::ExtractVoxelData(const HybridGrid& hybrid_grid,
|
||||||
common::RoundToInt(cell_center_global.z() * resolution_inverse),
|
common::RoundToInt(cell_center_global.z() * resolution_inverse),
|
||||||
probability_value);
|
probability_value);
|
||||||
|
|
||||||
voxel_indices_and_probabilities_.push_back(voxel_index_and_probability);
|
voxel_indices_and_probabilities.push_back(voxel_index_and_probability);
|
||||||
const Eigen::Array2i pixel_index = voxel_index_and_probability.head<2>();
|
const Eigen::Array2i pixel_index = voxel_index_and_probability.head<2>();
|
||||||
*min_index = min_index->cwiseMin(pixel_index);
|
*min_index = min_index->cwiseMin(pixel_index);
|
||||||
*max_index = max_index->cwiseMax(pixel_index);
|
*max_index = max_index->cwiseMax(pixel_index);
|
||||||
}
|
}
|
||||||
|
return voxel_indices_and_probabilities;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Submaps::ComputePixelValues(const int width, const int height) {
|
string Submaps::ComputePixelValues(
|
||||||
celldata_.resize(2 * width * height);
|
const std::vector<Submaps::PixelData>& accumulated_pixel_data) const {
|
||||||
|
string cell_data;
|
||||||
|
cell_data.reserve(2 * accumulated_pixel_data.size());
|
||||||
constexpr float kMinZDifference = 3.f;
|
constexpr float kMinZDifference = 3.f;
|
||||||
constexpr float kFreeSpaceWeight = 0.15f;
|
constexpr float kFreeSpaceWeight = 0.15f;
|
||||||
auto it = celldata_.begin();
|
for (const PixelData& pixel : accumulated_pixel_data) {
|
||||||
for (size_t i = 0; i < accumulated_pixel_data_.size(); ++i) {
|
|
||||||
const PixelData& pixel = accumulated_pixel_data_.at(i);
|
|
||||||
// TODO(whess): Take into account submap rotation.
|
// TODO(whess): Take into account submap rotation.
|
||||||
// TODO(whess): Document the approach and make it more independent from the
|
// TODO(whess): Document the approach and make it more independent from the
|
||||||
// chosen resolution.
|
// chosen resolution.
|
||||||
const float z_difference = pixel.count > 0 ? pixel.max_z - pixel.min_z : 0;
|
const float z_difference = pixel.count > 0 ? pixel.max_z - pixel.min_z : 0;
|
||||||
if (z_difference < kMinZDifference) {
|
if (z_difference < kMinZDifference) {
|
||||||
*it = 0; // value
|
cell_data.push_back(0); // value
|
||||||
++it;
|
cell_data.push_back(0); // alpha
|
||||||
*it = 0; // alpha
|
|
||||||
++it;
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const float free_space = std::max(z_difference - pixel.count, 0.f);
|
const float free_space = std::max(z_difference - pixel.count, 0.f);
|
||||||
|
@ -401,11 +401,10 @@ void Submaps::ComputePixelValues(const int width, const int height) {
|
||||||
128 - mapping::ProbabilityToLogOddsInteger(average_probability);
|
128 - mapping::ProbabilityToLogOddsInteger(average_probability);
|
||||||
const uint8 alpha = delta > 0 ? 0 : -delta;
|
const uint8 alpha = delta > 0 ? 0 : -delta;
|
||||||
const uint8 value = delta > 0 ? delta : 0;
|
const uint8 value = delta > 0 ? delta : 0;
|
||||||
*it = value; // value
|
cell_data.push_back(value); // value
|
||||||
++it;
|
cell_data.push_back((value || alpha) ? alpha : 1); // alpha
|
||||||
*it = (value || alpha) ? alpha : 1; // alpha
|
|
||||||
++it;
|
|
||||||
}
|
}
|
||||||
|
return cell_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace mapping_3d
|
} // namespace mapping_3d
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include "Eigen/Geometry"
|
#include "Eigen/Geometry"
|
||||||
|
#include "cartographer/common/port.h"
|
||||||
#include "cartographer/mapping/sparse_pose_graph.h"
|
#include "cartographer/mapping/sparse_pose_graph.h"
|
||||||
#include "cartographer/mapping/submaps.h"
|
#include "cartographer/mapping/submaps.h"
|
||||||
#include "cartographer/mapping_2d/laser_fan_inserter.h"
|
#include "cartographer/mapping_2d/laser_fan_inserter.h"
|
||||||
|
@ -66,7 +67,7 @@ class Submaps : public mapping::Submaps {
|
||||||
void SubmapToProto(
|
void SubmapToProto(
|
||||||
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
int index, const std::vector<mapping::TrajectoryNode>& trajectory_nodes,
|
||||||
const transform::Rigid3d& global_submap_pose,
|
const transform::Rigid3d& global_submap_pose,
|
||||||
mapping::proto::SubmapQuery::Response* response) override;
|
mapping::proto::SubmapQuery::Response* response) const override;
|
||||||
|
|
||||||
// Inserts 'laser_fan' into the Submap collection.
|
// Inserts 'laser_fan' into the Submap collection.
|
||||||
void InsertLaserFan(const sensor::LaserFan& laser_fan);
|
void InsertLaserFan(const sensor::LaserFan& laser_fan);
|
||||||
|
@ -90,15 +91,21 @@ class Submaps : public mapping::Submaps {
|
||||||
};
|
};
|
||||||
|
|
||||||
void AddSubmap(const Eigen::Vector3f& origin);
|
void AddSubmap(const Eigen::Vector3f& origin);
|
||||||
void AccumulatePixelData(const int width, const int height,
|
|
||||||
const Eigen::Array2i& min_index,
|
std::vector<PixelData> AccumulatePixelData(
|
||||||
const Eigen::Array2i& max_index);
|
const int width, const int height, const Eigen::Array2i& min_index,
|
||||||
void ExtractVoxelData(const HybridGrid& hybrid_grid,
|
const Eigen::Array2i& max_index,
|
||||||
const transform::Rigid3f& transform,
|
const std::vector<Eigen::Array4i>& voxel_indices_and_probabilities) const;
|
||||||
Eigen::Array2i* min_index, Eigen::Array2i* max_index);
|
// The first three entries of each returned value are a cell_index and the
|
||||||
|
// last is the corresponding probability value. We batch them together like
|
||||||
|
// this to only have one vector and have better cache locality.
|
||||||
|
std::vector<Eigen::Array4i> ExtractVoxelData(
|
||||||
|
const HybridGrid& hybrid_grid, const transform::Rigid3f& transform,
|
||||||
|
Eigen::Array2i* min_index, Eigen::Array2i* max_index) const;
|
||||||
// Builds texture data containing interleaved value and alpha for the
|
// Builds texture data containing interleaved value and alpha for the
|
||||||
// visualization from 'accumulated_pixel_data_' into 'celldata_'.
|
// visualization from 'accumulated_pixel_data'.
|
||||||
void ComputePixelValues(const int width, const int height);
|
string ComputePixelValues(
|
||||||
|
const std::vector<PixelData>& accumulated_pixel_data) const;
|
||||||
|
|
||||||
const proto::SubmapsOptions options_;
|
const proto::SubmapsOptions options_;
|
||||||
|
|
||||||
|
@ -110,15 +117,6 @@ class Submaps : public mapping::Submaps {
|
||||||
|
|
||||||
// Number of LaserFans inserted since the last Submap was added.
|
// Number of LaserFans inserted since the last Submap was added.
|
||||||
int num_laser_fans_in_last_submap_ = 0;
|
int num_laser_fans_in_last_submap_ = 0;
|
||||||
|
|
||||||
// The following members are used for visualization and kept around for
|
|
||||||
// performance reasons (mainly to avoid reallocations).
|
|
||||||
std::vector<PixelData> accumulated_pixel_data_;
|
|
||||||
string celldata_;
|
|
||||||
// The first three entries of this is are a cell_index and the last is the
|
|
||||||
// corresponding probability value. We batch them together like this to only
|
|
||||||
// have one vector and have better cache locality.
|
|
||||||
std::vector<Eigen::Array4i> voxel_indices_and_probabilities_;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace mapping_3d
|
} // namespace mapping_3d
|
||||||
|
|
|
@ -29,8 +29,8 @@ namespace sensor {
|
||||||
namespace {
|
namespace {
|
||||||
|
|
||||||
TEST(Collator, Ordering) {
|
TEST(Collator, Ordering) {
|
||||||
const std::array<string, 4> kSensorId = {"horizontal_laser", "vertical_laser",
|
const std::array<string, 4> kSensorId = {
|
||||||
"imu", "odometry"};
|
{"horizontal_laser", "vertical_laser", "imu", "odometry"}};
|
||||||
Data first(common::FromUniversal(100), sensor::LaserFan{});
|
Data first(common::FromUniversal(100), sensor::LaserFan{});
|
||||||
Data second(common::FromUniversal(200), sensor::LaserFan{});
|
Data second(common::FromUniversal(200), sensor::LaserFan{});
|
||||||
Data third(common::FromUniversal(300), Data::Imu{});
|
Data third(common::FromUniversal(300), Data::Imu{});
|
||||||
|
|
|
@ -331,6 +331,7 @@ macro(google_initialize_cartographer_project)
|
||||||
|
|
||||||
# Turn some warnings into errors.
|
# Turn some warnings into errors.
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=format-security")
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=format-security")
|
||||||
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=missing-braces")
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=reorder")
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=reorder")
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=return-type")
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=return-type")
|
||||||
google_add_flag(GOOG_CXX_FLAGS "-Werror=uninitialized")
|
google_add_flag(GOOG_CXX_FLAGS "-Werror=uninitialized")
|
||||||
|
|
Loading…
Reference in New Issue