-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathcreateMedium.m
151 lines (136 loc) · 5.45 KB
/
createMedium.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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function vmcmedium_out = createMedium(vmcmesh, vmcmedium)
%CREATEMEDIUM Creates a vmcmedium structure
%
% USAGE:
%
% vmcmedium = createMedium(vmcmesh);
%
% returns
%
% vmcmedium.refractive_index(:) = 1;
% vmcmedium.scattering_coefficient(:) = 0;
% vmcmedium.absorption_coefficient(:) = 0;
% vmcmedium.scattering_anisotropy(:) = 0;
%
% vmcmedium_out = createMedium(vmcmesh, vmcmedium);
%
% repeats the entries in vmcmedium so that the size of each array
% is equal to the number of elements in the mesh.
%
% DESCRIPTION:
%
% The purpose of this function is to create or resize the arrays in
% vmcmedium so that they match the number of elements in the mesh.
%
% INPUT:
%
% vmcmesh - mesh structure, contains the geometry of the
% system
%
% OPTIONAL INPUT:
%
% vmcmedium - medium structure, used to set optical
% coefficients
%
% OUTPUT:
%
% vmcmedium_out - formatted medium structure
%
% SEE ALSO:
%
% https://inverselight.github.io/ValoMC/structures.html
%
% This function is part of ValoMC toolbox
if(~exist('vmcmedium'))
vmcmedium.refractive_index = 1;
vmcmedium.scattering_coefficient = 0;
vmcmedium.absorption_coefficient = 0;
vmcmedium.scattering_anisotropy = 0;
end
vmcmedium_out = vmcmedium;
if(~isfield(vmcmedium, 'refractive_index'))
vmcmedium.refractive_index = 1;
end;
if(~isfield(vmcmedium, 'scattering_coefficient'))
vmcmedium.scattering_coefficient = 0.0;
end;
if(~isfield(vmcmedium, 'absorption_coefficient'))
vmcmedium.absorption_coefficient = 0.0;
end;
if(~isfield(vmcmedium, 'scattering_anisotropy'))
vmcmedium.scattering_anisotropy = 0.0;
end;
% check if the optical coefficients are given as multidimensional arrays
if(~isvector(vmcmedium.refractive_index))
vmcmedium_out.nx = size(vmcmedium.refractive_index,1);
vmcmedium_out.ny = size(vmcmedium.refractive_index,2);
if(size(vmcmedium.refractive_index, 3)>1)
vmcmedium_out.nz = size(vmcmedium.refractive_index,3);
if(vmcmedium_out.nx*vmcmedium_out.ny*vmcmedium_out.nz ~= length(vmcmesh.H)/6)
warning('Mesh size and medium size do not seem compatible.');
end
else
if(vmcmedium_out.nx*vmcmedium_out.ny ~= length(vmcmesh.H)/2)
warning('Mesh size and medium size do not seem compatible.');
end
end
end
if(~isvector(vmcmedium.scattering_coefficient))
vmcmedium_out.nx = size(vmcmedium.scattering_coefficient,1);
vmcmedium_out.ny = size(vmcmedium.scattering_coefficient,2);
if(size(vmcmedium.scattering_coefficient, 3)>1)
vmcmedium_out.nz = size(vmcmedium.scattering_coefficient,3);
if(vmcmedium_out.nx*vmcmedium_out.ny*vmcmedium_out.nz ~= length(vmcmesh.H)/6)
warning('Mesh size and medium size do not seem compatible.');
end
else
if(vmcmedium_out.nx*vmcmedium_out.ny ~= length(vmcmesh.H)/2)
warning('Mesh size and medium size do not seem compatible.');
end
end
end
if(~isvector(vmcmedium.absorption_coefficient))
vmcmedium_out.nx = size(vmcmedium.absorption_coefficient,1);
vmcmedium_out.ny = size(vmcmedium.absorption_coefficient,2);
if(size(vmcmedium.absorption_coefficient, 3)>1)
vmcmedium_out.nz = size(vmcmedium.absorption_coefficient,3);
if(vmcmedium_out.nx*vmcmedium_out.ny*vmcmedium_out.nz ~= length(vmcmesh.H)/6)
warning('Mesh size and medium size do not seem compatible.');
end
else
if(vmcmedium_out.nx*vmcmedium_out.ny ~= length(vmcmesh.H)/2)
warning('Mesh size and medium size do not seem compatible.');
end
end
end
if(~isvector(vmcmedium.scattering_anisotropy))
vmcmedium_out.nx = size(vmcmedium.scattering_anisotropy,1);
vmcmedium_out.ny = size(vmcmedium.scattering_anisotropy,2);
if(size(vmcmedium.scattering_anisotropy, 3)>1)
vmcmedium_out.nz = size(vmcmedium.scattering_anisotropy,3);
if(vmcmedium_out.nx*vmcmedium_out.ny*vmcmedium_out.nz ~= length(vmcmesh.H)/6)
warning('Mesh size and medium size do not seem compatible.');
end
else
if(vmcmedium_out.nx*vmcmedium_out.ny ~= length(vmcmesh.H)/2)
warning('Mesh size and medium size do not seem compatible.');
end
end
end
vmcmedium_out.refractive_index = duplicateArray(vmcmedium.refractive_index(:), size(vmcmesh.H,1));
vmcmedium_out.scattering_coefficient = duplicateArray(vmcmedium.scattering_coefficient(:), size(vmcmesh.H,1));
vmcmedium_out.absorption_coefficient = duplicateArray(vmcmedium.absorption_coefficient(:), size(vmcmesh.H,1));
vmcmedium_out.scattering_anisotropy = duplicateArray(vmcmedium.scattering_anisotropy(:), size(vmcmesh.H,1));
end
function array_out = duplicateArray(array_in, desired_size, defaultvalue)
% convert to column vector
if(size(array_in,2) > size(array_in,1))
array_in = transpose(array_in);
end
if(size(array_in,1) > desired_size)
tmp = array_in(1:desired_size);
else
tmp = repmat(array_in,ceil(desired_size/size(array_in,1)),1);
end
array_out = tmp(1:desired_size,:);
end