Skip to content

Commit c505d64

Browse files
committed
Matrix slice improvements. Closes #692
1 parent c723143 commit c505d64

File tree

8 files changed

+76
-26
lines changed

8 files changed

+76
-26
lines changed

src/Core/Algorithms/Math/GetMatrixSliceAlgo.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ using namespace SCIRun::Core::Algorithms::Math;
4242

4343
ALGORITHM_PARAMETER_DEF(Math, IsSliceColumn);
4444
ALGORITHM_PARAMETER_DEF(Math, SliceIndex);
45+
ALGORITHM_PARAMETER_DEF(Math, MaxIndex);
4546
ALGORITHM_PARAMETER_DEF(Math, PlayMode);
4647

4748
GetMatrixSliceAlgo::GetMatrixSliceAlgo()
@@ -57,43 +58,46 @@ AlgorithmOutput GetMatrixSliceAlgo::run_generic(const AlgorithmInput& input) con
5758
auto outputMatrix = runImpl(inputMatrix, get(Parameters::SliceIndex).toInt(), get(Parameters::IsSliceColumn).toBool());
5859

5960
AlgorithmOutput output;
60-
output[Variables::OutputMatrix] = outputMatrix;
61+
output[Variables::OutputMatrix] = outputMatrix.get<0>();
62+
output.setAdditionalAlgoOutput(boost::make_shared<Variable>(Name("maxIndex"), outputMatrix.get<1>()));
6163

6264
return output;
6365
}
6466

65-
MatrixHandle GetMatrixSliceAlgo::runImpl(MatrixHandle matrix, int index, bool getColumn) const
67+
boost::tuple<MatrixHandle, int> GetMatrixSliceAlgo::runImpl(MatrixHandle matrix, int index, bool getColumn) const
6668
{
6769
ENSURE_ALGORITHM_INPUT_NOT_NULL(matrix, "Input matrix");
6870
if (getColumn)
6971
{
7072
checkIndex(index, matrix->ncols());
73+
auto max = matrix->ncols() - 1;
7174

7275
// dense case only now
7376
auto dense = matrix_cast::as_dense(matrix);
7477
if (dense)
75-
return boost::make_shared<DenseMatrix>(dense->col(index));
78+
return boost::make_tuple(boost::make_shared<DenseMatrix>(dense->col(index)), max);
7679
else
7780
{
7881
auto sparse = matrix_cast::as_sparse(matrix);
7982
if (sparse)
80-
return boost::make_shared<SparseRowMatrix>(sparse->col(index));
83+
return boost::make_tuple(boost::make_shared<SparseRowMatrix>(sparse->col(index)), max);
8184
return nullptr;
8285
}
8386
}
8487
else
8588
{
8689
checkIndex(index, matrix->nrows());
90+
auto max = matrix->nrows() - 1;
8791

8892
// dense case only now
8993
auto dense = matrix_cast::as_dense(matrix);
9094
if (dense)
91-
return boost::make_shared<DenseMatrix>(dense->row(index));
95+
return boost::make_tuple(boost::make_shared<DenseMatrix>(dense->row(index)), max);
9296
else
9397
{
9498
auto sparse = matrix_cast::as_sparse(matrix);
9599
if (sparse)
96-
return boost::make_shared<SparseRowMatrix>(sparse->row(index));
100+
return boost::make_tuple(boost::make_shared<SparseRowMatrix>(sparse->row(index)), max);
97101
return nullptr;
98102
}
99103
}

src/Core/Algorithms/Math/GetMatrixSliceAlgo.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,14 +41,15 @@ namespace SCIRun {
4141

4242
ALGORITHM_PARAMETER_DECL(IsSliceColumn);
4343
ALGORITHM_PARAMETER_DECL(SliceIndex);
44+
ALGORITHM_PARAMETER_DECL(MaxIndex);
4445
ALGORITHM_PARAMETER_DECL(PlayMode);
4546

4647
class SCISHARE GetMatrixSliceAlgo : public AlgorithmBase
4748
{
4849
public:
4950
GetMatrixSliceAlgo();
5051
virtual AlgorithmOutput run_generic(const AlgorithmInput& input) const override;
51-
Datatypes::MatrixHandle runImpl(Datatypes::MatrixHandle matrix, int index, bool getColumn) const;
52+
boost::tuple<Datatypes::MatrixHandle, int> runImpl(Datatypes::MatrixHandle matrix, int index, bool getColumn) const;
5253
private:
5354
void checkIndex(int index, int max) const;
5455
};

src/Core/Algorithms/Math/Tests/GetMatrixSliceAlgoTests.cc

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ TEST(GetMatrixSliceAlgoTests, CanGetColumnOrRowDense)
7676
{
7777
auto col = algo.runImpl(m1, i, true);
7878
DenseMatrix expected(m1->col(i));
79-
EXPECT_EQ(expected, *matrix_cast::as_dense(col));
79+
EXPECT_EQ(expected, *matrix_cast::as_dense(col.get<0>()));
80+
EXPECT_EQ(m1->ncols() - 1, col.get<1>());
8081
}
8182
for (int i = 0; i < m1->nrows(); ++i)
8283
{
8384
auto row = algo.runImpl(m1, i, false);
8485
DenseMatrix expected(m1->row(i));
85-
EXPECT_EQ(expected, *matrix_cast::as_dense(row));
86+
EXPECT_EQ(expected, *matrix_cast::as_dense(row.get<0>()));
87+
EXPECT_EQ(m1->nrows() - 1, row.get<1>());
8688
}
8789
}
8890

@@ -96,15 +98,17 @@ TEST(GetMatrixSliceAlgoTests, CanGetColumnOrRowSparse)
9698
{
9799
auto col = algo.runImpl(m1, i, true);
98100
SparseRowMatrix expected(m1->col(i));
99-
ASSERT_TRUE(col != nullptr);
100-
EXPECT_EQ(expected, *matrix_cast::as_sparse(col));
101+
ASSERT_TRUE(col.get<0>() != nullptr);
102+
EXPECT_EQ(expected, *matrix_cast::as_sparse(col.get<0>()));
103+
EXPECT_EQ(m1->ncols() - 1, col.get<1>());
101104
}
102105
for (int i = 0; i < m1->nrows(); ++i)
103106
{
104107
auto row = algo.runImpl(m1, i, false);
105108
SparseRowMatrix expected(m1->row(i));
106-
ASSERT_TRUE(row != nullptr);
107-
EXPECT_EQ(expected, *matrix_cast::as_sparse(row));
109+
ASSERT_TRUE(row.get<0>() != nullptr);
110+
EXPECT_EQ(expected, *matrix_cast::as_sparse(row.get<0>()));
111+
EXPECT_EQ(m1->nrows() - 1, row.get<1>());
108112
}
109113
}
110114

src/ExampleNets/FwdInvToolkit/tikhonov-inverse.srn5

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,7 @@
420420
</module>
421421
<state>
422422
<stateMap>
423-
<count>3</count>
423+
<count>4</count>
424424
<item_version>0</item_version>
425425
<item>
426426
<first>
@@ -434,6 +434,18 @@
434434
</value>
435435
</second>
436436
</item>
437+
<item>
438+
<first>
439+
<name>MaxIndex</name>
440+
</first>
441+
<second>
442+
<name>MaxIndex</name>
443+
<value>
444+
<which>0</which>
445+
<value>20</value>
446+
</value>
447+
</second>
448+
</item>
437449
<item>
438450
<first>
439451
<name>PlayMode</name>
@@ -454,7 +466,7 @@
454466
<name>SliceIndex</name>
455467
<value>
456468
<which>0</which>
457-
<value>1</value>
469+
<value>0</value>
458470
</value>
459471
</second>
460472
</item>
@@ -850,7 +862,7 @@
850862
<name>LCurveText</name>
851863
<value>
852864
<which>2</which>
853-
<value>SolveInverseProblemWithTikhonov:0 plot_graph &quot; 2.0469 6.56293 2.0469 6.56166 2.0469 6.56017 2.0469 6.55842 2.04691 6.55638 2.04691 6.554 2.04692 6.55121 2.04693 6.54797 2.04694 6.5442 2.04696 6.53982 2.04698 6.53475 2.04701 6.52888 2.04705 6.5221 2.0471 6.51432 2.04717 6.50539 2.04726 6.49519 2.04737 6.48359 2.0475 6.47045 2.04767 6.45564 2.04788 6.43905 2.04814 6.42055 2.04844 6.40007 2.04879 6.37754 2.04919 6.35292 2.04965 6.32621 2.05016 6.29745 2.05072 6.26671 2.05132 6.23412 2.05195 6.19981 2.05261 6.16398 2.05328 6.12683 2.05397 6.08857 2.05466 6.04942 2.05534 6.00959 2.05602 5.96926 2.05668 5.92857 2.05733 5.88765 2.05796 5.84658 2.05858 5.8054 2.05918 5.76414 2.05976 5.72278 2.06032 5.68131 2.06087 5.63969 2.0614 5.59788 2.06192 5.55583 2.06242 5.5135 2.06291 5.47085 2.06339 5.42782 2.06385 5.38439 2.0643 5.34054 2.06473 5.29627 2.06515 5.2516 2.06555 5.20656 2.06594 5.16124 2.0663 5.1157 2.06666 5.07005 2.06699 5.02441 2.06731 4.97892 2.06761 4.93372 2.06789 4.88894 2.06816 4.84473 2.06842 4.8012 2.06866 4.75843 2.06888 4.71648 2.0691 4.67532 2.06931 4.63491 2.06951 4.59514 2.0697 4.55586 2.06989 4.51692 2.07007 4.47814 2.07025 4.4394 2.07043 4.40058 2.0706 4.36163 2.07077 4.32258 2.07094 4.28347 2.07111 4.24443 2.07127 4.20562 2.07142 4.16723 2.07158 4.12944 2.07172 4.09243 2.07187 4.05637 2.07201 4.02134 2.07214 3.9874 2.07227 3.95454 2.0724 3.92272 2.07253 3.89183 2.07265 3.86174 2.07278 3.8323 2.07291 3.80336 2.07304 3.77475 2.07317 3.74631 2.07331 3.7179 2.07345 3.68938 2.0736 3.66063 2.07375 3.63155 2.07391 3.60207 2.07408 3.57214 2.07425 3.54172 2.07443 3.51081 2.07462 3.47944 2.07481 3.44763 2.075 3.41545 2.0752 3.38295 2.07541 3.35019 2.07561 3.31721 2.07582 3.28404 2.07604 3.25069 2.07625 3.21711 2.07647 3.18325 2.07669 3.14902 2.07692 3.11431 2.07715 3.07902 2.07738 3.04305 2.07762 3.00633 2.07786 2.96883 2.0781 2.93054 2.07834 2.89154 2.07858 2.85193 2.07882 2.81185 2.07905 2.77149 2.07928 2.73102 2.0795 2.69064 2.07972 2.65051 2.07992 2.61076 2.08013 2.57145 2.08032 2.53257 2.08051 2.49405 2.0807 2.45573 2.08088 2.41745 2.08107 2.37899 2.08125 2.34013 2.08143 2.30068 2.08161 2.26046 2.08178 2.21937 2.08196 2.17734 2.08214 2.13438 2.08231 2.09054 2.08248 2.04593 2.08264 2.00068 2.0828 1.95497 2.08294 1.90897 2.08309 1.86283 2.08322 1.81666 2.08335 1.77052 2.08347 1.72444 2.08359 1.67834 2.0837 1.63214 2.08381 1.5857 2.08391 1.53888 2.084 1.49156 2.0841 1.44363 2.08418 1.39504 2.08427 1.34581 2.08435 1.296 2.08442 1.24573 2.08449 1.1952 2.08456 1.14463 2.08462 1.09428 2.08467 1.04442 2.08473 0.995277 2.08477 0.947073 2.08482 0.899941 2.08486 0.853942 2.0849 0.809045 2.08493 0.765138 2.08496 0.722035 2.085 0.679496 2.08503 0.637249 2.08506 0.595006 2.08509 0.552485 2.08511 0.509422 2.08514 0.465579 2.08517 0.42076 2.08519 0.374809 2.08522 0.327619 2.08525 0.279133 2.08527 0.229342 2.08529 0.178285 2.08531 0.126043 2.08534 0.0727277 2.08535 0.0184778 2.08537 -0.0365576 2.08539 -0.0922293 2.0854 -0.148402 2.08542 -0.204964 2.08543 -0.261839 2.08544 -0.31899 2.08545 -0.376417 2.08546 -0.434158 2.08547 -0.492277 2.08548 -0.550852 2.08548 -0.609967 2.08549 -0.669702 2.0855 -0.730121 2.0855 -0.791271 2.08551 -0.853177 2.08551 -0.915847 2.08551 -0.979267 2.08552 -1.04341 2.08552 -1.10824 &quot; &quot; 1.0469 6.56293 2.0469 6.56293 2.0469 -1.10824 &quot; 1e-006 0 ;
865+
<value>SolveInverseProblemWithTikhonov:0 plot_graph &quot; 2.04155 6.53215 2.04155 6.53083 2.04155 6.52928 2.04155 6.52746 2.04156 6.52534 2.04156 6.52285 2.04157 6.51996 2.04158 6.51658 2.04159 6.51265 2.0416 6.50808 2.04162 6.50279 2.04165 6.49665 2.04169 6.48958 2.04174 6.48142 2.0418 6.47207 2.04188 6.46137 2.04198 6.44917 2.04211 6.43534 2.04226 6.41972 2.04245 6.40216 2.04269 6.38255 2.04296 6.36076 2.04328 6.3367 2.04365 6.31031 2.04406 6.28157 2.04452 6.25048 2.04502 6.21711 2.04555 6.18154 2.0461 6.14393 2.04667 6.10449 2.04725 6.06344 2.04783 6.02107 2.0484 5.97769 2.04895 5.93365 2.04949 5.88929 2.05 5.84496 2.05049 5.80099 2.05094 5.75765 2.05138 5.71516 2.05179 5.67367 2.05218 5.63324 2.05254 5.59386 2.0529 5.55545 2.05324 5.51789 2.05357 5.48101 2.05389 5.44465 2.05421 5.40865 2.05452 5.37287 2.05484 5.33721 2.05515 5.30158 2.05546 5.26597 2.05577 5.23033 2.05607 5.19468 2.05638 5.15901 2.05669 5.1233 2.05699 5.08753 2.0573 5.05165 2.0576 5.01559 2.05791 4.97928 2.05821 4.94262 2.05852 4.90555 2.05883 4.86801 2.05913 4.82997 2.05944 4.79145 2.05974 4.75251 2.06004 4.71324 2.06034 4.67377 2.06063 4.63428 2.06091 4.59494 2.06119 4.55593 2.06145 4.51741 2.06171 4.47953 2.06196 4.44238 2.0622 4.40602 2.06244 4.37046 2.06267 4.33566 2.0629 4.30154 2.06312 4.26801 2.06335 4.23495 2.06357 4.2022 2.06379 4.16964 2.06402 4.1371 2.06425 4.10446 2.06448 4.07159 2.06472 4.03838 2.06496 4.00476 2.06521 3.97068 2.06546 3.93613 2.06571 3.90111 2.06597 3.86567 2.06623 3.82985 2.06649 3.79373 2.06675 3.75738 2.06701 3.72086 2.06727 3.68424 2.06753 3.64756 2.06778 3.61085 2.06804 3.57414 2.06829 3.53741 2.06854 3.50067 2.06878 3.46389 2.06903 3.42705 2.06927 3.39015 2.06951 3.35318 2.06975 3.31614 2.06999 3.27906 2.07023 3.24195 2.07046 3.20488 2.07069 3.16786 2.07092 3.13095 2.07114 3.09415 2.07137 3.05746 2.07159 3.02088 2.0718 2.98436 2.07202 2.94786 2.07224 2.91131 2.07245 2.87466 2.07266 2.83786 2.07288 2.80085 2.07309 2.76359 2.0733 2.72606 2.07351 2.68824 2.07372 2.65011 2.07393 2.61164 2.07413 2.5728 2.07434 2.53354 2.07454 2.49383 2.07474 2.45359 2.07494 2.41279 2.07513 2.37139 2.07533 2.32938 2.07552 2.2868 2.0757 2.24371 2.07588 2.20024 2.07605 2.15655 2.07622 2.11285 2.07638 2.06936 2.07653 2.0263 2.07667 1.98388 2.07681 1.94226 2.07694 1.90151 2.07706 1.86165 2.07718 1.82257 2.0773 1.78413 2.07741 1.74608 2.07752 1.7082 2.07763 1.67023 2.07774 1.63196 2.07785 1.59324 2.07795 1.55396 2.07806 1.5141 2.07817 1.47373 2.07827 1.43295 2.07837 1.39192 2.07847 1.35083 2.07857 1.30984 2.07866 1.26911 2.07875 1.22871 2.07884 1.18865 2.07893 1.14887 2.07901 1.10921 2.07909 1.06946 2.07917 1.02938 2.07925 0.988691 2.07933 0.947137 2.07941 0.904484 2.07949 0.860544 2.07957 0.815181 2.07964 0.768318 2.07971 0.71994 2.07979 0.670095 2.07985 0.618888 2.07992 0.566477 2.07998 0.513075 2.08004 0.458934 2.08009 0.404347 2.08014 0.349627 2.08018 0.295102 2.08022 0.241088 2.08025 0.187869 2.08029 0.135666 2.08032 0.0846159 2.08034 0.0347485 2.08037 -0.0140203 2.08039 -0.0618826 2.08041 -0.109119 2.08043 -0.15607 2.08045 -0.2031 2.08047 -0.250565 2.08048 -0.29879 2.0805 -0.348047 2.08052 -0.398547 2.08053 -0.450436 2.08055 -0.503801 2.08056 -0.558675 2.08057 -0.615045 2.08058 -0.672865 2.08059 -0.73206 2.0806 -0.792539 2.08061 -0.854203 &quot; &quot; 1.04155 6.53215 2.04155 6.53215 2.04155 -0.854203 &quot; 1e-006 0 ;
854866
</value>
855867
</value>
856868
</second>

src/Interface/Modules/Math/GetMatrixSlice.ui

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
<rect>
77
<x>0</x>
88
<y>0</y>
9-
<width>242</width>
9+
<width>263</width>
1010
<height>311</height>
1111
</rect>
1212
</property>
1313
<property name="minimumSize">
1414
<size>
15-
<width>188</width>
16-
<height>296</height>
15+
<width>263</width>
16+
<height>311</height>
1717
</size>
1818
</property>
1919
<property name="windowTitle">
@@ -100,6 +100,16 @@
100100
</property>
101101
</widget>
102102
</item>
103+
<item>
104+
<widget class="QToolButton" name="pauseButton_">
105+
<property name="text">
106+
<string>Pause</string>
107+
</property>
108+
<property name="autoRaise">
109+
<bool>true</bool>
110+
</property>
111+
</widget>
112+
</item>
103113
<item>
104114
<widget class="QToolButton" name="nextIndexButton_">
105115
<property name="enabled">
@@ -125,7 +135,7 @@
125135
<item>
126136
<widget class="QToolButton" name="lastIndexButton_">
127137
<property name="enabled">
128-
<bool>false</bool>
138+
<bool>true</bool>
129139
</property>
130140
<property name="minimumSize">
131141
<size>
@@ -170,7 +180,7 @@
170180
<item>
171181
<widget class="QSlider" name="indexSlider_">
172182
<property name="maximum">
173-
<number>1000</number>
183+
<number>100</number>
174184
</property>
175185
<property name="orientation">
176186
<enum>Qt::Horizontal</enum>
@@ -179,7 +189,7 @@
179189
<enum>QSlider::TicksBelow</enum>
180190
</property>
181191
<property name="tickInterval">
182-
<number>50</number>
192+
<number>1</number>
183193
</property>
184194
</widget>
185195
</item>

src/Interface/Modules/Math/GetMatrixSliceDialog.cc

Lines changed: 20 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,22 @@ GetMatrixSliceDialog::GetMatrixSliceDialog(const std::string& name, ModuleStateH
5555
lastIndexButton_->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaSeekForward));
5656
connect(lastIndexButton_, SIGNAL(clicked()), this, SLOT(selectLastIndex()));
5757

58+
connect(indexSlider_, SIGNAL(sliderReleased()), this, SIGNAL(executeActionTriggered()));
59+
5860
playButton_->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPlay));
59-
connect(playButton_, SIGNAL(clicked()), this, SLOT(initiatePlay()));
61+
connect(playButton_, SIGNAL(clicked()), this, SLOT(startPlay()));
62+
pauseButton_->setIcon(QApplication::style()->standardIcon(QStyle::SP_MediaPause));
63+
connect(pauseButton_, SIGNAL(clicked()), this, SLOT(stopPlay()));
64+
65+
playButton_->setDisabled(true);
66+
pauseButton_->setDisabled(true);
6067
}
6168

6269
void GetMatrixSliceDialog::pull()
6370
{
6471
pull_newVersionToReplaceOld();
72+
Pulling p(this);
73+
indexSlider_->setMaximum(state_->getValue(Parameters::MaxIndex).toInt());
6574
}
6675

6776
void GetMatrixSliceDialog::incrementIndex()
@@ -84,12 +93,20 @@ void GetMatrixSliceDialog::selectFirstIndex()
8493

8594
void GetMatrixSliceDialog::selectLastIndex()
8695
{
87-
std::cout << "end--needs requirements" << std::endl;
96+
indexSpinBox_->setValue(indexSlider_->maximum());
97+
Q_EMIT executeActionTriggered();
8898
}
8999

90-
void GetMatrixSliceDialog::initiatePlay()
100+
void GetMatrixSliceDialog::startPlay()
91101
{
92102
std::cout << "play--needs requirements" << std::endl;
93103
state_->setValue(Parameters::PlayMode, true);
94104
Q_EMIT executeActionTriggered();
95105
}
106+
107+
void GetMatrixSliceDialog::stopPlay()
108+
{
109+
std::cout << "pause--needs requirements" << std::endl;
110+
state_->setValue(Parameters::PlayMode, false);
111+
Q_EMIT executeActionTriggered();
112+
}

src/Interface/Modules/Math/GetMatrixSliceDialog.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ private Q_SLOTS:
5151
void decrementIndex();
5252
void selectFirstIndex();
5353
void selectLastIndex();
54-
void initiatePlay();
54+
void startPlay();
55+
void stopPlay();
5556
};
5657

5758
}

src/Modules/Math/GetMatrixSlice.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ void GetMatrixSlice::execute()
6060
setAlgoIntFromState(Parameters::SliceIndex);
6161
auto output = algo().run(withInputData((InputMatrix, input)));
6262
sendOutputFromAlgorithm(OutputMatrix, output);
63+
get_state()->setValue(Parameters::MaxIndex, output.additionalAlgoOutput()->toInt());
6364

6465
/*
6566
auto playMode = get_state()->getValue(Parameters::PlayMode).toBool();

0 commit comments

Comments
 (0)