26 #include "glog/logging.h" 35 void WriteBinaryPcdHeader(
const bool has_color,
const int64 num_points,
36 FileWriter*
const file_writer) {
37 string color_header_field = !has_color ?
"" :
" rgb";
38 string color_header_type = !has_color ?
"" :
" U";
39 string color_header_size = !has_color ?
"" :
" 4";
40 string color_header_count = !has_color ?
"" :
" 1";
42 std::ostringstream stream;
43 stream <<
"# generated by Cartographer\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" 49 <<
"WIDTH " << std::setw(15) << std::setfill(
'0') << num_points <<
"\n" 51 <<
"VIEWPOINT 0 0 0 1 0 0 0\n" 52 <<
"POINTS " << std::setw(15) << std::setfill(
'0') << num_points
55 const string out = stream.str();
56 file_writer->WriteHeader(out.data(), out.size());
59 void WriteBinaryPcdPointCoordinate(
const Eigen::Vector3f& point,
60 FileWriter*
const file_writer) {
62 memcpy(buffer, &point[0],
sizeof(
float));
63 memcpy(buffer + 4, &point[1],
sizeof(
float));
64 memcpy(buffer + 8, &point[2],
sizeof(
float));
65 CHECK(file_writer->Write(buffer, 12));
68 void WriteBinaryPcdPointColor(
const Color& color,
69 FileWriter*
const file_writer) {
75 CHECK(file_writer->Write(buffer, 4));
80 std::unique_ptr<PcdWritingPointsProcessor>
85 return common::make_unique<PcdWritingPointsProcessor>(
86 file_writer_factory(dictionary->
GetString(
"filename")), next);
105 LOG(FATAL) <<
"PCD generation must be configured to occur after any " 106 "stages that require multiple passes.";
112 if (batch->points.empty()) {
121 for (
size_t i = 0; i < batch->points.size(); ++i) {
122 WriteBinaryPcdPointCoordinate(batch->points[i],
file_writer_.get());
123 if (!batch->colors.empty()) {
124 WriteBinaryPcdPointColor(batch->colors[i],
file_writer_.get());
virtual void Process(std::unique_ptr< PointsBatch > points_batch)=0
FlushResult Flush() override
std::function< std::unique_ptr< FileWriter >(const string &filename)> FileWriterFactory
PointsProcessor *const next_
PcdWritingPointsProcessor(std::unique_ptr< FileWriter > file_writer, PointsProcessor *next)
static std::unique_ptr< PcdWritingPointsProcessor > FromDictionary(FileWriterFactory file_writer_factory, common::LuaParameterDictionary *dictionary, PointsProcessor *next)
std::array< uint8_t, 3 > Color
std::unique_ptr< FileWriter > file_writer_
virtual FlushResult Flush()=0
void Process(std::unique_ptr< PointsBatch > batch) override
string GetString(const string &key)