[Liblas-commits] hg-main-tree: added public initialize() method for all stages, w...

liblas-commits at liblas.org liblas-commits at liblas.org
Mon Aug 1 19:46:19 EDT 2011


details:   http://hg.libpc.orghg-main-tree/rev/f170d83eaf4d
changeset: 974:f170d83eaf4d
user:      Michael P. Gerlek <mpg at flaxen.com>
date:      Mon Aug 01 16:46:11 2011 -0700
description:
added public initialize() method for all stages, which must be called before any stage operation is done - typically you will do this after the last pipeline stage is constructed

diffstat:

 include/pdal/Filter.hpp                     |    8 +-
 include/pdal/MultiFilter.hpp                |    8 +-
 include/pdal/PipelineManager.hpp            |    8 +-
 include/pdal/Reader.hpp                     |    2 +
 include/pdal/Stage.hpp                      |    2 +
 include/pdal/StageBase.hpp                  |   12 ++
 include/pdal/StageFactory.hpp               |   12 +-
 include/pdal/Writer.hpp                     |   10 +-
 include/pdal/drivers/faux/Reader.hpp        |    6 +-
 include/pdal/drivers/faux/Writer.hpp        |    4 +-
 include/pdal/drivers/las/Reader.hpp         |    4 +-
 include/pdal/drivers/las/Writer.hpp         |    6 +-
 include/pdal/drivers/liblas/Reader.hpp      |    3 +-
 include/pdal/drivers/liblas/Writer.hpp      |    5 +-
 include/pdal/drivers/oci/Reader.hpp         |    1 +
 include/pdal/drivers/oci/Writer.hpp         |    5 +-
 include/pdal/drivers/qfit/Reader.hpp        |    2 +
 include/pdal/drivers/terrasolid/Reader.hpp  |    2 +
 include/pdal/filters/ByteSwapFilter.hpp     |    8 +-
 include/pdal/filters/CacheFilter.hpp        |    8 +-
 include/pdal/filters/Chipper.hpp            |    4 +-
 include/pdal/filters/ColorFilter.hpp        |    5 +-
 include/pdal/filters/CropFilter.hpp         |    8 +-
 include/pdal/filters/DecimationFilter.hpp   |    7 +-
 include/pdal/filters/MosaicFilter.hpp       |    3 +-
 include/pdal/filters/ReprojectionFilter.hpp |    6 +-
 include/pdal/filters/ScalingFilter.hpp      |   21 ++--
 src/Filter.cpp                              |   20 ++++-
 src/MultiFilter.cpp                         |   44 +++------
 src/PipelineManager.cpp                     |    9 +-
 src/PipelineReader.cpp                      |    2 +-
 src/Reader.cpp                              |    8 +
 src/Stage.cpp                               |    8 +
 src/StageBase.cpp                           |   33 +++++++-
 src/StageFactory.cpp                        |   12 +-
 src/StageIterator.cpp                       |    5 +
 src/Writer.cpp                              |   23 ++++-
 src/drivers/faux/Reader.cpp                 |   38 +++-----
 src/drivers/faux/Writer.cpp                 |    8 +-
 src/drivers/las/Reader.cpp                  |    6 +-
 src/drivers/las/Writer.cpp                  |    8 +-
 src/drivers/liblas/Reader.cpp               |    6 +-
 src/drivers/liblas/Writer.cpp               |    8 +-
 src/drivers/oci/Reader.cpp                  |    6 +
 src/drivers/oci/Writer.cpp                  |    8 +-
 src/drivers/qfit/Reader.cpp                 |    6 +
 src/drivers/terrasolid/Reader.cpp           |    6 +
 src/filters/ByteSwapFilter.cpp              |    8 +-
 src/filters/CacheFilter.cpp                 |    8 +-
 src/filters/Chipper.cpp                     |   10 ++-
 src/filters/ColorFilter.cpp                 |   10 +-
 src/filters/CropFilter.cpp                  |   10 +-
 src/filters/DecimationFilter.cpp            |   10 +-
 src/filters/MosaicFilter.cpp                |   33 ++----
 src/filters/ReprojectionFilter.cpp          |  125 +++++++++++++--------------
 src/filters/ScalingFilter.cpp               |   42 +++-----
 test/unit/ByteSwapFilterTest.cpp            |    2 +
 test/unit/CacheFilterTest.cpp               |    4 +-
 test/unit/ChipperTest.cpp                   |    6 +-
 test/unit/CropFilterTest.cpp                |    2 +-
 test/unit/DecimationFilterTest.cpp          |    2 +
 test/unit/FauxReaderTest.cpp                |   10 ++-
 test/unit/FauxWriterTest.cpp                |    4 +-
 test/unit/LasReaderTest.cpp                 |   13 ++-
 test/unit/LasWriterTest.cpp                 |   11 +-
 test/unit/LiblasReaderTest.cpp              |   34 +++++--
 test/unit/LiblasWriterTest.cpp              |   30 +++--
 test/unit/MosaicFilterTest.cpp              |    3 +-
 test/unit/PipelineManagerTest.cpp           |    4 +
 test/unit/PipelineReaderTest.cpp            |    6 +-
 test/unit/QFITReaderTest.cpp                |    3 +-
 test/unit/ReprojectionFilterTest.cpp        |   43 +++++++--
 test/unit/ScalingFilterTest.cpp             |    5 +-
 test/unit/SpatialReferenceTest.cpp          |    5 +
 test/unit/StageFactoryTest.cpp              |   15 ++-
 test/unit/TerraSolidTest.cpp                |    2 +
 76 files changed, 559 insertions(+), 335 deletions(-)

diffs (truncated from 2772 to 300 lines):

diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/Filter.hpp
--- a/include/pdal/Filter.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/Filter.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -45,14 +45,18 @@
 class PDAL_DLL Filter : public Stage
 {
 public:
-    Filter(const Stage& prevStage, const Options& options);
+    Filter(Stage& prevStage, const Options& options);
+
+    virtual void initialize();
 
     const Stage& getPrevStage() const;
 
     virtual boost::property_tree::ptree generatePTree() const;
 
 protected:
-    const Stage& m_prevStage;
+    Stage& getPrevStage();
+
+    Stage& m_prevStage;
 
 private:
     Filter& operator=(const Filter&); // not implemented
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/MultiFilter.hpp
--- a/include/pdal/MultiFilter.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/MultiFilter.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -47,14 +47,16 @@
 public:
     // entries may not be null
     // vector.size() must be > 0
-    MultiFilter(const std::vector<const Stage*>& prevStages, const Options& options);
+    MultiFilter(const std::vector<Stage*>& prevStages, const Options& options);
 
-    const std::vector<const Stage*>& getPrevStages() const;
+    virtual void initialize();
+
+    const std::vector<const Stage*> getPrevStages() const;
 
     virtual boost::property_tree::ptree generatePTree() const;
 
 protected:
-    std::vector<const Stage*> m_prevStages;
+    std::vector<Stage*> m_prevStages;
 
 private:
     MultiFilter& operator=(const MultiFilter&); // not implemented
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/PipelineManager.hpp
--- a/include/pdal/PipelineManager.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/PipelineManager.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -59,9 +59,9 @@
 
     // Use these to manually add stages into the pipeline manager.
     Reader* addReader(const std::string& type, const Options&);
-    Filter* addFilter(const std::string& type, const Stage& prevStage, const Options&);
-    MultiFilter* addMultiFilter(const std::string& type, const std::vector<const Stage*>& prevStages, const Options&);
-    Writer* addWriter(const std::string& type, const Stage& prevStage, const Options&);
+    Filter* addFilter(const std::string& type, Stage& prevStage, const Options&);
+    MultiFilter* addMultiFilter(const std::string& type, const std::vector<Stage*>& prevStages, const Options&);
+    Writer* addWriter(const std::string& type, Stage& prevStage, const Options&);
     
     // returns true iff the pipeline endpoint is a writer
     bool isWriterPipeline() const;
@@ -70,7 +70,7 @@
     Writer* getWriter() const;
 
     // return the pipeline reader endpoint (or NULL, if not a reader pipeline)
-    const Stage* getStage() const;
+    Stage* getStage() const;
 
     // for writer pipelines, this convenience function calls getWriter()->write() so that
     // the user doesn't even need to know anything about the Writer class
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/Reader.hpp
--- a/include/pdal/Reader.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/Reader.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -52,6 +52,8 @@
     Reader(const Options& options);
     virtual ~Reader();
 
+    virtual void initialize();
+
     virtual boost::property_tree::ptree generatePTree() const;
 };
 
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/Stage.hpp
--- a/include/pdal/Stage.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/Stage.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -58,6 +58,8 @@
     Stage(const Options& options);
     virtual ~Stage();
 
+    virtual void initialize();
+
     // core properties of all stages
     const Schema& getSchema() const;
     virtual boost::uint64_t getNumPoints() const;
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/StageBase.hpp
--- a/include/pdal/StageBase.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/StageBase.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -50,6 +50,17 @@
 {
 public:
     StageBase(const Options& options);
+    virtual ~StageBase();
+
+    // This function is for derived stages to perform "static" validation, e.g. bad Option arguments.
+    // It will recursively call initialize() on all previous stages.
+    // Users must call this after the last stage in the pipeline has been consturcted.  
+    // It is not illegal to call this twice for a stage, but that doesn't mean you should.
+    // Derived stages should feel free to provide their own implementations.  Remeber to call initialize() on
+    //   the parent class before your own class-specific code.
+    // This function will throw when errors are found.
+    virtual void initialize();
+    bool isInitialized() const;
 
     const Options& getOptions() const;
 
@@ -111,6 +122,7 @@
     Options& getOptions();
 
 private:
+    bool m_initialized;
     Options m_options;
     bool m_debug;
     boost::uint8_t m_verbose;
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/StageFactory.hpp
--- a/include/pdal/StageFactory.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/StageFactory.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -72,9 +72,9 @@
 {
 public:
     typedef Reader* ReaderCreator(const Options&);
-    typedef Filter* FilterCreator(const Stage& prevStage, const Options&);
-    typedef MultiFilter* MultiFilterCreator(const std::vector<const Stage*>& prevStages, const Options&);
-    typedef Writer* WriterCreator(const Stage& prevStage, const Options&);
+    typedef Filter* FilterCreator(Stage& prevStage, const Options&);
+    typedef MultiFilter* MultiFilterCreator(const std::vector<Stage*>& prevStages, const Options&);
+    typedef Writer* WriterCreator(Stage& prevStage, const Options&);
     
     typedef std::map<std::string, ReaderCreator*> ReaderCreatorList;
     typedef std::map<std::string, FilterCreator*> FilterCreatorList;
@@ -85,9 +85,9 @@
     StageFactory();
 
     Reader* createReader(const std::string& type, const Options& options);
-    Filter* createFilter(const std::string& type, const Stage& prevStage, const Options& options);
-    MultiFilter* createMultiFilter(const std::string& type, const std::vector<const Stage*>& prevStages, const Options& options);
-    Writer* createWriter(const std::string& type, const Stage& prevStage, const Options& options);
+    Filter* createFilter(const std::string& type, Stage& prevStage, const Options& options);
+    MultiFilter* createMultiFilter(const std::string& type, const std::vector<Stage*>& prevStages, const Options& options);
+    Writer* createWriter(const std::string& type, Stage& prevStage, const Options& options);
 
     void registerReader(const std::string& type, ReaderCreator* f);
     void registerFilter(const std::string& type, FilterCreator* f);
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/Writer.hpp
--- a/include/pdal/Writer.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/Writer.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -50,9 +50,11 @@
 class PDAL_DLL Writer : public StageBase
 {
 public:
-    Writer(const Stage& prevStage, const Options& options);
+    Writer(Stage& prevStage, const Options& options);
     virtual ~Writer() {}
 
+    virtual void initialize();
+
     // size of the PointBuffer buffer to use
     void setChunkSize(boost::uint32_t);
     boost::uint32_t getChunkSize() const;
@@ -65,6 +67,8 @@
 
     virtual boost::property_tree::ptree generatePTree() const;
 
+    const Stage& getPrevStage() const;
+
 protected:
     // this is called once before the loop with the writeBuffer calls
     virtual void writeBegin() = 0;
@@ -75,14 +79,14 @@
     // called once, after the writeBuffer calls
     virtual void writeEnd() = 0;
 
-    const Stage& getPrevStage() const;
+    Stage& getPrevStage();
 
     // these two are valid for use after writeBegin has been called
     boost::uint64_t m_actualNumPointsWritten;
     boost::uint64_t m_targetNumPointsToWrite;
 
 private:
-    const Stage& m_prevStage;
+    Stage& m_prevStage;
     boost::uint32_t m_chunkSize;
     static const boost::uint32_t s_defaultChunkSize;
 
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/drivers/faux/Reader.hpp
--- a/include/pdal/drivers/faux/Reader.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/drivers/faux/Reader.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -79,6 +79,8 @@
     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);
+
+    virtual void initialize();
     
     Mode getMode() const;
     
@@ -97,12 +99,10 @@
     boost::uint32_t processBuffer(PointBuffer& data, boost::uint64_t index) const;
 
 private:
-    void initialize();
-    void initialize(const std::vector<Dimension>& dimensions);
-
     Bounds<double> m_bounds;
     boost::uint64_t m_numPoints;
     Mode m_mode;
+    std::vector<Dimension> m_dimensions;
 
     Reader& operator=(const Reader&); // not implemented
     Reader(const Reader&); // not implemented
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/drivers/faux/Writer.hpp
--- a/include/pdal/drivers/faux/Writer.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/drivers/faux/Writer.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -54,7 +54,9 @@
     DECLARE_STATICS
 
 public:
-    Writer(const Stage& prevStage, const Options&);
+    Writer(Stage& prevStage, const Options&);
+
+    virtual void initialize();
 
     // retrieve the summary info
     double getMinX() const { return m_minimumX; }
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/drivers/las/Reader.hpp
--- a/include/pdal/drivers/las/Reader.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/drivers/las/Reader.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -61,6 +61,8 @@
     LasReader(const Options&);
     LasReader(const std::string& filename);
 
+    virtual void initialize();
+
     const std::string& getFileName() const;
 
     bool supportsIterator (StageIteratorType t) const
@@ -98,8 +100,6 @@
     MetadataRecord& getMetadataRecordRef(int index);
 
 private:
-    void initialize();
-
     std::string m_filename;
     LasHeader m_lasHeader;
     std::vector<MetadataRecord> m_metadataRecords;
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/drivers/las/Writer.hpp
--- a/include/pdal/drivers/las/Writer.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/drivers/las/Writer.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -56,10 +56,12 @@
     DECLARE_STATICS
 
 public:
-    LasWriter(const Stage& prevStage, const Options&);
+    LasWriter(Stage& prevStage, const Options&);
     LasWriter(Stage& prevStage, std::ostream*);
     ~LasWriter();
 
+    virtual void initialize();
+
     void setFormatVersion(boost::uint8_t majorVersion, boost::uint8_t minorVersion);
     void setPointFormat(PointFormat);
     void setDate(boost::uint16_t dayOfYear, boost::uint16_t year);
@@ -88,8 +90,6 @@
     virtual void writeEnd();
 
 private:
-    void initialize();
-
     OStreamManager m_streamManager;
 
     LasHeader m_lasHeader;
diff -r aed3e9b3938f -r f170d83eaf4d include/pdal/drivers/liblas/Reader.hpp
--- a/include/pdal/drivers/liblas/Reader.hpp	Sat Jul 30 16:53:37 2011 -0700
+++ b/include/pdal/drivers/liblas/Reader.hpp	Mon Aug 01 16:46:11 2011 -0700
@@ -62,6 +62,8 @@
     LiblasReader(const std::string& filename);
     ~LiblasReader();
 
+    virtual void initialize();
+
     const std::string& getFileName() const;
 
     ::pdal::drivers::las::PointFormat getPointFormat() const;
@@ -86,7 +88,6 @@
     pdal::StageRandomIterator* createRandomIterator() const;
 
 private:
-    void initialize();


More information about the Liblas-commits mailing list