setGrid

Essentially set grids on ROI and CD.

Contents

Syntax

seti = setGrid(seti)
seti = setGrid(seti,dispDepth)

Description

seti = setGrid(seti) essentially sets grids on ROI and CD in seti.grid and seti.gridROI for seti.dim dimensions, seti.nCD discretization points for each dimension of CD, which has a size of [-seti.rCD,seti.rCD)^seti.dim.

seti = setGrid(seti,dispDepth) does the same, but allows to control the depth of displayed messages by dispDepth.

ROI is the biggest square in 2D (and cube in 3D) in the mathematical sensible region (open ball with radius rCD/2).

Example

Example 1

init;
seti.dim = 2;           % dimension 2
seti.rCD = 0.2;         % size of computational domain [-rCD,rCD)^dim
seti.nCD = 256;         % number of discretization points for each dimension of CD
seti = setGrid(seti);

Example 2

init;
seti.dim = 2;           % dimension 2
seti.rCD = 0.2;         % size of computational domain [-rCD,rCD)^dim
seti.nCD = 256;         % number of discretization points for each dimension of CD
seti = setGrid(seti,1);

Input Arguments

If input arguments are not set, default values will be used.

Optional Input Argument

Output Arguments

More About

$-\frac{r_\mathrm{CD}}{2} \cdot \frac{1}{\sqrt{2}} < x_i < \frac{r_\mathrm{CD}}{2} \cdot \frac{1}{\sqrt{2}}$

The areas are also defined and illustrated in Section 3 in [1]. (Note that in [1] is a small mistake: The interval must be open to be inside the mathematical sensible region $B_R$.) Note that the radius $R$ in [1] is related to the mentioned $\texttt{rCD}$ by $\texttt{rCD} = 2 R$.

The masks...

% Alternative:
indx = (-seti.rCD/2<x1)&(x1<seti.rCD/2); % ROI with length rCD

References

See Also

Code

function seti = setGrid(seti,varargin)
if nargin == 2
    dispDepth = varargin{1};
else
    dispDepth = 0;
end

Check consistency

if ~(isfield(seti,'dim') && seti.dim >= 2 && seti.dim <= 3)
    seti.dim = 2;
    setmessage(seti,'dim',dispDepth);
end

seti = checkfield(seti,'rCD',0.2,dispDepth);

seti = checkfield(seti,'nCD',256,dispDepth);

Element size and volume

% Length of the infinitesimal element of CD
seti.h = 2*seti.rCD/seti.nCD;

% Volume of the infinitesimal element of CD
seti.dV = seti.h^seti.dim;

Set grid on CD in seti.grid

x1 = (-seti.rCD:seti.h:seti.rCD-seti.h);
% x1: discr. intervall [-rCD,rCD)
% in setKernel [-N/2, N/2) is used analog

if seti.dim == 2
    [X1CD, X2CD] = meshgrid(x1,x1);
    seti.grid = [X1CD(:).'; X2CD(:).'];
elseif seti.dim == 3
    [X1CD,X2CD,X3CD] = meshgrid(x1,x1,x1);
    seti.grid = [X1CD(:).'; X2CD(:).'; X3CD(:).'];
else
    error('Error - please choose seti.dim = 2 or 3.');
end

Set ballMask on CD in seti.ballMask...

... to restrict (later) the contrast to the mathematical sensible region (ball with radius rCD/2).

switch seti.dim
    case 2
        seti.ballMask = (hypot(X1CD,X2CD) < seti.rCD/2);
    case 3
        h3 = @(a,b,c) sqrt(abs(a).^2+abs(b).^2+abs(c).^2);
        seti.ballMask = (h3(X1CD,X2CD,X3CD) < seti.rCD/2);
end

seti.ballMask = logical(seti.ballMask); % logical is important(!)

Set grid seti.gridROI and for restriction seti.ballMaskROI on ROI

% ROI will be the biggest square in 2D (and cube in 3D) in ballMask:
indx = (-seti.rCD/2*1/sqrt(2)<x1)&(x1<seti.rCD/2*1/sqrt(2));

x1ROI = x1(indx);
seti.nROI = length(x1ROI);

if seti.dim == 2
    [X1ROI,X2ROI] = meshgrid(x1ROI,x1ROI);
    seti.gridROI = [X1ROI(:).'; X2ROI(:).'];

    seti.ROImask = zeros(seti.nCD,seti.nCD);
    seti.ROImask(indx,indx) = 1;

    seti.ballMaskROI = (hypot(X1ROI,X2ROI) < seti.rCD/2);

elseif seti.dim == 3
    [X1ROI,X2ROI,X3ROI] = meshgrid(x1ROI,x1ROI,x1ROI);
    seti.gridROI = [X1ROI(:).'; X2ROI(:).'; X3ROI(:).'];

    % To reconstruct X1ROI, X2ROI and X3ROI later you could use:
    % X1ROI = reshape(seti.gridROI(1,:),seti.nROI,seti.nROI,seti.nROI);
    % X2ROI = reshape(seti.gridROI(2,:),seti.nROI,seti.nROI,seti.nROI);
    % X3ROI = reshape(seti.gridROI(3,:),seti.nROI,seti.nROI,seti.nROI);

    seti.ROImask = zeros(seti.nCD,seti.nCD,seti.nCD);
    seti.ROImask(indx,indx,indx) = 1;

    seti.ballMaskROI = (h3(X1ROI,X2ROI,X3ROI) < seti.rCD/2);

else
    error('Error - please choose seti.dim = 2 or 3.'); % checked in checkConsistency
end

seti.ROImask = logical(seti.ROImask); % logical is important(!)
end