Created
November 21, 2016 06:53
-
-
Save NigoroJr/d17a3b4f9902a058edde10c0e6850b9c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
class PCD | |
# PCD file must have fields precisely in this order | |
DATA_FIELDS = %w( | |
VERSION | |
FIELDS | |
SIZE | |
TYPE | |
COUNT | |
WIDTH | |
HEIGHT | |
VIEWPOINT | |
POINTS | |
DATA | |
).freeze | |
def initialize(opts) | |
DATA_FIELDS.each do |field_name| | |
method_name = field_name.upcase | |
# Define readers for each field | |
self.class.class_eval do | |
attr_reader method_name.to_sym | |
alias_method method_name.to_sym, method_name.to_sym | |
end | |
val = opts[method_name.to_sym] || opts[method_name.downcase.to_sym] | |
self.instance_variable_set("@#{method_name}", val) | |
end | |
end | |
end | |
opts = { | |
VERSION: 0.7, | |
FIELDS: %w(rgb x y z _), | |
SIZE: %w(4 4 4 4 1), | |
TYPE: %w(F F F F U), | |
COUNT: %w(1 1 1 1 4), | |
WIDTH: 4728, | |
HEIGHT: 1, | |
VIEWPOINT: %w(0 0 0 1 0 0 0), | |
POINTS: 4728, | |
DATA: 'binary' | |
} | |
pcd = PCD.new(opts) | |
puts pcd.inspect |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment