-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_rect.rb
More file actions
133 lines (125 loc) · 3.52 KB
/
Copy pathprocess_rect.rb
File metadata and controls
133 lines (125 loc) · 3.52 KB
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
require_relative 'record'
require_relative 'network'
require_relative 'voro_table'
require 'set'
type = ARGV[0]
oper = ARGV[1]
src = ARGV[2]
des = ARGV[3]
report = ARGV[4]
records = Record.seperate_records(src, IO.foreach(report), Record.parsers[:origin])
puts "there are #{records.length} records"
# head nodes, legacy
clufn = ARGV[5]
head = IO.readlines(clufn).map(&:to_i).to_set
c = 0
# all pair stat table and selected network2 edges
begin
netfn = ARGV[7]
nettable = Network.loadTable(netfn)
elfn = ARGV[8]
nettable.restrict elfn
rescue StandardError => e
puts e
end
# global position for each node
begin
global_fn = ARGV[9]
global_table = Point.loadGlobal(global_fn)
rescue StandardError => e
puts e
end
# voronoi table for group quality assessment
begin
vorofn = ARGV[10]
vorotable = VoroTable.loadTable(vorofn)
rescue StandardError => e
puts e
end
if oper == 'list'
process = lambda { |x|
puts x.filename
}
elsif oper == 'draw_group_net_global'
process = lambda { |x|
x.group_rects_with_graph nettable
goodgroups = x.groups.values.to_set
unless goodgroups.empty?
goodgroups.each_with_index do |g, _i|
next unless g.rects.map(&:type).to_set.length > 2
begin
g.calibrate_global global_table
x.draw_rect(g.infer_part_globally(global_table, 100), "\#ffffff")
x.draw_rect(g.infer_part_globally(global_table, 482), "\#ffff00")
rescue StandardError => e
puts e
end
end
x.export des
end
}
elsif oper == 'draw_group_quality'
process = lambda { |x|
x.group_rects_with_graph(nettable)
goodgroups = x.groups.values.to_set
bettergroups = goodgroups.select { |g| g.rects.map(&:type).to_set.length > 2 }
unless bettergroups.empty?
bettergroups.each_with_index do |g, _i|
begin
# g.aggregate_with_table nettable # tweaking position according to neighbors' position
g.calibrate_global global_table
rescue StandardError => e
puts e
puts e.backtrace
puts
end
end
# changed = x.prune_group #grouping merging
# x.bettergroups.each_with_index do |g,i|
bettergroups.each_with_index do |g, i|
gqual = vorotable.group_quality g
x.draw_group(g, x.colortab[(i + 1) * 31], gqual.to_s)
puts "#{x.filename}\t#{i}\t#{gqual}"
end
x.export des
end
}
elsif oper == 'draw_group_car'
process = lambda { |x|
x.prune_rect 10
x.group_rects_with_graph nettable
goodgroups = x.groups.values.to_set
bettergroups = goodgroups.select { |g| g.rects.map(&:type).to_set.length > 2 }
unless bettergroups.empty?
bettergroups.each_with_index do |g, _i|
begin
# g.aggregate_with_table nettable # tweaking position according to neighbors' position
g.calibrate_global global_table
rescue StandardError => e
puts e
puts e.backtrace
puts
end
end
bettergroups.each_with_index do |g, i|
gqual = vorotable.group_quality g
x.draw_group(g, x.colortab[(i + 1) * 31], gqual.to_s)
puts "#{x.filename}\t#{i}\t#{gqual}"
end
x.export des
end
}
end
records.each do |x|
begin
unless x.rects.empty?
c += 1
process.call(x)
end
rescue StandardError => e
puts 'process_rect=======================Error!====================='
puts e.backtrace.join("\n")
puts 'process_rect=======================Error!====================='
end
end
puts " #{c} images processed"