Class: Panomosity::NeighborhoodGroup
- Inherits:
-
Object
- Object
- Panomosity::NeighborhoodGroup
show all
- Extended by:
- Utils
- Includes:
- Utils
- Defined in:
- lib/panomosity/neighborhood_group.rb
Class Attribute Summary collapse
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Methods included from Utils
calculate_average, calculate_average_and_std, remove_outliers
Constructor Details
#initialize(center:, total_neighborhoods:) ⇒ NeighborhoodGroup
94
95
96
97
|
# File 'lib/panomosity/neighborhood_group.rb', line 94
def initialize(center:, total_neighborhoods:)
@center = center
@total_neighborhoods = total_neighborhoods
end
|
Class Attribute Details
.logger ⇒ Object
Returns the value of attribute logger.
12
13
14
|
# File 'lib/panomosity/neighborhood_group.rb', line 12
def logger
@logger
end
|
Instance Attribute Details
#center ⇒ Object
Returns the value of attribute center.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def center
@center
end
|
#control_points ⇒ Object
Returns the value of attribute control_points.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def control_points
@control_points
end
|
#neighborhoods ⇒ Object
Returns the value of attribute neighborhoods.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def neighborhoods
@neighborhoods
end
|
#prdist_avg ⇒ Object
Returns the value of attribute prdist_avg.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def prdist_avg
@prdist_avg
end
|
#prdist_std ⇒ Object
Returns the value of attribute prdist_std.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def prdist_std
@prdist_std
end
|
#rx_avg ⇒ Object
Returns the value of attribute rx_avg.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def rx_avg
@rx_avg
end
|
#ry_avg ⇒ Object
Returns the value of attribute ry_avg.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def ry_avg
@ry_avg
end
|
#total_neighborhoods ⇒ Object
Returns the value of attribute total_neighborhoods.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def total_neighborhoods
@total_neighborhoods
end
|
#x_avg ⇒ Object
Returns the value of attribute x_avg.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def x_avg
@x_avg
end
|
#y_avg ⇒ Object
Returns the value of attribute y_avg.
8
9
10
|
# File 'lib/panomosity/neighborhood_group.rb', line 8
def y_avg
@y_avg
end
|
Class Method Details
.calculate(name: :horizontal, pairs: []) ⇒ Object
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
|
# File 'lib/panomosity/neighborhood_group.rb', line 60
def self.calculate(name: :horizontal, pairs: [])
@type = name
default_count = 3
self.neighborhoods = pairs.map { |p| p.good_neighborhoods_within_std(count: default_count) }.flatten
if neighborhoods.empty?
logger.warn 'total neighborhoods came up empty, neighborhood default count to 2'
default_count = 2
self.neighborhoods = pairs.map { |p| p.good_neighborhoods_within_std(count: default_count) }.flatten
raise 'still could not find neighborhoods' if neighborhoods.empty?
end
logger.debug "twice reducing #{name} neighborhood std outliers"
avg, std = *calculate_average_and_std(values: neighborhoods.map(&:prdist_std))
neighborhoods.select! { |n| (avg - n.prdist_std).abs <= std }
avg, std = *calculate_average_and_std(values: neighborhoods.map(&:prdist_std))
neighborhoods.select! { |n| (avg - n.prdist_std).abs <= std }
self.neighborhood_groups = neighborhoods.map do |neighborhood|
group = NeighborhoodGroup.new(center: neighborhood, total_neighborhoods: neighborhoods)
group.calculate
end
neighborhood_groups.max_by(5) { |ng| ng.control_points.count }.each do |ng|
logger.debug "#{ng.prdist_avg} #{ng.prdist_std} #{ng.control_points.count} x#{ng.x_avg} y#{ng.y_avg} rx#{ng.rx_avg} ry#{ng.ry_avg}"
end
self.neighborhood_groups = neighborhood_groups.sort_by { |ng| -ng.control_points.count }
end
|
.horizontal ⇒ Object
22
23
24
|
# File 'lib/panomosity/neighborhood_group.rb', line 22
def horizontal
@horizontal_neighborhood_groups
end
|
.horizontal? ⇒ Boolean
14
15
16
|
# File 'lib/panomosity/neighborhood_group.rb', line 14
def horizontal?
@type == :horizontal
end
|
.info ⇒ Object
90
91
92
|
# File 'lib/panomosity/neighborhood_group.rb', line 90
def self.info
end
|
.neighborhood_groups ⇒ Object
42
43
44
|
# File 'lib/panomosity/neighborhood_group.rb', line 42
def neighborhood_groups
horizontal? ? @horizontal_neighborhood_groups : @vertical_neighborhood_groups
end
|
.neighborhood_groups=(value) ⇒ Object
46
47
48
49
50
51
52
|
# File 'lib/panomosity/neighborhood_group.rb', line 46
def neighborhood_groups=(value)
if horizontal?
@horizontal_neighborhood_groups = value
else
@vertical_neighborhood_groups = value
end
end
|
.neighborhoods ⇒ Object
30
31
32
|
# File 'lib/panomosity/neighborhood_group.rb', line 30
def neighborhoods
horizontal? ? @horizontal_neighborhoods : @vertical_neighborhoods
end
|
.neighborhoods=(value) ⇒ Object
34
35
36
37
38
39
40
|
# File 'lib/panomosity/neighborhood_group.rb', line 34
def neighborhoods=(value)
if horizontal?
@horizontal_neighborhoods = value
else
@vertical_neighborhoods = value
end
end
|
.parse_info(panorama) ⇒ Object
54
55
56
57
|
# File 'lib/panomosity/neighborhood_group.rb', line 54
def parse_info(panorama)
@panorama = panorama
@logger = @panorama.logger
end
|
.vertical ⇒ Object
26
27
28
|
# File 'lib/panomosity/neighborhood_group.rb', line 26
def vertical
@vertical_neighborhood_groups
end
|
.vertical? ⇒ Boolean
18
19
20
|
# File 'lib/panomosity/neighborhood_group.rb', line 18
def vertical?
@type == :vertical
end
|
Instance Method Details
#calculate ⇒ Object
99
100
101
102
103
104
105
106
107
108
|
# File 'lib/panomosity/neighborhood_group.rb', line 99
def calculate
@neighborhoods = total_neighborhoods.select { |n| (n.prdist_avg - center.prdist_avg).abs <= center.prdist_std }
@control_points = neighborhoods.map(&:control_points_within_std).flatten.uniq(&:raw)
@x_avg = calculate_average(values: control_points.map(&:px))
@rx_avg = calculate_average(values: control_points.map(&:prx))
@y_avg = calculate_average(values: control_points.map(&:py))
@ry_avg = calculate_average(values: control_points.map(&:pry))
@prdist_avg, @prdist_std = *calculate_average_and_std(values: control_points.map(&:prdist))
self
end
|
#serialize ⇒ Object
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/panomosity/neighborhood_group.rb', line 110
def serialize
delta_cp_x = calculate_average(values: control_points.map { |cp| cp.x2 - cp.x1 })
delta_cp_y = calculate_average(values: control_points.map { |cp| cp.y2 - cp.y1 })
{
x_avg: x_avg,
y_avg: y_avg,
prdist_avg: prdist_avg,
prdist_std: prdist_std,
cp_count: control_points.count,
delta_cp_x: delta_cp_x,
delta_cp_y: delta_cp_y
}
end
|