Skip to content

Commit

Permalink
Don't use stage in iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Bell authored and Andrew Bell committed Mar 27, 2014
1 parent 904a852 commit 2482805
Show file tree
Hide file tree
Showing 21 changed files with 256 additions and 215 deletions.
6 changes: 2 additions & 4 deletions include/pdal/StageBase.hpp
Expand Up @@ -104,10 +104,8 @@ class PDAL_DLL StageBase
virtual boost::property_tree::ptree serializePipeline() const = 0;

/// @return the pdal::LogPtr for this pdal::Stage.
virtual LogPtr log(void) const
{
return m_log;
}
virtual LogPtr log() const
{ return m_log; }


/// Put data to the log
Expand Down
2 changes: 0 additions & 2 deletions include/pdal/StageIterator.hpp
Expand Up @@ -51,8 +51,6 @@ class PDAL_DLL StageIterator
virtual ~StageIterator()
{}

const Stage& getStage() const;

// This reads a set of points at the current position in the file.
//
// The schema of the PointBuffer buffer we are given here might
Expand Down
5 changes: 4 additions & 1 deletion include/pdal/drivers/buffer/Reader.hpp
Expand Up @@ -91,14 +91,17 @@ namespace sequential
class PDAL_DLL Reader : public pdal::ReaderSequentialIterator
{
public:
Reader(pdal::drivers::buffer::Reader const& reader, PointBuffer& buffer);
Reader(pdal::drivers::buffer::Reader const& reader, PointBuffer& buffer,
boost::uint32_t numPoints, LogPtr log);

private:
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;

pdal::drivers::buffer::Reader const& m_reader;
boost::uint32_t m_numPoints;
LogPtr m_log;
};

}
Expand Down
20 changes: 14 additions & 6 deletions include/pdal/drivers/faux/Reader.hpp
Expand Up @@ -61,10 +61,14 @@ namespace faux
// Time - uint64
//
// It supports a few modes:
// - "random" generates points that are randomly distributed within the given bounding box
// - "constant" generates its points to always be at the minimum of the bounding box
// - "ramp" generates its points as a linear ramp from the minimum of the bbox to the maximum
// In all these modes, however, the Time field is always set to the point number.
// - "random" generates points that are randomly distributed within the
// given bounding box
// - "constant" generates its points to always be at the minimum of the
// bounding box
// - "ramp" generates its points as a linear ramp from the minimum of the
// bbox to the maximum
// In all these modes, however, the Time field is always set to the point
// number.
//
class PDAL_DLL Reader : public pdal::Reader
{
Expand All @@ -81,7 +85,8 @@ class PDAL_DLL Reader : public pdal::Reader

Reader(const Options& options);
Reader(const Bounds<double>&, boost::uint64_t numPoints, Mode mode);
Reader(const Bounds<double>&, boost::uint64_t numPoints, Mode mode, const std::vector<Dimension>& dimensions);
Reader(const Bounds<double>&, boost::uint64_t numPoints, Mode mode,
const std::vector<Dimension>& dimensions);

virtual void initialize();
static Options getDefaultOptions();
Expand Down Expand Up @@ -116,14 +121,17 @@ namespace sequential
class PDAL_DLL Reader : public pdal::ReaderSequentialIterator
{
public:
Reader(pdal::drivers::faux::Reader const& reader, PointBuffer& buffer);
Reader(pdal::drivers::faux::Reader const& reader, PointBuffer& buffer,
boost::uint32_t numPoints, LogPtr log);

private:
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;

pdal::drivers::faux::Reader const& m_reader;
boost::uint32_t m_numPoints;
LogPtr m_log;
};

}
Expand Down
5 changes: 4 additions & 1 deletion include/pdal/drivers/las/Reader.hpp
Expand Up @@ -161,7 +161,8 @@ namespace sequential
class Reader : public Base, public pdal::ReaderSequentialIterator
{
public:
Reader(const pdal::drivers::las::Reader& reader, PointBuffer& buffer);
Reader(const pdal::drivers::las::Reader& reader, PointBuffer& buffer,
boost::uint32_t numPoints);
~Reader();

protected:
Expand All @@ -172,6 +173,8 @@ class Reader : public Base, public pdal::ReaderSequentialIterator
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;

boost::uint32_t m_numPoints;
};

} // sequential
Expand Down
9 changes: 6 additions & 3 deletions include/pdal/drivers/qfit/Reader.hpp
Expand Up @@ -186,7 +186,8 @@ namespace sequential
class Reader : public pdal::ReaderSequentialIterator
{
public:
Reader(const pdal::drivers::qfit::Reader& reader, PointBuffer& buffer);
Reader(const pdal::drivers::qfit::Reader& reader, PointBuffer& buffer,
boost::uint32_t numPoints);
~Reader();

private:
Expand All @@ -196,9 +197,9 @@ class Reader : public pdal::ReaderSequentialIterator

const pdal::drivers::qfit::Reader& m_reader;
std::istream* m_istream;
boost::uint32_t m_numPoints;
};


} // sequential

namespace random
Expand All @@ -207,7 +208,8 @@ namespace random
class Reader : public pdal::ReaderRandomIterator
{
public:
Reader(const pdal::drivers::qfit::Reader& reader, PointBuffer& buffer);
Reader(const pdal::drivers::qfit::Reader& reader, PointBuffer& buffer,
boost::uint32_t numPoints);
~Reader();

private:
Expand All @@ -216,6 +218,7 @@ class Reader : public pdal::ReaderRandomIterator

const pdal::drivers::qfit::Reader& m_reader;
std::istream* m_istream;
boost::uint32_t m_numPoints;
};

} // random
Expand Down
8 changes: 6 additions & 2 deletions include/pdal/drivers/terrasolid/Reader.hpp
Expand Up @@ -190,7 +190,8 @@ namespace sequential
class Reader : public pdal::ReaderSequentialIterator
{
public:
Reader(const pdal::drivers::terrasolid::Reader& reader, PointBuffer& buffer);
Reader(const pdal::drivers::terrasolid::Reader& reader,
PointBuffer& buffer, uint32_t m_numPoints);
~Reader();

private:
Expand All @@ -200,6 +201,7 @@ class Reader : public pdal::ReaderSequentialIterator

const pdal::drivers::terrasolid::Reader& m_reader;
std::istream* m_istream;
boost::uint32_t m_numPoints;
};


Expand All @@ -211,7 +213,8 @@ namespace random
class Reader : public pdal::ReaderRandomIterator
{
public:
Reader(const pdal::drivers::terrasolid::Reader& reader, PointBuffer& buffer);
Reader(const pdal::drivers::terrasolid::Reader& reader,
PointBuffer& buffer, uint32_t numPoints);
~Reader();

private:
Expand All @@ -220,6 +223,7 @@ class Reader : public pdal::ReaderRandomIterator

const pdal::drivers::terrasolid::Reader& m_reader;
std::istream* m_istream;
uint32_t m_numPoints;
};

} // random
Expand Down
5 changes: 3 additions & 2 deletions include/pdal/filters/Decimation.hpp
Expand Up @@ -115,7 +115,6 @@ class PDAL_DLL Decimation : public pdal::FilterSequentialIterator, public decima
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;

};


Expand All @@ -127,14 +126,16 @@ namespace random
class PDAL_DLL Decimation : public pdal::FilterRandomIterator, public decimation::IteratorBase
{
public:
Decimation(const pdal::filters::Decimation& filter, PointBuffer& buffer);
Decimation(const pdal::filters::Decimation& filter, PointBuffer& buffer,
boost::uint32_t offset);
virtual ~Decimation() {};

protected:
virtual boost::uint32_t readBufferImpl(PointBuffer& buffer);

virtual boost::uint64_t seekImpl(boost::uint64_t);

boost::uint32_t m_offset;
};
} // random

Expand Down
10 changes: 6 additions & 4 deletions include/pdal/filters/Mosaic.hpp
Expand Up @@ -88,21 +88,23 @@ namespace sequential
class PDAL_DLL Mosaic : public pdal::MultiFilterSequentialIterator
{
public:
Mosaic(const pdal::filters::Mosaic& filter, PointBuffer& buffer);
Mosaic(const pdal::filters::Mosaic& filter, PointBuffer& buffer,
LogPtr log, const Options& options);
~Mosaic();

private:
boost::uint64_t skipImpl(boost::uint64_t);
boost::uint32_t readBufferImpl(PointBuffer&);
bool atEndImpl() const;
DimensionMapPtr fetchDimensionMap(PointBuffer const& user_buffer, BufferPtr stage_buffer);
DimensionMapPtr fetchDimensionMap(PointBuffer const& user_buffer,
BufferPtr stage_buffer);
BufferPtr fetchPointBuffer(PointBuffer const& user_buffer);
DimensionMapPtr m_active_dimension;
DimensionMaps m_dimensions;

BufferMap m_buffers;


LogPtr m_log;
Options m_options;
};


Expand Down
8 changes: 7 additions & 1 deletion include/pdal/filters/Stats.hpp
Expand Up @@ -224,7 +224,9 @@ typedef boost::shared_ptr<Dimension> DimensionPtr;
class PDAL_DLL Stats : public pdal::FilterSequentialIterator
{
public:
Stats(const pdal::filters::Stats& filter, PointBuffer& buffer);
Stats(const pdal::filters::Stats& filter, PointBuffer& buffer,
LogPtr log, boost::uint64_t numPoints, const std::string& name,
const Options& options);
boost::property_tree::ptree toPTree() const;
pdal::Metadata toMetadata() const;
stats::Summary const& getStats(Dimension const& dim) const;
Expand All @@ -246,6 +248,10 @@ class PDAL_DLL Stats : public pdal::FilterSequentialIterator
std::vector<std::string> m_exact_dimension_names;

std::multimap<DimensionPtr,stats::SummaryPtr> m_stats; // one Stats item per field in the schema
LogPtr m_log;
boost::uint64_t m_numPoints;
std::string m_name;
Options m_options;
};


Expand Down
19 changes: 6 additions & 13 deletions src/StageIterator.cpp
Expand Up @@ -60,11 +60,12 @@ StageIterator::StageIterator(const Stage& stage, PointBuffer& buffer)
, m_readBufferBeginPerformed(false)
{}

/**
const Stage& StageIterator::getStage() const
{
return m_stage;
}

**/

boost::uint64_t StageIterator::getIndex() const
{
Expand Down Expand Up @@ -194,7 +195,8 @@ boost::uint64_t StageIterator::naiveSkipImpl(boost::uint64_t count)
boost::uint32_t thisCount =
static_cast<boost::uint32_t>(thisCount64);

PointBuffer junk(getStage().getSchema(), thisCount);
// PointBuffer junk(getStage().getSchema(), thisCount);
PointBuffer junk(Schema(), thisCount);
boost::uint32_t numRead = read(junk);
if (numRead == 0)
break; // end of file or something
Expand Down Expand Up @@ -254,17 +256,8 @@ StageRandomIterator::~StageRandomIterator()

boost::uint64_t StageRandomIterator::seek(boost::uint64_t position)
{
boost::uint64_t size = getStage().getNumPoints();
if (size != 0 && position >= size)
{
std::ostringstream oss;
oss << "position '" << position <<
"' is out of bounds of size of stage '" << size << "'";
throw invalid_seek_error(oss.str());
}
boost::uint64_t newPos = seekImpl(position);
m_index = newPos;
return newPos;
m_index = seekImpl(position);
return m_index;
}

} // namespace pdal
24 changes: 10 additions & 14 deletions src/drivers/buffer/Reader.cpp
Expand Up @@ -75,7 +75,8 @@ Options Reader::getDefaultOptions()

pdal::StageSequentialIterator* Reader::createSequentialIterator(PointBuffer& buffer) const
{
return new pdal::drivers::buffer::iterators::sequential::Reader(*this, buffer);
return new pdal::drivers::buffer::iterators::sequential::Reader(
*this, buffer, getNumPoints(), log());
}


Expand Down Expand Up @@ -120,12 +121,11 @@ namespace sequential



Reader::Reader(const pdal::drivers::buffer::Reader& reader, PointBuffer& buffer)
Reader::Reader(const pdal::drivers::buffer::Reader& reader, PointBuffer& buffer,
boost::uint32_t numPoints, LogPtr log)
: pdal::ReaderSequentialIterator(reader, buffer)
, m_reader(reader)
{
return;
}
, m_reader(reader), m_numPoints(numPoints), m_log(log)
{}


boost::uint64_t Reader::skipImpl(boost::uint64_t count)
Expand All @@ -136,16 +136,14 @@ boost::uint64_t Reader::skipImpl(boost::uint64_t count)

bool Reader::atEndImpl() const
{
const boost::uint64_t numPoints = getStage().getNumPoints();
const boost::uint64_t currPoint = getIndex();

return currPoint >= numPoints;
return getIndex() >= m_numPoints;
}


boost::uint32_t Reader::readBufferImpl(PointBuffer& data)
{
m_reader.log()->get(logDEBUG5) << "Reading a point buffer of " << data.getCapacity() << " points." << std::endl;
m_log->get(logDEBUG5) << "Reading a point buffer of " <<
data.getCapacity() << " points." << std::endl;
return m_reader.processBuffer(data, getIndex());
}

Expand All @@ -161,9 +159,7 @@ namespace random
Reader::Reader(const pdal::drivers::buffer::Reader& reader, PointBuffer& buffer)
: pdal::ReaderRandomIterator(reader, buffer)
, m_reader(reader)
{
return;
}
{}


boost::uint64_t Reader::seekImpl(boost::uint64_t count)
Expand Down

0 comments on commit 2482805

Please sign in to comment.