Skip to content

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
Member

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
<< "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.


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]>
}

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.

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