Skip to content

Commit 79ac213

Browse files
committed
Intensities from Lidar topic into the generated PCD
Signed-off-by: Ханинаев Даниил Витальевич <daniil.khaninaev@PC870-Ubuntu.nami.local> Signed-off-by: Daniil Khaninaev <khaninaev@yahoo.com>
1 parent cad3378 commit 79ac213

File tree

2 files changed

+26
-8
lines changed

2 files changed

+26
-8
lines changed

cartographer/io/pcd_writing_points_processor.cc

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,20 +32,25 @@ namespace {
3232

3333
// Writes the PCD header claiming 'num_points' will follow it into
3434
// 'output_file'.
35-
void WriteBinaryPcdHeader(const bool has_color, const int64 num_points,
36-
FileWriter* const file_writer) {
35+
void WriteBinaryPcdHeader(const bool has_color, const bool has_intensities,
36+
const int64 num_points, FileWriter* const file_writer) {
3737
std::string color_header_field = !has_color ? "" : " rgb";
3838
std::string color_header_type = !has_color ? "" : " U";
3939
std::string color_header_size = !has_color ? "" : " 4";
4040
std::string color_header_count = !has_color ? "" : " 1";
4141

42+
std::string intensity_header_field = !has_intensities ? "" : " intensity";
43+
std::string intensity_header_type = !has_intensities ? "" : " F";
44+
std::string intensity_header_size = !has_intensities ? "" : " 4";
45+
std::string intensity_header_count = !has_intensities ? "" : " 1";
46+
4247
std::ostringstream stream;
4348
stream << "# generated by Cartographer\n"
4449
<< "VERSION .7\n"
45-
<< "FIELDS x y z" << color_header_field << "\n"
46-
<< "SIZE 4 4 4" << color_header_size << "\n"
47-
<< "TYPE F F F" << color_header_type << "\n"
48-
<< "COUNT 1 1 1" << color_header_count << "\n"
50+
<< "FIELDS x y z" << intensity_header_field << color_header_field <<"\n"
51+
<< "SIZE 4 4 4" << intensity_header_size << color_header_size << "\n"
52+
<< "TYPE F F F" << intensity_header_type << color_header_type << "\n"
53+
<< "COUNT 1 1 1" << intensity_header_count << color_header_count << "\n"
4954
<< "WIDTH " << std::setw(15) << std::setfill('0') << num_points << "\n"
5055
<< "HEIGHT 1\n"
5156
<< "VIEWPOINT 0 0 0 1 0 0 0\n"
@@ -65,6 +70,12 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point,
6570
CHECK(file_writer->Write(buffer, 12));
6671
}
6772

73+
void WriteBinaryPcdIntensity(const float intensity,
74+
FileWriter* const file_writer) {
75+
CHECK(file_writer->Write(reinterpret_cast<const char*>(&intensity),
76+
sizeof(float)));
77+
}
78+
6879
void WriteBinaryPcdPointColor(const Uint8Color& color,
6980
FileWriter* const file_writer) {
7081
char buffer[4];
@@ -91,10 +102,11 @@ PcdWritingPointsProcessor::PcdWritingPointsProcessor(
91102
: next_(next),
92103
num_points_(0),
93104
has_colors_(false),
105+
has_intensities_(false),
94106
file_writer_(std::move(file_writer)) {}
95107

96108
PointsProcessor::FlushResult PcdWritingPointsProcessor::Flush() {
97-
WriteBinaryPcdHeader(has_colors_, num_points_, file_writer_.get());
109+
WriteBinaryPcdHeader(has_colors_, has_intensities_, num_points_, file_writer_.get());
98110
CHECK(file_writer_->Close());
99111

100112
switch (next_->Flush()) {
@@ -116,7 +128,8 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
116128

117129
if (num_points_ == 0) {
118130
has_colors_ = !batch->colors.empty();
119-
WriteBinaryPcdHeader(has_colors_, 0, file_writer_.get());
131+
has_intensities_ = !batch->intensities.empty();
132+
WriteBinaryPcdHeader(has_colors_, has_intensities_, 0, file_writer_.get());
120133
}
121134
for (size_t i = 0; i < batch->points.size(); ++i) {
122135
WriteBinaryPcdPointCoordinate(batch->points[i].position,
@@ -125,6 +138,10 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
125138
WriteBinaryPcdPointColor(ToUint8Color(batch->colors[i]),
126139
file_writer_.get());
127140
}
141+
if (has_intensities_) {
142+
WriteBinaryPcdIntensity(batch->intensities[i],
143+
file_writer_.get());
144+
}
128145
++num_points_;
129146
}
130147
next_->Process(std::move(batch));

cartographer/io/pcd_writing_points_processor.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class PcdWritingPointsProcessor : public PointsProcessor {
4848

4949
int64 num_points_;
5050
bool has_colors_;
51+
bool has_intensities_;
5152
std::unique_ptr<FileWriter> file_writer_;
5253
};
5354

0 commit comments

Comments
 (0)