Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

ikhann
Copy link

@ikhann ikhann commented Oct 14, 2020

✸ Add intensity field from the Lidar topic into the generated PCD file.

If you have topic messages with intensities from the lidar measurements, it will be added when you generate a .pcd file.
For some reason, this functionality was implemented only when generating a .ply file.

@MichaelGrupp
Copy link
Contributor

Hi, thanks for the pull request. You need to sign-off your commit with Git, otherwise we can't merge.

It takes 1 minute. The DCO check shows you what you need to do: https://github.com/cartographer-project/cartographer/pull/1762/checks?check_run_id=1253819084

@ikhann ikhann force-pushed the master branch 2 times, most recently from e5bf488 to 79ac213 Compare October 14, 2020 14:16
@ikhann ikhann changed the title Intensities from Lidar topic into the generated PCD Intensities from Lidar PointCloud2 topic into the generated PCD Oct 15, 2020
cartographer/io/pcd_writing_points_processor.cc Outdated Show resolved Hide resolved
<< "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"
Copy link
Member

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.

Copy link
Author

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.

Copy link
Member

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.

cartographer/io/pcd_writing_points_processor.cc Outdated Show resolved Hide resolved
@@ -65,6 +70,12 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point,
CHECK(file_writer->Write(buffer, 12));
}

void WriteBinaryPcdIntensity(const float intensity,
FileWriter* const file_writer) {
CHECK(file_writer->Write(reinterpret_cast<const char*>(&intensity),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is undefined behavior. See https://en.cppreference.com/w/cpp/language/reinterpret_cast. Use memcpy as above?
nit: You probably want to #include <cstring> for this and use std::memcpy. Similar for the existing code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. These comments were implemented in the commit below.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you see my nit? It is good practice to include what you use (IWYU) which here means: #include <cstring>. Also, in C++ memcpy is in the std namespace.

1. Added the keyword const to PCD headers.
2. Changed writing intensity from reinterpret_cast to memcpy due undefined behavior

Signed-off-by: Daniil Khaninaev <[email protected]>
@@ -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) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: you should run clang-format.

@@ -125,6 +139,10 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
WriteBinaryPcdPointColor(ToUint8Color(batch->colors[i]),
file_writer_.get());
}
if (has_intensities_) {
Copy link
Member

Choose a reason for hiding this comment

The 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?

@bochen87
Copy link

@ikhann friendly ping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants