@@ -32,20 +32,25 @@ namespace {
32
32
33
33
// Writes the PCD header claiming 'num_points' will follow it into
34
34
// '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) {
37
37
std::string color_header_field = !has_color ? " " : " rgb" ;
38
38
std::string color_header_type = !has_color ? " " : " U" ;
39
39
std::string color_header_size = !has_color ? " " : " 4" ;
40
40
std::string color_header_count = !has_color ? " " : " 1" ;
41
41
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
+
42
47
std::ostringstream stream;
43
48
stream << " # generated by Cartographer\n "
44
49
<< " 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 "
49
54
<< " WIDTH " << std::setw (15 ) << std::setfill (' 0' ) << num_points << " \n "
50
55
<< " HEIGHT 1\n "
51
56
<< " VIEWPOINT 0 0 0 1 0 0 0\n "
@@ -65,6 +70,12 @@ void WriteBinaryPcdPointCoordinate(const Eigen::Vector3f& point,
65
70
CHECK (file_writer->Write (buffer, 12 ));
66
71
}
67
72
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
+
68
79
void WriteBinaryPcdPointColor (const Uint8Color& color,
69
80
FileWriter* const file_writer) {
70
81
char buffer[4 ];
@@ -91,10 +102,11 @@ PcdWritingPointsProcessor::PcdWritingPointsProcessor(
91
102
: next_(next),
92
103
num_points_ (0 ),
93
104
has_colors_(false ),
105
+ has_intensities_(false ),
94
106
file_writer_(std::move(file_writer)) {}
95
107
96
108
PointsProcessor::FlushResult PcdWritingPointsProcessor::Flush () {
97
- WriteBinaryPcdHeader (has_colors_, num_points_, file_writer_.get ());
109
+ WriteBinaryPcdHeader (has_colors_, has_intensities_, num_points_, file_writer_.get ());
98
110
CHECK (file_writer_->Close ());
99
111
100
112
switch (next_->Flush ()) {
@@ -116,7 +128,8 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
116
128
117
129
if (num_points_ == 0 ) {
118
130
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 ());
120
133
}
121
134
for (size_t i = 0 ; i < batch->points .size (); ++i) {
122
135
WriteBinaryPcdPointCoordinate (batch->points [i].position ,
@@ -125,6 +138,10 @@ void PcdWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
125
138
WriteBinaryPcdPointColor (ToUint8Color (batch->colors [i]),
126
139
file_writer_.get ());
127
140
}
141
+ if (has_intensities_) {
142
+ WriteBinaryPcdIntensity (batch->intensities [i],
143
+ file_writer_.get ());
144
+ }
128
145
++num_points_;
129
146
}
130
147
next_->Process (std::move (batch));
0 commit comments