-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathRT_GeometryQuantizer.m
62 lines (45 loc) · 2.04 KB
/
RT_GeometryQuantizer.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
function ShapePoints = RT_GeometryQuantizer(Geometries, Delta, Coeff)
MAX_MEM = 1000; % maximum length of temporary memory
dx = Delta(1); % x resolution
dy = Delta(2); % y resolution
NoS = size(Geometries, 1); % number of embedded shapes
Temp = zeros(MAX_MEM, 2); % temperary memory
Mem_Index = 1; % memory index
for Index = 1:NoS
t_s = Geometries{Index, 2}(1); % start point of the shape
t_e = Geometries{Index, 2}(2); % end point of the shape
if(t_s < t_e) % if t parameter is increasing
dt_0 = +min(dx, dy); % initial delta t
else % if t parameter is decreasing
dt_0 = -min(dx, dy); % initial delta t
end
dt = dt_0; % intialize delta t
t = t_s; % start from the beginning
p_s = Geometries{Index, 1}(t); % start point
Temp(Mem_Index, :) = p_s; % insert the first point
t_1 = t; % previous t parameter
if(t_s < t_e) % if t parameter is increasing
Cond = t < t_e; % loop condition
else % if t parameter is decreasing
Cond = t > t_e; % loop condition
end
while( Cond ) % while the piece is not finished
t = t_1 + dt; % calculate next t
p_s = Geometries{Index, 1}(t); % next point
while( (abs(p_s(1) - Temp(Mem_Index, 1)) > dx) || (abs(p_s(2) - Temp(Mem_Index, 2)) > dy) )
dt = dt*Coeff; % set a new delta t
t = t_1 + dt; % calculate next t
p_s = Geometries{Index, 1}(t); % next point
end
Mem_Index = Mem_Index + 1; % update memory index
t_1 = t; % update previous t parameter
dt = dt_0; % intialize delta t
Temp(Mem_Index, :) = p_s; % insert the point
if(t_s < t_e) % if t parameter is increasing
Cond = t < t_e; % loop condition
else % if t parameter is decreasing
Cond = t > t_e; % loop condition
end
end
end
ShapePoints = Temp([1:Mem_Index - 1, 1], :); % generate quantised shape matrix