Skip to content

Commit 01b3228

Browse files
committed
Merge pull request #1417 from moritzdannhauer/ConvertRealToComplexMatrix
Closes #1370
2 parents 0775950 + ab154f6 commit 01b3228

File tree

7 files changed

+521
-0
lines changed

7 files changed

+521
-0
lines changed
Lines changed: 211 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,211 @@
1+
<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
2+
<!DOCTYPE boost_serialization>
3+
<boost_serialization signature="serialization::archive" version="12">
4+
<networkFile class_id="0" tracking_level="0" version="4">
5+
<networkInfo class_id="1" tracking_level="0" version="0">
6+
<modules class_id="2" tracking_level="0" version="0">
7+
<count>4</count>
8+
<item_version>0</item_version>
9+
<item class_id="3" tracking_level="0" version="0">
10+
<first>ConvertRealToComplexMatrix:0</first>
11+
<second class_id="4" tracking_level="0" version="0">
12+
<module class_id="5" tracking_level="0" version="0">
13+
<package_name_>SCIRun</package_name_>
14+
<category_name_>Converters</category_name_>
15+
<module_name_>ConvertRealToComplexMatrix</module_name_>
16+
</module>
17+
<state class_id="6" tracking_level="0" version="0">
18+
<stateMap class_id="7" tracking_level="0" version="0">
19+
<count>0</count>
20+
<item_version>0</item_version>
21+
</stateMap>
22+
</state>
23+
</second>
24+
</item>
25+
<item>
26+
<first>CreateMatrix:0</first>
27+
<second>
28+
<module>
29+
<package_name_>SCIRun</package_name_>
30+
<category_name_>Math</category_name_>
31+
<module_name_>CreateMatrix</module_name_>
32+
</module>
33+
<state>
34+
<stateMap>
35+
<count>1</count>
36+
<item_version>0</item_version>
37+
<item class_id="8" tracking_level="0" version="0">
38+
<first class_id="9" tracking_level="0" version="0">
39+
<name>TextEntry</name>
40+
</first>
41+
<second class_id="10" tracking_level="0" version="0">
42+
<name>TextEntry</name>
43+
<value class_id="11" tracking_level="0" version="0">
44+
<which>2</which>
45+
<value>1 2
46+
3 4</value>
47+
</value>
48+
</second>
49+
</item>
50+
</stateMap>
51+
</state>
52+
</second>
53+
</item>
54+
<item>
55+
<first>CreateMatrix:1</first>
56+
<second>
57+
<module>
58+
<package_name_>SCIRun</package_name_>
59+
<category_name_>Math</category_name_>
60+
<module_name_>CreateMatrix</module_name_>
61+
</module>
62+
<state>
63+
<stateMap>
64+
<count>1</count>
65+
<item_version>0</item_version>
66+
<item>
67+
<first>
68+
<name>TextEntry</name>
69+
</first>
70+
<second>
71+
<name>TextEntry</name>
72+
<value>
73+
<which>2</which>
74+
<value>-1 -2
75+
-3 -4</value>
76+
</value>
77+
</second>
78+
</item>
79+
</stateMap>
80+
</state>
81+
</second>
82+
</item>
83+
<item>
84+
<first>ReportComplexMatrixInfo:0</first>
85+
<second>
86+
<module>
87+
<package_name_>SCIRun</package_name_>
88+
<category_name_>Math</category_name_>
89+
<module_name_>ReportComplexMatrixInfo</module_name_>
90+
</module>
91+
<state>
92+
<stateMap>
93+
<count>0</count>
94+
<item_version>0</item_version>
95+
</stateMap>
96+
</state>
97+
</second>
98+
</item>
99+
</modules>
100+
<connections class_id="12" tracking_level="0" version="0">
101+
<count>3</count>
102+
<item_version>0</item_version>
103+
<item class_id="13" tracking_level="0" version="0">
104+
<moduleId1_>ConvertRealToComplexMatrix:0</moduleId1_>
105+
<port1_ class_id="14" tracking_level="0" version="0">
106+
<name>Output</name>
107+
<id>0</id>
108+
</port1_>
109+
<moduleId2_>ReportComplexMatrixInfo:0</moduleId2_>
110+
<port2_>
111+
<name>InputMatrix</name>
112+
<id>0</id>
113+
</port2_>
114+
</item>
115+
<item>
116+
<moduleId1_>CreateMatrix:0</moduleId1_>
117+
<port1_>
118+
<name>EnteredMatrix</name>
119+
<id>0</id>
120+
</port1_>
121+
<moduleId2_>ConvertRealToComplexMatrix:0</moduleId2_>
122+
<port2_>
123+
<name>RealPartMatrix</name>
124+
<id>0</id>
125+
</port2_>
126+
</item>
127+
<item>
128+
<moduleId1_>CreateMatrix:1</moduleId1_>
129+
<port1_>
130+
<name>EnteredMatrix</name>
131+
<id>0</id>
132+
</port1_>
133+
<moduleId2_>ConvertRealToComplexMatrix:0</moduleId2_>
134+
<port2_>
135+
<name>ComplexPartMatrix</name>
136+
<id>0</id>
137+
</port2_>
138+
</item>
139+
</connections>
140+
</networkInfo>
141+
<modulePositions class_id="15" tracking_level="0" version="0">
142+
<count>4</count>
143+
<item_version>0</item_version>
144+
<item class_id="16" tracking_level="0" version="0">
145+
<first>ConvertRealToComplexMatrix:0</first>
146+
<second class_id="17" tracking_level="0" version="0">
147+
<first>7.60000000000000000e+01</first>
148+
<second>-7.40000000000000000e+01</second>
149+
</second>
150+
</item>
151+
<item>
152+
<first>CreateMatrix:0</first>
153+
<second>
154+
<first>-1.52000000000000000e+02</first>
155+
<second>-2.28000000000000000e+02</second>
156+
</second>
157+
</item>
158+
<item>
159+
<first>CreateMatrix:1</first>
160+
<second>
161+
<first>2.28000000000000000e+02</first>
162+
<second>-2.28000000000000000e+02</second>
163+
</second>
164+
</item>
165+
<item>
166+
<first>ReportComplexMatrixInfo:0</first>
167+
<second>
168+
<first>7.60000000000000000e+01</first>
169+
<second>7.60000000000000000e+01</second>
170+
</second>
171+
</item>
172+
</modulePositions>
173+
<moduleNotes class_id="18" tracking_level="0" version="0">
174+
<count>0</count>
175+
<item_version>0</item_version>
176+
</moduleNotes>
177+
<connectionNotes>
178+
<count>0</count>
179+
<item_version>0</item_version>
180+
</connectionNotes>
181+
<moduleTags class_id="19" tracking_level="0" version="0">
182+
<count>4</count>
183+
<item_version>0</item_version>
184+
<item class_id="20" tracking_level="0" version="0">
185+
<first>ConvertRealToComplexMatrix:0</first>
186+
<second>0</second>
187+
</item>
188+
<item>
189+
<first>CreateMatrix:0</first>
190+
<second>0</second>
191+
</item>
192+
<item>
193+
<first>CreateMatrix:1</first>
194+
<second>0</second>
195+
</item>
196+
<item>
197+
<first>ReportComplexMatrixInfo:0</first>
198+
<second>0</second>
199+
</item>
200+
</moduleTags>
201+
<disabledModules class_id="21" tracking_level="0" version="0">
202+
<count>0</count>
203+
<item_version>0</item_version>
204+
</disabledModules>
205+
<disabledConnections>
206+
<count>0</count>
207+
<item_version>0</item_version>
208+
</disabledConnections>
209+
</networkFile>
210+
</boost_serialization>
211+
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
{
2+
"module": {
3+
"name": "ConvertRealToComplexMatrix",
4+
"namespace": "Math",
5+
"status": "New module. Needs testing.",
6+
"description": "Converts two real-valued to a complex-valued matrix",
7+
"header": "Modules/Math/ConvertRealToComplexMatrix.h"
8+
},
9+
"algorithm": {
10+
"name": "N/A",
11+
"namespace": "N/A",
12+
"header": "N/A"
13+
},
14+
"UI": {
15+
"name": "N/A",
16+
"header": "N/A"
17+
}
18+
}

src/Modules/Math/CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ SET(Modules_Math_SRCS
4444
ReportMatrixSliceMeasure.cc
4545
SolveLinearSystem.cc
4646
ComputePCA.cc
47+
ConvertRealToComplexMatrix.cc
4748
)
4849

4950
SET(Modules_Math_HEADERS
@@ -65,6 +66,7 @@ SET(Modules_Math_HEADERS
6566
share.h
6667
SolveLinearSystem.h
6768
ComputePCA.h
69+
ConvertRealToComplexMatrix.h
6870
)
6971

7072
SCIRUN_ADD_LIBRARY(Modules_Math
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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+
License for the specific language governing rights and limitations under
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+
author: Moritz Dannhauer
29+
last change: 05/06/16
30+
*/
31+
32+
#include <Modules/Math/ConvertRealToComplexMatrix.h>
33+
34+
#include <Core/Datatypes/DenseMatrix.h>
35+
#include <Core/Datatypes/MatrixTypeConversions.h>
36+
37+
using namespace SCIRun::Modules::Math;
38+
using namespace SCIRun::Core::Algorithms;
39+
using namespace SCIRun::Dataflow::Networks;
40+
using namespace SCIRun::Core::Datatypes;
41+
42+
const ModuleLookupInfo ConvertRealToComplexMatrix::staticInfo_("ConvertRealToComplexMatrix", "Converters", "SCIRun");
43+
44+
ConvertRealToComplexMatrix::ConvertRealToComplexMatrix() : Module(staticInfo_,false)
45+
{
46+
INITIALIZE_PORT(RealPartMatrix);
47+
INITIALIZE_PORT(ComplexPartMatrix);
48+
INITIALIZE_PORT(Output);
49+
}
50+
51+
52+
void ConvertRealToComplexMatrix::execute()
53+
{
54+
auto input_matrix1 = getRequiredInput(RealPartMatrix);
55+
auto input_matrix2 = getRequiredInput(ComplexPartMatrix);
56+
57+
if (needToExecute())
58+
{
59+
update_state(Executing);
60+
61+
if(!input_matrix1 || !input_matrix2)
62+
{
63+
error("One of the input matrices is empty.");
64+
return;
65+
}
66+
67+
if (!matrixIs::dense(input_matrix1))
68+
{
69+
//TODO implement something with sparse
70+
error("Currently only works with dense matrices (check first module input).");
71+
return;
72+
}
73+
74+
if (!matrixIs::dense(input_matrix2))
75+
{
76+
//TODO implement something with sparse
77+
error("Currently only works with dense matrices (check second module input).");
78+
return;
79+
}
80+
81+
auto nr_cols_mat1=input_matrix1->ncols(), nr_rows_mat1=input_matrix1->nrows(),
82+
nr_cols_mat2=input_matrix2->ncols(), nr_rows_mat2=input_matrix2->nrows();
83+
84+
if(nr_cols_mat1!=nr_cols_mat2 || nr_rows_mat1!=nr_rows_mat2)
85+
{
86+
error("Input matrices do not have same number of rows or columns.");
87+
return;
88+
}
89+
90+
auto out(boost::make_shared<ComplexDenseMatrix>(nr_rows_mat1,nr_cols_mat1));
91+
auto mat1 = castMatrix::toDense (input_matrix1), mat2 = castMatrix::toDense (input_matrix2);
92+
93+
for(auto i=0; i<nr_rows_mat1; i++)
94+
for(auto j=0; j<nr_cols_mat1; j++)
95+
(*out)(i,j) = complex((*mat1)(i,j),(*mat2)(i,j));
96+
97+
sendOutput(Output,out);
98+
}
99+
}

0 commit comments

Comments
 (0)