1 /******************************************************************************
2 * Copyright (c) 2016, Howard Butler (howard@hobu.co)
3 *
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following
8 * conditions are met:
9 *
10 *     * Redistributions of source code must retain the above copyright
11 *       notice, this list of conditions and the following disclaimer.
12 *     * Redistributions in binary form must reproduce the above copyright
13 *       notice, this list of conditions and the following disclaimer in
14 *       the documentation and/or other materials provided
15 *       with the distribution.
16 *     * Neither the name of Hobu, Inc. or Flaxen Geo Consulting nor the
17 *       names of its contributors may be used to endorse or promote
18 *       products derived from this software without specific prior
19 *       written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
24 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
25 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
26 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
27 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
28 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
29 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
30 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
31 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
32 * OF SUCH DAMAGE.
33 ****************************************************************************/
34 
35 #pragma once
36 
37 #include <pdal/PipelineManager.hpp>
38 #include <pdal/PipelineWriter.hpp>
39 #include <pdal/util/FileUtils.hpp>
40 #include <pdal/pdal_export.hpp>
41 
42 #include <string>
43 
44 namespace pdal
45 {
46 
47 /**
48   An executor hides the management of constructing, executing, and
49   fetching data from a PipelineManager.
50 
51   It is constructed with JSON defining a pipeline.
52 */
53 
54 class PDAL_DLL PipelineExecutor {
55 public:
56 
57     /**
58       Construct a PipelineExecutor
59 
60       \param json Pipeline JSON defining the PDAL operations
61     */
62     PipelineExecutor(std::string const& json);
63 
64     /**
65       dtor
66     */
~PipelineExecutor()67     ~PipelineExecutor(){};
68 
69     /**
70       Execute the pipeline
71 
72       \return total number of points produced by the pipeline.
73     */
74     int64_t execute();
75 
76     /**
77       Validate the pipeline
78 
79       \return does PDAL think the pipeline is valid?
80     */
81     bool validate();
82 
83     /**
84       \return the transliterated pipeline
85     */
86     std::string getPipeline() const;
87 
88     /**
89       \return computed metadata for the pipeline and all stages
90     */
91     std::string getMetadata() const;
92 
93     /**
94       \return computed schema for the pipeline
95     */
96     std::string getSchema() const;
97 
98     /**
99       \return log output for the executed pipeline. use
100       setLogLevel to adjust verbosity.
101     */
102     std::string getLog() const;
103 
104     /**
105       set the log verbosity. Use values 0-8.
106     */
107     void setLogLevel(int level);
108 
109     /**
110       \return log verbosity
111     */
112     int getLogLevel() const;
113 
114     /**
115       \return has the pipeline been executed
116     */
executed() const117     inline bool executed() const
118     {
119         return m_executed;
120     }
121 
122 
123     /**
124       \return a const reference to the pipeline manager
125     */
getManagerConst() const126     PipelineManager const& getManagerConst() const { return m_manager; }
127 
128     /**
129       \return a reference to the pipeline manager
130     */
getManager()131     PipelineManager & getManager() { return m_manager; }
132 
133 private:
134     void setLogStream(std::ostream& strm);
135 
136     std::string m_json;
137     pdal::PipelineManager m_manager;
138     bool m_executed;
139     std::stringstream m_logStream;
140     pdal::LogLevel m_logLevel;
141 
142 };
143 
144 }
145