Module: Voxelamming

Defined in:
lib/voxelamming.rb,
lib/voxelamming/version.rb

Defined Under Namespace

Classes: Error, Turtle, VoxelammingManager

Constant Summary collapse

VERSION =
"0.3.7"

Class Method Summary collapse

Class Method Details

.get_box_color(height, max_height, high_color, low_color) ⇒ Object



703
704
705
706
707
708
709
710
# File 'lib/voxelamming.rb', line 703

def self.get_box_color(height, max_height, high_color, low_color)
  # 高さによって色を変える
  r = (high_color[0] - low_color[0]) * height * 1.0 / max_height + low_color[0]
  g = (high_color[1] - low_color[1]) * height * 1.0 / max_height + low_color[1]
  b = (high_color[2] - low_color[2]) * height * 1.0 / max_height + low_color[2]

  [r, g, b]
end

.get_boxes_from_ply(ply_file) ⇒ Object

Make model



630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
# File 'lib/voxelamming.rb', line 630

def self.get_boxes_from_ply(ply_file)
  box_positions = Set.new
  File.open(ply_file, 'r') do |f|
    lines = f.read
    lines = lines.gsub("\r\n", "\n")
    lines = lines.strip
    positions = lines.split("\n").select { |ln| self.is_included_six_numbers(ln) }.map { |ln| ln.split.map(&:to_f) }

    number_of_faces = positions.length / 4
    (0...number_of_faces).each do |i|
      vertex1 = positions[i * 4]
      vertex2 = positions[i * 4 + 1]
      vertex3 = positions[i * 4 + 2]
      vertex4 = positions[i * 4 + 3] # no need
      x = [vertex1[0], vertex2[0], vertex3[0]].min
      y = [vertex1[1], vertex2[1], vertex3[1]].min
      z = [vertex1[2], vertex2[2], vertex3[2]].min
      r = vertex1[3] / 255.0
      g = vertex1[4] / 255.0
      b = vertex1[5] / 255.0
      alpha = 1

      # ボックスを置く方向を解析
      if vertex1[0] == vertex2[0] && vertex2[0] == vertex3[0] # y-z plane
        step = [vertex1[1], vertex2[1], vertex3[1]].max - y
        x -= step if vertex1[1] != vertex2[1]
      elsif vertex1[1] == vertex2[1] && vertex2[1] == vertex3[1] # z-x plane
        step = [vertex1[2], vertex2[2], vertex3[2]].max - z
        y -= step if vertex1[2] != vertex2[2]
      else # x-y plane
        step = [vertex1[0], vertex2[0], vertex3[0]].max - x
        z -= step if vertex1[0] != vertex2[0]
      end

      # minimum unit: 0.1
      position_x = (x * 10.0 / step).round / 10.0
      position_y = (y * 10.0 / step).round / 10.0
      position_z = (z * 10.0 / step).round / 10.0
      box_positions.add([position_x, position_z, -position_y, r, g, b, alpha])
    end
  end

  box_positions
end

.get_map_data_from_csv(csv_file, height_scale, column_num = 257, row_num = 257) ⇒ Object

Map



683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
# File 'lib/voxelamming.rb', line 683

def self.get_map_data_from_csv(csv_file, height_scale, column_num = 257, row_num = 257)
  # csvファイルから地図データを読み込み
  heights = []

  CSV.foreach(csv_file) do |row|
    for h in row
      h = h.to_f
      h = h != 0 ? (h * height_scale).floor : -1
      heights << h
    end
  end
  #   puts "heights: #{heights}"

  max_height = heights.max.floor
  box_positions = (0...row_num).map { |i| heights[i * column_num, column_num] }
  puts "max_height: #{max_height}"
  #   puts "box_positions: #{box_positions}"
  { 'boxes' => box_positions, 'max_height' => max_height }
end

.greet(name) ⇒ Object

test



15
16
17
# File 'lib/voxelamming.rb', line 15

def self.greet(name)
  puts "Hello, #{name}! I'm Ruby!"
end

.is_included_six_numbers(line) ⇒ Object



675
676
677
678
679
680
# File 'lib/voxelamming.rb', line 675

def self.is_included_six_numbers(line)
  line_list = line.split
  return false if line_list.length != 6

  line_list.all? { |num| Float(num) rescue false }
end