-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Intensities from Lidar PointCloud2 topic into the generated PCD #1762
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,20 +32,25 @@ namespace { | |
|
||
// Writes the PCD header claiming 'num_points' will follow it into | ||
// 'output_file'. | ||
void WriteBinaryPcdHeader(const bool has_color, 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"; | ||
void WriteBinaryPcdHeader(const bool has_color, const bool has_intensities, | ||
const int64 num_points, FileWriter* const file_writer) { | ||
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"; | ||
|
||
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" | ||
<< "VERSION .7\n" | ||
<< "FIELDS x y z" << color_header_field << "\n" | ||
<< "SIZE 4 4 4" << color_header_size << "\n" | ||
<< "TYPE F F F" << color_header_type << "\n" | ||
<< "COUNT 1 1 1" << color_header_count << "\n" | ||
<< "FIELDS x y z" << intensity_header_field << color_header_field <<"\n" | ||
<< "SIZE 4 4 4" << intensity_header_size << color_header_size << "\n" | ||
<< "TYPE F F F" << intensity_header_type << color_header_type << "\n" | ||
<< "COUNT 1 1 1" << intensity_header_count << color_header_count << "\n" | ||
<< "WIDTH " << std::setw(15) << std::setfill('0') << num_points << "\n" | ||
<< "HEIGHT 1\n" | ||
<< "VIEWPOINT 0 0 0 1 0 0 0\n" | ||
|
@@ -65,6 +70,13 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point, | |
CHECK(file_writer->Write(buffer, 12)); | ||
} | ||
|
||
void WriteBinaryPcdIntensity(const float intensity, | ||
FileWriter* const file_writer) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: you should run clang-format. |
||
char buffer[4]; | ||
memcpy(buffer, &intensity, sizeof(float)); | ||
CHECK(file_writer->Write(buffer, 4)); | ||
} | ||
|
||
void WriteBinaryPcdPointColor(const Uint8Color& color, | ||
FileWriter* const file_writer) { | ||
char buffer[4]; | ||
|
@@ -91,10 +103,11 @@ PcdWritingPointsProcessor::PcdWritingPointsProcessor( | |
: next_(next), | ||
num_points_(0), | ||
has_colors_(false), | ||
has_intensities_(false), | ||
file_writer_(std::move(file_writer)) {} | ||
|
||
PointsProcessor::FlushResult PcdWritingPointsProcessor::Flush() { | ||
WriteBinaryPcdHeader(has_colors_, num_points_, file_writer_.get()); | ||
WriteBinaryPcdHeader(has_colors_, has_intensities_, num_points_, file_writer_.get()); | ||
CHECK(file_writer_->Close()); | ||
|
||
switch (next_->Flush()) { | ||
|
@@ -116,7 +129,8 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) { | |
|
||
if (num_points_ == 0) { | ||
has_colors_ = !batch->colors.empty(); | ||
WriteBinaryPcdHeader(has_colors_, 0, file_writer_.get()); | ||
has_intensities_ = !batch->intensities.empty(); | ||
WriteBinaryPcdHeader(has_colors_, has_intensities_, 0, file_writer_.get()); | ||
} | ||
for (size_t i = 0; i < batch->points.size(); ++i) { | ||
WriteBinaryPcdPointCoordinate(batch->points[i].position, | ||
|
@@ -125,6 +139,10 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) { | |
WriteBinaryPcdPointColor(ToUint8Color(batch->colors[i]), | ||
file_writer_.get()); | ||
} | ||
if (has_intensities_) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Isn't this wrong? Which would be another argument for consistency. In case of both colors and intensities you declare that intensities come first, but here you right them in the wrong order. Or do I misread this? |
||
WriteBinaryPcdIntensity(batch->intensities[i], | ||
file_writer_.get()); | ||
} | ||
++num_points_; | ||
} | ||
next_->Process(std::move(batch)); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason why the ordering between color and intensity is swapped here compared to above for arguments? Some consistency would be nice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The order is not important.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You mean not important for correctness, but this is setting the bar too low. Please have a look at https://google.github.io/styleguide/cppguide.html#Goals. Inconsistencies should be there for a reason, not consistency. If you aim for readable code everyone who later reads the code, including yourself, has an easier time.