Skip to content

Commit

Permalink
Revert "Revert "make the PointBuffer that the pdal::Writer uses heap-…
Browse files Browse the repository at this point in the history
…allocated and owned by the pdal::Writer instance. Add a public method to fetch it so that others may get the properties of the writer's PointBuffer""

This reverts commit e800967.
  • Loading branch information
hobu committed Oct 30, 2012
1 parent e800967 commit 7753d52
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
4 changes: 3 additions & 1 deletion include/pdal/Writer.hpp
Expand Up @@ -52,7 +52,7 @@ class PDAL_DLL Writer : public StageBase
{
public:
Writer(Stage& prevStage, const Options& options);
virtual ~Writer() {}
virtual ~Writer();

virtual void initialize();

Expand All @@ -76,6 +76,7 @@ class PDAL_DLL Writer : public StageBase

// for dumping
virtual boost::property_tree::ptree toPTree() const;
virtual PointBuffer const* getPointBuffer() const { return m_buffer; }

static const boost::uint32_t s_defaultChunkSize = 1048576;

Expand All @@ -102,6 +103,7 @@ class PDAL_DLL Writer : public StageBase

SpatialReference m_spatialReference;
UserCallback* m_userCallback;
PointBuffer* m_buffer;

Writer& operator=(const Writer&); // not implemented
Writer(const Writer&); // not implemented
Expand Down
33 changes: 20 additions & 13 deletions src/Writer.cpp
Expand Up @@ -54,6 +54,7 @@ Writer::Writer(Stage& prevStage, const Options& options)
: StageBase(StageBase::makeVector(prevStage), options)
, m_chunkSize(options.getValueOrDefault("chunk_size", s_defaultChunkSize))
, m_userCallback(0)
, m_buffer(0)
{
return;
}
Expand All @@ -66,6 +67,12 @@ void Writer::initialize()
return;
}

Writer::~Writer()
{
if (m_buffer != 0)
delete m_buffer;
}


void Writer::setChunkSize(boost::uint32_t chunkSize)
{
Expand Down Expand Up @@ -153,9 +160,9 @@ boost::uint64_t Writer::write( boost::uint64_t targetNumPointsToWrite,
do_callback(0.0, callback);

const Schema& schema = getPrevStage().getSchema();
PointBuffer buffer(schema, m_chunkSize);
m_buffer = new PointBuffer (schema, m_chunkSize);

boost::scoped_ptr<StageSequentialIterator> iter(getPrevStage().createSequentialIterator(buffer));
boost::scoped_ptr<StageSequentialIterator> iter(getPrevStage().createSequentialIterator(*m_buffer));

if (startingPosition)
iter->skip(startingPosition);
Expand Down Expand Up @@ -193,28 +200,28 @@ boost::uint64_t Writer::write( boost::uint64_t targetNumPointsToWrite,
const boost::uint32_t numPointsToReadThisChunk = static_cast<boost::uint32_t>(numPointsToReadThisChunk64);

// we are reusing the buffer, so we may need to adjust the capacity for the last (and likely undersized) chunk
if (buffer.getCapacity() != numPointsToReadThisChunk)
if (m_buffer->getCapacity() != numPointsToReadThisChunk)
{
buffer.resize(numPointsToReadThisChunk);
m_buffer->resize(numPointsToReadThisChunk);
}
}

// read...
iter->readBufferBegin(buffer);
const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(buffer);
iter->readBufferEnd(buffer);
iter->readBufferBegin(*m_buffer);
const boost::uint32_t numPointsReadThisChunk = iter->readBuffer(*m_buffer);
iter->readBufferEnd(*m_buffer);

assert(numPointsReadThisChunk == buffer.getNumPoints());
assert(numPointsReadThisChunk <= buffer.getCapacity());
assert(numPointsReadThisChunk == m_buffer->getNumPoints());
assert(numPointsReadThisChunk <= m_buffer->getCapacity());

// have we reached the end yet?
if (numPointsReadThisChunk == 0) break;

// write...
writeBufferBegin(buffer);
const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(buffer);
writeBufferBegin(*m_buffer);
const boost::uint32_t numPointsWrittenThisChunk = writeBuffer(*m_buffer);
assert(numPointsWrittenThisChunk == numPointsReadThisChunk);
writeBufferEnd(buffer);
writeBufferEnd(*m_buffer);

// update count
actualNumPointsWritten += numPointsWrittenThisChunk;
Expand All @@ -228,7 +235,7 @@ boost::uint64_t Writer::write( boost::uint64_t targetNumPointsToWrite,
}

// reset the buffer, so we can use it again
buffer.setNumPoints(0);
m_buffer->setNumPoints(0);
}

iter->readEnd();
Expand Down

0 comments on commit 7753d52

Please sign in to comment.