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

Method getMatlabStruct

plugins/matlab/filters/Script.cpp:141–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

139
140
141void Script::getMatlabStruct(mxArray* array, PointViewPtr view, const Dimension::IdList& indims, std::string& pdalargs, MetadataNode pdalmetadata, LogPtr log)
142{
143 std::vector<mxArray*> arrays;
144 std::vector<std::string> dimNames;
145
146 mxClassID ml_id = mxGetClassID(array);
147 if (ml_id != mxSTRUCT_CLASS)
148 throw pdal::pdal_error("Selected array must be a Matlab struct array!");
149
150 mxArray* metadata = mxGetField(array, 0, "metadata");
151 if (metadata)
152 {
153
154 mxArray* args = mxGetField(metadata, 0, "pdalargs");
155 if (args)
156 {
157 mxClassID mt = mxGetClassID(args);
158 if (mt == mxCHAR_CLASS)
159 {
160 size_t len = mxGetN(args);
161 std::string data;
162 data.resize(len+1);
163 int ret = mxGetString(args, const_cast<char*>(data.data()),
164 len+1);
165 pdalargs = std::string(data);
166 }
167 }
168 }
169 Dimension::IdList dims;
170 if (!indims.size())
171 dims = view->dims();
172 else
173 dims = indims;
174
175 for (auto d: dims)
176 {
177 std::string dimName = view->dimName(d);
178
179 mxArray* f = mxGetField(array, 0, dimName.c_str());
180 if (!f)
181 {
182 std::ostringstream oss;
183 oss << "No dimension named '" << dimName << "' exists on struct array.";
184 throw pdal::pdal_error(oss.str());
185 }
186
187 mwSize numElements = mxGetNumberOfElements(f);
188 if (numElements != view->size())
189 {
190 std::ostringstream oss;
191 oss << "Array shape is not the same as the PDAL PointView. ";
192 oss << "Matlab array is has '" << numElements << "' elements. ";
193 oss << "PointView has '" << view->size() << "' elements.";
194 throw pdal::pdal_error(oss.str());
195 }
196
197 mxClassID mt = mxGetClassID(f);
198 Dimension::Type pt = Script::getPDALDataType(mt);

Callers

nothing calls this directly

Calls 7

resizeMethod · 0.80
dimNameMethod · 0.80
strMethod · 0.80
dimSizeMethod · 0.80
dataMethod · 0.45
sizeMethod · 0.45
setFieldMethod · 0.45

Tested by

no test coverage detected