Skip to content

Commit 1d75a9c

Browse files
committed
Closes #2204 again
1 parent a42ca0a commit 1d75a9c

File tree

3 files changed

+14
-168
lines changed

3 files changed

+14
-168
lines changed

src/Core/Matlab/matlabconverter.cc

Lines changed: 12 additions & 166 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,12 @@
4444
#include <Core/Datatypes/Legacy/Field/VMesh.h>
4545
#include <Core/Datatypes/Legacy/Field/VField.h>
4646
#include <Core/Datatypes/MatrixTypeConversions.h>
47-
#include <boost/assign/std/vector.hpp>
47+
#include <Core/Logging/Log.h>
4848

4949
using namespace SCIRun;
5050
using namespace SCIRun::MatlabIO;
5151
using namespace SCIRun::Core::Logging;
5252
using namespace SCIRun::Core::Datatypes;
53-
using namespace boost::assign;
5453

5554
// Currently the property converter only manages strings
5655
// all other data is ignored both on Matlab side as well
@@ -161,8 +160,8 @@ matlabarray::mitype matlabconverter::convertnrrdtype(int type)
161160

162161
bool matlabconverter::isvalidmatrixname(const std::string& name)
163162
{
164-
const std::string validchar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
165-
const std::string validstartchar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
163+
static const std::string validchar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_");
164+
static const std::string validstartchar("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ");
166165

167166
bool valid = true;
168167
bool foundchar = false;
@@ -186,167 +185,12 @@ bool matlabconverter::isvalidmatrixname(const std::string& name)
186185
if (name[p] == validchar[q]) { foundchar = true; break; }
187186
}
188187
}
189-
if (foundchar == false) { valid = false; break; }
188+
if (!foundchar) { valid = false; break; }
190189
}
191190
return(valid);
192191
}
193192

194193
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
195-
void matlabconverter::mlPropertyTOsciProperty(matlabarray &ma,PropertyManager *handle)
196-
{
197-
int numfields;
198-
matlabarray::mlclass mclass;
199-
matlabarray subarray;
200-
std::string propname;
201-
std::string propval;
202-
matlabarray proparray;
203-
204-
std::string dummyinfo;
205-
int matrixscore;
206-
int fieldscore;
207-
208-
NrrdDataHandle nrrd;
209-
MatrixHandle matrix;
210-
FieldHandle field;
211-
212-
// properties are stored in field property
213-
int propindex = ma.getfieldnameindexCI("property");
214-
215-
if (propindex > -1)
216-
{ // field property exists
217-
218-
proparray = ma.getfield(0,propindex);
219-
if (proparray.isempty()) return;
220-
221-
numfields = proparray.getnumfields();
222-
223-
for (int p=0; p<numfields; p++)
224-
{
225-
subarray = proparray.getfield(0,p);
226-
mclass = subarray.getclass();
227-
228-
// Check whether property is string
229-
// In the property manager string are STL strings
230-
if (mclass == matlabarray::mlSTRING)
231-
{ // only string arrays are converted
232-
propname = proparray.getfieldname(p);
233-
propval = subarray.getstring();
234-
handle->set_property(propname,propval,false);
235-
continue;
236-
}
237-
238-
if ((fieldscore = sciFieldCompatible(subarray,dummyinfo)))
239-
{
240-
if (fieldscore > 1)
241-
{
242-
propname = proparray.getfieldname(p);
243-
mlArrayTOsciField(subarray,field);
244-
handle->set_property(propname,field,false);
245-
continue;
246-
}
247-
}
248-
249-
if ((matrixscore = sciMatrixCompatible(subarray,dummyinfo)))
250-
{
251-
if (matrixscore > 1)
252-
{
253-
propname = proparray.getfieldname(p);
254-
mlArrayTOsciMatrix(subarray,matrix);
255-
handle->set_property(propname,matrix,false);
256-
continue;
257-
}
258-
else
259-
{
260-
if (sciNrrdDataCompatible(subarray,dummyinfo))
261-
{
262-
propname = proparray.getfieldname(p);
263-
mlArrayTOsciNrrdData(subarray,nrrd);
264-
handle->set_property(propname,nrrd,false);
265-
continue;
266-
}
267-
propname = proparray.getfieldname(p);
268-
mlArrayTOsciMatrix(subarray,matrix);
269-
handle->set_property(propname,matrix,false);
270-
continue;
271-
}
272-
}
273-
274-
if (sciNrrdDataCompatible(subarray,dummyinfo))
275-
{
276-
propname = proparray.getfieldname(p);
277-
mlArrayTOsciNrrdData(subarray,nrrd);
278-
handle->set_property(propname,nrrd,false);
279-
continue;
280-
}
281-
if (fieldscore > 0)
282-
{
283-
propname = proparray.getfieldname(p);
284-
mlArrayTOsciField(subarray,field);
285-
handle->set_property(propname,field,false);
286-
continue;
287-
}
288-
}
289-
}
290-
}
291-
292-
void matlabconverter::sciPropertyTOmlProperty(PropertyManager *handle,matlabarray &ma)
293-
{
294-
size_t numfields;
295-
matlabarray proparray;
296-
std::string propname;
297-
std::string propvalue;
298-
matlabarray subarray;
299-
300-
StringHandle str;
301-
MatrixHandle matrix;
302-
NrrdDataHandle nrrd;
303-
FieldHandle field;
304-
305-
proparray.createstructarray();
306-
numfields = handle->nproperties();
307-
308-
for (size_t p=0;p<numfields;p++)
309-
{
310-
propname = handle->get_property_name(p);
311-
if (handle->get_property(propname,propvalue))
312-
{
313-
subarray.createstringarray(propvalue);
314-
proparray.setfield(0,propname,subarray);
315-
}
316-
if (handle->get_property(propname,nrrd))
317-
{
318-
subarray.clear();
319-
bool oldnumericarray_ = numericarray_;
320-
numericarray_ = true;
321-
sciNrrdDataTOmlArray(nrrd,subarray);
322-
numericarray_ = oldnumericarray_;
323-
proparray.setfield(0,propname,subarray);
324-
}
325-
if (handle->get_property(propname,matrix))
326-
{
327-
subarray.clear();
328-
bool oldnumericarray_ = numericarray_;
329-
numericarray_ = true;
330-
sciMatrixTOmlArray(matrix,subarray);
331-
numericarray_ = oldnumericarray_;
332-
proparray.setfield(0,propname,subarray);
333-
}
334-
if (handle->get_property(propname,field))
335-
{
336-
subarray.clear();
337-
sciFieldTOmlArray(field,subarray);
338-
proparray.setfield(0,propname,subarray);
339-
}
340-
if (handle->get_property(propname,str))
341-
{
342-
subarray.clear();
343-
sciStringTOmlArray(str,subarray);
344-
proparray.setfield(0,propname,subarray);
345-
}
346-
}
347-
ma.setfield(0,"property",proparray);
348-
}
349-
350194
int matlabconverter::sciColorMapCompatible(matlabarray &ma, std::string &infotext, bool postremark)
351195
{
352196
infotext = "";
@@ -465,15 +309,17 @@ int matlabconverter::sciMatrixCompatible(const matlabarray &ma, std::string &inf
465309
if (index == -1) index = ma.getfieldnameindexCI("tensorfield");
466310
if (index == -1)
467311
{
468-
if (postremark) remark(std::string("Matrix '" + ma.getname() + "' cannot be translated into a SCIRun Matrix (cannot find a field with data: create a .data field)."));
312+
if (postremark)
313+
SCIRun::logWarning("Matlab object '{}' cannot be translated into a SCIRun Field (cannot find a field with data: create a .data field).", ma.getname());
469314
return(0); // incompatible
470315
}
471316

472317
int numel;
473318
numel = ma.getnumelements();
474319
if (numel > 1)
475320
{
476-
if (postremark) remark(std::string("Matrix '" + ma.getname() + "' cannot be translated into a SCIRun Matrix (the struct matrix is not 1x1: do not define more than one matrix)."));
321+
if (postremark)
322+
remark(std::string("Matrix '" + ma.getname() + "' cannot be translated into a SCIRun Matrix (the struct matrix is not 1x1: do not define more than one matrix)."));
477323
return(0); // incompatible
478324
}
479325

@@ -1442,8 +1288,8 @@ void matlabconverter::sciNrrdDataTOmlArray(NrrdDataHandle scinrrd, matlabarray &
14421288
mlarray.setfield(0,"data",matrix);
14431289

14441290
// Set the properties of the axis
1445-
std::vector<std::string> axisfieldnames;
1446-
axisfieldnames += "size", "spacing", "min", "max", "center", "label", "unit";
1291+
const std::vector<std::string> axisfieldnames =
1292+
{"size", "spacing", "min", "max", "center", "label", "unit"};
14471293

14481294
Nrrd *nrrdptr;
14491295
nrrdptr = scinrrd->getNrrd();
@@ -1453,7 +1299,7 @@ void matlabconverter::sciNrrdDataTOmlArray(NrrdDataHandle scinrrd, matlabarray &
14531299
dims[0] = nrrdptr->dim;
14541300
dims[1] = 1;
14551301

1456-
axisma.createstructarray(dims,axisfieldnames);
1302+
axisma.createstructarray(dims, axisfieldnames);
14571303

14581304
for (int p=0; p<static_cast<int>(nrrdptr->dim); p++ )
14591305
{
@@ -1535,7 +1381,7 @@ int matlabconverter::sciFieldCompatible(const matlabarray& mlarray, std::string&
15351381
{
15361382
MatlabToFieldAlgo algo;
15371383
algo.setreporter(pr_);
1538-
return (algo.analyze_iscompatible(mlarray, infostring, postremark));
1384+
return algo.analyze_iscompatible(mlarray, infostring, postremark);
15391385
}
15401386

15411387
void matlabconverter::mlArrayTOsciField(const matlabarray& mlarray, FieldHandle &scifield)

src/Core/Matlab/matlabtofield.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ int MatlabToFieldAlgo::analyze_iscompatible(const matlabarray& mlarray, std::str
393393
catch (matlabconverter::error_type& e)
394394
{
395395
if (postremark || Core::Logging::LogSettings::Instance().verbose())
396-
SCIRun::logError("analyze_fieldtype error: {}", e.what());
396+
SCIRun::logWarning("analyze_fieldtype error: {}", e.what());
397397
return 0;
398398
}
399399

src/Modules/Legacy/Matlab/DataIO/ImportMatricesFromMatlab.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,5 +92,5 @@ DatatypeHandle ImportMatricesFromMatlab::processMatlabData(const matlabarray& ma
9292

9393
int ImportMatricesFromMatlab::indexMatlabFile(matlabconverter& converter, const matlabarray& mlarray, std::string& infostring) const
9494
{
95-
return converter.sciMatrixCompatible(mlarray, infostring);
95+
return converter.sciMatrixCompatible(mlarray, infostring, Core::Logging::LogSettings::Instance().verbose());
9696
}

0 commit comments

Comments
 (0)