Skip to content

Commit

Permalink
First workings of reading without an iterator.
Browse files Browse the repository at this point in the history
BPF works.
CARIS should work :)
  • Loading branch information
abellgithub committed Sep 3, 2014
1 parent e8ce7c8 commit 0608d55
Show file tree
Hide file tree
Showing 34 changed files with 554 additions and 695 deletions.
4 changes: 3 additions & 1 deletion include/pdal/Charbuf.hpp
Expand Up @@ -32,6 +32,8 @@
* OF SUCH DAMAGE.
****************************************************************************/

#pragma once

#include <streambuf>
#include <vector>

Expand Down Expand Up @@ -63,4 +65,4 @@ class Charbuf : public std::streambuf
pos_type m_bufOffset;
};

} //namespace
} //namespace pdal
13 changes: 12 additions & 1 deletion include/pdal/IStream.hpp
Expand Up @@ -54,13 +54,22 @@ class IStream
friend class IStreamMarker;

public:
IStream() : m_stream(NULL), m_fstream(NULL)
{}
IStream(const std::string& filename)
{ m_stream = m_fstream = new std::ifstream(filename); }
{ open(filename); }
IStream(std::istream *stream) : m_stream(stream), m_fstream(NULL)
{}
~IStream()
{ delete m_fstream; }

int open(const std::string& filename)
{
if (m_stream)
return -1;
m_stream = m_fstream = new std::ifstream(filename);
return 0;
}
operator bool ()
{ return (bool)(*m_stream); }
void seek(std::streampos pos)
Expand Down Expand Up @@ -98,6 +107,8 @@ class IStream
class ILeStream : public IStream
{
public:
ILeStream() : IStream()
{}
ILeStream(const std::string& filename) : IStream(filename)
{}
ILeStream(std::istream *stream) : IStream(stream)
Expand Down
25 changes: 15 additions & 10 deletions include/pdal/Reader.hpp
Expand Up @@ -32,8 +32,7 @@
* OF SUCH DAMAGE.
****************************************************************************/

#ifndef INCLUDED_READER_HPP
#define INCLUDED_READER_HPP
#pragma once

#include <pdal/Stage.hpp>
#include <pdal/Options.hpp>
Expand All @@ -52,26 +51,32 @@ namespace pdal
class PDAL_DLL Reader : public Stage
{
public:
Reader()
{}
Reader(Options const& options) : Stage(options)
{};
virtual ~Reader()
{};
Reader(Options const& options) : Stage(options),
m_count(std::numeric_limits<point_count_t>::max())
{}

protected:
std::string m_filename;
point_count_t m_count;

private:
virtual PointBufferSet run(PointBufferPtr buffer)
{
PointBufferSet pbSet;

StageSequentialIterator *it = createSequentialIterator();
it->read(*buffer);
if (it)
it->read(*buffer);
else
read(*buffer, m_count);
pbSet.insert(buffer);
return pbSet;
}
virtual void readerProcessOptions(const Options& options);
virtual point_count_t read(PointBuffer& buf, point_count_t num)
{ return 0; }
virtual boost::property_tree::ptree serializePipeline() const;
};

} // namespace pdal

#endif
66 changes: 0 additions & 66 deletions include/pdal/ReaderIterator.hpp

This file was deleted.

10 changes: 3 additions & 7 deletions include/pdal/Stage.hpp
Expand Up @@ -121,13 +121,7 @@ class PDAL_DLL Stage
static bool s_isEnabled() { return YES_OR_NO; } \
bool isEnabled() const { return YES_OR_NO; }

virtual StageSequentialIterator*
createSequentialIterator(PointBuffer&) const
{ return NULL; }
virtual StageSequentialIterator*
createSequentialIterator() const
{ std::cerr << "Created crap sequential iterator!\n"; return NULL; }
virtual StageRandomIterator* createRandomIterator(PointBuffer&) const
virtual StageSequentialIterator* createSequentialIterator() const
{ return NULL; }
inline MetadataNode getMetadata() const
{ return m_metadata; }
Expand All @@ -151,6 +145,8 @@ class PDAL_DLL Stage
void l_processOptions(const Options& options);
virtual void processOptions(const Options& /*options*/)
{}
virtual void readerProcessOptions(const Options& /*options*/)
{}
virtual void writerProcessOptions(const Options& /*options*/)
{}
void l_initialize(PointContext ctx);
Expand Down
31 changes: 0 additions & 31 deletions include/pdal/StageIterator.hpp
Expand Up @@ -47,7 +47,6 @@ class PointBuffer;
class PDAL_DLL StageIterator
{
public:
StageIterator(PointBuffer& buffer);
StageIterator();
virtual ~StageIterator()
{}
Expand Down Expand Up @@ -150,11 +149,6 @@ class PDAL_DLL StageIterator
class PDAL_DLL StageSequentialIterator : public StageIterator
{
public:
StageSequentialIterator(PointBuffer& buffer);
StageSequentialIterator()
{}
virtual ~StageSequentialIterator();

// returns true after we've read all the points available to this stage
bool atEnd() const;

Expand All @@ -166,31 +160,6 @@ class PDAL_DLL StageSequentialIterator : public StageIterator
virtual bool atEndImpl() const = 0;
};


class PDAL_DLL StageRandomIterator : public StageIterator
{
public:
StageRandomIterator(PointBuffer& buffer);
virtual ~StageRandomIterator();

// seek to point N (an absolute value)
//
// In some cases, this might be a very slow, painful function to call
// because it might entail physically reading the N points (and dropping
// the data on the floor)
//
// Returns the number actually seeked to (which might be less than asked
// for, if the end of the stage was reached first).
boost::uint64_t seek(boost::uint64_t position);

protected:
// from Iterator
virtual point_count_t readImpl(PointBuffer& /*data*/, point_count_t /*count*/)
{ std::cerr << "No random readImpl for stage/iterator!\n"; return 0; }
virtual boost::uint64_t seekImpl(boost::uint64_t position) = 0;
virtual boost::uint64_t skipImpl(boost::uint64_t position);
};

} // namespace pdal

#endif
42 changes: 32 additions & 10 deletions include/pdal/drivers/bpf/BpfReader.hpp
Expand Up @@ -34,9 +34,11 @@

#pragma once

#include <vector>

#include <pdal/Charbuf.hpp>
#include <pdal/IStream.hpp>
#include <pdal/Reader.hpp>
#include <pdal/ReaderIterator.hpp>

#include "BpfHeader.hpp"

Expand All @@ -50,15 +52,11 @@ class PDAL_DLL BpfReader : public Reader
SET_STAGE_LINK("http://pdal.io/stages/drivers.bpf.reader.html")
SET_STAGE_ENABLED(true)

BpfReader(const Options&);
BpfReader(const std::string&);

virtual boost::uint64_t getNumPoints() const
{ return m_header.m_numPts; }

StageSequentialIterator* createSequentialIterator() const;
StageRandomIterator* createRandomIterator(PointBuffer& buffer) const;
BpfReader(const Options& options) : Reader(options)
{}

virtual point_count_t numPoints() const
{ return (point_count_t)m_header.m_numPts; }
private:
ILeStream m_stream;
BpfHeader m_header;
Expand All @@ -68,12 +66,36 @@ class PDAL_DLL BpfReader : public Reader
std::vector<BpfUlemFrame> m_ulemFrames;
BpfPolarHeader m_polarHeader;
std::vector<BpfPolarFrame> m_polarFrames;
/// Stream position at the beginning of point records.
std::streampos m_start;
/// Index of the next point to read.
point_count_t m_index;
/// Buffer for deflated data.
std::vector<char> m_deflateBuf;
/// Streambuf for deflated data.
Charbuf m_charbuf;

virtual void processOptions(const Options& options);
virtual void initialize();
virtual void addDimensions(PointContext ctx);
virtual void ready(PointContext ctx);
virtual point_count_t read(PointBuffer& buf, point_count_t num);
virtual void done(PointContext ctx);
virtual bool eof();

bool readUlemData();
bool readPolarData();
point_count_t readPointMajor(PointBuffer& data, point_count_t count);
point_count_t readDimMajor(PointBuffer& data, point_count_t count);
point_count_t readByteMajor(PointBuffer& data, point_count_t count);
size_t readBlock(std::vector<char>& outBuf, size_t index);
#ifdef PDAL_HAVE_ZLIB
int inflate(char *inbuf, size_t insize, char *outbuf, size_t outsize);
#endif
void seekPointMajor(PointId ptIdx);
void seekDimMajor(size_t dimIdx, PointId ptIdx);
void seekByteMajor(size_t dimIdx, size_t byteIdx, PointId ptIdx);
};

} // namespace
} // namespace pdal

4 changes: 2 additions & 2 deletions include/pdal/drivers/bpf/BpfSeqIterator.hpp
Expand Up @@ -36,7 +36,7 @@

#include <pdal/Charbuf.hpp>
#include <pdal/IStream.hpp>
#include <pdal/ReaderIterator.hpp>
#include <pdal/StageIterator.hpp>
#include "BpfHeader.hpp"

#include <vector>
Expand All @@ -47,7 +47,7 @@ namespace pdal
class BpfReader;
class PointBuffer;

class BpfSeqIterator : public ReaderSequentialIterator
class BpfSeqIterator : public StageSequentialIterator
{
public:
BpfSeqIterator(const BpfDimensionList& dims, point_count_t numPoints,
Expand Down

0 comments on commit 0608d55

Please sign in to comment.