Skip to content

Commit 6cf46c8

Browse files
committed
Should build
1 parent be6caf8 commit 6cf46c8

File tree

2 files changed

+79
-21
lines changed

2 files changed

+79
-21
lines changed

src/Modules/Legacy/Matlab/Interface/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ TARGET_LINK_LIBRARIES(Modules_Legacy_MatlabInterface
5656
#Dataflow_TkExtensions
5757
Dataflow_Network
5858
#Core_XMLUtil
59-
#Core_Matlab
59+
Core_Matlab
6060
Core_Services
6161
Core_ICom
6262
Core_SystemCall

src/Modules/Legacy/Matlab/Interface/InterfaceWithMatlab.cc

Lines changed: 78 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,26 @@ namespace MatlabImpl
148148
namespace Matlab {
149149
namespace Interface {
150150

151+
enum //TODO: keep this in sync with number of output ports
152+
{
153+
NUM_OUTPUT_MATRICES = 2,
154+
NUM_OUTPUT_FIELDS = 2,
155+
NUM_OUTPUT_NRRDS = 0,
156+
NUM_OUTPUT_STRINGS = 2
157+
};
158+
151159
class InterfaceWithMatlabImpl : public ServiceBase
152160
{
153161
public:
154162
explicit InterfaceWithMatlabImpl(InterfaceWithMatlab* module) :
155163
module_(module),
156164
//matlab_timeout_old_(180),
157-
need_file_transfer_(false) {}
165+
need_file_transfer_(false),
166+
output_matrix_matfile_(NUM_OUTPUT_MATRICES),
167+
output_field_matfile_(NUM_OUTPUT_FIELDS),
168+
output_nrrd_matfile_(NUM_OUTPUT_NRRDS),
169+
output_string_matfile_(NUM_OUTPUT_STRINGS)
170+
{}
158171
#if 0
159172

160173
// Constructor
@@ -200,6 +213,11 @@ namespace MatlabImpl
200213

201214
std::string temp_directory_;
202215

216+
//TODO: need a better solution for this one
217+
bool isMatrixOutputPortConnected(int index) const;
218+
bool isFieldOutputPortConnected(int index) const;
219+
bool isStringOutputPortConnected(int index) const;
220+
203221
// GUI variables
204222
#if 0
205223
// Names of matrices
@@ -1242,18 +1260,19 @@ bool InterfaceWithMatlabImpl::generate_matlab_code()
12421260
{
12431261
std::ofstream m_file;
12441262

1245-
mfile_ = std::string("scirun_code.m");
1263+
mfile_ = "scirun_code.m";
12461264
std::string filename = file_transfer_->local_file(mfile_);
12471265
m_file.open(filename.c_str(), std::ios::app);
12481266

1249-
int port = 0;
12501267
m_file << matlab_code_list_ << "\n";
1251-
for (int p = 0; p < NUM_MATRIX_PORTS; p++)
1268+
1269+
for (int p = 0; p < NUM_OUTPUT_MATRICES; p++)
12521270
{
1253-
// Test whether the matrix port exists
1254-
if (!oport_connected(port)) { port++; continue; }
1255-
port++;
1256-
if (output_matrix_name_list_[p] == "") continue;
1271+
if (!isMatrixOutputPortConnected(p))
1272+
continue;
1273+
1274+
if (output_matrix_name_list_[p].empty())
1275+
continue;
12571276

12581277
std::ostringstream oss;
12591278
oss << "output_matrix" << p << ".mat";
@@ -1262,12 +1281,11 @@ bool InterfaceWithMatlabImpl::generate_matlab_code()
12621281
cmd = "if exist('" + output_matrix_name_list_[p] + "','var'), save " + file_transfer_->remote_file(output_matrix_matfile_[p]) + " " + output_matrix_name_list_[p] + "; end\n";
12631282
m_file << cmd;
12641283
}
1265-
1266-
for (int p = 0; p < NUM_FIELD_PORTS; p++)
1284+
for (int p = 0; p < NUM_OUTPUT_FIELDS; p++)
12671285
{
1268-
// Test whether the matrix port exists
1269-
if (!oport_connected(port)) { port++; continue; }
1270-
port++;
1286+
if (!isFieldOutputPortConnected(p))
1287+
continue;
1288+
12711289
if (output_field_name_list_[p] == "") continue;
12721290

12731291
std::ostringstream oss;
@@ -1277,7 +1295,7 @@ bool InterfaceWithMatlabImpl::generate_matlab_code()
12771295
cmd = "if exist('" + output_field_name_list_[p] + "','var'), save " + file_transfer_->remote_file(output_field_matfile_[p]) + " " + output_field_name_list_[p] + "; end\n";
12781296
m_file << cmd;
12791297
}
1280-
1298+
#ifdef SCIRUN4_CODE_TO_BE_ENABLED_LATER
12811299
for (int p = 0; p < NUM_NRRD_PORTS; p++)
12821300
{
12831301
// Test whether the matrix port exists
@@ -1293,12 +1311,12 @@ bool InterfaceWithMatlabImpl::generate_matlab_code()
12931311
cmd = "if exist('" + output_nrrd_name_list_[p] + "','var'), save " + file_transfer_->remote_file(output_nrrd_matfile_[p]) + " " + output_nrrd_name_list_[p] + "; end\n";
12941312
m_file << cmd;
12951313
}
1296-
1297-
for (int p = 0; p < NUM_STRING_PORTS; p++)
1314+
#endif
1315+
for (int p = 0; p < NUM_OUTPUT_STRINGS; p++)
12981316
{
1299-
// Test whether the matrix port exists
1300-
if (!oport_connected(port)) { port++; continue; }
1301-
port++;
1317+
if (!isStringOutputPortConnected(p))
1318+
continue;
1319+
13021320
if (output_string_name_list_[p] == "") continue;
13031321

13041322
std::ostringstream oss;
@@ -1312,11 +1330,51 @@ bool InterfaceWithMatlabImpl::generate_matlab_code()
13121330

13131331
m_file.close();
13141332

1315-
if (need_file_transfer_) file_transfer_->put_file(file_transfer_->local_file(mfile_), file_transfer_->remote_file(mfile_));
1333+
if (need_file_transfer_)
1334+
file_transfer_->put_file(file_transfer_->local_file(mfile_), file_transfer_->remote_file(mfile_));
13161335

13171336
return(true);
13181337
}
13191338

1339+
bool InterfaceWithMatlabImpl::isMatrixOutputPortConnected(int index) const
1340+
{
1341+
switch (index)
1342+
{
1343+
case 0:
1344+
return module_->oport_connected(module_->OutputMatrix0);
1345+
case 1:
1346+
return module_->oport_connected(module_->OutputMatrix1);
1347+
default:
1348+
return false;
1349+
}
1350+
}
1351+
1352+
bool InterfaceWithMatlabImpl::isFieldOutputPortConnected(int index) const
1353+
{
1354+
switch (index)
1355+
{
1356+
case 0:
1357+
return module_->oport_connected(module_->OutputField0);
1358+
case 1:
1359+
return module_->oport_connected(module_->OutputField1);
1360+
default:
1361+
return false;
1362+
}
1363+
}
1364+
1365+
bool InterfaceWithMatlabImpl::isStringOutputPortConnected(int index) const
1366+
{
1367+
switch (index)
1368+
{
1369+
case 0:
1370+
return module_->oport_connected(module_->OutputString0);
1371+
case 1:
1372+
return module_->oport_connected(module_->OutputString1);
1373+
default:
1374+
return false;
1375+
}
1376+
}
1377+
13201378
bool InterfaceWithMatlabImpl::save_input_matrices()
13211379
{
13221380
try

0 commit comments

Comments
 (0)