Class: SigFil::VoxelGrid

Inherits:
Object
  • Object
show all
Defined in:
lib/sigfil/voxel_grid.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(dataset, leaf_size) ⇒ VoxelGrid

Returns a new instance of VoxelGrid.



9
10
11
12
13
14
# File 'lib/sigfil/voxel_grid.rb', line 9

def initialize dataset, leaf_size
  @dataset   = dataset
  @leaf_size = leaf_size
  get_inverse_leaf_size
  
end

Instance Attribute Details

#datasetObject

Returns the value of attribute dataset.



6
7
8
# File 'lib/sigfil/voxel_grid.rb', line 6

def dataset
  @dataset
end

#leaf_sizeObject

Returns the value of attribute leaf_size.



7
8
9
# File 'lib/sigfil/voxel_grid.rb', line 7

def leaf_size
  @leaf_size
end

Instance Method Details

#apply_filterObject



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
# File 'lib/sigfil/voxel_grid.rb', line 16

def apply_filter
  min, max = get_min_max

  bb_min, bb_max = get_bb(min, max)

  #div_b = bb_max.zip(bb_min).map {|x| x[0] - x[1] + 1}

  index = []
  @dataset.each_row do |pt|
    id = (pt*@inverse_leaf_size - bb_min).floor
    index << id.to_a
  end

  grid_idx = {}
  df = Daru::DataFrame.rows(index)
  #df.sort!(df.vectors)
  df.each_row_with_index do |row, id|
    grid_idx[row.to_a] ||= []
    grid_idx[row.to_a] << id
  end

  voxel_ary = []
  grid_idx.each do |g_id, d_id|
    ary = d_id.map {|i| @dataset.row(i).to_a}
    nm = NMatrix[*ary]
    voxel_ary << nm.mean(0).to_a
  end

  return NMatrix[*voxel_ary]
end

#get_bb(min, max) ⇒ Object

Get bounding box



56
57
58
59
60
61
# File 'lib/sigfil/voxel_grid.rb', line 56

def get_bb min, max
  bb_min = (min*@inverse_leaf_size).floor
  bb_max = (max*@inverse_leaf_size).floor

  return bb_min, bb_max
end

#get_inverse_leaf_sizeObject



67
68
69
# File 'lib/sigfil/voxel_grid.rb', line 67

def get_inverse_leaf_size
  @inverse_leaf_size = NMatrix[@leaf_size.map {|x| 1.0/x}]
end

#get_min_maxObject



47
48
49
50
51
52
# File 'lib/sigfil/voxel_grid.rb', line 47

def get_min_max
  min = @dataset.min(0)
  max = @dataset.max(0)

  return min, max
end