Skip to content

Commit d75c796

Browse files
committed
CalcTMP Module and (pseudo) algo code
1 parent b6e1d7f commit d75c796

File tree

3 files changed

+438
-0
lines changed

3 files changed

+438
-0
lines changed
Lines changed: 113 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,113 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2011 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+
//#include <Core/Datatypes/SparseRowMatrix.h>
30+
#include <Core/Datatypes/DenseMatrix.h>
31+
#include <Core/Datatypes/Matrix.h>
32+
#include <Core/Datatypes/Field.h>
33+
34+
#include <Dataflow/Network/Ports/MatrixPort.h>
35+
#include <Dataflow/Network/Ports/FieldPort.h>
36+
#include <Dataflow/GuiInterface/GuiVar.h>
37+
#include <Dataflow/Network/Module.h>
38+
39+
#include <Packages/BioPSE/Core/Algorithms/NumApproximation/CalcTMP.h>
40+
41+
//#include <algorithm>
42+
43+
namespace BioPSE {
44+
45+
using namespace SCIRun;
46+
47+
class CalcTMP : public Module, public CalcTMPAlgo {
48+
public:
49+
CalcTMP(GuiContext*);
50+
virtual ~CalcTMP() {}
51+
52+
virtual void execute();
53+
54+
private:
55+
//SCIRunAlgo::CalcTMPAlgo algo_;
56+
CalcTMPAlgo algo_;
57+
};
58+
59+
60+
DECLARE_MAKER(CalcTMP)
61+
62+
CalcTMP::CalcTMP(GuiContext* ctx)
63+
: Module("CalcTMP", ctx, Source, "Forward", "BioPSE")
64+
{
65+
//algo_.set_progress_reporter(this);
66+
}
67+
68+
69+
void CalcTMP::execute()
70+
{
71+
//FieldHandle Field;
72+
MatrixHandle amplitudes;
73+
MatrixHandle deps;
74+
MatrixHandle depslopes;
75+
MatrixHandle platslopes;
76+
MatrixHandle reps;
77+
MatrixHandle repslopes;
78+
MatrixHandle rests;
79+
MatrixHandle TMPs;
80+
81+
//if (!(get_input_handle("Mesh",Field,true))) return;
82+
get_input_handle("Amplitude", amplitudes, false);
83+
get_input_handle("Depolarization Time", deps, false);
84+
get_input_handle("Depolarization Slope", depslopes, false);
85+
get_input_handle("Plateau Slope", platslopes, false);
86+
get_input_handle("Repolarization Time", reps, false);
87+
get_input_handle("Repolarization Slope", repslopes, false);
88+
get_input_handle("Rest Potential", rests, false);
89+
90+
if (inputs_changed_ || !oport_cached("TMPs") )
91+
{
92+
//algo_.set_bool("generate_basis",gui_use_basis_.get());
93+
//algo_.set_bool("force_symmetry",gui_force_symmetry_.get());
94+
//if(!(algo_.run(Field,Conductivity,SysMatrix))) return;
95+
96+
algo_.calc_TMPs(amplitudes,
97+
deps,
98+
depslopes,
99+
platslopes,
100+
reps,
101+
repslopes,
102+
rests,
103+
500,
104+
TMPs);
105+
106+
send_output_handle("TMPs", TMPs);
107+
}
108+
}
109+
110+
} // End namespace BioPSE
111+
112+
113+
Lines changed: 221 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,221 @@
1+
/*
2+
For more information, please see: http://software.sci.utah.edu
3+
4+
The MIT License
5+
6+
Copyright (c) 2011 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+
30+
/*
31+
* CalcTMP.cc: class to calcuate transmenbrane potential
32+
* using algorithm from ECGSim.
33+
*
34+
* Written by:
35+
* Michael Steffen
36+
* Scientific Computing and Imaging Institute
37+
* May 2011
38+
*/
39+
40+
#include <Packages/BioPSE/Core/Algorithms/NumApproximation/CalcTMP.h>
41+
#include <Core/Datatypes/MatrixTypeConverter.h>
42+
43+
namespace BioPSE {
44+
45+
using namespace SCIRun;
46+
47+
bool CalcTMPAlgo::calc_single_TMP(
48+
const double amplitude,
49+
const double dep,
50+
const double depslope,
51+
const double platslope,
52+
const double rep,
53+
const double repslope,
54+
const double rest,
55+
DenseMatrix& TMP_values)
56+
{
57+
/*
58+
Inputs: tdep: Depolarization Time
59+
trep: Repolarization Time
60+
depslope: Depolarization Slope
61+
platslope: Plateau Slope
62+
repslope: Repolarization Slope
63+
res:
64+
amplitude: Amplitude
65+
Output: Dense Matrix (1xsize of matrix) containing the transmembrane potential
66+
*/
67+
68+
size_type nrows = TMP_values.nrows();
69+
size_type ncols = TMP_values.ncols();
70+
71+
if(nrows != 1){
72+
error("CalcTMPAlgo: TMP_values size incorrect");
73+
return false;
74+
}
75+
76+
if(ncols <= 0){
77+
error("CalcTMPAlgo: TMP_values size incorrect");
78+
return false;
79+
}
80+
81+
double tdep = -dep;
82+
double trep = -rep;
83+
double maxAmpl = 1e-6;
84+
85+
for(index_type t = 0; t < ncols; ++t)
86+
{
87+
double vali = 1.0 / (1.0 + exp(-depslope * tdep)) *
88+
(1.0 / (1.0 + exp(platslope * trep))) *
89+
(1.0 / (1.0 + exp(repslope * trep)));
90+
TMP_values.put(0,t,vali);
91+
if(vali > maxAmpl)
92+
{
93+
maxAmpl = vali;
94+
}
95+
96+
tdep += 1.0;
97+
trep += 1.0;
98+
}
99+
double ampl = (amplitude - rest) / maxAmpl;
100+
for(index_type t = 0; t < ncols; ++t)
101+
{
102+
TMP_values.put(0,t,TMP_values.get(0,t)*ampl + rest);
103+
}
104+
105+
return true;
106+
}
107+
108+
bool CalcTMPAlgo::calc_all_TMPs(
109+
const DenseMatrix& amplitudes,
110+
const DenseMatrix& deps,
111+
const DenseMatrix& depslopes,
112+
const DenseMatrix& platslopes,
113+
const DenseMatrix& reps,
114+
const DenseMatrix& repslopes,
115+
const DenseMatrix& rests,
116+
DenseMatrix& TMP_values)
117+
{
118+
if(amplitudes.ncols() != 1 ||
119+
deps.ncols() != 1 ||
120+
depslopes.ncols() != 1 ||
121+
platslopes.ncols() != 1 ||
122+
reps.ncols() != 1 ||
123+
repslopes.ncols() != 1 ||
124+
rests.ncols() != 1)
125+
{
126+
error("CalcTMPAlgo: All inputs must be of size 1 x nodes");
127+
return false;
128+
}
129+
130+
size_type nnodes = amplitudes.nrows();
131+
if(nnodes <= 0){
132+
error("CalcTMPAlgo: Size of inputs must be > 0");
133+
return false;
134+
}
135+
136+
if(deps.nrows() != nnodes ||
137+
depslopes.nrows() != nnodes ||
138+
platslopes.nrows() != nnodes ||
139+
reps.nrows() != nnodes ||
140+
repslopes.nrows() != nnodes ||
141+
rests.nrows() != nnodes)
142+
{
143+
error("CalcTMPAlgo: All inputs sizes must match");
144+
return false;
145+
}
146+
147+
if(TMP_values.nrows() != nnodes)
148+
{
149+
error("CalcTMPAlgo: MP_values size does not match number of nodes");
150+
return false;
151+
}
152+
153+
if(TMP_values.ncols() <= 0)
154+
{
155+
error("CalcTMPAlgo: Number of columns in TMP_values must be greater than 0 for output");
156+
return false;
157+
}
158+
159+
DenseMatrix mat(1, TMP_values.ncols());
160+
for(index_type node = 0; node < nnodes; ++node)
161+
{
162+
if (!calc_single_TMP(amplitudes.get(node,0),
163+
deps.get(node,0),
164+
depslopes.get(node,0),
165+
platslopes.get(node,0),
166+
reps.get(node,0),
167+
repslopes.get(node,0),
168+
rests.get(node,0),
169+
mat))
170+
{
171+
return false;
172+
}
173+
for(index_type t = 0; t < TMP_values.ncols(); ++t)
174+
{
175+
TMP_values.put(node, t, mat.get(0, t));
176+
}
177+
}
178+
179+
return true;
180+
}
181+
182+
bool CalcTMPAlgo::calc_TMPs(MatrixHandle amplitudes,
183+
MatrixHandle deps,
184+
MatrixHandle depslopes,
185+
MatrixHandle platslopes,
186+
MatrixHandle reps,
187+
MatrixHandle repslopes,
188+
MatrixHandle rests,
189+
unsigned int nsamples,
190+
MatrixHandle& output)
191+
{
192+
if(matrix_is::sparse(amplitudes) ||
193+
matrix_is::sparse(deps) ||
194+
matrix_is::sparse(depslopes) ||
195+
matrix_is::sparse(platslopes) ||
196+
matrix_is::sparse(reps) ||
197+
matrix_is::sparse(repslopes) ||
198+
matrix_is::sparse(rests))
199+
{
200+
error("CalcTMPAlgo: Sparse matrices not supported.");
201+
return false;
202+
}
203+
204+
output = new DenseMatrix(amplitudes->nrows(), nsamples);
205+
206+
if(!calc_all_TMPs(*(amplitudes->dense()),
207+
*(deps->dense()),
208+
*(depslopes->dense()),
209+
*(platslopes->dense()),
210+
*(reps->dense()),
211+
*(repslopes->dense()),
212+
*(rests->dense()),
213+
*(output->dense())))
214+
{
215+
return false;
216+
}
217+
return true;
218+
}
219+
220+
221+
} // end namespace BioPSE

0 commit comments

Comments
 (0)