Skip to content

Commit 98ba7e6

Browse files
committed
Hook up matlab readers to Read/WriteField
1 parent 9ddcb48 commit 98ba7e6

File tree

9 files changed

+382
-75
lines changed

9 files changed

+382
-75
lines changed

src/Core/Datatypes/Legacy/Nrrd/NrrdData.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@
4242

4343
#include <Core/Datatypes/Datatype.h>
4444
#include <Core/GeometryPrimitives/GeomFwd.h>
45+
#include <Core/Datatypes/PropertyManagerExtensions.h>
4546
#include <teem/nrrd.h>
4647
#include <Core/Datatypes/Legacy/Nrrd/share.h>
4748

4849
namespace SCIRun {
4950

50-
class SCISHARE NrrdData : public Core::Datatypes::Datatype
51+
class SCISHARE NrrdData : public Core::Datatypes::Datatype, public Core::Datatypes::HasPropertyManager
5152
{
5253
public:
5354
NrrdData();

src/Core/Datatypes/Matrix.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232

3333
#include <Core/Datatypes/Datatype.h>
3434
#include <Core/Datatypes/MatrixFwd.h>
35+
#include <Core/Datatypes/PropertyManagerExtensions.h>
3536
#include <iosfwd>
3637
#include <Core/Datatypes/share.h>
3738

@@ -65,7 +66,7 @@ namespace Datatypes {
6566
};
6667

6768
template <typename T>
68-
class MatrixBase : public MatrixIOBase
69+
class MatrixBase : public MatrixIOBase, public Core::Datatypes::HasPropertyManager
6970
{
7071
public:
7172
virtual size_t nrows() const = 0;

src/Core/IEPlugin/CMakeLists.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ SET(Core_IEPlugin_SRCS
3737
IEPluginInit.cc
3838
#MRC_Plugin.cc
3939
#MTextFileToTriSurf_Plugin.cc
40-
#MatlabFiles_Plugin.cc
40+
MatlabFiles_Plugin.cc
4141
NrrdField_Plugin.cc
4242
#NrrdToMatrix_Plugin.cc
4343
ObjToField_Plugin.cc
@@ -64,7 +64,7 @@ SET(Core_IEPlugin_HEADERS
6464
#HexVolField_Plugin.h
6565
#MRC_Plugin.h
6666
#MTextFileToTriSurf_Plugin.h
67-
#MatlabFiles_Plugin.h
67+
MatlabFiles_Plugin.h
6868
NrrdField_Plugin.h
6969
#NrrdToMatrix_Plugin.h
7070
ObjToField_Plugin.h
@@ -91,7 +91,7 @@ TARGET_LINK_LIBRARIES(Core_IEPlugin
9191
#Core_Geometry
9292
#Core_Math
9393
#Core_Util
94-
#Core_Matlab
94+
Core_Matlab
9595
Core_Datatypes
9696
Core_Datatypes_Legacy_Field
9797
Core_ImportExport

src/Core/IEPlugin/IEPluginInit.cc

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828

2929
#include <Core/IEPlugin/ObjToField_Plugin.h>
3030
#include <Core/IEPlugin/NrrdField_Plugin.h>
31+
#include <Core/IEPlugin/MatlabFiles_Plugin.h>
3132
#include <Core/ImportExport/Field/FieldIEPlugin.h>
33+
#include <Core/ImportExport/Matrix/MatrixIEPlugin.h>
3234
#include <Core/IEPlugin/IEPluginInit.h>
3335

3436
using namespace SCIRun;
@@ -37,6 +39,7 @@ using namespace SCIRun::Core::Logging;
3739
namespace SCIRun
3840
{
3941
template class GenericIEPluginManager<Field>;
42+
template class GenericIEPluginManager<Core::Datatypes::Matrix>;
4043
}
4144

4245
void IEPluginManager::Initialize()
@@ -48,4 +51,9 @@ void IEPluginManager::Initialize()
4851
static FieldIEPluginLegacyAdapter ModalNrrdToField_plugin("NrrdFile[DataOnElements]","*.nhdr *.nrrd", "", Modal_NrrdToField_reader, 0);
4952
static FieldIEPluginLegacyAdapter IPNodalNrrdToField_plugin("NrrdFile[DataOnNodes,InvertParity]","*.nhdr *.nrrd", "", IPNodal_NrrdToField_reader, 0);
5053
static FieldIEPluginLegacyAdapter IPModalNrrdToField_plugin("NrrdFile[DataOnElements,InvertParity]","*.nhdr *.nrrd", "", IPModal_NrrdToField_reader, 0);
54+
55+
static MatrixIEPluginLegacyAdapter MatlabMatrix_plugin("Matlab Matrix",".mat", "*.mat", MatlabMatrix_reader, MatlabMatrix_writer);
56+
static FieldIEPluginLegacyAdapter MatlabField_plugin("Matlab Field", "*.mat", "*.mat", MatlabField_reader, MatlabField_writer);
57+
//TODO
58+
//static NrrdIEPluginLegacyAdapter MatlabNrrd_plugin("Matlab Matrix",".mat", "*.mat",MatlabNrrd_reader,MatlabNrrd_writer);
5159
}

src/Core/IEPlugin/MatlabFiles_Plugin.cc

Lines changed: 23 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -26,25 +26,26 @@
2626
DEALINGS IN THE SOFTWARE.
2727
*/
2828

29-
#include <Core/ImportExport/Matrix/MatrixIEPlugin.h>
30-
#include <Core/ImportExport/Field/FieldIEPlugin.h>
31-
#include <Core/ImportExport/Nrrd/NrrdIEPlugin.h>
29+
#include <Core/IEPlugin/MatlabFiles_Plugin.h>
3230
#include <Core/Matlab/matlabfile.h>
3331
#include <Core/Matlab/matlabarray.h>
3432
#include <Core/Matlab/matlabconverter.h>
35-
33+
#include <Core/Datatypes/Matrix.h>
34+
#include <Core/Datatypes/Legacy/Field/Field.h>
35+
#include <Core/Datatypes/Legacy/Nrrd/NrrdData.h>
36+
#include <Core/Datatypes/Legacy/Base/PropertyManager.h>
3637

3738
// This file contains plugins to read and write files in MathWork's Matlab
3839
// file format.
3940

40-
41-
namespace SCIRun {
42-
43-
using namespace MatlabIO;
41+
using namespace SCIRun;
42+
using namespace SCIRun::MatlabIO;
43+
using namespace SCIRun::Core::Logging;
44+
using namespace SCIRun::Core::Datatypes;
4445

4546
// Write a matrix as matlab object
4647
MatrixHandle
47-
MatlabMatrix_reader(ProgressReporter *pr, const char *filename)
48+
SCIRun::MatlabMatrix_reader(LoggerHandle pr, const char *filename)
4849
{
4950
// Create a matlab file object, which will be linked to input file
5051
matlabfile mf;
@@ -90,7 +91,7 @@ MatlabMatrix_reader(ProgressReporter *pr, const char *filename)
9091
}
9192

9293
bool
93-
MatlabMatrix_writer(ProgressReporter *pr,
94+
SCIRun::MatlabMatrix_writer(LoggerHandle pr,
9495
MatrixHandle mh, const char *filename)
9596
{
9697
matlabfile mf;
@@ -106,7 +107,7 @@ MatlabMatrix_writer(ProgressReporter *pr,
106107
// Convert the matrix into a matlab object
107108
mc.sciMatrixTOmlArray(mh,ma);
108109
// If the SCIRun object has a name, use it
109-
mh->get_property("name",name);
110+
mh->properties().get_property("name",name);
110111
// Set a default name if none was supplied
111112
if ((name=="")||(!mc.isvalidmatrixname(name))) name = "scirunmatrix";
112113
// Open the file
@@ -126,7 +127,7 @@ MatlabMatrix_writer(ProgressReporter *pr,
126127

127128

128129
NrrdDataHandle
129-
MatlabNrrd_reader(ProgressReporter *pr, const char *filename)
130+
SCIRun::MatlabNrrd_reader(LoggerHandle pr, const char *filename)
130131
{
131132
matlabfile mf;
132133
matlabconverter mc(pr);
@@ -168,8 +169,8 @@ MatlabNrrd_reader(ProgressReporter *pr, const char *filename)
168169
}
169170

170171
bool
171-
MatlabNrrd_writer(ProgressReporter *pr,
172-
NrrdDataHandle mh, const char *filename)
172+
SCIRun::MatlabNrrd_writer(LoggerHandle pr,
173+
NrrdDataHandle nrrd, const char *filename)
173174
{
174175
matlabfile mf;
175176
matlabconverter mc(pr);
@@ -178,12 +179,12 @@ MatlabNrrd_writer(ProgressReporter *pr,
178179

179180
try
180181
{
181-
// Make sure we make it into a numeric array, no annotion and headers
182+
// Make sure we make it into a numeric array, no annotation and headers
182183
mc.converttonumericmatrix();
183184
// Convert the object
184-
mc.sciNrrdDataTOmlArray(mh,ma);
185+
mc.sciNrrdDataTOmlArray(nrrd,ma);
185186
// Check if the object has a name
186-
mh->get_property("name",name);
187+
nrrd->properties().get_property("name",name);
187188
// if no name available give it one
188189
if ((name=="")||(!mc.isvalidmatrixname(name))) name = "scirunnrrd";
189190
// Open the file
@@ -203,7 +204,7 @@ MatlabNrrd_writer(ProgressReporter *pr,
203204

204205

205206
FieldHandle
206-
MatlabField_reader(ProgressReporter *pr, const char *filename)
207+
SCIRun::MatlabField_reader(LoggerHandle pr, const char *filename)
207208
{
208209
matlabfile mf;
209210
// Make sure that errors are forwarded in the conversion process
@@ -248,8 +249,8 @@ MatlabField_reader(ProgressReporter *pr, const char *filename)
248249
}
249250

250251
bool
251-
MatlabField_writer(ProgressReporter *pr,
252-
FieldHandle mh, const char *filename)
252+
SCIRun::MatlabField_writer(LoggerHandle pr,
253+
FieldHandle field, const char *filename)
253254
{
254255
matlabfile mf;
255256
// Make sure that errors are forwarded in the conversion process
@@ -262,9 +263,9 @@ MatlabField_writer(ProgressReporter *pr,
262263
// We want all the annotation. A field without annotation is hard to use
263264
mc.converttostructmatrix();
264265
// Convert the object
265-
mc.sciFieldTOmlArray(mh,ma);
266+
mc.sciFieldTOmlArray(field,ma);
266267
// Get the name
267-
mh->get_property("name",name);
268+
field->properties().get_property("name",name);
268269
// If no name, set a default
269270
if ((name=="")||(!mc.isvalidmatrixname(name))) name = "scirunfield";
270271
// Write the object to the file
@@ -280,9 +281,3 @@ MatlabField_writer(ProgressReporter *pr,
280281
return(true);
281282
}
282283

283-
static MatrixIEPlugin MatlabMatrix_plugin("Matlab Matrix",".mat", "*.mat", MatlabMatrix_reader, MatlabMatrix_writer);
284-
static FieldIEPlugin MatlabField_plugin("Matlab Field",".mat", "*.mat",MatlabField_reader,MatlabField_writer);
285-
static NrrdIEPlugin MatlabNrrd_plugin("Matlab Matrix",".mat", "*.mat",MatlabNrrd_reader,MatlabNrrd_writer);
286-
287-
} // end namespace SCIRun
288-
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2009 Scientific Computing and Imaging Institute,
7+
University of Utah.
8+
9+
10+
Permission is hereby granted, free of charge, to any person obtaining a
11+
copy of this software and associated documentation files (the "Software"),
12+
to deal in the Software without restriction, including without limitation
13+
the rights to use, copy, modify, merge, publish, distribute, sublicense,
14+
and/or sell copies of the Software, and to permit persons to whom the
15+
Software is furnished to do so, subject to the following conditions:
16+
17+
The above copyright notice and this permission notice shall be included
18+
in all copies or substantial portions of the Software.
19+
20+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21+
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23+
THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25+
FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26+
DEALINGS IN THE SOFTWARE.
27+
*/
28+
29+
#ifndef CORE_IEPLUGIN_MATLABFILES_PLUGIN_H__
30+
#define CORE_IEPLUGIN_MATLABFILES_PLUGIN_H__
31+
32+
#include <Core/Logging/LoggerFwd.h>
33+
#include <Core/Datatypes/DatatypeFwd.h>
34+
#include <Core/Datatypes/Legacy/Field/FieldFwd.h>
35+
#include <Core/IEPlugin/share.h>
36+
37+
namespace SCIRun
38+
{
39+
SCISHARE Core::Datatypes::MatrixHandle MatlabMatrix_reader(Core::Logging::LoggerHandle pr, const char *filename);
40+
SCISHARE NrrdDataHandle MatlabNrrd_reader(Core::Logging::LoggerHandle pr, const char *filename);
41+
SCISHARE FieldHandle MatlabField_reader(Core::Logging::LoggerHandle pr, const char *filename);
42+
43+
SCISHARE bool MatlabMatrix_writer(Core::Logging::LoggerHandle pr, Core::Datatypes::MatrixHandle fh, const char* filename);
44+
SCISHARE bool MatlabNrrd_writer(Core::Logging::LoggerHandle pr, NrrdDataHandle fh, const char* filename);
45+
SCISHARE bool MatlabField_writer(Core::Logging::LoggerHandle pr, FieldHandle fh, const char* filename);
46+
}
47+
48+
#endif

0 commit comments

Comments
 (0)