Ability to pass additional comments to ply header. (#1549)

master
Marco Feuerstein 2019-03-26 11:33:03 +01:00 committed by Wally B. Feed
parent a6050b5870
commit 111d7bb5aa
2 changed files with 17 additions and 6 deletions

View File

@ -33,6 +33,7 @@ namespace {
// Writes the PLY header claiming 'num_points' will follow it into // Writes the PLY header claiming 'num_points' will follow it into
// 'output_file'. // 'output_file'.
void WriteBinaryPlyHeader(const bool has_color, const bool has_intensities, void WriteBinaryPlyHeader(const bool has_color, const bool has_intensities,
const std::vector<std::string>& comments,
const int64 num_points, const int64 num_points,
FileWriter* const file_writer) { FileWriter* const file_writer) {
const std::string color_header = !has_color ? "" const std::string color_header = !has_color ? ""
@ -44,8 +45,11 @@ void WriteBinaryPlyHeader(const bool has_color, const bool has_intensities,
std::ostringstream stream; std::ostringstream stream;
stream << "ply\n" stream << "ply\n"
<< "format binary_little_endian 1.0\n" << "format binary_little_endian 1.0\n"
<< "comment generated by Cartographer\n" << "comment generated by Cartographer\n";
<< "element vertex " << std::setw(15) << std::setfill('0') for (const std::string& comment : comments) {
stream << "comment " << comment << "\n";
}
stream << "element vertex " << std::setw(15) << std::setfill('0')
<< num_points << "\n" << num_points << "\n"
<< "property float x\n" << "property float x\n"
<< "property float y\n" << "property float y\n"
@ -86,18 +90,22 @@ PlyWritingPointsProcessor::FromDictionary(
common::LuaParameterDictionary* const dictionary, common::LuaParameterDictionary* const dictionary,
PointsProcessor* const next) { PointsProcessor* const next) {
return absl::make_unique<PlyWritingPointsProcessor>( return absl::make_unique<PlyWritingPointsProcessor>(
file_writer_factory(dictionary->GetString("filename")), next); file_writer_factory(dictionary->GetString("filename")),
std::vector<std::string>(), next);
} }
PlyWritingPointsProcessor::PlyWritingPointsProcessor( PlyWritingPointsProcessor::PlyWritingPointsProcessor(
std::unique_ptr<FileWriter> file_writer, PointsProcessor* const next) std::unique_ptr<FileWriter> file_writer,
const std::vector<std::string>& comments, PointsProcessor* const next)
: next_(next), : next_(next),
comments_(comments),
num_points_(0), num_points_(0),
has_colors_(false), has_colors_(false),
file_(std::move(file_writer)) {} file_(std::move(file_writer)) {}
PointsProcessor::FlushResult PlyWritingPointsProcessor::Flush() { PointsProcessor::FlushResult PlyWritingPointsProcessor::Flush() {
WriteBinaryPlyHeader(has_colors_, has_intensities_, num_points_, file_.get()); WriteBinaryPlyHeader(has_colors_, has_intensities_, comments_, num_points_,
file_.get());
CHECK(file_->Close()) << "Closing PLY file_writer failed."; CHECK(file_->Close()) << "Closing PLY file_writer failed.";
switch (next_->Flush()) { switch (next_->Flush()) {
@ -120,7 +128,8 @@ void PlyWritingPointsProcessor::Process(std::unique_ptr<PointsBatch> batch) {
if (num_points_ == 0) { if (num_points_ == 0) {
has_colors_ = !batch->colors.empty(); has_colors_ = !batch->colors.empty();
has_intensities_ = !batch->intensities.empty(); has_intensities_ = !batch->intensities.empty();
WriteBinaryPlyHeader(has_colors_, has_intensities_, 0, file_.get()); WriteBinaryPlyHeader(has_colors_, has_intensities_, comments_, 0,
file_.get());
} }
if (has_colors_) { if (has_colors_) {
CHECK_EQ(batch->points.size(), batch->colors.size()) CHECK_EQ(batch->points.size(), batch->colors.size())

View File

@ -26,6 +26,7 @@ class PlyWritingPointsProcessor : public PointsProcessor {
public: public:
constexpr static const char* kConfigurationFileActionName = "write_ply"; constexpr static const char* kConfigurationFileActionName = "write_ply";
PlyWritingPointsProcessor(std::unique_ptr<FileWriter> file_writer, PlyWritingPointsProcessor(std::unique_ptr<FileWriter> file_writer,
const std::vector<std::string>& comments,
PointsProcessor* next); PointsProcessor* next);
static std::unique_ptr<PlyWritingPointsProcessor> FromDictionary( static std::unique_ptr<PlyWritingPointsProcessor> FromDictionary(
@ -44,6 +45,7 @@ class PlyWritingPointsProcessor : public PointsProcessor {
private: private:
PointsProcessor* const next_; PointsProcessor* const next_;
std::vector<std::string> comments_;
int64 num_points_; int64 num_points_;
bool has_colors_; bool has_colors_;
bool has_intensities_; bool has_intensities_;