From 0abebe8cb37a9861d8477d3369900e5d24ad17ac Mon Sep 17 00:00:00 2001 From: Howard Butler Date: Wed, 28 Jun 2017 11:55:01 -0500 Subject: [PATCH] matlab cleanups --- doc/stages/filters.matlab.rst | 5 ++--- doc/stages/writers.matlab.rst | 3 +++ plugins/matlab/filters/MatlabFilter.cpp | 18 ++++++------------ plugins/matlab/filters/MatlabFilter.hpp | 1 + plugins/matlab/filters/Script.hpp | 2 -- 5 files changed, 12 insertions(+), 17 deletions(-) diff --git a/doc/stages/filters.matlab.rst b/doc/stages/filters.matlab.rst index 96eae98ab9..7b95a6ecd3 100644 --- a/doc/stages/filters.matlab.rst +++ b/doc/stages/filters.matlab.rst @@ -69,8 +69,7 @@ source add_dimension The name of a dimension to add to the pipeline that does not already exist. -pdalargs - A JSON dictionary of items you wish to pass into the modules globals as the - ``pdalargs`` object. +struct + Array structure name to read [OPTIONAL, defaults ``PDAL``] .. _Matlab: https://www.mathworks.com/products/matlab.html diff --git a/doc/stages/writers.matlab.rst b/doc/stages/writers.matlab.rst index 4a16f5083b..696af48ce4 100644 --- a/doc/stages/writers.matlab.rst +++ b/doc/stages/writers.matlab.rst @@ -42,3 +42,6 @@ filename output_dims Dimensions to include in the output file [OPTIONAL, defaults to all available dimensions] + +struct + Array structure name to read [OPTIONAL, defaults ``PDAL``] diff --git a/plugins/matlab/filters/MatlabFilter.cpp b/plugins/matlab/filters/MatlabFilter.cpp index 291c459f4e..891324b31f 100644 --- a/plugins/matlab/filters/MatlabFilter.cpp +++ b/plugins/matlab/filters/MatlabFilter.cpp @@ -59,11 +59,8 @@ std::string MatlabFilter::getName() const { return s_info.name; } void MatlabFilter::addArgs(ProgramArgs& args) { args.add("source", "Matlab script to run", m_script.m_source); - args.add("script", "File containing script to run", m_script.m_scriptFilename); - args.add("module", "Matlab module containing the function to run", - m_script.m_module); - args.add("function", "Function to call", m_script.m_function); args.add("add_dimension", "Dimensions to add", m_addDimensions); + args.add("struct", "Matlab struct array to read", m_structName, "PDAL"); args.add("pdalargs", "Dictionary to add to module globals when calling function", m_pdalargs); } @@ -79,11 +76,6 @@ void MatlabFilter::ready(PointTableRef table) { if (m_script.m_source.empty()) m_script.m_source = FileUtils::readFileIntoString(m_script.m_scriptFilename); -// static_cast(plang::Environment::get())->set_stdout(log()->getLogStream()); -// m_script = new plang::Script(m_source, m_module, m_function); -// m_pythonMethod = new plang::Invocation(*m_script); -// m_pythonMethod->compile(); -// m_totalMetadata = table.metadata(); } @@ -102,9 +94,11 @@ PointViewSet MatlabFilter::run(PointViewPtr view) Dimension::IdList dims; mxArray* matlabData = mlang::Script::setMatlabStruct(view, dims, log()); - if (engPutVariable(engine, "PDAL", matlabData)) + if (engPutVariable(engine, m_structName.c_str(), matlabData)) { - throwError("Could not push PDAL struct to Matlab"); + std::ostringstream oss; + oss << "Could not push '" << m_structName << "' struct to Matlab"; + throwError(oss.str()); } engEvalString(engine, m_script.m_source.c_str()); @@ -112,7 +106,7 @@ PointViewSet MatlabFilter::run(PointViewPtr view) std::string noise(m_MatlabOutputBuffer.get(), strlen(m_MatlabOutputBuffer.get())); log()->get(LogLevel::Debug) << "filters.matlab " << noise << std::endl; - matlabData = engGetVariable(engine, "PDAL"); + matlabData = engGetVariable(engine, m_structName.c_str()); if (!matlabData) throwError("No 'PDAL' variable is available in Matlab scope!"); diff --git a/plugins/matlab/filters/MatlabFilter.hpp b/plugins/matlab/filters/MatlabFilter.hpp index 3d7c493fa9..01bc04a7a2 100644 --- a/plugins/matlab/filters/MatlabFilter.hpp +++ b/plugins/matlab/filters/MatlabFilter.hpp @@ -71,6 +71,7 @@ class PDAL_DLL MatlabFilter : public Filter MetadataNode m_totalMetadata; Json::Value m_pdalargs; + std::string m_structName; }; diff --git a/plugins/matlab/filters/Script.hpp b/plugins/matlab/filters/Script.hpp index a671c14a52..3e87ae0325 100644 --- a/plugins/matlab/filters/Script.hpp +++ b/plugins/matlab/filters/Script.hpp @@ -63,8 +63,6 @@ class PDAL_DLL Script std::string m_source; std::string m_scriptFilename; - std::string m_module; - std::string m_function; private: