Skip to content

Commit c0a5818

Browse files
committed
ECGSim to matrix
1 parent 32dc8fb commit c0a5818

File tree

4 files changed

+68
-22
lines changed

4 files changed

+68
-22
lines changed

src/Core/IEPlugin/CMakeLists.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ SET(Core_IEPlugin_SRCS
3131
#CVRTIFileToMatrix_Plugin.cc
3232
CurveField_Plugin.cc
3333
#DIF_Plugin.cc
34-
#EcgsimFileToMatrix_Plugin.cc
34+
EcgsimFileToMatrix_Plugin.cc
3535
#EcgsimFileToTriSurf_Plugin.cc
3636
#HexVolField_Plugin.cc
3737
IEPluginInit.cc
@@ -59,7 +59,7 @@ SET(Core_IEPlugin_HEADERS
5959
#CVRTIFileToMatrix_Plugin.h
6060
CurveField_Plugin.h
6161
#DIF_Plugin.h
62-
#EcgsimFileToMatrix_Plugin.h
62+
EcgsimFileToMatrix_Plugin.h
6363
#EcgsimFileToTriSurf_Plugin.h
6464
#HexVolField_Plugin.h
6565
#MRC_Plugin.h

src/Core/IEPlugin/EcgsimFileToMatrix_Plugin.cc

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,27 @@
3737
*/
3838

3939

40-
// This is a plugin is meant to read simple text files with pure data
41-
// in ascii format into a SCIRun matrix.
42-
40+
#include <Core/ImportExport/Matrix/MatrixIEPlugin.h>
41+
#include <Core/IEPlugin/EcgsimFileToMatrix_Plugin.h>
42+
#include <Core/Datatypes/DenseMatrix.h>
43+
#include <Core/Datatypes/MatrixTypeConversions.h>
44+
#include <Core/Utils/Legacy/StringUtil.h>
45+
#include <Core/Logging/LoggerInterface.h>
4346
#include <Core/ImportExport/Matrix/MatrixIEPlugin.h>
4447
#include <Core/Datatypes/DenseMatrix.h>
4548

4649
#include <iostream>
4750
#include <fstream>
4851
#include <sstream>
4952

50-
namespace SCIRun {
51-
52-
MatrixHandle EcgsimFileMatrix_reader(ProgressReporter *pr, const char *filename);
53-
bool EcgsimFileMatrix_writer(ProgressReporter *pr, MatrixHandle matrix, const char *filename);
53+
using namespace SCIRun;
54+
using namespace SCIRun::Core;
55+
using namespace SCIRun::Core::Logging;
56+
using namespace SCIRun::Core::Datatypes;
5457

55-
MatrixHandle EcgsimFileMatrix_reader(ProgressReporter *pr, const char *filename)
58+
MatrixHandle SCIRun::EcgsimFileMatrix_reader(LoggerHandle pr, const char *filename)
5659
{
57-
MatrixHandle result;
60+
DenseMatrixHandle result;
5861

5962
int ncols = 0;
6063
int nrows = 0;
@@ -154,14 +157,14 @@ MatrixHandle EcgsimFileMatrix_reader(ProgressReporter *pr, const char *filename)
154157
std::ifstream inputfile;
155158
inputfile.exceptions( std::ifstream::badbit );
156159

157-
result = new DenseMatrix(header_rows,header_cols);
158-
if (result.get_rep() == 0)
160+
result.reset(new DenseMatrix(header_rows,header_cols));
161+
if (!result)
159162
{
160163
if (pr) pr->error("Could not allocate matrix");
161164
return(result);
162165
}
163166

164-
double* dataptr = result->get_data_pointer();
167+
double* dataptr = result->data();
165168
int k = 0;
166169

167170
try
@@ -211,23 +214,22 @@ MatrixHandle EcgsimFileMatrix_reader(ProgressReporter *pr, const char *filename)
211214
}
212215

213216

214-
bool EcgsimFileMatrix_writer(ProgressReporter *pr, MatrixHandle matrix, const char *filename)
217+
bool SCIRun::EcgsimFileMatrix_writer(LoggerHandle pr, MatrixHandle matrixInput, const char *filename)
215218
{
216219

217220
std::ofstream outputfile;
218221
outputfile.exceptions( std::ofstream::failbit | std::ofstream::badbit );
219222

220-
MatrixHandle temp = matrix->dense();
221-
matrix = temp;
223+
DenseMatrixHandle matrix = matrix_cast::as_dense(matrixInput);
222224

223-
if (matrix.get_rep() == 0)
225+
if (!matrix)
224226
{
225227
if (pr) pr->error("Empty matrix detected");
226228
return(false);
227229
}
228230

229-
double* dataptr = matrix->get_data_pointer();
230-
if (dataptr == 0)
231+
double* dataptr = matrix->data();
232+
if (!dataptr)
231233
{
232234
if (pr) pr->error("Empty matrix detected");
233235
return(false);
@@ -261,7 +263,5 @@ bool EcgsimFileMatrix_writer(ProgressReporter *pr, MatrixHandle matrix, const ch
261263
return (true);
262264
}
263265

264-
static MatrixIEPlugin EcgsimFileMatrix_plugin("ECGSimFile","", "",EcgsimFileMatrix_reader,EcgsimFileMatrix_writer);
265266

266-
} // end namespace
267267

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2015 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_ECGSIMFILETOMATRIX_PLUGIN_H__
30+
#define CORE_IEPLUGIN_ECGSIMFILETOMATRIX_PLUGIN_H__
31+
32+
#include <Core/Logging/LoggerFwd.h>
33+
#include <Core/Datatypes/DatatypeFwd.h>
34+
#include <Core/IEPlugin/share.h>
35+
36+
namespace SCIRun
37+
{
38+
SCISHARE Core::Datatypes::MatrixHandle EcgsimFileMatrix_reader(Core::Logging::LoggerHandle pr, const char *filename);
39+
40+
SCISHARE bool EcgsimFileMatrix_writer(Core::Logging::LoggerHandle pr, Core::Datatypes::MatrixHandle fh, const char* filename);
41+
}
42+
43+
#endif

src/Core/IEPlugin/IEPluginInit.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <Core/IEPlugin/NrrdField_Plugin.h>
3131
#include <Core/IEPlugin/MatlabFiles_Plugin.h>
3232
#include <Core/IEPlugin/SimpleTextFileToMatrix_Plugin.h>
33+
#include <Core/IEPlugin/EcgsimFileToMatrix_Plugin.h>
3334
#include <Core/IEPlugin/PointCloudField_Plugin.h>
3435
#include <Core/IEPlugin/CurveField_Plugin.h>
3536
#include <Core/ImportExport/Field/FieldIEPlugin.h>
@@ -60,4 +61,6 @@ void IEPluginManager::Initialize()
6061
static FieldIEPluginLegacyAdapter PointCloudField_plugin("PointCloudField", "*.pts *.pos *.txt", "", TextToPointCloudField_reader, PointCloudFieldToText_writer);
6162

6263
static FieldIEPluginLegacyAdapter CurveField_plugin("CurveField", "*.pts *.pos *.edge", "", TextToCurveField_reader, CurveFieldToTextBaseIndexZero_writer);
64+
65+
static MatrixIEPluginLegacyAdapter EcgsimFileMatrix_plugin("ECGSimFile", "", "", EcgsimFileMatrix_reader, EcgsimFileMatrix_writer);
6366
}

0 commit comments

Comments
 (0)