Skip to content

Commit

Permalink
Fix PcdWriter compression option
Browse files Browse the repository at this point in the history
Rearrange workflow for determining compression level
for option writers.pcd.compression. Previous version
set write method before the program arguments were
set! This resulted in always ascii compression.

This also fixes a potential free() error that can occur
when this writer is ran within a pipeline.
  • Loading branch information
Logan Byers committed Sep 12, 2016
1 parent 4b1bfe4 commit 1579aa5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 15 deletions.
17 changes: 2 additions & 15 deletions plugins/pcl/io/PcdWriter.cpp
@@ -1,5 +1,6 @@
/******************************************************************************
* Copyright (c) 2011, Brad Chambers (brad.chambers@gmail.com)
* Copytight (c) 2016, Logan Byers (logan.c.byers@gmail.com)
*
* All rights reserved.
*
Expand Down Expand Up @@ -63,9 +64,8 @@ std::string PcdWriter::getName() const { return s_info.name; }
void PcdWriter::addArgs(ProgramArgs& args)
{

std::string compression;
args.add("filename", "Filename to write PCD file to", m_filename);
args.add("compression","Level of PCD compression to use (ascii, binary, compressed)", compression, "ascii");
args.add("compression", "Level of PCD compression to use (ascii, binary, compressed)", m_compression_string);
args.add("xyz", "Write only XYZ dimensions?", m_xyz, false);
args.add("subtract_minimum", "Set origin to minimum of XYZ dimension", m_subtract_minimum, true);
args.add("offset_x", "Offset to be subtracted from XYZ position", m_offset_x, 0.0);
Expand All @@ -75,19 +75,6 @@ void PcdWriter::addArgs(ProgramArgs& args)
args.add("scale_y", "Scale to divide from XYZ dimension", m_scale_y, 1.0);
args.add("scale_z", "Scale to divide from XYZ dimension", m_scale_z, 1.0);

if (compression == "binary")
{
m_compression = 1;
}
else if (compression == "compressed")
{
m_compression = 2;
}
else // including "ascii"
{
m_compression = 0;
}

}

void PcdWriter::write(const PointViewPtr view)
Expand Down
16 changes: 16 additions & 0 deletions plugins/pcl/io/PcdWriter.hpp
@@ -1,5 +1,6 @@
/******************************************************************************
* Copyright (c) 2014, Brad Chambers (brad.chambers@gmail.com)
* Copytight (c) 2016, Logan Byers (logan.c.byers@gmail.com)
*
* All rights reserved.
*
Expand Down Expand Up @@ -67,6 +68,7 @@ class PDAL_DLL PcdWriter : public Writer
inline void writeView(const PointViewPtr view); // implemented in header

std::string m_filename;
std::string m_compression_string;
uint8_t m_compression;
bool m_xyz;
bool m_subtract_minimum;
Expand Down Expand Up @@ -101,6 +103,20 @@ void PcdWriter::writeView(const PointViewPtr view)
}
pclsupport::PDALtoPCD(view, *cloud, bounds, m_scale_x, m_scale_y, m_scale_z);
pcl::PCDWriter w;

if (m_compression_string == "binary")
{
m_compression = 1;
}
else if (m_compression_string == "compressed")
{
m_compression = 2;
}
else // including "ascii"
{
m_compression = 0;
}

switch (m_compression)
{
case 0 : w.writeASCII<PointT>(m_filename, *cloud); break;
Expand Down

0 comments on commit 1579aa5

Please sign in to comment.