Module: VoxelammingGem
- Defined in:
- lib/voxelamming_gem.rb,
lib/voxelamming_gem/version.rb
Defined Under Namespace
Classes: BuildBox, Error, Turtle
Constant Summary collapse
- VERSION =
"0.1.3"
Class Method Summary collapse
- .get_box_color(height, max_height, high_color, low_color) ⇒ Object
-
.get_boxes_from_ply(ply_file) ⇒ Object
Make model.
-
.get_map_data_from_csv(csv_file, height_scale, column_num = 257, row_num = 257) ⇒ Object
Map.
-
.greet(name) ⇒ Object
test.
- .is_included_six_numbers(line) ⇒ Object
Class Method Details
.get_box_color(height, max_height, high_color, low_color) ⇒ Object
514 515 516 517 518 519 520 521 |
# File 'lib/voxelamming_gem.rb', line 514 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
441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 |
# File 'lib/voxelamming_gem.rb', line 441 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
494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 |
# File 'lib/voxelamming_gem.rb', line 494 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_gem.rb', line 15 def self.greet(name) puts "Hello, #{name}! I'm Ruby!" end |
.is_included_six_numbers(line) ⇒ Object
486 487 488 489 490 491 |
# File 'lib/voxelamming_gem.rb', line 486 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 |