MCPcopy Create free account
hub / github.com/PDAL/PDAL / makeJSONPipeline

Method makeJSONPipeline

kernels/TranslateKernel.cpp:117–164  ·  view source on GitHub ↗

Build a pipeline from a JSON filter specification. */

Source from the content-addressed store, hash-verified

115 Build a pipeline from a JSON filter specification.
116*/
117void TranslateKernel::makeJSONPipeline()
118{
119 std::string json;
120
121 if (pdal::FileUtils::fileExists(m_filterJSON))
122 json = pdal::FileUtils::readFileIntoString(m_filterJSON);
123
124 if (json.empty())
125 json = m_filterJSON;
126 std::stringstream in(json);
127 m_manager.readPipeline(in);
128
129 std::vector<Stage *> roots = m_manager.roots();
130 if (roots.size() > 1)
131 throw pdal_error("Can't process pipeline with more than one root.");
132
133 Stage *r(nullptr);
134 if (roots.size())
135 r = dynamic_cast<Reader *>(roots[0]);
136 if (r)
137 {
138 StageCreationOptions ops { m_inputFile, m_readerType, nullptr,
139 Options(), r->tag() };
140 m_manager.replace(r, &m_manager.makeReader(ops));
141 }
142 else
143 {
144 r = &m_manager.makeReader(m_inputFile, m_readerType);
145 if (roots.size())
146 roots[0]->setInput(*r);
147 }
148
149 std::vector<Stage *> leaves = m_manager.leaves();
150 if (leaves.size() != 1)
151 throw pdal_error("Can't process pipeline with more than one "
152 "terminal stage.");
153
154 Stage *w = dynamic_cast<Writer *>(leaves[0]);
155 if (w)
156 m_manager.replace(w, &m_manager.makeWriter(m_outputFile, m_writerType));
157 else
158 {
159 // We know we have a leaf because we added a reader.
160 StageCreationOptions ops { m_outputFile, m_writerType, leaves[0],
161 Options(), "" }; // These last two args just keep compiler quiet.
162 m_manager.makeWriter(ops);
163 }
164}
165
166
167/*

Callers

nothing calls this directly

Calls 10

readFileIntoStringFunction · 0.85
rootsMethod · 0.80
makeReaderMethod · 0.80
leavesMethod · 0.80
OptionsClass · 0.70
fileExistsFunction · 0.50
emptyMethod · 0.45
readPipelineMethod · 0.45
sizeMethod · 0.45
replaceMethod · 0.45

Tested by

no test coverage detected