forked from KIT-IBT/Cobiveco
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_assignTissue.m
100 lines (79 loc) · 3.6 KB
/
example_assignTissue.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
%% example_assignTissue
% This script creates a tissue based on a CobivecoX coordinate
% in shape of an ellipsoid, and if given, several small spheres
% around the main ellipsoid.
% Note: The rotated result is needed to run this example.
%
% To define the tissue, the parameters in
% constructTissueEllipsoidWithSmallSpheres are needed.
%
% That is, the ellipse is defined by
% centroidCobiveco = [tv, tm, ab, rt],
% xSemiaxisLength, ySemiaxisLength, zSemiaxisLength
% and the spheres are defined by
% numberOfSmallSpheres,
% distanceBetweenCentroidAndSphereCenters
% radiusSmallSphere
% planeSpecificationForSpheres
%
% See also constructTissueEllipsoidWithSmallSpheres
%
% Simula 2022
% The main idea is to
% label target points intersecting with an ellipsoid given as input as tissue.
% The ellipsoid may be surrounded by spheres which also should will labelled as tissue.
%% Define paths
addpath('result_example/');
sourcePrefix = 'result_example/';
outputPrefix = 'result_example/';
%% Create directory if it does not exist
outPath = fileparts(outputPrefix);
if ~isempty(outPath) && ~exist(outPath, 'dir')
mkdir(outPath);
end
%% Load geometries
% Important that one uses the rotated result
% (heart axis parallel with xyz-axes in Cartesian)
source = vtkRead(sprintf('%sresult_R.vtu', sourcePrefix));
%% Choose characteristics of the ellipsoid and small spheres
% Choosing centroid: centroidCobiveco = [tv, tm, ab, rt]
centroidCobiveco = [1, 0.3,0.845, 0.67];
% Choosing values for the semi-axes
[xSemiaxisLength, ySemiaxisLength, zSemiaxisLength] = deal(9,2,2);
% Choosing distanceBetweenCentroidAndSphereCenters
distanceBetweenCentroidAndSphereCenters = 5;
% Choosing numberOfSmallSpheres and radiusSmallSphere
numberOfSmallSpheres = 5; % aim for interger value (represented as double); 0 for non
radiusSmallSphere = 1.5;
planeSpecificationForSpheres = "yz";
%% Call constructTissueEllipsoid to flag tissue intersecting with the ellipsoid determined above
% Adds the flag "tissue" to all vertices in ellipsoid
tissueEllipsoidOnly = constructTissueEllipsoidWithoutSavingIndices(source,centroidCobiveco,xSemiaxisLength,ySemiaxisLength,zSemiaxisLength);
% Adds the flag "tissue" to all vertices in ellipsoid and small spheres
tissueIncludingSpheres = constructTissueEllipsoidWithSmallSpheres(source,centroidCobiveco,xSemiaxisLength,ySemiaxisLength,zSemiaxisLength,distanceBetweenCentroidAndSphereCenters,numberOfSmallSpheres,radiusSmallSphere,planeSpecificationForSpheres);
%% Export results
vtkWrite(tissueEllipsoidOnly, sprintf('%sresult_tissueEllipsoidOnly.vtu', outputPrefix));
vtkWrite(tissueIncludingSpheres, sprintf('%sresult_tissueIncludingSpheres.vtu', outputPrefix));
%% Helper function
% Probably not needed
function [xSemiaxisLength, ySemiaxisLength, zSemiaxisLength] = determingAppropriateLengthsOfSemiaxes(source)
% Determine appropriate lengths of semiaxes based on how big the given
% heart is.
%
% [xSemiaxisLength, ySemiaxisLength, zSemiaxisLength] = determingAppropriateLengthsOfSemiaxes(source)
%
% Inputs:
% source: object provided with cobivecoX coordinates, structure
%
% Output:
% xSemiaxisLength: length of semiaxes parallel to the x-axis, double
% ySemiaxisLength: length of semiaxes parallel to the y-axis, double
% zSemiaxisLength: length of semiaxes parallel to the z-axis, double
%
% Copyright 2022 Simula Research Laboratory
% size(source.points) % nx3
maxAbsX = max(abs(source.points(1,:)));
maxAbsY = max(abs(source.points(2,:)));
maxAbsZ = max(abs(source.points(3,:)));
[xSemiaxisLength, ySemiaxisLength, zSemiaxisLength] = deal(0.15*maxAbsX,0.25*maxAbsY,0.15*maxAbsZ);
end