-
Notifications
You must be signed in to change notification settings - Fork 0
/
ALGT_MARGIN2D.pl
168 lines (114 loc) · 4.35 KB
/
ALGT_MARGIN2D.pl
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
152
153
154
155
156
157
158
%% ALGT_MARGIN2D Test Case 4.2.4
%%
%% Verification test of the DWS 2D margin algorithm.
%%
%% Copyright (C) 2003 DG Lane
:- consult(pl/geom).
:- consult(pl/vrml).
:- consult(pl/io_basics).
:- set_prolog_flag(optimise, true).
%% ok_margin2D/3
%%
%% asserts that the passed polygons are correctly margined
ok_margin2D(PolysExpand, Polys, Margin) :-
flag(positional_tolerance, Epsilon, Epsilon),
format_log(' Testing Expanded -> Original Distances~n', []),
%% assert for all vertices in the expanded polygon
forall((member(PolyExpand, PolysExpand),
member(Vert, PolyExpand)),
( skip_sample, !;
format('Testing vertex ~p~n', [Vert]),
(
%% assert for each member of poly, min distance from
%% the point to the original polygon
member(Poly, Polys),
dist_point_poly(Vert, Poly, Distance),
%% is within tolerance of the margin distance
is_approx_equal(Distance, Margin, Epsilon) ;
%% failure, so notify user
format_log(' **** Expanded -> Original distance ', []),
format_log('failed at vertex ~p, dist ~p ~n', [Vert, Distance]),
%% see if we should continue
format('continue (y/n)? '), get_single_char("y") ;
%% otherwise fail test
fail
)
)),
format_log(' Expanded -> Original Distances OK~n', []),
format_log(' Testing Original -> Expanded Distances~n', []),
%% assert for all vertices in the original polygon
forall((member(Poly, Polys),
member(Vert, Poly)),
( skip_sample, !;
format('Testing vertex ~p~n', [Vert]),
(
%% assert for each member of poly, min distance from
%% the point to the original polygon
member(PolyExpand, PolysExpand),
dist_point_poly(Vert, PolyExpand, Distance),
%% is greater than or within tolerance of the margin
%% distance
Distance > Margin - Epsilon ;
%% failure, so notify user
format_log(' **** Original -> Expanded distance ', []),
format_log('failed at vertex ~p, dist ~p ~n', [Vert, Distance]),
%% see if we should continue
format('continue (y/n)? '), get_single_char("y") ;
%% otherwise fail test
fail
)
)),
format_log(' Original -> Expanded Distances OK~n', []),
%% assert that the expanded polygon area
findall(Area, (member(Poly, Polys), poly_area(Poly, [[0,0,0],[0,0,1]], Area)),
PolyAreas),
sumlist(PolyAreas, PolyArea),
format_log(' Original polygon areas: ~p ~n', [PolyArea]),
findall(Area, (member(Poly, PolysExpand), poly_area(Poly, [[0,0,0],[0,0,1]], Area)),
PolyExpAreas),
sumlist(PolyExpAreas, ExpArea),
format_log(' Expanded polygon areas: ~p ~n', [ExpArea]),
%% is greater than the original
ExpArea > PolyArea,
format_log(' Polygon Areas OK~n', []).
%% test case execution
:- open_log,
format_log('**** Test case 4.2.4: ALGT_MARGIN2D ****~n', []),
read_string(' Patient / Study / ROI Name', _),
read_string(' StructureSet LOID', Loid),
read_number(' ROI Number', ROI_Number),
read_number(' Z Plane (mm)', Z_plane),
read_number(' Margin (mm)', Margin),
sformat(Cmd, '../bin/ALGT_MARGIN2D.exe -S ~s -R ~d -Z ~e -M ~e',
[Loid, ROI_Number, Z_plane, Margin]),
chdir('temp'),
shell(Cmd),
chdir('..'),
% read original polygons
format_log(' Reading original polygons...', []),
read_file_to_codes('temp/ALGT_MARGIN2D_format1.dat', C, []),
phrase(format1_file(Polys), C),
format_log(' done~n', []),
% output statistics on original polys
write_poly_stats('Original', Polys),
% read expanded polygons
format_log(' Reading expanded polygons...', []),
read_file_to_codes('temp/ALGT_MARGIN2D_Expanded_Format1.dat', C_exp, []),
phrase(format1_file(Polys_exp), C_exp),
format_log(' done~n', []),
% output statistics on expanded polys
write_poly_stats('Expanded', Polys_exp),
repeat,
% obtain testing parameters
format_log('~n', []),
read_number(' Sample Rate (%)', SampleRate),
flag(sample_rate, _, SampleRate),
read_number(' Positional Tolerance (+/- mm)', Epsilon),
flag(positional_tolerance, _, Epsilon),
% begin test
write_test_time('begins'),
ok_margin2D(Polys_exp, Polys, Margin),
% begin test
write_test_time('ends'),
format_log('**** TEST ALGT_MARGIN2D PASSED ****~n~n~n~n', []),
close_log.