-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathvoro_table.rb
More file actions
62 lines (54 loc) · 1.39 KB
/
Copy pathvoro_table.rb
File metadata and controls
62 lines (54 loc) · 1.39 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
require 'fileutils'
require 'set'
require_relative 'rect_group'
require_relative 'transform'
class VoroTable
# pick best rules from each outier nodes to core nodes
attr_accessor :table
def initialize(anarr)
@table = anarr
end
def group_quality(group)
group.rects.map { |r| query_raw(group.abs2gbl(r)) }.to_set.length
end
def group_quality_inspect(group) # to figure out the detected part indices
iset = group.rects.map { |r| query_raw(group.abs2gbl(r)) }.to_set
end
def query_raw(gcor)
gx, gy, gs_raw = gcor
gs = Math.log(gs_raw)
mind2 = 100
mini = -1
@table.each_with_index do |c, i|
d2 = (c[0] - gx) * (c[0] - gx) / (gs_raw * gs_raw) +
(c[1] - gy) * (c[1] - gy) / (gs_raw * gs_raw) + (c[2] - gs) * (c[2] - gs)
if d2 < mind2
mini = i
mind2 = d2
end
end
mini
end
def query(from, to)
return LCTransform.new(from, from, 0, 0, 1) if from == to
target = from * 10_000 + to
invtarget = to * 10_000 + from
if !@good_set.empty?
if @good_set.include?(target) || @good_set.include?(invtarget)
return @table[target]
else
return nil
end
else
return @table[target]
end
end
def self.loadTable(fname)
centers = []
IO.foreach(fname) do |line|
eles = line.chomp.split.map(&:to_f)
centers << eles
end
VoroTable.new(centers)
end
end