Skip to content

Commit

Permalink
Update pcd_writing_points_processor.cc
Browse files Browse the repository at this point in the history
1. Added the keyword const to PCD headers.
2. Changed writing intensity from reinterpret_cast to memcpy due undefined behavior
  • Loading branch information
ikhann authored Oct 15, 2020
1 parent e96598c commit 8504948
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions cartographer/io/pcd_writing_points_processor.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace {
// 'output_file'.
void WriteBinaryPcdHeader(const bool has_color, const bool has_intensities,
const int64 num_points, FileWriter* const file_writer) {
std::string color_header_field = !has_color ? "" : " rgb";
std::string color_header_type = !has_color ? "" : " U";
std::string color_header_size = !has_color ? "" : " 4";
std::string color_header_count = !has_color ? "" : " 1";
const std::string color_header_field = !has_color ? "" : " rgb";
const std::string color_header_type = !has_color ? "" : " U";
const std::string color_header_size = !has_color ? "" : " 4";
const std::string color_header_count = !has_color ? "" : " 1";

std::string intensity_header_field = !has_intensities ? "" : " intensity";
std::string intensity_header_type = !has_intensities ? "" : " F";
std::string intensity_header_size = !has_intensities ? "" : " 4";
std::string intensity_header_count = !has_intensities ? "" : " 1";
const std::string intensity_header_field = !has_intensities ? "" : " intensity";
const std::string intensity_header_type = !has_intensities ? "" : " F";
const std::string intensity_header_size = !has_intensities ? "" : " 4";
const std::string intensity_header_count = !has_intensities ? "" : " 1";

std::ostringstream stream;
stream << "# generated by Cartographer\n"
Expand Down Expand Up @@ -71,9 +71,10 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point,
}

void WriteBinaryPcdIntensity(const float intensity,
FileWriter* const file_writer) {
CHECK(file_writer->Write(reinterpret_cast<const char*>(&intensity),
sizeof(float)));
FileWriter* const file_writer) {
char buffer[4];
memcpy(buffer, &intensity, sizeof(float));
CHECK(file_writer->Write(buffer, 4));
}

void WriteBinaryPcdPointColor(const Uint8Color& color,
Expand Down

0 comments on commit 8504948

Please sign in to comment.