Skip to content

LUA Scripting Examples 1

The context is:

$ROICIIndex contains index of ROI sampling point
$ROICIIndexMin = 1
$ROICIIndexMax = 7
$ROICIIndexMin <= $ROICIIndex <= $ROICIIndexMax

The following example shows how to use the cache in LUA Scripting by using the reserved variable _luacache, array of objects:

vec = vector.new
mat = matrix.new

-- Create matrix with static values
local weights = mat(
    {
        {0.2, 0.8, -0.5, 1.0},
        {0.5, -0.91, 0.26, -0.5},
        {-0.26, -0.27, 0.17, 0.87}
    }
)

-- Set initially _luacache['z'] to matrix weights and on each next sampling
-- point of ROI, add the vector(1,2,3) to it
if $ROICIIndex == $ROICIIndexMin then
  _luacache['z'] = weights
else
  _luacache['z'] = _luacache['z'] + vec({1,2,3})
end

print(_luacache['z'])

-- Returns row 0 of matrix containing in _luacache['z'], row 0 being a vector of dimension 3
_luareturnvalue = _luacache['z']:r(0)

The function 'print' outputs the following information from _luacache['z']:

[{0.2;0.8;-0.5;1};{0.5;-0.91;0.26;-0.5};{-0.26;-0.27;0.17;0.87}]
[{1.2;1.8;0.5;2};{2.5;1.09;2.26;1.5};{2.74;2.73;3.17;3.87}]
[{2.2;2.8;1.5;3};{4.5;3.09;4.26;3.5};{5.74;5.73;6.17;6.87}]
[{3.2;3.8;2.5;4};{6.5;5.09;6.26;5.5};{8.74;8.73;9.17;9.87}]
[{4.2;4.8;3.5;5};{8.5;7.09;8.26;7.5};{11.74;11.73;12.17;12.87}]
[{5.2;5.8;4.5;6};{10.5;9.09;10.26;9.5};{14.74;14.73;15.17;15.87}]
[{6.2;6.8;5.5;7};{12.5;11.09;12.26;11.5};{17.74;17.73;18.17;18.87}]
[{7.2;7.8;6.5;8};{14.5;13.09;14.26;13.5};{20.74;20.73;21.17;21.87}]