26 #include "glog/logging.h" 35 void WriteBinaryPlyHeader(
const bool has_color,
const int64 num_points,
36 FileWriter*
const file_writer) {
37 string color_header = !has_color ?
"" 38 :
"property uchar red\n" 39 "property uchar green\n" 40 "property uchar blue\n";
41 std::ostringstream stream;
43 <<
"format binary_little_endian 1.0\n" 44 <<
"comment generated by Cartographer\n" 45 <<
"element vertex " << std::setw(15) << std::setfill(
'0')
47 <<
"property float x\n" 48 <<
"property float y\n" 49 <<
"property float z\n" 50 << color_header <<
"end_header\n";
51 const string out = stream.str();
52 CHECK(file_writer->WriteHeader(out.data(), out.size()));
55 void WriteBinaryPlyPointCoordinate(
const Eigen::Vector3f& point,
56 FileWriter*
const file_writer) {
58 memcpy(buffer, &point[0],
sizeof(
float));
59 memcpy(buffer + 4, &point[1],
sizeof(
float));
60 memcpy(buffer + 8, &point[2],
sizeof(
float));
61 CHECK(file_writer->Write(buffer, 12));
64 void WriteBinaryPlyPointColor(
const Color& color,
65 FileWriter*
const file_writer) {
66 CHECK(file_writer->Write(reinterpret_cast<const char*>(color.data()),
72 std::unique_ptr<PlyWritingPointsProcessor>
77 return common::make_unique<PlyWritingPointsProcessor>(
78 file_writer_factory(dictionary->
GetString(
"filename")), next);
86 file_(std::move(file_writer)) {}
90 CHECK(
file_->Close()) <<
"Closing PLY file_writer failed.";
97 LOG(FATAL) <<
"PLY generation must be configured to occur after any " 98 "stages that require multiple passes.";
104 if (batch->points.empty()) {
114 CHECK_EQ(batch->points.size(), batch->colors.size())
115 <<
"First PointsBatch had colors, but encountered one without. " 120 for (
size_t i = 0; i < batch->points.size(); ++i) {
121 WriteBinaryPlyPointCoordinate(batch->points[i],
file_.get());
123 WriteBinaryPlyPointColor(batch->colors[i],
file_.get());
virtual void Process(std::unique_ptr< PointsBatch > points_batch)=0
PointsProcessor *const next_
std::unique_ptr< FileWriter > file_
std::function< std::unique_ptr< FileWriter >(const string &filename)> FileWriterFactory
std::array< uint8_t, 3 > Color
void Process(std::unique_ptr< PointsBatch > batch) override
PlyWritingPointsProcessor(std::unique_ptr< FileWriter > file, PointsProcessor *next)
virtual FlushResult Flush()=0
string GetString(const string &key)
static std::unique_ptr< PlyWritingPointsProcessor > FromDictionary(FileWriterFactory file_writer_factory, common::LuaParameterDictionary *dictionary, PointsProcessor *next)
FlushResult Flush() override