int GroundKernel::execute() { PointTable table; Options readerOptions; readerOptions.add<std::string>("filename", m_inputFile); setCommonOptions(readerOptions); Stage& readerStage(Kernel::makeReader(m_inputFile)); readerStage.setOptions(readerOptions); Options groundOptions; groundOptions.add<double>("maxWindowSize", m_maxWindowSize); groundOptions.add<double>("slope", m_slope); groundOptions.add<double>("maxDistance", m_maxDistance); groundOptions.add<double>("initialDistance", m_initialDistance); groundOptions.add<double>("cellSize", m_cellSize); groundOptions.add<bool>("classify", m_classify); groundOptions.add<bool>("extract", m_extract); groundOptions.add<bool>("approximate", m_approximate); groundOptions.add<bool>("debug", isDebug()); groundOptions.add<uint32_t>("verbose", getVerboseLevel()); StageFactory f; std::unique_ptr<Stage> groundStage(f.createStage("filters.ground")); groundStage->setOptions(groundOptions); groundStage->setInput(readerStage); // setup the Writer and write the results Options writerOptions; writerOptions.add<std::string>("filename", m_outputFile); setCommonOptions(writerOptions); Stage& writer(Kernel::makeWriter(m_outputFile, *groundStage)); writer.setOptions(writerOptions); std::vector<std::string> cmd = getProgressShellCommand(); UserCallback *callback = cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); writer.setUserCallback(callback); applyExtraStageOptionsRecursive(&writer); writer.prepare(table); // process the data, grabbing the PointViewSet for visualization of the // resulting PointView PointViewSet viewSetOut = writer.execute(table); if (isVisualize()) visualize(*viewSetOut.begin()); //visualize(*viewSetIn.begin(), *viewSetOut.begin()); return 0; }
int TranslateKernel::execute() { // setting common options for each stage propagates the debug flag and // verbosity level Options readerOptions, filterOptions, writerOptions; setCommonOptions(readerOptions); setCommonOptions(filterOptions); setCommonOptions(writerOptions); m_manager = std::unique_ptr<PipelineManager>(new PipelineManager); if (!m_readerType.empty()) { m_manager->addReader(m_readerType); } else { StageFactory factory; std::string driver = factory.inferReaderDriver(m_inputFile); if (driver.empty()) throw app_runtime_error("Cannot determine input file type of " + m_inputFile); m_manager->addReader(driver); } if (m_manager == NULL) throw pdal_error("Error making pipeline\n"); Stage* reader = m_manager->getStage(); if (reader == NULL) throw pdal_error("Error getting reader\n"); readerOptions.add("filename", m_inputFile); reader->setOptions(readerOptions); Stage* stage = reader; // add each filter provided on the command-line, updating the stage pointer for (auto const f : m_filterType) { std::string filter_name(f); if (!Utils::startsWith(f, "filters.")) filter_name.insert(0, "filters."); Stage* filter = &(m_manager->addFilter(filter_name)); if (filter == NULL) { std::ostringstream oss; oss << "Unable to add filter " << filter_name << ". Filter " "is invalid or plugin could not be loaded. Check " "'pdal --drivers'."; throw pdal_error("Error getting filter\n"); } filter->setOptions(filterOptions); filter->setInput(*stage); stage = filter; } if (!m_writerType.empty()) { m_manager->addWriter(m_writerType); } else { StageFactory factory; std::string driver = factory.inferWriterDriver(m_outputFile); if (driver.empty()) throw app_runtime_error("Cannot determine output file type of " + m_outputFile); Options options = factory.inferWriterOptionsChanges(m_outputFile); writerOptions += options; m_manager->addWriter(driver); } Stage* writer = m_manager->getStage(); if (writer == NULL) throw pdal_error("Error getting writer\n"); writerOptions.add("filename", m_outputFile); writer->setOptions(writerOptions); writer->setInput(*stage); // be sure to recurse through any extra stage options provided by the user applyExtraStageOptionsRecursive(writer); m_manager->execute(); if (m_pipelineOutput.size() > 0) PipelineWriter::writePipeline(m_manager->getStage(), m_pipelineOutput); return 0; }
int SmoothKernel::execute() { PointTable table; Options readerOptions; readerOptions.add("filename", m_inputFile); setCommonOptions(readerOptions); Stage& readerStage(Kernel::makeReader(m_inputFile)); readerStage.setOptions(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointViewSet, this makes the input PointView available to both the // processing pipeline and the visualizer readerStage.prepare(table); PointViewSet viewSetIn = readerStage.execute(table); // the input PointViewSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointViewPtr input_view = *viewSetIn.begin(); std::shared_ptr<BufferReader> bufferReader(new BufferReader); bufferReader->setOptions(readerOptions); bufferReader->addView(input_view); Options smoothOptions; std::ostringstream ss; ss << "{"; ss << " \"pipeline\": {"; ss << " \"filters\": [{"; ss << " \"name\": \"MovingLeastSquares\""; ss << " }]"; ss << " }"; ss << "}"; std::string json = ss.str(); smoothOptions.add("json", json); smoothOptions.add("debug", isDebug()); smoothOptions.add("verbose", getVerboseLevel()); auto& smoothStage = createStage("filters.pclblock"); smoothStage.setOptions(smoothOptions); smoothStage.setInput(*bufferReader); Options writerOptions; writerOptions.add("filename", m_outputFile); setCommonOptions(writerOptions); Stage& writer(Kernel::makeWriter(m_outputFile, smoothStage)); writer.setOptions(writerOptions); writer.prepare(table); // process the data, grabbing the PointViewSet for visualization of the // resulting PointView PointViewSet viewSetOut = writer.execute(table); if (isVisualize()) visualize(*viewSetOut.begin()); //visualize(*viewSetIn.begin(), *viewSetOut.begin()); return 0; }
int SmoothKernel::execute() { PointContext ctx; Options readerOptions; readerOptions.add("filename", m_inputFile); readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); std::unique_ptr<Stage> readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the // processing pipeline and the visualizer readerStage->prepare(ctx); PointBufferSet pbSetIn = readerStage->execute(ctx); // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); BufferReader bufferReader; bufferReader.setOptions(readerOptions); bufferReader.addBuffer(input_buffer); Options smoothOptions; std::ostringstream ss; ss << "{"; ss << " \"pipeline\": {"; ss << " \"filters\": [{"; ss << " \"name\": \"MovingLeastSquares\""; ss << " }]"; ss << " }"; ss << "}"; std::string json = ss.str(); smoothOptions.add("json", json); smoothOptions.add("debug", isDebug()); smoothOptions.add("verbose", getVerboseLevel()); std::unique_ptr<Stage> smoothStage(new filters::PCLBlock()); smoothStage->setOptions(smoothOptions); smoothStage->setInput(&bufferReader); Options writerOptions; writerOptions.add("filename", m_outputFile); setCommonOptions(writerOptions); WriterPtr writer(KernelSupport::makeWriter(m_outputFile, smoothStage.get())); writer->setOptions(writerOptions); std::vector<std::string> cmd = getProgressShellCommand(); UserCallback *callback = cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); writer->setUserCallback(callback); std::map<std::string, Options> extra_opts = getExtraStageOptions(); std::map<std::string, Options>::iterator pi; for (pi = extra_opts.begin(); pi != extra_opts.end(); ++pi) { std::string name = pi->first; Options options = pi->second; std::vector<Stage*> stages = writer->findStage(name); std::vector<Stage*>::iterator s; for (s = stages.begin(); s != stages.end(); ++s) { Options opts = (*s)->getOptions(); std::vector<Option>::iterator o; for (o = options.getOptions().begin(); o != options.getOptions().end(); ++o) opts.add(*o); (*s)->setOptions(opts); } } writer->prepare(ctx); // process the data, grabbing the PointBufferSet for visualization of the // resulting PointBuffer PointBufferSet pbSetOut = writer->execute(ctx); if (isVisualize()) visualize(*pbSetOut.begin()); //visualize(*pbSetIn.begin(), *pbSetOut.begin()); return 0; }
int Ground::execute() { PointContext ctx; Options readerOptions; readerOptions.add<std::string>("filename", m_inputFile); readerOptions.add<bool>("debug", isDebug()); readerOptions.add<boost::uint32_t>("verbose", getVerboseLevel()); std::unique_ptr<Stage> readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the // processing pipeline and the visualizer readerStage->prepare(ctx); PointBufferSet pbSetIn = readerStage->execute(ctx); // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); BufferReader bufferReader; bufferReader.setOptions(readerOptions); bufferReader.addBuffer(input_buffer); Options groundOptions; std::ostringstream ss; ss << "{"; ss << " \"pipeline\": {"; ss << " \"filters\": [{"; ss << " \"name\": \"ProgressiveMorphologicalFilter\","; ss << " \"setMaxWindowSize\": " << m_maxWindowSize << ","; ss << " \"setSlope\": " << m_slope << ","; ss << " \"setMaxDistance\": " << m_maxDistance << ","; ss << " \"setInitialDistance\": " << m_initialDistance << ","; ss << " \"setCellSize\": " << m_cellSize << ","; ss << " \"setBase\": " << m_base << ","; ss << " \"setExponential\": " << m_exponential; ss << " }]"; ss << " }"; ss << "}"; std::string json = ss.str(); groundOptions.add<std::string>("json", json); groundOptions.add<bool>("debug", isDebug()); groundOptions.add<boost::uint32_t>("verbose", getVerboseLevel()); std::unique_ptr<Stage> groundStage(new filters::PCLBlock()); groundStage->setInput(&bufferReader); groundStage->setOptions(groundOptions); // the PCLBlock groundStage consumes the BufferReader rather than the // readerStage groundStage->setInput(&bufferReader); Options writerOptions; writerOptions.add<std::string>("filename", m_outputFile); setCommonOptions(writerOptions); std::unique_ptr<Writer> writer(AppSupport::makeWriter(m_outputFile, groundStage.get())); writer->setOptions(writerOptions); std::vector<std::string> cmd = getProgressShellCommand(); UserCallback *callback = cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); writer->setUserCallback(callback); for (auto pi: getExtraStageOptions()) { std::string name = pi.first; Options options = pi.second; std::vector<Stage*> stages = writer->findStage(name); for (auto s: stages) { Options opts = s->getOptions(); for (auto o: options.getOptions()) opts.add(o); s->setOptions(opts); } } writer->prepare(ctx); // process the data, grabbing the PointBufferSet for visualization of the // resulting PointBuffer PointBufferSet pbSetOut = writer->execute(ctx); if (isVisualize()) visualize(*pbSetOut.begin()); //visualize(*pbSetIn.begin(), *pbSetOut.begin()); return 0; }
int SortKernel::execute() { PointTable table; Options readerOptions; readerOptions.add("filename", m_inputFile); readerOptions.add("debug", isDebug()); readerOptions.add("verbose", getVerboseLevel()); Stage& readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointViewSet, this makes the input PointView available to both the // processing pipeline and the visualizer readerStage.prepare(table); PointViewSet viewSetIn = readerStage.execute(table); // the input PointViewSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointViewPtr inView = *viewSetIn.begin(); BufferReader bufferReader; bufferReader.setOptions(readerOptions); bufferReader.addView(inView); Options sortOptions; sortOptions.add<bool>("debug", isDebug()); sortOptions.add<uint32_t>("verbose", getVerboseLevel()); StageFactory f; Stage& sortStage = ownStage(f.createStage("filters.mortonorder")); sortStage.setInput(bufferReader); sortStage.setOptions(sortOptions); Options writerOptions; writerOptions.add("filename", m_outputFile); setCommonOptions(writerOptions); if (m_bCompress) writerOptions.add("compression", true); if (m_bForwardMetadata) writerOptions.add("forward_metadata", true); std::vector<std::string> cmd = getProgressShellCommand(); UserCallback *callback = cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); Stage& writer = makeWriter(m_outputFile, sortStage); // Some options are inferred by makeWriter based on filename // (compression, driver type, etc). writer.setOptions(writerOptions + writer.getOptions()); writer.setUserCallback(callback); for (const auto& pi : getExtraStageOptions()) { std::string name = pi.first; Options options = pi.second; //ABELL - Huh? std::vector<Stage *> stages = writer.findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); for (const auto& o : options.getOptions()) opts.add(o); s->setOptions(opts); } } writer.prepare(table); // process the data, grabbing the PointViewSet for visualization of the PointViewSet viewSetOut = writer.execute(table); if (isVisualize()) visualize(*viewSetOut.begin()); return 0; }
int PCLKernel::execute() { PointContext ctx; Options readerOptions; readerOptions.add<std::string>("filename", m_inputFile); readerOptions.add<bool>("debug", isDebug()); readerOptions.add<uint32_t>("verbose", getVerboseLevel()); std::unique_ptr<Stage> readerStage = makeReader(readerOptions); // go ahead and prepare/execute on reader stage only to grab input // PointBufferSet, this makes the input PointBuffer available to both the // processing pipeline and the visualizer readerStage->prepare(ctx); PointBufferSet pbSetIn = readerStage->execute(ctx); // the input PointBufferSet will be used to populate a BufferReader that is // consumed by the processing pipeline PointBufferPtr input_buffer = *pbSetIn.begin(); BufferReader bufferReader; bufferReader.addBuffer(input_buffer); Options pclOptions; pclOptions.add<std::string>("filename", m_pclFile); pclOptions.add<bool>("debug", isDebug()); pclOptions.add<uint32_t>("verbose", getVerboseLevel()); std::unique_ptr<Stage> pclStage(new filters::PCLBlock()); pclStage->setInput(&bufferReader); pclStage->setOptions(pclOptions); // the PCLBlock stage consumes the BufferReader rather than the // readerStage Options writerOptions; writerOptions.add<std::string>("filename", m_outputFile); setCommonOptions(writerOptions); if (m_bCompress) writerOptions.add<bool>("compression", true); if (m_bForwardMetadata) writerOptions.add("forward_metadata", true); std::vector<std::string> cmd = getProgressShellCommand(); UserCallback *callback = cmd.size() ? (UserCallback *)new ShellScriptCallback(cmd) : (UserCallback *)new HeartbeatCallback(); WriterPtr writer(KernelSupport::makeWriter(m_outputFile, pclStage.get())); // Some options are inferred by makeWriter based on filename // (compression, driver type, etc). writer->setOptions(writerOptions+writer->getOptions()); writer->setUserCallback(callback); for (const auto& pi : getExtraStageOptions()) { std::string name = pi.first; Options options = pi.second; std::vector<Stage*> stages = writer->findStage(name); for (const auto& s : stages) { Options opts = s->getOptions(); for (const auto& o : options.getOptions()) opts.add(o); s->setOptions(opts); } } writer->prepare(ctx); // process the data, grabbing the PointBufferSet for visualization of the // resulting PointBuffer PointBufferSet pbSetOut = writer->execute(ctx); if (isVisualize()) visualize(*pbSetOut.begin()); //visualize(*pbSetIn.begin(), *pbSetOut.begin()); return 0; }
int Random::execute() { Options readerOptions; { boost::char_separator<char> sep(SEPARATORS); std::vector<double> means; tokenizer mean_tokens(m_means, sep); for (tokenizer::iterator t = mean_tokens.begin(); t != mean_tokens.end(); ++t) { means.push_back(boost::lexical_cast<double>(*t)); } if (means.size()) { readerOptions.add<double >("mean_x", means[0]); readerOptions.add<double >("mean_y", means[1]); readerOptions.add<double >("mean_z", means[2]); } std::vector<double> stdevs; tokenizer stdev_tokens(m_stdevs, sep); for (tokenizer::iterator t = stdev_tokens.begin(); t != stdev_tokens.end(); ++t) { stdevs.push_back(boost::lexical_cast<double>(*t)); } if (stdevs.size()) { readerOptions.add<double >("stdev_x", stdevs[0]); readerOptions.add<double >("stdev_y", stdevs[1]); readerOptions.add<double >("stdev_z", stdevs[2]); } if (!m_bounds.empty()) readerOptions.add<BOX3D >("bounds", m_bounds); if (boost::iequals(m_distribution, "uniform")) readerOptions.add<std::string>("mode", "uniform"); else if (boost::iequals(m_distribution, "normal")) readerOptions.add<std::string>("mode", "normal"); else if (boost::iequals(m_distribution, "random")) readerOptions.add<std::string>("mode", "random"); else throw pdal_error("invalid distribution: " + m_distribution); readerOptions.add<int>("num_points", m_numPointsToWrite); readerOptions.add<bool>("debug", isDebug()); readerOptions.add<boost::uint32_t>("verbose", getVerboseLevel()); } Options writerOptions; { writerOptions.add<std::string>("filename", m_outputFile); setCommonOptions(writerOptions); if (m_bCompress) { writerOptions.add<bool>("compression", true); } } Stage* final_stage = makeReader(readerOptions); Writer* writer = AppSupport::makeWriter(m_outputFile, final_stage); writer->setOptions(writerOptions); PointContext ctx; UserCallback* callback; if (!getProgressShellCommand().size()) callback = static_cast<pdal::UserCallback*>(new PercentageCallback); else callback = static_cast<pdal::UserCallback*>(new ShellScriptCallback(getProgressShellCommand())); writer->setUserCallback(callback); writer->prepare(ctx); PointBufferSet pbSet = writer->execute(ctx); if (isVisualize()) visualize(*pbSet.begin()); delete writer; delete final_stage; return 0; }