-
Notifications
You must be signed in to change notification settings - Fork 13
/
checkRingOrderWithOriginalPerTarget.m
185 lines (173 loc) · 8.27 KB
/
checkRingOrderWithOriginalPerTarget.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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
%{
* Copyright (C) 2013-2025, The Regents of The University of Michigan.
* All rights reserved.
* This software was developed in the Biped Lab (https://www.biped.solutions/)
* under the direction of Jessy Grizzle, [email protected]. This software may
* be available under alternative licensing terms; contact the address above.
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
* 1. Redistributions of source code must retain the above copyright notice, this
* list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
* this list of conditions and the following disclaimer in the documentation
* and/or other materials provided with the distribution.
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* The views and conclusions contained in the software and documentation are those
* of the authors and should not be interpreted as representing official policies,
* either expressed or implied, of the Regents of The University of Michigan.
*
* AUTHOR: Bruce JK Huang (bjhuang[at]umich.edu)
* WEBSITE: https://www.brucerobot.com/
%}
function [ring_ordered, ring_misorder_list] = checkRingOrderWithOriginalPerTarget(data_split_with_ring_original, data_split_with_ring, target_num, num_ring, num_scan, display)
if ~exist('display', 'var')
display = 0;
end
ring_order(num_ring) = struct();
ring_order_original(num_ring) = struct();
% centroid = mean([data_split_with_ring_original(target_num).scan(1).ring(:).points]');
if checkDisplay(display)
if ishandle(target_num)
clf(target_num)
else
figure(target_num)
end
if ishandle(target_num+100)
clf(target_num+100)
else
figure(target_num+100)
end
end
for ring = 1:num_ring
ring_points = [];
ring_points_org = [];
for scan = 1:num_scan
if (isempty(data_split_with_ring_original(target_num).scan(scan).ring(ring).points))
continue;
else
ring_points_org = [ring_points_org, data_split_with_ring_original(target_num).scan(scan).ring(ring).points];
end
if (isempty(data_split_with_ring(target_num).scan(scan).ring(ring).points))
continue;
else
ring_points = [ring_points, data_split_with_ring(target_num).scan(scan).ring(ring).points];
end
end
ring_order(ring).ring = ring;
if size(ring_points, 2) >= 4
ring_order(ring).ring_mean = mean(ring_points(1:3, :), 2)';
ring_order(ring).z_axis = ring_order(ring).ring_mean(3);
if checkDisplay(display)
figure(target_num)
view(79, 12)
axis equal
hold on
scatter3(ring_points(1, :), ring_points(2, :), ring_points(3, :), 'r.')
text(ring_order(ring).ring_mean(1), ring_order(ring).ring_mean(2), ring_order(ring).ring_mean(3), ...
num2str(ring))
xlabel('X','FontSize',20,'Color','k')
ylabel('Y','FontSize',20,'Color','k')
zlabel('Z','FontSize',20,'Color','k')
end
else
ring_order(ring).ring_mean = [0 0 0];
ring_order(ring).z_axis = 0;
end
ring_order_original(ring).ring = ring;
if size(ring_points_org, 2) >= 4
ring_order_original(ring).ring_mean = mean(ring_points_org(1:3, :), 2)';
ring_order_original(ring).z_axis = ring_order_original(ring).ring_mean(3);
if checkDisplay(display)
figure(target_num+100)
view(79, 12)
axis equal
hold on
scatter3(ring_points_org(1, :), ring_points_org(2, :), ring_points_org(3, :), 'r.')
text(ring_order_original(ring).ring_mean(1), ring_order_original(ring).ring_mean(2), ring_order_original(ring).ring_mean(3), ...
num2str(ring))
xlabel('X','FontSize',20,'Color','k')
ylabel('Y','FontSize',20,'Color','k')
zlabel('Z','FontSize',20,'Color','k')
end
else
ring_order_original(ring).ring_mean = [0 0 0];
ring_order_original(ring).z_axis = 0;
end
% ring_order(ring).ring = ring;
% if size(ring_points, 2) >= 4
% pc = ring_points(1:3, :);
% ring_line = fit3DLine(pc, 'not display');
% t = centroid(1)/ring_line.m(1);
% line_point = t*ring_line.m + ring_line.X0;
% ring_order(ring).z_axis = line_point(3);
% ring_order(ring).ring_mean = mean(ring_points(1:3, :), 2)';
%
% if checkDisplay(display)
% figure(target_num)
% view(79, 12)
% axis equal
% hold on
% scatter3(ring_points(1, :), ring_points(2, :), ring_points(3, :), 'r.')
% text(ring_order(ring).ring_mean(1), ring_order(ring).ring_mean(2), ring_order(ring).ring_mean(3), ...
% num2str(ring))
% xlabel('X','FontSize',20,'Color','k')
% ylabel('Y','FontSize',20,'Color','k')
% zlabel('Z','FontSize',20,'Color','k')
% end
% else
% ring_order(ring).ring_mean = [0 0 0];
% ring_order(ring).z_axis = 0;
% end
%
% ring_order_original(ring).ring = ring;
% if size(ring_points_org, 2) >= 4
% pc = ring_points_org(1:3, :);
% ring_line = fit3DLine(pc, 'not display');
% t = centroid(1)/ring_line.m(1);
% line_point = t*ring_line.m + ring_line.X0;
% ring_order_original(ring).z_axis = line_point(3);
% ring_order_original(ring).ring_mean = mean(ring_points_org(1:3, :), 2)';
%
% if checkDisplay(display)
% figure(target_num+100)
% view(79, 12)
% axis equal
% hold on
% scatter3(ring_points_org(1, :), ring_points_org(2, :), ring_points_org(3, :), 'r.')
% text(ring_order_original(ring).ring_mean(1), ring_order_original(ring).ring_mean(2), ring_order_original(ring).ring_mean(3), ...
% num2str(ring))
% xlabel('X','FontSize',20,'Color','k')
% ylabel('Y','FontSize',20,'Color','k')
% zlabel('Z','FontSize',20,'Color','k')
% end
% else
% ring_order_original(ring).ring_mean = [0 0 0];
% ring_order_original(ring).z_axis = 0;
% end
end
non_zeros = find([ring_order(:).z_axis] ~= 0);
ring_order_no_zeros = ring_order(non_zeros);
[~, idx] = sort([ring_order_no_zeros(:).z_axis]);
ordered_ring = ring_order_no_zeros(idx);
non_zeros_org = find([ring_order(:).z_axis] ~= 0);
ring_order_org_no_zeros = ring_order(non_zeros);
[~, idx] = sort([ring_order_org_no_zeros(:).z_axis]);
ordered_ring_original = ring_order_org_no_zeros(idx);
diff_vec = find([ordered_ring_original.ring] ~= [ordered_ring.ring]);
if isempty(diff_vec)
fprintf("Rings on target #%i are ordered!\n", target_num)
ring_misorder_list = ring_order;
else
warning("Rings on target #%i are mis-ordered.....\n", target_num)
[ordered_ring_original.ring; ordered_ring.ring]'
end
end